Skip to content

Commit

Permalink
feat(gen:gulp): port updateFixtures to Gulp (hot damn is it faster 🔥)
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
Awk34 committed Apr 24, 2016
1 parent 11f5719 commit 94d69da
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
47 changes: 47 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
'use strict';
var fs = require('fs');
var path = require('path');
var Promise = require('bluebird');
var gulp = require('gulp');
var babel = require('gulp-babel');
var del = require('del');
Expand Down Expand Up @@ -31,3 +34,47 @@ gulp.task('build', cb => {
cb
);
});

var processJson = function(src, dest, opt) {
return new Promise((resolve, reject) => {
// read file, strip all ejs conditionals, and parse as json
fs.readFile(path.resolve(src), 'utf8', (err, data) => {
if(err) return reject(err);

var json = JSON.parse(data.replace(/<%(.*)%>/g, ''));

// set properties
json.name = opt.appName;
json.version = opt.genVer;
json.private = opt.private;

// stringify json and write it to the destination
fs.writeFile(path.resolve(dest), JSON.stringify(json, null, 2), err => {
if(err) reject(err);
else resolve();
});
});
});
};

function updateFixtures(target) {
const deps = target === 'deps';
const genVer = require('./package.json').version;
const dest = __dirname + (deps ? '/angular-fullstack-deps/' : '/test/fixtures/');
const appName = deps ? 'angular-fullstack-deps' : 'tempApp';

return Promise.all([
processJson('templates/app/_package.json', dest + 'package.json', {appName, genVer, private: !!deps}),
processJson('templates/app/_bower.json', dest + 'bower.json', {appName, genVer, private: !!deps})
]);
}

gulp.task('updateFixtures', cb => {
return runSequence(['updateFixtures:test', 'updateFixtures:deps'], cb);
});
gulp.task('updateFixtures:test', () => {
return updateFixtures('test');
});
gulp.task('updateFixtures:deps', () => {
return updateFixtures('deps');
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"babel-plugin-transform-class-properties": "^6.6.0",
"babel-preset-es2015": "^6.6.0",
"babel-register": "^6.6.5",
"bluebird": "^3.3.5",
"chai": "^3.2.0",
"del": "^2.2.0",
"grunt": "^1.0.1",
Expand Down

0 comments on commit 94d69da

Please sign in to comment.