-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
238 lines (219 loc) · 7.54 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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
var gulp = require('gulp');
var tsconfig = require('gulp-tsconfig');
var exec = require('child_process').execSync;
var install = require('gulp-install');
var runSequence = require('run-sequence');
var del = require('del');
var uglify = require('gulp-uglify');
var useref = require('gulp-useref');
var rename = require('gulp-rename');
var debug = require('gulp-debug');
var concat = require('gulp-concat');
var plumber = require('gulp-plumber');
var watch = require('gulp-watch');
var changed = require('gulp-changed');
var templateCache = require('gulp-angular-templatecache');
var deploy = require('gulp-gh-pages');
var purify = require('gulp-purifycss');
var concatCss = require('gulp-concat-css');
var ts = require('gulp-typescript');
var tslint = require('gulp-tslint');
var tstypings = require('gulp-typings');
var OfflineSearch = require('csweb-offline-search');
var sourcemaps = require('gulp-sourcemaps');
var debug = require('gulp-debug');
var nodemon = require('gulp-nodemon');
var gulpIgnore = require('gulp-ignore');
var print = require('gulp-print');
/** Destination of the client/server distribution */
var dest = 'dist/';
var path2csWeb = '../csWeb/';
var path2dist = './';
// Gulp task upstream...
// Configure gulp scripts
// Output application name
var appName = 'sim-city-cs';
/** Create a new distribution by copying all required CLIENT files to the dist folder. */
gulp.task('dist_client', function() {
// Copy client side files
// Copy app, images, css, data and swagger
gulp.src('public/app/**/*.js*')
.pipe(plumber())
.pipe(gulp.dest(dest + 'public/app/'));
gulp.src('public/css/**/*.*')
.pipe(plumber())
.pipe(gulp.dest(dest + 'public/css/'));
gulp.src('public/data/**/*.*')
.pipe(plumber())
.pipe(gulp.dest(dest + 'public/data/'));
gulp.src('public/swagger/**/*.*')
.pipe(plumber())
.pipe(gulp.dest(dest + 'public/swagger/'));
gulp.src('./public/images/**/*.*')
.pipe(plumber())
.pipe(gulp.dest(dest + 'public/images/'));
// Copy index files and favicon
gulp.src(['./public/*.html', './public/favicon.ico', './public/mode-json.js'])
.pipe(plumber())
.pipe(gulp.dest(dest + 'public/'));
// Copy bower components of csweb, and others (ignoring any linked csweb files)
gulp.src('public/bower_components/csweb/dist-bower/**/*.*')
.pipe(plumber())
.pipe(gulp.dest(dest + 'public/bower_components/csweb/dist-bower/'));
gulp.src(['public/bower_components/**/*.*', '!public/bower_components/csweb/**/*.*'])
.pipe(plumber())
.pipe(gulp.dest(dest + 'public/bower_components/'));
});
/** Create a new distribution by copying all required SERVER files to the dist folder. */
gulp.task('dist_server', function() {
// Copy server side files
gulp.src(['./server.js', './server.js.map', './configuration.json', './LICENSE'])
.pipe(plumber())
.pipe(gulp.dest(dest));
// Copy npm modules of csweb, and others (ignoring any linked csweb files)
gulp.src(['node_modules/**/*.*', '!node_modules/csweb/**/*.*'])
.pipe(plumber())
.pipe(changed(dest + 'node_modules/'))
.pipe(gulp.dest(dest + 'node_modules/'));
gulp.src('node_modules/csweb/dist-npm/package.json')
.pipe(plumber())
.pipe(gulp.dest(dest + 'node_modules/csweb/'));
return gulp.src('node_modules/csweb/dist-npm/**/*.*')
.pipe(plumber())
.pipe(changed(dest + 'node_modules/csweb/dist-npm/'))
.pipe(gulp.dest(dest + 'node_modules/csweb/dist-npm/'));
});
/** Create a new distribution by copying all required CLIENT+SERVER files to the dist folder. */
gulp.task('dist', ['dist_client', 'dist_server']);
gulp.task('typings', function (cb) {
return gulp.src("./typings.json")
.pipe(tstypings(), cb);
//will install all typingsfiles in pipeline.
});
function buildTsconfig(config, globPattern, basedir) {
config.tsConfig.comment = '! This tsconfig.json file has been generated automatically, please DO NOT edit manually.';
return gulp.src(globPattern, { base: '.' })
.pipe(rename(function (path) {
path.dirname = path.dirname.replace(basedir, '.');
}))
.pipe(tsconfig(config)())
.pipe(gulp.dest(basedir));
}
// This task updates the typescript dependencies on tsconfig file
gulp.task('tsconfig', function () {
var globPattern = [
"./public/bower_components/csweb/dist-bower/csComp.d.ts",
"typings/index.d.ts",
"server.ts",
"public/app/**/*.ts",
"!public/app/**/*.d.ts"
];
var config = {
tsOrder: ['**/*.ts'],
tsConfig: {
version: '2.5.1',
compilerOptions: {
target: 'es6',
module: 'commonjs',
noImplicitAny: false,
removeComments: false,
preserveConstEnums: true,
noLib: false,
outDir: '.',
sourceMap: true,
typeRoots: [
"node_modules/@types"
]
},
filesGlob: globPattern
}
};
return buildTsconfig(config, globPattern, './');
});
gulp.task('ts-lint', function () {
var tsProject = ts.createProject('tsconfig.json');
return tsProject.src()
.pipe(gulpIgnore.exclude('*.d.ts'))
.pipe(tslint())
.pipe(tslint.report('prose', {
emitError: false
}));
});
gulp.task('tsc', function() {
var tsProject = ts.createProject('tsconfig.json');
return tsProject.src()
.pipe(sourcemaps.init())
.pipe(print())
.pipe(tsProject())
.pipe(sourcemaps.write('.'))
.pipe(debug({title: 'compiled:'}))
.pipe(gulp.dest('.'));
});
// Install required npm and bower installs for example folder
gulp.task('install', function(cb) {
return gulp.src([
'./package.json', // npm install
'./public/bower.json', // bower install
])
.pipe(install(cb));
});
/** Initialiaze the project */
gulp.task('init', function(cb) {
return runSequence(
'typings',
'tsconfig',
'compile',
cb
);
});
gulp.task('compile', function(cb) {
return runSequence(
'ts-lint',
'tsc',
cb
);
});
gulp.task('clean', function(cb) {
// NOTE Careful! Removes all generated javascript files and certain folders.
return del([
'server.js',
'server.js.map',
'public/app/**/*.js',
'public/app/**/*.js.map'
], {
force: true
}, cb);
});
/** Deploy it to the github pages */
gulp.task('deploy-githubpages', function() {
return gulp.src(dest + 'public/**/*')
.pipe(deploy({
branch: 'master',
cacheDir: '.deploy'
}));
});
gulp.task('serve', function(cb) {
return nodemon({
script: 'server.js'
, verbose: false
, legacyWatch: true
, delayTime: 2
, ext: 'js html css'
, watch: [
'public/js/**',
'public/index.html',
'public/css/*.css'
]
, env: { 'NODE_ENV': 'development' }
})
.on('start', ['watch'])
.on('change', ['watch'])
.on('restart', function () {
console.log('restarted!');
}, cb);
});
gulp.task('watch', function(cb) {
return gulp.watch(['public/**/*.ts', 'public/**/*.html'], ['compile'], cb)
});
gulp.task('deploy', ['dist_client', 'deploy-githubpages']);
gulp.task('default', ['compile']);