Skip to content
New issue

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

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

Already on GitHub? # to your account

Add angular cli version support #339

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@ const fs = require("fs");
const commandExists = util.promisify(require("command-exists"));
const chalk = require("chalk");
const validate = require("../validate-naming");
const validateCLIVersion = require("./validate-cli-version");

module.exports = class SingleSpaAngularGenerator extends Generator {
_globalInstallation = false;
constructor(args, opts) {
super(args, opts);

this.option("projectName", {
type: String,
});
this.option("angularCLIVersion", {
type: String,
});
}
async getOptions() {
const answers = await this.prompt([
this._globalInstallation = await commandExists("ng");
const questions = [
{
type: "input",
name: "projectName",
Expand All @@ -25,20 +31,30 @@ module.exports = class SingleSpaAngularGenerator extends Generator {
when: !this.options.projectName,
validate,
},
]);
];
if (!this._globalInstallation) {
questions.push({
type: "input",
name: "angularCLIVersion",
message: "Angular CLI version",
suffix: " (can use letters, numbers, dash or underscore)",
default: "latest",
when: !this.options.angularCLIVersion,
validateCLIVersion,
});
}
const answers = await this.prompt(questions);

Object.assign(this.options, answers, { framework: "angular" });
}
async runAngularCli() {
const globalInstallation = await commandExists("ng");

let command,
args = [];
if (globalInstallation) {
if (this._globalInstallation) {
command = "ng";
} else {
command = "npx";
args.push("@angular/cli");
args.push(["@angular/cli", "@", this.options.angularCLIVersion].join(""));
}

if (process.platform === "win32") {
Expand Down
11 changes: 11 additions & 0 deletions packages/generator-single-spa/src/angular/validate-cli-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const ALLOWED_CHARACTERS = /^[a-zA-Z0-9\-]+$/;

module.exports = function validateCLIVersion(input) {
if (!input) {
return `Cannot be empty!`;
} else if (!ALLOWED_CHARACTERS.test(input)) {
return `May only contain letters, numbers, dash or underscore`;
} else {
return true;
}
};