-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulp-loadfile.js
More file actions
103 lines (86 loc) · 2.54 KB
/
gulp-loadfile.js
File metadata and controls
103 lines (86 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
'use strict';
var path = require('path'),
gulp = require('gulp'),
gutil = require('gulp-util'),
_ = require('lodash');
// Config
var pkg = {},
loadfile = {};
module.exports = function (packageJSON, loadfileJSON) {
pkg = packageJSON;
loadfile = loadfileJSON;
if (_.isEmpty(pkg) || _.isEmpty(loadfile)) {
gutil.log('gulp-loadfile', gutil.colors.red('warning jsonfiles not valid'));
return;
}
return module.exports;
};
module.exports.task = function (task, cb) {
var files = [],
tasks = [];
if (_.isEmpty(pkg) || _.isEmpty(loadfile)) {
gutil.log('gulp-loadfile', gutil.colors.red('warning jsonfiles not valid'));
}
gutil.log('Using gulp-loadfile', gutil.colors.cyan(task));
// modules definition
_.forEach(loadfile.modules, function (module, Modulekey) {
var streams = false;
tasks.push(Modulekey + ':' + task);
// tasks definition
_.forEach(module[task], function (taskStream) {
var moduleFiles = [],
stream,
args;
// add all sub files
_.forEach(taskStream.src, function (file) {
var filePath = path.join(loadfile.config.src, task, file);
moduleFiles.push(filePath);
files.push(filePath);
});
args = [
moduleFiles,
taskStream.dest,
{meta: loadfile.config.meta.banner.join('\n'), pkg: { pkg: pkg }},
loadfile.config.dist + '/' + Modulekey + '/' + pkg.version + '/' + task
];
// gulp stream injection
stream = cb.apply(this, args);
// concat all streams
if (streams !== false) {
streams = gutil.combine(streams, stream, stream.pipe(gulp.dest(
path.join(loadfile.config.dist, Modulekey, 'latest', task)
)));
} else {
streams = gutil.combine(stream, stream.pipe(gulp.dest(
path.join(loadfile.config.dist, Modulekey, 'latest', task)
)));
}
});
// Less deployment task
gulp.task(
Modulekey + ':' + task,
function () {
return streams;
}
);
});
// only dist tasks
gulp.task(task, tasks);
// watch all and run less tasks
// gulp.task(
// task + ':watch',
// tasks,
// function () {
// var watch = gulp.watch(files, tasks);
// watch.on('change', function (event) {
// gutil.log(
// gutil.colors.green(" " + event.type + " '"),
// gutil.colors.cyan(event.path.replace(__dirname, "")),
// gutil.colors.green("'"),
// gutil.colors.magenta('running tasks...')
// );
// });
// }
// );
return true;
};