Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
216 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict'; | ||
|
||
// Example of a generator with options. | ||
// | ||
// It takes a list of arguments (usually CLI args) and a Hash of options | ||
// (CLI options), the context of the function is a `new Generator.Base` | ||
// object, which means that you can use the API as if you were extending | ||
// `Base`. | ||
|
||
var Base = require('../../../../'); | ||
|
||
module.exports = class extends Base { | ||
constructor(args, opts) { | ||
super(args, opts); | ||
|
||
console.log(require('./options')); | ||
this.option(require('./options')); | ||
|
||
this.registerConfigPrompts(require('./prompts')); | ||
} | ||
}; | ||
|
||
module.exports.namespace = 'options:generator'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = [ | ||
{ name: 'extra', type: String, storage: 'config' } | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module.exports = [ | ||
{ | ||
name: 'foo', | ||
type: 'input', | ||
message: 'Test foo value', | ||
default: 'bar', | ||
exportOption: true | ||
} | ||
]; |
2 changes: 2 additions & 0 deletions
2
test/fixtures/generator-defaults/app/templates/foo-template.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
var <%= foo %> = '<%= foo %>'; | ||
<%= extra %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"author": "", | ||
"name": "generator-defaults", | ||
"version": "0.0.0", | ||
"main": "main.js", | ||
"dependencies": {}, | ||
"devDependencies": {}, | ||
"optionalDependencies": {}, | ||
"engines": { | ||
"node": "*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use strict'; | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const assert = require('yeoman-assert'); | ||
const helpers = require('yeoman-test'); | ||
|
||
describe('Integration', () => { | ||
let content; | ||
before(function() { | ||
this.timeout(5000); | ||
let tmpDir; | ||
return helpers | ||
.create(path.join(__dirname, 'fixtures/generator-defaults/app')) | ||
.inTmpDir(() => { | ||
tmpDir = process.cwd(); | ||
}) | ||
.withPrompts({ foo: 'fooValue' }) | ||
.withOptions({ extra: 'extraValue' }) | ||
.build() | ||
.run() | ||
.then(() => { | ||
const file = path.join(tmpDir, 'foo-template.js'); | ||
content = fs.readFileSync(path.resolve(file)).toString(); | ||
}); | ||
}); | ||
it('writes prompt value to foo-template.js', () => { | ||
assert(content.includes("fooValue = 'fooValue")); | ||
}); | ||
it('writes option value foo-template.js', () => { | ||
assert(content.includes('extraValue')); | ||
}); | ||
}); |