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

Saving options in .particle-rc #924

Merged
merged 3 commits into from
Jul 31, 2020
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
26 changes: 25 additions & 1 deletion packages/generator-particle-base/src/generators/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,18 @@ module.exports = class extends Generator {
// configuration will come from the constructor argument
configuration: Answers
packageJson: Record<string, any>
cliVersion = ''

constructor(args: any, opts: any) {
super(args, opts)
for (let i = 0; i < args.length; i++) {
const value = args[i]
mealeyst marked this conversation as resolved.
Show resolved Hide resolved
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,
Expand Down Expand Up @@ -64,6 +73,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)
Expand All @@ -82,7 +106,6 @@ module.exports = class extends Generator {
options: configOptions[results.config],
}
}

this.packageJson.name = results.projectName
}

Expand Down Expand Up @@ -111,6 +134,7 @@ module.exports = class extends Generator {

writing() {
this._createPackageJson()
this._writeParticleConfig()

// Installs all dependencies
this.npmInstall()
Expand Down
14 changes: 11 additions & 3 deletions packages/particle-cli/bin/particle-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down