Skip to content

Commit 984ee59

Browse files
committed
fix: include package-lock.json in initial commit, replace ts-node with tsx for ESM support
1 parent e379303 commit 984ee59

File tree

2 files changed

+54
-21
lines changed

2 files changed

+54
-21
lines changed

src/configs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ export const DEFAULT_OPTIONS: Omit<ToolOptions, 'yes' | 'default'> = {
3030
*/
3131
export const TOOL_CONFIGS = {
3232
nodemon: {
33-
deps: ['nodemon', 'ts-node'],
33+
deps: ['nodemon', 'tsx'],
3434
scripts: {
35-
dev: 'nodemon --watch src -e ts --exec "ts-node src/index.ts"',
35+
dev: 'nodemon --watch src -e ts --exec "tsx src/index.ts"',
3636
},
3737
},
3838
eslint: {

src/generator.ts

Lines changed: 52 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -387,25 +387,6 @@ export async function createProject(opts: CreateOptions) {
387387
'node_modules\ndist\n.env\n',
388388
'utf8',
389389
);
390-
if (!(toolOptions.noCommit ?? false)) {
391-
try {
392-
runCommand(
393-
'git',
394-
['add', '-A'],
395-
target,
396-
toolOptions.verbose ?? false,
397-
);
398-
runCommand(
399-
'git',
400-
['commit', '-m', 'chore: initial commit'],
401-
target,
402-
toolOptions.verbose ?? false,
403-
);
404-
} catch (e) {
405-
const errMsg = e instanceof Error ? e.message : String(e);
406-
console.warn(MESSAGES.gitCommitFailed(errMsg));
407-
}
408-
}
409390
}
410391
}
411392
} catch (e) {
@@ -447,4 +428,56 @@ export async function createProject(opts: CreateOptions) {
447428
console.warn(MESSAGES.installFailed(pm, errMsg));
448429
}
449430
}
431+
432+
// Git initial commit AFTER npm install to include package-lock.json
433+
if ((toolOptions.git ?? true) && !(toolOptions.noCommit ?? false)) {
434+
try {
435+
const gitAvailable = runCommand(
436+
'git',
437+
['--version'],
438+
target,
439+
false,
440+
true,
441+
);
442+
if (gitAvailable) {
443+
const insideRepo = runCommand(
444+
'git',
445+
['rev-parse', '--is-inside-work-tree'],
446+
target,
447+
false,
448+
true,
449+
);
450+
const hasCommits = runCommand(
451+
'git',
452+
['rev-parse', 'HEAD'],
453+
target,
454+
false,
455+
true,
456+
);
457+
458+
if (!insideRepo || !hasCommits) {
459+
try {
460+
runCommand(
461+
'git',
462+
['add', '-A'],
463+
target,
464+
toolOptions.verbose ?? false,
465+
);
466+
runCommand(
467+
'git',
468+
['commit', '-m', 'chore: initial commit'],
469+
target,
470+
toolOptions.verbose ?? false,
471+
);
472+
} catch (e) {
473+
const errMsg = e instanceof Error ? e.message : String(e);
474+
console.warn(MESSAGES.gitCommitFailed(errMsg));
475+
}
476+
}
477+
}
478+
} catch (e) {
479+
const errMsg = e instanceof Error ? e.message : String(e);
480+
console.warn(MESSAGES.gitCommitFailed(errMsg));
481+
}
482+
}
450483
}

0 commit comments

Comments
 (0)