-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
178 lines (149 loc) · 4.92 KB
/
gulpfile.js
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
'use strict';
// fetch command line arguments
const arg = (argList => {
let arg = {}, a, opt, thisOpt, curOpt;
for (a = 0; a < argList.length; a++) {
thisOpt = argList[a].trim();
opt = thisOpt.replace(/^\-+/, '');
if (opt === thisOpt) {
// argument value
if (curOpt) arg[curOpt] = opt;
curOpt = null;
}
else {
// argument name
curOpt = opt;
arg[curOpt] = true;
}
}
return arg;
})(process.argv);
//includes
var gulp = require('gulp'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
cleancss = require('gulp-clean-css'),
less = require('gulp-less'),
rename = require('gulp-rename'),
config = require('./App/config.json');
//get config variables from config.json
var environment = config.environment;
//determine environment
var prod = false;
if (environment != 'dev' && environment != 'development' && environment != null) {
//using staging or production environment
prod = true;
}
//paths
var paths = {
scripts: './App/Scripts/',
css: './App/CSS/',
app: './App/',
themes: './App/Content/themes/',
vendor: {
root: './App/Vendor/**/'
},
webroot: './App/wwwroot/',
};
//working paths
paths.working = {
js: {
platform: [
paths.scripts + 'selector/selector.js',
//paths.scripts + 'utility/velocity.min.js',
paths.scripts + 'platform/_super.js', // <---- Datasilk Core Js: S object
paths.scripts + 'platform/ajax.js', // <---- Optional platform features
//paths.scripts + 'platform/loader.js',
paths.scripts + 'platform/message.js',
//paths.scripts + 'platform/polyfill.js',
//paths.scripts + 'platform/popup.js',
//paths.scripts + 'platform/scaffold.js',
paths.scripts + 'platform/svg.js',
//paths.scripts + 'platform/util.js',
//paths.scripts + 'platform/util.color.js',
//paths.scripts + 'platform/util.file.js',
//paths.scripts + 'platform/validate.js',
paths.scripts + 'platform/window.js', // <---- End of Optional features
paths.app + 'Pages/Frames/frames.js',
],
app: paths.app + '**/*.js',
utility: [
paths.scripts + 'utility/*.*',
paths.scripts + 'utility/**/*.*'
]
},
less: {
website: paths.css + 'website.less'
},
exclude: {
app: [
'!' + paths.app + 'Pages/Frames/*.*',
'!' + paths.app + 'chrome.js',
'!' + paths.app + 'wwwroot/**/',
'!' + paths.app + 'Content/**/',
'!' + paths.app + 'CSS/**/',
'!' + paths.app + 'CSS/',
'!' + paths.app + 'Scripts/**/'
]
}
};
//compiled paths
paths.compiled = {
platform: paths.webroot + 'js/platform.js',
js: paths.webroot + 'js/',
css: paths.webroot + 'css/',
};
//tasks for compiling javascript //////////////////////////////////////////////////////////////
gulp.task('js:app', function () {
var pathlist = paths.working.exclude.app.slice(0);
pathlist.unshift(paths.working.js.app);
var p = gulp.src(pathlist)
.pipe(rename(function (path) {
path.dirname = path.dirname.toLowerCase();
path.basename = path.basename.toLowerCase();
path.extname = path.extname.toLowerCase();
}));
if (prod == true) { p = p.pipe(uglify()); }
return p.pipe(gulp.dest(paths.compiled.js, { overwrite: true }));
});
gulp.task('js:platform', function () {
var p = gulp.src(paths.working.js.platform, { base: '.' })
.pipe(concat(paths.compiled.platform));
if (prod == true) { p = p.pipe(uglify()); }
return p.pipe(gulp.dest('.', { overwrite: true }));
});
gulp.task('js', function () {
gulp.start('js:app');
gulp.start('js:platform');
});
//tasks for compiling LESS & CSS /////////////////////////////////////////////////////////////////////
gulp.task('less:website', function () {
var p = gulp.src(paths.working.less.website)
.pipe(less());
if (prod == true) { p = p.pipe(cleancss({ compatibility: 'ie8' })); }
return p.pipe(gulp.dest(paths.compiled.css, { overwrite: true }));
});
gulp.task('less', function () {
gulp.start('less:website');
});
//default task
gulp.task('default', ['js', 'less']);
//watch task
gulp.task('watch', function () {
//watch platform JS
gulp.watch(paths.working.js.platform, ['js:platform']);
//watch app JS
var pathjs = paths.working.exclude.app.slice(0);
for (var x = 0; x < pathjs.length; x++) {
pathjs[x] += '*.js';
}
pathjs.unshift(paths.working.js.app);
gulp.watch(pathjs, ['js:app']);
//watch website LESS
gulp.watch([
[
paths.working.less.website,
paths.app + 'Pages/Frames/frames.less'
]
], ['less:website']);
});