Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion lib/services/project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
IFileSystem,
IProjectHelper,
IStringDictionary,
IChildProcess,
} from "../common/declarations";
import * as _ from "lodash";
import { injector } from "../common/yok";
Expand All @@ -42,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: {
Expand Down Expand Up @@ -103,6 +105,17 @@ export class ProjectService implements IProjectService {
projectName,
});

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 --no-verify -m "init"`);
} catch (err) {
this.$logger.trace(
"Unable to initialize git repository. Error is: ",
err
);
}

this.$logger.info();
this.$logger.printMarkdown(
"__Project `%s` was successfully created.__",
Expand Down
21 changes: 20 additions & 1 deletion test/project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand All @@ -98,16 +105,27 @@ describe("projectService", () => {
const projectService = testInjector.resolve<IProjectService>(
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 --no-verify -m "init"`,
]
);
});

it("fails when invalid name is passed when projectNameService fails", async () => {
Expand Down Expand Up @@ -188,6 +206,7 @@ describe("projectService", () => {
downloadAndExtract: () => Promise.resolve(),
});
testInjector.register("tempService", TempServiceStub);
testInjector.register("childProcess", {});

return testInjector;
};
Expand Down