Repository navigation
Expand file tree
/
Copy pathgulpfile.js
More file actions
186 lines (186 loc) · 6.24 KB
/
Copy pathgulpfile.js
File metadata and controls
186 lines (186 loc) · 6.24 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
var gulp=require('gulp'),
sass=require('gulp-sass'),
uglify=require('gulp-uglify'),
concat=require('gulp-concat'),
include=require('gulp-include'),
replace=require('gulp-replace'),
exec=require('child_process').exec,
eventStream = require('event-stream');
var data=require('./scripts/task')({
json:{
package:'package.json',
scriptive:'scriptive.json'
},
version:{
},
initial:function() {
if (this.status.success()){
// gulp --pro=lst
this.json.scriptive.app['buildDate'] = new Date().toISOString().slice(0,10).replace(/-/g,'.');
// this.BuildDate = new Date().toISOString().slice(0,10).replace(/-/g,'.');
// this.BuildDate = this.json.package.version;
if (this.json.scriptive.project && this.json.scriptive.project.root) {
this.assetRoot = path.join(this.json.scriptive.project.root,this.json.scriptive.app.asset.root);
this.devRoot = path.join(this.json.scriptive.project.root,this.json.scriptive.app.dev.root);
if (this.json.scriptive.gulp.hasOwnProperty('custom'))this.custom(this.json.scriptive.gulp.custom,this.json.scriptive.project.root);
} else {
this.assetRoot = path.join(this.json.scriptive.app.asset.root);
this.devRoot = path.join(this.json.scriptive.app.dev.root);
}
extend(this.AssetSASS,this.json.scriptive.gulp.sass);
extend(this.AssetJS,this.json.scriptive.gulp.js);
}
},
AssetSASS:{
debugInfo: true,
lineNumbers: false,
errLogToConsole: true,
// sourceComments: "normal",//normal, map
outputStyle: "compact"//compact, compressed, expanded
},
AssetJS:{
//mangle:false,
output:{
beautify: true,
comments:"license"
},
compress:true,
//outSourceMap: true,
preserveComments:"license"
},
watch:['watch'],
custom:function(obj,root){
Object.keys(obj).forEach(name=>{
var o=obj[name], src = path.join(root,o.source);
gulp.task(name, task=>{
var w = gulp.src(src);
for(var i in o.pipe)w=w.pipe(require(i)(o.pipe[i]));
w.pipe(replace(/\{(application.*?)\}/gm, data.replace.app))
w.pipe(replace(/\{((package|scriptive).*?)\}/gm, data.replace.json))
if (o.target.constructor === Array){
o.target.map(dir=>{w=w.pipe(gulp.dest(path.join(root,dir)))});
} else {
w=w.pipe(gulp.dest(path.join(root,o.target)));
}
return w;
});
this.watch.push(name);
gulp.watch(o.hasOwnProperty('watch')?path.join(root,o.watch):src,[name]);
});
},
replace:{
// version:function(){
// return 'v' +data.json.scriptive.app.version;
// },
app:function(){
var e = data.json.scriptive.app;
arguments[1].split('.').forEach(function(v){
if (e.hasOwnProperty(v))e=e[v];
});
return (typeof e === 'string')?e:arguments[0];
},
json:function(){
var e = data.json;
arguments[1].split('.').forEach(function(v){
if (e.hasOwnProperty(v))e=e[v];
});
// return (typeof e === 'string')?e:arguments[0];
return (typeof e === 'string')?e:arguments[0];
}
}
});
//SASS
gulp.task('AssetSASS', function () {
this.src(path.join(data.assetRoot,'sass','*([^A-Z0-9-]).scss'))//!([^A-Z0-9-])
.pipe(sass(data.AssetSASS).on('error', sass.logError))
.pipe(this.dest(path.join(data.devRoot,'css')));
});
//Scripts
gulp.task('AssetJS',function(){
this.src(path.join(data.assetRoot,'js','*([^A-Z0-9-]).js'))
.pipe(include().on('error', console.log))
.pipe(replace(/\{(application.*?)\}/gm, data.replace.app))
.pipe(replace(/\{((package|scriptive).*?)\}/gm, data.replace.json))
.pipe(uglify(data.AssetJS).on('error', console.log))
.pipe(this.dest(path.join(data.devRoot,'js')));
});
//startDeveloper
gulp.task('scriptive',function(){
this.src(path.join(data.json.scriptive.app.asset.root,'scriptive','scriptive.js'))
.pipe(include())
.pipe(replace(/\{(application.*?)\}/gm, data.replace.app))
.pipe(replace(/\{((package|scriptive).*?)\}/gm, data.replace.json))
.pipe(uglify({
mangle:true,
output:{
beautify: false, comments:'license'
},
compress:true,
preserveComments:'license'
}).on('error', console.log))
.pipe(concat('scriptive.min.js'))
.pipe(this.dest(data.json.scriptive.app.dist.root))
.pipe(this.dest(path.join(data.devRoot,data.json.scriptive.app.dev.lib)));
});
// fileStorage
/*
gulp.task('filestorage',function(){
this.src(path.join(data.json.scriptive.app.asset.root,'filestorage','fileStorage.js'))
.pipe(include())
.pipe(uglify({
mangle:false,
output:{
beautify: false, comments:'license'
},
compress:true,
preserveComments:'license'
}).on('error', console.log))
.pipe(concat('filestorage.min.js'))
.pipe(this.dest(data.json.scriptive.app.dist.root));
});
*/
// fileSystask
/*
gulp.task('filesystask',function(){
this.src(path.join(data.json.scriptive.app.asset.root,'filesystask','fileSystask.js'))
.pipe(include())
.pipe(uglify({
mangle:false,
output:{
beautify: false, comments:'license'
},
compress:true,
preserveComments:'license'
}).on('error', console.log))
.pipe(concat('filesystask.min.js'))
.pipe(this.dest(data.json.scriptive.app.dist.root));
});
*/
// fileHtmltask
gulp.task('filehtmltask',function(){
this.src(path.join(data.json.scriptive.app.asset.root,'filehtmltask','fileHtmltask.js'))
.pipe(include())
.pipe(uglify({
mangle:false,
output:{
beautify: false, comments:'license'
},
compress:true,
preserveComments:'license'
}).on('error', console.log))
.pipe(concat('filehtmltask.min.js'))
.pipe(this.dest(data.json.scriptive.app.dist.root));
});
//endDeveloper
gulp.task('watch', function() {
this.watch(path.join(data.assetRoot,'sass','*.scss'), ['AssetSASS']);
this.watch(path.join(data.assetRoot,'js','*.js'), ['AssetJS']);
//scriptDeveloper
// this.watch(path.join(data.json.scriptive.app.asset.root,'filestorage','*.js'), ['filestorage']);
// this.watch(path.join(data.json.scriptive.app.asset.root,'filesystask','*.js'), ['filesystask']);
this.watch(path.join(data.json.scriptive.app.asset.root,'filehtmltask','*.js'), ['filehtmltask']);
this.watch(path.join(data.json.scriptive.app.asset.root,'scriptive','*.js'), ['scriptive']);
//scriptDeveloper
});
//TASK
gulp.task('default', data.watch);