Skip to content
This repository has been archived by the owner on Dec 13, 2018. It is now read-only.

Commit

Permalink
feat(package): generate package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
yhuard committed Feb 12, 2017
1 parent 79e20f7 commit b2f31d3
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 14 deletions.
31 changes: 25 additions & 6 deletions generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
);
}
}
});
2 changes: 1 addition & 1 deletion generators/app/templates/_component.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<div>
<div class="<%= componentName %>">
<%= componentName %> template file
</div>
15 changes: 15 additions & 0 deletions generators/app/templates/_package.json
Original file line number Diff line number Diff line change
@@ -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"
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
30 changes: 24 additions & 6 deletions test/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
]);
});
});

0 comments on commit b2f31d3

Please sign in to comment.