From 75a77c7888bebca541de09af49fa994d588a6502 Mon Sep 17 00:00:00 2001 From: Shawn Mealey Date: Wed, 29 Jul 2020 15:38:40 -0400 Subject: [PATCH 1/3] Saving options in .particle-rc --- .../src/generators/app/index.ts | 20 ++++++++++++++++++- packages/particle-cli/bin/particle-cli.ts | 14 ++++++++++--- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/packages/generator-particle-base/src/generators/app/index.ts b/packages/generator-particle-base/src/generators/app/index.ts index bff6d07eea..2e4c582b7d 100644 --- a/packages/generator-particle-base/src/generators/app/index.ts +++ b/packages/generator-particle-base/src/generators/app/index.ts @@ -19,9 +19,20 @@ module.exports = class extends Generator { // configuration will come from the constructor argument configuration: Answers packageJson: Record + cliVersion: string constructor(args: any, opts: any) { super(args, opts) + console.log(args) + this.cliVersion = '' + for (let i = 0; i < args.length; i++) { + const value = args[i] + const regex = /(cli-version=)(\d.*)/ + const matches = regex.exec(value) + if (matches) { + this.cliVersion = matches[2] + } + } // makes config a required argument this.option('configuration', { type: String, @@ -82,7 +93,14 @@ module.exports = class extends Generator { options: configOptions[results.config], } } - + fs.writeFileSync( + '.particle-rc', + JSON.stringify( + { ...this.configuration, ...{ 'cli-version': this.cliVersion } }, + null, + 2 + ) + ) this.packageJson.name = results.projectName } diff --git a/packages/particle-cli/bin/particle-cli.ts b/packages/particle-cli/bin/particle-cli.ts index 3c38f0f984..e7e67a7cf0 100755 --- a/packages/particle-cli/bin/particle-cli.ts +++ b/packages/particle-cli/bin/particle-cli.ts @@ -16,9 +16,17 @@ program .description('Scaffold your project from a set of prompts.') .action(function () { // runs yeoman under the hood and resolves the yeoman module directly - spawn('yo', [require.resolve('@phase2/generator-particle-base')], { - stdio: 'inherit', - }) + spawn( + 'yo', + [ + require.resolve('@phase2/generator-particle-base'), + `cli-version=${pkg.version}`, + 'example-arg', + ], + { + stdio: 'inherit', + } + ) }) // allow commander to parse `process.argv` From ed995ed650782c8eb831fe7a3ed714548dcd6538 Mon Sep 17 00:00:00 2001 From: Shawn Mealey Date: Wed, 29 Jul 2020 16:33:55 -0400 Subject: [PATCH 2/3] Moving config write to the `writing()` function --- .../src/generators/app/index.ts | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/packages/generator-particle-base/src/generators/app/index.ts b/packages/generator-particle-base/src/generators/app/index.ts index 2e4c582b7d..927e420049 100644 --- a/packages/generator-particle-base/src/generators/app/index.ts +++ b/packages/generator-particle-base/src/generators/app/index.ts @@ -75,6 +75,21 @@ module.exports = class extends Generator { ) } + /** + * Creeate a particle config file + */ + + _writeParticleConfig() { + fs.writeFileSync( + '.particle-rc', + JSON.stringify( + { ...this.configuration, ...{ 'cli-version': this.cliVersion } }, + null, + 2 + ) + ) + } + async _promptUser() { // Initialize storybook const results: ConfigurationAnswers = await this.prompt(configurationPrompt) @@ -93,14 +108,6 @@ module.exports = class extends Generator { options: configOptions[results.config], } } - fs.writeFileSync( - '.particle-rc', - JSON.stringify( - { ...this.configuration, ...{ 'cli-version': this.cliVersion } }, - null, - 2 - ) - ) this.packageJson.name = results.projectName } @@ -129,6 +136,7 @@ module.exports = class extends Generator { writing() { this._createPackageJson() + this._writeParticleConfig() // Installs all dependencies this.npmInstall() From 3b625f7e6134aca30a69ae0dc326af829fdc5f75 Mon Sep 17 00:00:00 2001 From: Shawn Mealey Date: Wed, 29 Jul 2020 16:39:28 -0400 Subject: [PATCH 3/3] Initializing cliVersion and removing log --- packages/generator-particle-base/src/generators/app/index.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/generator-particle-base/src/generators/app/index.ts b/packages/generator-particle-base/src/generators/app/index.ts index 927e420049..c3479636dc 100644 --- a/packages/generator-particle-base/src/generators/app/index.ts +++ b/packages/generator-particle-base/src/generators/app/index.ts @@ -19,12 +19,10 @@ module.exports = class extends Generator { // configuration will come from the constructor argument configuration: Answers packageJson: Record - cliVersion: string + cliVersion = '' constructor(args: any, opts: any) { super(args, opts) - console.log(args) - this.cliVersion = '' for (let i = 0; i < args.length; i++) { const value = args[i] const regex = /(cli-version=)(\d.*)/