Skip to content

Commit 6c29f66

Browse files
committed
changed
1 parent 30fdf4d commit 6c29f66

File tree

3 files changed

+49
-26
lines changed

3 files changed

+49
-26
lines changed

.tmtworkflowrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
"supportREM": false,
2929

30+
"supportChanged": false,
31+
3032
"reversion": false
3133

3234
}

_tasks/TaskBuildDist.js

Lines changed: 46 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
var _ = require('lodash');
12
var fs = require('fs');
23
var del = require('del');
34
var path = require('path');
@@ -192,40 +193,65 @@ module.exports = function (gulp, config) {
192193
cb();
193194
}
194195
}
195-
196-
function findChanged(cb) {
197196

198-
var diff = changed('./tmp');
199-
var tmpSrc = [];
197+
function findChanged(cb) {
200198

201-
if(process.argv[2].indexOf(':all') > -1){
199+
if (!config['supportChanged']) {
202200
return gulp.src('./tmp/**/*', {base: paths.tmp.dir})
203201
.pipe(gulp.dest(paths.dist.dir))
204-
.on('end', function(){
202+
.on('end', function () {
205203
delTmp();
206204
})
207-
}
205+
} else {
206+
var diff = changed('./tmp');
207+
var tmpSrc = [];
208208

209-
if(diff){
210-
for(var i in diff){
211-
tmpSrc.push('./tmp/' + i);
212-
console.log(i + ' has changed!');
213-
}
209+
if (!_.isEmpty(diff)) {
210+
211+
//如果有reversion
212+
if (config['reversion'] && config['reversion']['available']) {
213+
var keys = _.keys(diff);
214+
215+
//先取得 reversion 生成的manifest.json
216+
var reversionManifest = require(path.resolve('./tmp/manifest.json'));
217+
218+
if (reversionManifest) {
219+
reversionManifest = _.invert(reversionManifest);
220+
221+
reversionManifest = _.pick(reversionManifest, keys);
222+
223+
reversionManifest = _.invert(reversionManifest);
224+
225+
_.forEach(reversionManifest, function (item, index) {
226+
tmpSrc.push('./tmp/' + item);
227+
console.log('[changed:] ' + util.colors.blue(index));
228+
});
229+
230+
//将新的 manifest.json 保存
231+
fs.writeFileSync('./tmp/manifest.json', JSON.stringify(reversionManifest));
232+
233+
tmpSrc.push('./tmp/manifest.json');
234+
}
235+
} else {
236+
_.forEach(diff, function (item, index) {
237+
tmpSrc.push('./tmp/' + index);
238+
console.log('[changed:] ' + util.colors.blue(index));
239+
});
240+
}
214241

215-
if(!tmpSrc.length){
216-
console.log('Nothing changed!');
217-
delTmp();
218-
cb();
219-
}else{
220242
return gulp.src(tmpSrc, {base: paths.tmp.dir})
221243
.pipe(gulp.dest(paths.dist.dir))
222-
.on('end', function(){
244+
.on('end', function () {
223245
delTmp();
224246
})
247+
248+
} else {
249+
console.log('Nothing changed!');
250+
delTmp();
251+
cb();
225252
}
226-
}else{
227-
cb();
228253
}
254+
229255
}
230256

231257

@@ -253,10 +279,5 @@ module.exports = function (gulp, config) {
253279
findChanged,
254280
loadPlugin
255281
));
256-
257-
//注册 build_dist 任务
258-
gulp.task('build_dist:all', gulp.series(
259-
'build_dist'
260-
));
261282
};
262283

_tasks/common/changed.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function changed(dir) {
99
var manifestPath = path.resolve('./src/manifest.json');
1010
var manifest = {};
1111
var originManifest = {};
12-
12+
1313
//如果存在 manifest.json, 则加载保存
1414
if (fs.existsSync(manifestPath)) {
1515
originManifest = require(manifestPath);

0 commit comments

Comments
 (0)