diff --git a/src/index.ts b/src/index.ts index f73a7e9..eabcd68 100644 --- a/src/index.ts +++ b/src/index.ts @@ -35,6 +35,7 @@ class CreateKromeApp extends Command { await this.stageRunner.runAll(); + this.log(''); this.log(bold(underline('Quickstart'))); this.log(''); this.log(` cd ${this.context.appName}`); @@ -93,7 +94,6 @@ class CreateKromeApp extends Command { this.stageRunner.afterEach = () => { this.spinner.succeed(); - this.log(''); }; } } diff --git a/src/stage-runner/stage-runner.ts b/src/stage-runner/stage-runner.ts index 1962692..699ee83 100644 --- a/src/stage-runner/stage-runner.ts +++ b/src/stage-runner/stage-runner.ts @@ -1,6 +1,11 @@ import type { ParamsContext } from '../params'; import type { Stage } from './interfaces'; -import { copyFiles, renderTemplates, installDependencies } from './stages'; +import { + copyFiles, + renderTemplates, + installDependencies, + initVersionControl, +} from './stages'; export class StageRunner { beforeEach: (stage: Stage) => void = () => null; @@ -33,6 +38,10 @@ export class StageRunner { label: 'Render templates', callback: renderTemplates, }, + { + label: 'Init version control', + callback: initVersionControl, + }, { label: 'Install dependencies', callback: installDependencies, diff --git a/src/stage-runner/stages/index.ts b/src/stage-runner/stages/index.ts index a4f652b..290dbae 100644 --- a/src/stage-runner/stages/index.ts +++ b/src/stage-runner/stages/index.ts @@ -1,3 +1,4 @@ export * from './copyFiles'; export * from './renderTemplates'; export * from './installDependencies'; +export * from './initVersionControl'; diff --git a/src/stage-runner/stages/initVersionControl.ts b/src/stage-runner/stages/initVersionControl.ts new file mode 100644 index 0000000..031e67e --- /dev/null +++ b/src/stage-runner/stages/initVersionControl.ts @@ -0,0 +1,24 @@ +import execa from 'execa'; +import * as fse from 'fs-extra'; +import type { ParamsContext } from '../../params'; + +export async function initVersionControl( + context: ParamsContext, +): Promise { + const { targetDir } = context; + const execaOption: execa.Options = { cwd: targetDir }; + + if ( + fse.pathExistsSync(`${targetDir}/.npmignore`) && + !fse.pathExistsSync(`${targetDir}/.gitignore`) + ) { + await fse.move(`${targetDir}/.npmignore`, `${targetDir}/.gitignore`); + } + await execa('git', ['init'], execaOption); + await execa('git', ['add', '-A'], execaOption); + await execa( + 'git', + ['commit', '-m', 'Initialize by create-krome-app'], + execaOption, + ); +}