diff --git a/generators/app/index.js b/generators/app/index.js index ad9fc47..6bd3660 100644 --- a/generators/app/index.js +++ b/generators/app/index.js @@ -12,17 +12,23 @@ module.exports = Generator.extend({ var formats = ['css', 'scss', 'less']; var prompts = [{ - type: 'String', + type: 'input', name: 'componentName', required: true, message: 'What\'s the name of your component?', - description: 'Component name' + description: 'Component name', + default: this.appname // Default to current folder name }, { type: 'list', name: 'format', required: true, message: 'In what format would you like the stylesheet?', choices: formats + }, { + type: 'confirm', + name: 'npm', + message: 'Is it a npm package?', + default: true }]; return this.prompt(prompts).then(function (props) { @@ -35,7 +41,7 @@ module.exports = Generator.extend({ this.fs.copyTpl( this.templatePath(path.join('styles', '_component.' + this.props.format)), - this.destinationPath(path.join(this.props.componentName, outputFile)), + this.destinationPath(outputFile), { componentName: this.props.componentName } @@ -45,7 +51,7 @@ module.exports = Generator.extend({ componentNotes: function () { this.fs.copyTpl( this.templatePath('_README.md'), - this.destinationPath(path.join(this.props.componentName, 'README.md')), + this.destinationPath('README.md'), { componentName: this.props.componentName } @@ -57,7 +63,7 @@ module.exports = Generator.extend({ this.fs.copyTpl( this.templatePath('_component.html'), - this.destinationPath(path.join(this.props.componentName, outputFile)), + this.destinationPath(outputFile), { componentName: this.props.componentName } @@ -69,10 +75,23 @@ module.exports = Generator.extend({ this.fs.copyTpl( this.templatePath('_component.config.js'), - this.destinationPath(path.join(this.props.componentName, outputFile)), + this.destinationPath(outputFile), { componentName: this.props.componentName } ); + }, + + componentPackageJSON: function () { + if (this.props.npm) { + this.fs.copyTpl( + this.templatePath('_package.json'), + this.destinationPath('package.json'), + { + componentName: this.props.componentName, + componentStylesheet: this.props.componentName + '.' + this.props.format + } + ); + } } }); diff --git a/generators/app/templates/_component.html b/generators/app/templates/_component.html index 44ebcc1..a4688fa 100644 --- a/generators/app/templates/_component.html +++ b/generators/app/templates/_component.html @@ -1,3 +1,3 @@ -
+
<%= componentName %> template file
diff --git a/generators/app/templates/_package.json b/generators/app/templates/_package.json new file mode 100644 index 0000000..4ac79ae --- /dev/null +++ b/generators/app/templates/_package.json @@ -0,0 +1,15 @@ +{ + "name": "<%= componentName %>", + "version": "1.0.0", + "description": "<%= componentName %> component", + "main": "<%= componentName %>.config.js", + "style": "<%= componentStylesheet %>", + "test": "echo \"Error: no test specified\" && exit 1", + "repo": "", + "keywords": [ + "fractal", + "component" + ], + "author": "", + "license": "MIT" +} diff --git a/package.json b/package.json index 485ae90..64bb6c5 100644 --- a/package.json +++ b/package.json @@ -18,8 +18,8 @@ "yeoman-generator" ], "dependencies": { - "yeoman-generator": "^1.0.0", "chalk": "^1.1.3", + "yeoman-generator": "^1.0.0", "yosay": "^1.2.1" }, "devDependencies": { diff --git a/test/app.js b/test/app.js index 1531172..1455d73 100644 --- a/test/app.js +++ b/test/app.js @@ -3,19 +3,37 @@ var path = require('path'); var assert = require('yeoman-assert'); var helpers = require('yeoman-test'); -describe('generator-fractal-component:app', function () { +describe('generator-fractal-component:css-with-npm', function () { before(function () { return helpers.run(path.join(__dirname, '../generators/app')) - .withPrompts({componentName: 'myComponent', format: 'css'}) + .withPrompts({componentName: 'myComponent', format: 'css', npm: true}) .toPromise(); }); it('creates files', function () { assert.file([ - 'myComponent/myComponent.config.js', - 'myComponent/myComponent.css', - 'myComponent/myComponent.html', - 'myComponent/README.md' + 'myComponent.config.js', + 'myComponent.css', + 'myComponent.html', + 'package.json', + 'README.md' + ]); + }); +}); + +describe('generator-fractal-component:less-without-npm', function () { + before(function () { + return helpers.run(path.join(__dirname, '../generators/app')) + .withPrompts({componentName: 'myOtherComponent', format: 'less', npm: false}) + .toPromise(); + }); + + it('creates files', function () { + assert.file([ + 'myOtherComponent.config.js', + 'myOtherComponent.less', + 'myOtherComponent.html', + 'README.md' ]); }); });