Skip to content

Commit 9cef723

Browse files
committed
Merge pull request #13 from eddiemonge/jsonjson
Generate package.json from js object written out as json
2 parents ae7bc96 + 5de627f commit 9cef723

File tree

2 files changed

+45
-37
lines changed

2 files changed

+45
-37
lines changed

app/index.js

+45-1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ GruntpluginGenerator.prototype.askFor = function askFor() {
8686
this.slugname = this._.slugify(props.name);
8787

8888
this.shortName = props.name.replace(/^grunt[\-_]?/, '').replace(/[\W_]+/g, '_').replace(/^(\d)/, '_$1');
89+
this.authorOriginalName = props.authorName;
8990
this.authorName = props.authorName.replace(/[\\"']/g, '\\$&').replace(/\u0000/g, '\\0');
9091

9192
if (!props.homepage) {
@@ -115,5 +116,48 @@ GruntpluginGenerator.prototype.projectfiles = function projectfiles() {
115116

116117
this.template('_README.md', 'README.md');
117118
this.template('_Gruntfile.js', 'Gruntfile.js');
118-
this.template('_package.json', 'package.json');
119+
};
120+
121+
GruntpluginGenerator.prototype.packageFile = function packageFile() {
122+
var pkgFile = {
123+
name: this.slugname,
124+
version: this.props.version,
125+
description: this.props.description,
126+
homepage: this.props.homepage,
127+
repository: this.props.repository,
128+
bugs: this.props.repository + 'issues',
129+
author: {
130+
name: this.authorOriginalName,
131+
email: this.props.authorEmail
132+
},
133+
keywords: [
134+
'gruntplugin'
135+
],
136+
main: 'Gruntfile.js',
137+
engines: {
138+
node: this.props.nodeVersion
139+
},
140+
licenses: [
141+
{
142+
type: this.props.license
143+
}
144+
],
145+
devDependencies: {
146+
'grunt-contrib-clean': '~0.4.0',
147+
'grunt-contrib-jshint': '~0.2.0',
148+
'grunt-contrib-nodeunit': '~0.1.2',
149+
'grunt': this.props.gruntVersion,
150+
'jshint-stylish': '~0.1.3',
151+
'load-grunt-tasks': '~0.2.0'
152+
},
153+
scripts: {
154+
test: 'grunt test'
155+
}
156+
};
157+
158+
if (this.props.authorUrl) {
159+
pkgFile.author.url = this.props.authorUrl;
160+
}
161+
162+
this.writeFileFromString(JSON.stringify(pkgFile, null, 2), 'package.json');
119163
};

app/templates/_package.json

-36
This file was deleted.

0 commit comments

Comments
 (0)