Skip to content

Commit 4f8f8b6

Browse files
committed
feat(gen): extend updateFixtures task to populate angular-fullstack-deps
Usage: ```bash $ grunt updateFixtures:deps` ```
1 parent b764716 commit 4f8f8b6

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

Gruntfile.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -220,21 +220,23 @@ module.exports = function (grunt) {
220220
}
221221
});
222222

223-
grunt.registerTask('updateFixtures', 'updates package and bower fixtures', function() {
224-
var packageJson = fs.readFileSync(path.resolve('app/templates/_package.json'), 'utf8');
225-
var bowerJson = fs.readFileSync(path.resolve('app/templates/_bower.json'), 'utf8');
226-
227-
// replace package name
228-
packageJson = packageJson.replace(/"name": "<%(.*)%>"/g, '"name": "tempApp"');
229-
packageJson = packageJson.replace(/<%(.*)%>/g, '');
230-
231-
// remove all ejs conditionals
232-
bowerJson = bowerJson.replace(/"name": "<%(.*)%>"/g, '"name": "tempApp"');
233-
bowerJson = bowerJson.replace(/<%(.*)%>/g, '');
234-
235-
// save files
236-
fs.writeFileSync(path.resolve(__dirname + '/test/fixtures/package.json'), packageJson);
237-
fs.writeFileSync(path.resolve(__dirname + '/test/fixtures/bower.json'), bowerJson);
223+
grunt.registerTask('updateFixtures', 'updates package and bower fixtures', function(target) {
224+
var genVer = require('./package.json').version;
225+
var dest = __dirname + ((target === 'deps') ? '/angular-fullstack-deps/' : '/test/fixtures/');
226+
var appName = (target === 'deps') ? 'angular-fullstack-deps' : 'tempApp';
227+
228+
var processJson = function(s, d) {
229+
// read file, strip all ejs conditionals, and parse as json
230+
var json = JSON.parse(fs.readFileSync(path.resolve(s), 'utf8').replace(/<%(.*)%>/g, ''));
231+
// set properties
232+
json.name = appName, json.version = genVer;
233+
if (target === 'deps') { json.private = false; }
234+
// stringify json and write it to the destination
235+
fs.writeFileSync(path.resolve(d), JSON.stringify(json, null, 2));
236+
};
237+
238+
processJson('app/templates/_package.json', dest + 'package.json');
239+
processJson('app/templates/_bower.json', dest + 'bower.json');
238240
});
239241

240242
grunt.registerTask('installFixtures', 'install package and bower fixtures', function() {

0 commit comments

Comments
 (0)