Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(generator-single-spa): add skipGit #385

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions .changeset/young-drinks-notice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"generator-single-spa": minor
---

add skipGit option
32 changes: 28 additions & 4 deletions packages/generator-single-spa/src/PnpmGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ module.exports = class PnpmGenerator extends Generator {
}
// This overrides https://github.com/yeoman/generator/blob/9cd93ee0fe8babd26cce4e22a6f1db7637573801/lib/actions/install.js#L119
// to include support for pnpm installations
installDependencies(options) {
options = options || {};
_installDependencies() {
const options = {
npm: this.options.packageManager === "npm",
yarn: this.options.packageManager === "yarn",
pnpm: this.options.packageManager === "pnpm",
bower: false,
};
const msg = {
commands: [],
template: _.template(
Expand Down Expand Up @@ -42,7 +47,7 @@ module.exports = class PnpmGenerator extends Generator {

if (options.pnpm !== false) {
msg.commands.push("pnpm install");
this.pnpmInstall(null, getOptions(options.pnpm));
this._pnpmInstall(null, getOptions(options.pnpm));
}

assert(
Expand All @@ -63,7 +68,26 @@ module.exports = class PnpmGenerator extends Generator {
this.log(msg.template(tplValues));
}
}
pnpmInstall(pkgs, options, spawnOptions) {
_pnpmInstall(pkgs, options, spawnOptions) {
this.scheduleInstallTask("pnpm", pkgs, options, spawnOptions);
}
install() {
this._installDependencies();
this._gitInit();
}
_gitInit() {
if (this.options.skipGit || this.options["skip-git"]) {
this.log("Skipping git initialization");
return;
} else {
const childGitInitProcess = this.spawnCommandSync("git", ["init"]);
if (childGitInitProcess.error) {
this.log(chalk.red("************"));
this.log(chalk.red("Cannot initialize git repository"));
this.log(chalk.red("************"));
} else {
this.log(chalk.green("Initialized git repository"));
}
}
}
};
4 changes: 4 additions & 0 deletions packages/generator-single-spa/src/generator-single-spa.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ module.exports = class SingleSpaGenerator extends Generator {
type: Boolean,
});

this.option("skipGit", {
type: Boolean,
});

if (args.length > 0 && !this.options.dir) {
this.options.dir = args[0];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,25 +200,9 @@ module.exports = class SingleSpaReactGenerator extends PnpmGenerator {
}
);
}

const childGitInitProcess = this.spawnCommandSync("git", ["init"]);
if (childGitInitProcess.error) {
console.log(chalk.red("\n************"));
console.log(chalk.red("Cannot initialize git repository"));
console.log(chalk.red("************\n"));
} else {
console.log(chalk.green("\nInitialized git repository\n"));
}
}
install() {
if (!this.skipInstall) {
this.installDependencies({
npm: this.options.packageManager === "npm",
yarn: this.options.packageManager === "yarn",
pnpm: this.options.packageManager === "pnpm",
bower: false,
});
}
super.install();
}
finished() {
this.on(`${this.options.packageManager}Install:end`, () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,25 +194,9 @@ module.exports = class SingleSpaRootConfigGenerator extends PnpmGenerator {
);
this.fs.extendJSON(this.destinationPath("package.json"), layoutJson);
}

const childGitInitProcess = this.spawnCommandSync("git", ["init"]);
if (childGitInitProcess.error) {
console.log(chalk.red("\n************"));
console.log(chalk.red("Cannot initialize git repository"));
console.log(chalk.red("************\n"));
} else {
console.log(chalk.green("\nInitialized git repository\n"));
}
}
install() {
if (!this.skipInstall) {
this.installDependencies({
npm: this.options.packageManager === "npm",
yarn: this.options.packageManager === "yarn",
pnpm: this.options.packageManager === "pnpm",
bower: false,
});
}
super.install();
}
finished() {
this.on(`${this.options.packageManager}Install:end`, () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,25 +146,9 @@ module.exports = class SingleSpaSvelteGenerator extends PnpmGenerator {
// this.options
// );
// }

const childGitInitProcess = this.spawnCommandSync("git", ["init"]);
if (childGitInitProcess.error) {
console.log(chalk.red("\n************"));
console.log(chalk.red("Cannot initialize git repository"));
console.log(chalk.red("************\n"));
} else {
console.log(chalk.green("\nInitialized git repository\n"));
}
}
install() {
if (!this.skipInstall) {
this.installDependencies({
npm: this.options.packageManager === "npm",
yarn: this.options.packageManager === "yarn",
pnpm: this.options.packageManager === "pnpm",
bower: false,
});
}
super.install();
}
finished() {
this.on(`${this.options.packageManager}Install:end`, () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,25 +161,9 @@ module.exports = class SingleSpaUtilModuleGenerator extends PnpmGenerator {
}
);
}

const childGitInitProcess = this.spawnCommandSync("git", ["init"]);
if (childGitInitProcess.error) {
console.log(chalk.red("\n************"));
console.log(chalk.red("Cannot initialize git repository"));
console.log(chalk.red("************\n"));
} else {
console.log(chalk.green("\nInitialized git repository\n"));
}
}
install() {
if (!this.skipInstall) {
this.installDependencies({
npm: this.options.packageManager === "npm",
yarn: this.options.packageManager === "yarn",
pnpm: this.options.packageManager === "pnpm",
bower: false,
});
}
super.install();
}
finished() {
this.on(`${this.options.packageManager}Install:end`, () => {
Expand Down
35 changes: 35 additions & 0 deletions packages/generator-single-spa/test/git.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const generator = require("../src/generator-single-spa");
const helpers = require("yeoman-test");

describe("generator-single-spa", () => {
it("can do git init", async () => {
const runResult = await helpers
.create(generator)
.withOptions({
moduleType: "root-config",
packageManager: "pnpm",
orgName: "org",
projectName: "proj",
layout: false,
skipInstall: true,
})
.run();
runResult.assertFile(".git/HEAD");
});

it("can skip git init", async () => {
const runResult = await helpers
.create(generator)
.withOptions({
moduleType: "root-config",
packageManager: "pnpm",
orgName: "org",
projectName: "proj",
layout: false,
skipInstall: true,
skipGit: true,
})
.run();
runResult.assertNoFile(".git/HEAD");
});
});