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

Commit b2f31d3

Browse files
committed
feat(package): generate package.json
1 parent 79e20f7 commit b2f31d3

File tree

5 files changed

+66
-14
lines changed

5 files changed

+66
-14
lines changed

generators/app/index.js

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,23 @@ module.exports = Generator.extend({
1212
var formats = ['css', 'scss', 'less'];
1313

1414
var prompts = [{
15-
type: 'String',
15+
type: 'input',
1616
name: 'componentName',
1717
required: true,
1818
message: 'What\'s the name of your component?',
19-
description: 'Component name'
19+
description: 'Component name',
20+
default: this.appname // Default to current folder name
2021
}, {
2122
type: 'list',
2223
name: 'format',
2324
required: true,
2425
message: 'In what format would you like the stylesheet?',
2526
choices: formats
27+
}, {
28+
type: 'confirm',
29+
name: 'npm',
30+
message: 'Is it a npm package?',
31+
default: true
2632
}];
2733

2834
return this.prompt(prompts).then(function (props) {
@@ -35,7 +41,7 @@ module.exports = Generator.extend({
3541

3642
this.fs.copyTpl(
3743
this.templatePath(path.join('styles', '_component.' + this.props.format)),
38-
this.destinationPath(path.join(this.props.componentName, outputFile)),
44+
this.destinationPath(outputFile),
3945
{
4046
componentName: this.props.componentName
4147
}
@@ -45,7 +51,7 @@ module.exports = Generator.extend({
4551
componentNotes: function () {
4652
this.fs.copyTpl(
4753
this.templatePath('_README.md'),
48-
this.destinationPath(path.join(this.props.componentName, 'README.md')),
54+
this.destinationPath('README.md'),
4955
{
5056
componentName: this.props.componentName
5157
}
@@ -57,7 +63,7 @@ module.exports = Generator.extend({
5763

5864
this.fs.copyTpl(
5965
this.templatePath('_component.html'),
60-
this.destinationPath(path.join(this.props.componentName, outputFile)),
66+
this.destinationPath(outputFile),
6167
{
6268
componentName: this.props.componentName
6369
}
@@ -69,10 +75,23 @@ module.exports = Generator.extend({
6975

7076
this.fs.copyTpl(
7177
this.templatePath('_component.config.js'),
72-
this.destinationPath(path.join(this.props.componentName, outputFile)),
78+
this.destinationPath(outputFile),
7379
{
7480
componentName: this.props.componentName
7581
}
7682
);
83+
},
84+
85+
componentPackageJSON: function () {
86+
if (this.props.npm) {
87+
this.fs.copyTpl(
88+
this.templatePath('_package.json'),
89+
this.destinationPath('package.json'),
90+
{
91+
componentName: this.props.componentName,
92+
componentStylesheet: this.props.componentName + '.' + this.props.format
93+
}
94+
);
95+
}
7796
}
7897
});
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
<div>
1+
<div class="<%= componentName %>">
22
<%= componentName %> template file
33
</div>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "<%= componentName %>",
3+
"version": "1.0.0",
4+
"description": "<%= componentName %> component",
5+
"main": "<%= componentName %>.config.js",
6+
"style": "<%= componentStylesheet %>",
7+
"test": "echo \"Error: no test specified\" && exit 1",
8+
"repo": "",
9+
"keywords": [
10+
"fractal",
11+
"component"
12+
],
13+
"author": "",
14+
"license": "MIT"
15+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
"yeoman-generator"
1919
],
2020
"dependencies": {
21-
"yeoman-generator": "^1.0.0",
2221
"chalk": "^1.1.3",
22+
"yeoman-generator": "^1.0.0",
2323
"yosay": "^1.2.1"
2424
},
2525
"devDependencies": {

test/app.js

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,37 @@ var path = require('path');
33
var assert = require('yeoman-assert');
44
var helpers = require('yeoman-test');
55

6-
describe('generator-fractal-component:app', function () {
6+
describe('generator-fractal-component:css-with-npm', function () {
77
before(function () {
88
return helpers.run(path.join(__dirname, '../generators/app'))
9-
.withPrompts({componentName: 'myComponent', format: 'css'})
9+
.withPrompts({componentName: 'myComponent', format: 'css', npm: true})
1010
.toPromise();
1111
});
1212

1313
it('creates files', function () {
1414
assert.file([
15-
'myComponent/myComponent.config.js',
16-
'myComponent/myComponent.css',
17-
'myComponent/myComponent.html',
18-
'myComponent/README.md'
15+
'myComponent.config.js',
16+
'myComponent.css',
17+
'myComponent.html',
18+
'package.json',
19+
'README.md'
20+
]);
21+
});
22+
});
23+
24+
describe('generator-fractal-component:less-without-npm', function () {
25+
before(function () {
26+
return helpers.run(path.join(__dirname, '../generators/app'))
27+
.withPrompts({componentName: 'myOtherComponent', format: 'less', npm: false})
28+
.toPromise();
29+
});
30+
31+
it('creates files', function () {
32+
assert.file([
33+
'myOtherComponent.config.js',
34+
'myOtherComponent.less',
35+
'myOtherComponent.html',
36+
'README.md'
1937
]);
2038
});
2139
});

0 commit comments

Comments
 (0)