Skip to content

Commit

Permalink
feat(stages): implement initVersionControl
Browse files Browse the repository at this point in the history
  • Loading branch information
hankchiutw committed Apr 24, 2021
1 parent 6693db6 commit 24da5e1
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down Expand Up @@ -93,7 +94,6 @@ class CreateKromeApp extends Command {

this.stageRunner.afterEach = () => {
this.spinner.succeed();
this.log('');
};
}
}
Expand Down
11 changes: 10 additions & 1 deletion src/stage-runner/stage-runner.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -33,6 +38,10 @@ export class StageRunner {
label: 'Render templates',
callback: renderTemplates,
},
{
label: 'Init version control',
callback: initVersionControl,
},
{
label: 'Install dependencies',
callback: installDependencies,
Expand Down
1 change: 1 addition & 0 deletions src/stage-runner/stages/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './copyFiles';
export * from './renderTemplates';
export * from './installDependencies';
export * from './initVersionControl';
24 changes: 24 additions & 0 deletions src/stage-runner/stages/initVersionControl.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
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,
);
}

0 comments on commit 24da5e1

Please sign in to comment.