Skip to content

Commit be9202a

Browse files
committed
some refactoring
1 parent 2f074fa commit be9202a

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

packages/ferric/src/init.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,12 @@ async function copyAllTemplateFiles(outputFilePath: string) {
4242
await fsPromise.cp(templateDir, outputFilePath, {
4343
recursive: true,
4444
});
45-
await fsPromise.rename(
46-
`${outputFilePath}/lib.rs`,
47-
`${outputFilePath}/src/lib.rs`,
48-
);
49-
await fsPromise.rename(
50-
`${outputFilePath}/gitignore`,
51-
`${outputFilePath}/.gitignore`,
52-
);
45+
await moveFile(`${outputFilePath}/lib.rs`, `${outputFilePath}/src/lib.rs`);
46+
await moveFile(`${outputFilePath}/gitignore`, `${outputFilePath}/.gitignore`);
47+
}
48+
49+
async function moveFile(currentPath: string, newPath: string) {
50+
await fsPromise.rename(currentPath, newPath);
5351
}
5452

5553
async function generateProject({
@@ -62,14 +60,11 @@ async function generateProject({
6260
createFolder(outputPath);
6361
createFolder(`${outputPath}/src`);
6462
await copyAllTemplateFiles(outputPath);
63+
const strToReplace = "project_name";
6564
await replaceStrInFile(
6665
`${outputPath}/package.json`,
67-
"project_name",
68-
projectName,
69-
);
70-
await replaceStrInFile(
71-
`${outputPath}/Cargo.toml`,
72-
"project_name",
66+
strToReplace,
7367
projectName,
7468
);
69+
await replaceStrInFile(`${outputPath}/Cargo.toml`, strToReplace, projectName);
7570
}

0 commit comments

Comments
 (0)