Skip to content

Commit 07476c6

Browse files
committed
[Fixes #10] Check for dirName before prepending timestamp
1 parent d6ea96b commit 07476c6

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ function prompt(question, defaultAnswer) {
2626
});
2727
}
2828

29+
function getDirName(defaultDirName) {
30+
let dirName = args._[0] ?? defaultDirName;
31+
if (fs.existsSync(dirName)) dirName += `-${timestamp}`;
32+
return dirName;
33+
}
34+
2935
async function installDependencies(dirName) {
3036
console.log(`Installing dependencies ...`);
3137
await run(`cd ${dirName} && npm install`);
@@ -68,7 +74,7 @@ const timestamp = Math.round(new Date().getTime() / 1000);
6874

6975
async function cloneStarter() {
7076
// Set references
71-
const dirName = args._[0] ?? `${config.defaults.dirName}-${timestamp}`;
77+
const dirName = getDirName(config.defaults.dirName);
7278

7379
// Clone repo
7480
const cloneCommand = `git clone --depth=1 ${starter.repoUrl} ${dirName}`;
@@ -92,7 +98,7 @@ Follow the instructions for getting Started here:
9298
/* --- New Project from Example --- */
9399

94100
async function cloneExample() {
95-
const dirName = args._[0] ?? `${args.example}-${timestamp}`;
101+
const dirName = getDirName(args.example);
96102
const tmpDir = `__tmp${timestamp}__`;
97103
console.log(`\nCreating new project in ${dirName} ...`);
98104

0 commit comments

Comments
 (0)