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 1 commit
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
20 changes: 19 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,20 @@ module.exports = class extends Generator {
// configuration will come from the constructor argument
configuration: Answers
packageJson: Record<string, any>
cliVersion: string
mealeyst marked this conversation as resolved.
Show resolved Hide resolved

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]
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 @@ -82,7 +93,14 @@ module.exports = class extends Generator {
options: configOptions[results.config],
}
}

fs.writeFileSync(
mealeyst marked this conversation as resolved.
Show resolved Hide resolved
'.particle-rc',
JSON.stringify(
{ ...this.configuration, ...{ 'cli-version': this.cliVersion } },
null,
2
)
)
this.packageJson.name = results.projectName
}

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