-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
185 lines (167 loc) · 6.85 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
var gulp = require('gulp');
var tsconfig = require('gulp-tsconfig-files');
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');
/** Destination of the client/server distribution */
var dest = 'dist/';
var path2csWeb = '../csWeb/';
function run(command, cb) {
console.log('Run command: ' + command);
try {
exec(command);
cb();
} catch (err) {
console.log('### Exception encountered on command: ' + command);
console.log(err.stdout.toString());
console.log('####################################');
cb();
throw err;
}
}
/** 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('update_tsconfig', function() {
return gulp.src(['./**/*.ts',
'!./node_modules/**/*.ts',
'!./dist/**/*.*',
'!./public/bower_components/**/*.d.ts',
],
{base: ''})
.pipe(tsconfig({
path: 'tsconfig.json',
relative_dir: '',
}));
});
gulp.task('copy_servercomponents', function() {
gulp.src(path2csWeb + 'dist-npm/ServerComponents/**/*.*')
.pipe(plumber())
.pipe(gulp.dest('./ServerComponents/'));
});
gulp.task('tsc', function(cb) {
//var cmd = 'tsc -w -p ' + path2csWeb + 'csServerComp & tsc -w -p ' + path2csWeb + 'csComp & tsc -w -p .'
return run("tsc -w -p .", cb);
});
// 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) {
runSequence(
'update_tsconfig',
'tsc',
cb
);
});
// Gulp task upstream...
// Configure gulp scripts
// Output application name
var appName = 'csWebApp';
gulp.task('clean', function(cb) {
// NOTE Careful! Removes all generated javascript files and certain folders.
del([
'dist',
'public/**/*.js',
'public/**/*.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'
}));
});
// var watchTS = gulp.watch('./**/*.ts');
// watchTS.on('added', function(event) {
// console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
// update_tsconfig
// });
gulp.task('watch', function() {
// gulp.watch(path2csWeb + 'csServerComp/ServerComponents/**/*.js', ['copy_csServerComp']);
// gulp.watch(path2csWeb + 'csServerComp/Scripts/**/*.ts', ['copy_csServerComp_scripts']);
//gulp.watch(path2csWeb + 'csServerComp/ServerComponents/**/*.d.ts', ['built_csServerComp.d.ts']);
// gulp.watch(path2csWeb + 'csServerComp/ServerComponents/dynamic/ClientConnection.d.ts', ['built_csServerComp.d.ts']);
gulp.watch(path2csWeb + 'dist-npm/ServerComponents/**/*.js', ['copy_servercomponents']);
// gulp.watch(path2csWeb + 'csComp/includes/**/*.scss', ['sass']);
// gulp.watch(path2csWeb + 'csComp/js/**/*.js', ['built_csComp']);
// gulp.watch(path2csWeb + 'csComp/js/**/*.d.ts', ['built_csComp.d.ts']);
// gulp.watch(path2csWeb + 'csComp/**/*.tpl.html', ['create_templateCache']);
// gulp.watch(path2csWeb + 'csComp/includes/**/*.css', ['include_css']);
// gulp.watch(path2csWeb + 'csComp/includes/**/*.js', ['include_js']);
// gulp.watch(path2csWeb + 'csComp/includes/images/*.*', ['include_images']);
});
//gulp.task('all', ['create_templateCache', 'copy_csServerComp', 'built_csServerComp.d.ts', 'copy_csServerComp_scripts', 'built_csComp', 'built_csComp.d.ts', 'include_css', 'include_js', 'include_images', 'copy_example_scripts', 'sass']);
gulp.task('deploy', ['dist_client', 'deploy-githubpages']);
gulp.task('default', ['copy_servercomponents','init','watch']);