Skip to content

Commit

Permalink
fix-path-separator-issue (#1745)
Browse files Browse the repository at this point in the history
* fix-path-separator-issue

* fix multi client clear src folder

* fix ci failure

* fix issues in windows

* Update packages/rlc-common/src/helpers/pathUtils.ts

Co-authored-by: Mary Gao <yanmeigao1210@gmail.com>

---------

Co-authored-by: Mary Gao <yanmeigao1210@gmail.com>
  • Loading branch information
qiaozha and MaryGao authored Feb 9, 2023
1 parent c7d27d7 commit 0e32e7e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
14 changes: 12 additions & 2 deletions packages/cadl-typescript/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,22 @@ import {
import { transformRLCModel } from "./transform/transform.js";
import { emitContentByBuilder, emitModels } from "./emitUtil.js";
import { listClients } from "@azure-tools/cadl-dpg";
import * as path from "path";

export async function $onEmit(context: EmitContext) {
const program: Program = context.program;
const options: RLCOptions = context.options;
const clients = listClients(program);
let count = -1;
for (const client of clients) {
count++;
const rlcModels = await transformRLCModel(
program,
options,
client,
context.emitterOutputDir
);
clearSrcFolder(rlcModels);
clearSrcFolder(rlcModels, count);
await emitModels(rlcModels, program);
await emitContentByBuilder(program, buildClientDefinitions, rlcModels);
await emitContentByBuilder(program, buildResponseTypes, rlcModels);
Expand Down Expand Up @@ -86,7 +89,14 @@ export async function $onEmit(context: EmitContext) {
}
}

function clearSrcFolder(model: RLCModel) {
function clearSrcFolder(model: RLCModel, count: number) {
const srcPath = model.srcPath;
fsextra.emptyDirSync(srcPath);
if (model?.options?.multiClient && count === 0) {
const folderPath = path.join(
srcPath.substring(0, srcPath.indexOf(path.sep + "src") + 4)
);
fsextra.emptyDirSync(folderPath);
}

}
2 changes: 1 addition & 1 deletion packages/rlc-common/src/buildTopLevelIndexFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function buildTopLevelIndex(model: RLCModel) {
});
const content = indexFile.getFullText();
const filePath = path.join(
srcPath.substring(0, srcPath.indexOf("/src/") + 5),
srcPath.substring(0, srcPath.indexOf(path.sep + "src") + 4),
`index.ts`
);
return { path: filePath, content };
Expand Down
7 changes: 4 additions & 3 deletions packages/rlc-common/src/helpers/pathUtils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// FIXME https://github.com/Azure/autorest.typescript/issues/1720
import * as path from "path";

export function getRelativePartFromSrcPath(srcPath: string) {
const relativePart = srcPath.substring(srcPath.indexOf("/src/") + 4);
return relativePart.startsWith("/")
const relativePart = srcPath.substring(srcPath.indexOf(path.sep + "src") + 4);
return relativePart.startsWith(path.sep)
? relativePart.substring(1)
: relativePart;
}

0 comments on commit 0e32e7e

Please sign in to comment.