From b549c9a751eadf014477e101e4a982fefee53280 Mon Sep 17 00:00:00 2001 From: Janos Hrubos <33330538+janoshrubos@users.noreply.github.com> Date: Tue, 12 Jan 2021 20:46:55 +0100 Subject: [PATCH 1/5] feat: initialize git repo on project create --- lib/services/project-service.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/services/project-service.ts b/lib/services/project-service.ts index 4e4930a273..f0f8df3a2c 100644 --- a/lib/services/project-service.ts +++ b/lib/services/project-service.ts @@ -26,6 +26,7 @@ import { IStringDictionary, } from "../common/declarations"; import * as _ from "lodash"; +import * as shelljs from "shelljs"; import { injector } from "../common/yok"; export class ProjectService implements IProjectService { @@ -103,6 +104,10 @@ export class ProjectService implements IProjectService { projectName, }); + shelljs.exec(`git init ${projectDir}`); + shelljs.exec(`git -C ${projectDir} add --all`); + shelljs.exec(`git -C ${projectDir} commit -m "Initialize new project"`); + this.$logger.info(); this.$logger.printMarkdown( "__Project `%s` was successfully created.__", From 5c1117eff68ca06548ef2c7c3903e533ceb270ae Mon Sep 17 00:00:00 2001 From: Janos Hrubos <33330538+janoshrubos@users.noreply.github.com> Date: Wed, 13 Jan 2021 16:02:10 +0100 Subject: [PATCH 2/5] refactor: use child process --- lib/services/project-service.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/services/project-service.ts b/lib/services/project-service.ts index f0f8df3a2c..c21b811268 100644 --- a/lib/services/project-service.ts +++ b/lib/services/project-service.ts @@ -24,9 +24,9 @@ import { IFileSystem, IProjectHelper, IStringDictionary, + IChildProcess, } from "../common/declarations"; import * as _ from "lodash"; -import * as shelljs from "shelljs"; import { injector } from "../common/yok"; export class ProjectService implements IProjectService { @@ -43,7 +43,8 @@ export class ProjectService implements IProjectService { private $projectNameService: IProjectNameService, private $projectTemplatesService: IProjectTemplatesService, private $tempService: ITempService, - private $staticConfig: IStaticConfig + private $staticConfig: IStaticConfig, + private $childProcess: IChildProcess ) {} public async validateProjectName(opts: { @@ -104,9 +105,16 @@ export class ProjectService implements IProjectService { projectName, }); - shelljs.exec(`git init ${projectDir}`); - shelljs.exec(`git -C ${projectDir} add --all`); - shelljs.exec(`git -C ${projectDir} commit -m "Initialize new project"`); + try { + await this.$childProcess.exec(`git init ${projectDir}`); + await this.$childProcess.exec(`git -C ${projectDir} add --all`); + await this.$childProcess.exec(`git -C ${projectDir} commit -m "init"`); + } catch (err) { + this.$logger.trace( + "Unable to initialize git repository. Error is: ", + err + ); + } this.$logger.info(); this.$logger.printMarkdown( From ede2eb0f12218d2f0b5ddf209bb77337f41f9cd2 Mon Sep 17 00:00:00 2001 From: Janos Hrubos <33330538+janoshrubos@users.noreply.github.com> Date: Wed, 13 Jan 2021 16:02:58 +0100 Subject: [PATCH 3/5] test: git init commands --- test/project-service.ts | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/test/project-service.ts b/test/project-service.ts index 5c986a4865..61a02f64a4 100644 --- a/test/project-service.ts +++ b/test/project-service.ts @@ -87,6 +87,13 @@ describe("projectService", () => { extractPackage: () => Promise.resolve(), }); testInjector.register("tempService", TempServiceStub); + const executedCommands: string[] = []; + testInjector.register("childProcess", { + _getExecutedCommands: () => executedCommands, + exec: (executedCommand: string) => { + executedCommands.push(executedCommand); + }, + }); return testInjector; }; @@ -98,16 +105,27 @@ describe("projectService", () => { const projectService = testInjector.resolve( ProjectServiceLib.ProjectService ); + const projectDir = path.join(dirToCreateProject, projectName); const projectCreationData = await projectService.createProject({ projectName: projectName, pathToProject: dirToCreateProject, force: true, template: constants.RESERVED_TEMPLATE_NAMES["default"], }); + assert.deepStrictEqual(projectCreationData, { projectName, - projectDir: path.join(dirToCreateProject, projectName), + projectDir, }); + + assert.deepEqual( + testInjector.resolve("childProcess")._getExecutedCommands(), + [ + `git init ${projectDir}`, + `git -C ${projectDir} add --all`, + `git -C ${projectDir} commit -m "init"`, + ] + ); }); it("fails when invalid name is passed when projectNameService fails", async () => { @@ -188,6 +206,7 @@ describe("projectService", () => { downloadAndExtract: () => Promise.resolve(), }); testInjector.register("tempService", TempServiceStub); + testInjector.register("childProcess", {}); return testInjector; }; From 4ffab89d2e23da27a3b8144fab64177a9c72c941 Mon Sep 17 00:00:00 2001 From: Igor Randjelovic Date: Wed, 13 Jan 2021 16:46:26 +0100 Subject: [PATCH 4/5] fix: ignore commit hooks --- lib/services/project-service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/services/project-service.ts b/lib/services/project-service.ts index c21b811268..3c24ece6f7 100644 --- a/lib/services/project-service.ts +++ b/lib/services/project-service.ts @@ -108,7 +108,7 @@ export class ProjectService implements IProjectService { try { await this.$childProcess.exec(`git init ${projectDir}`); await this.$childProcess.exec(`git -C ${projectDir} add --all`); - await this.$childProcess.exec(`git -C ${projectDir} commit -m "init"`); + await this.$childProcess.exec(`git -C ${projectDir} commit --no-verify -m "init"`); } catch (err) { this.$logger.trace( "Unable to initialize git repository. Error is: ", From 188286f94b2ed721649720af40b5527a1b1d4849 Mon Sep 17 00:00:00 2001 From: Igor Randjelovic Date: Wed, 13 Jan 2021 16:47:40 +0100 Subject: [PATCH 5/5] test: update test with --no-verify --- test/project-service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/project-service.ts b/test/project-service.ts index 61a02f64a4..0fea4151ba 100644 --- a/test/project-service.ts +++ b/test/project-service.ts @@ -123,7 +123,7 @@ describe("projectService", () => { [ `git init ${projectDir}`, `git -C ${projectDir} add --all`, - `git -C ${projectDir} commit -m "init"`, + `git -C ${projectDir} commit --no-verify -m "init"`, ] ); });