[tsp-client] Fix additional directory support for remote project scenario (#7483)
* fix additional directory support for url scenario * changelog * clean up * newline
This commit is contained in:
Родитель
0c65b7cf7b
Коммит
de40f27177
|
@ -6,7 +6,8 @@
|
|||
- Use `resolveCompilerOptions` to get emitter configurations from tspconfig.yaml.
|
||||
- Remove unused functions: `getEmitterOptions()`, `resolveCliOptions()`, `resolveImports()`.
|
||||
- Fix `additionalDirectories` property outputted by the `init` command.
|
||||
- Fixed support for local specs using additional directories.
|
||||
- Fixed support for local and remote specs using additional directories.
|
||||
- Switched to use path helper functions from `@typespec/compiler`.
|
||||
|
||||
## 2023-12-8 - 0.2.0
|
||||
|
||||
|
|
|
@ -7,8 +7,8 @@ import { mkdir, writeFile, cp, readFile } from "node:fs/promises";
|
|||
import { addSpecFiles, checkoutCommit, cloneRepo, getRepoRoot, sparseCheckout } from "./git.js";
|
||||
import { fetch } from "./network.js";
|
||||
import { parse as parseYaml } from "yaml";
|
||||
import { joinPaths, normalizeSlashes, resolvePath } from "@typespec/compiler";
|
||||
import { formatAdditionalDirectories } from "./utils.js";
|
||||
import { joinPaths, resolvePath } from "@typespec/compiler";
|
||||
import { formatAdditionalDirectories, getAdditionalDirectoryName } from "./utils.js";
|
||||
|
||||
|
||||
async function sdkInit(
|
||||
|
@ -116,16 +116,8 @@ async function syncTspFiles(outputDir: string, localSpecRepo?: string) {
|
|||
throw new Error("Could not find local spec repo root, please make sure the path is correct");
|
||||
}
|
||||
for (const dir of tspLocation.additionalDirectories!) {
|
||||
Logger.info(`Syncing additional directory: ${dir}`);
|
||||
let normalizedDir = normalizeSlashes(dir);
|
||||
if (normalizedDir.slice(-1) === "/") {
|
||||
normalizedDir = normalizedDir.slice(0, -1);
|
||||
}
|
||||
const finalDirName = normalizedDir.split("/").pop();
|
||||
if (!finalDirName) {
|
||||
throw new Error(`Could not find a final directory for the following value: ${normalizedDir}`);
|
||||
}
|
||||
await cp(joinPaths(localSpecRepoRoot, dir), joinPaths(tempRoot, finalDirName), { recursive: true, filter: filter });
|
||||
Logger.info(`Syncing additional directory: ${dir}`);;
|
||||
await cp(joinPaths(localSpecRepoRoot, dir), joinPaths(tempRoot, getAdditionalDirectoryName(dir)), { recursive: true, filter: filter });
|
||||
}
|
||||
} else {
|
||||
const cloneDir = joinPaths(repoRoot, "..", "sparse-spec");
|
||||
|
@ -142,10 +134,8 @@ async function syncTspFiles(outputDir: string, localSpecRepo?: string) {
|
|||
await checkoutCommit(cloneDir, tspLocation.commit);
|
||||
await cp(joinPaths(cloneDir, tspLocation.directory), srcDir, { recursive: true });
|
||||
for (const dir of tspLocation.additionalDirectories!) {
|
||||
const dirSplit = dir.split("/");
|
||||
let projectName = dirSplit[dirSplit.length - 1];
|
||||
const dirName = joinPaths(tempRoot, projectName!);
|
||||
await cp(joinPaths(cloneDir, dir), dirName, { recursive: true });
|
||||
Logger.info(`Syncing additional directory: ${dir}`);
|
||||
await cp(joinPaths(cloneDir, dir), joinPaths(tempRoot, getAdditionalDirectoryName(dir)), { recursive: true });
|
||||
}
|
||||
Logger.debug(`Removing sparse-checkout directory ${cloneDir}`);
|
||||
await removeDirectory(cloneDir);
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import { normalizeSlashes } from "@typespec/compiler";
|
||||
|
||||
export function formatAdditionalDirectories(additionalDirectories?: string[]): string {
|
||||
let additionalDirOutput = "";
|
||||
for (const dir of additionalDirectories ?? []) {
|
||||
|
@ -5,3 +7,15 @@ export function formatAdditionalDirectories(additionalDirectories?: string[]): s
|
|||
}
|
||||
return additionalDirOutput;
|
||||
}
|
||||
|
||||
export function getAdditionalDirectoryName(dir: string): string {
|
||||
let normalizedDir = normalizeSlashes(dir);
|
||||
if (normalizedDir.slice(-1) === "/") {
|
||||
normalizedDir = normalizedDir.slice(0, -1);
|
||||
}
|
||||
const finalDirName = normalizedDir.split("/").pop();
|
||||
if (!finalDirName) {
|
||||
throw new Error(`Could not find a final directory for the following value: ${normalizedDir}`);
|
||||
}
|
||||
return finalDirName;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче