-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
175 lines (143 loc) · 5.34 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
'use strict';
var gulp = require('gulp');
var gutil = require('gulp-util');
var bower = require('bower');
var ts = require('gulp-typescript');
var sourcemaps = require('gulp-sourcemaps');
var merge = require('merge2');
var server = require('gulp-server-livereload');
var typescript15 = require('typescript');
var template = require('gulp-template');
var url = require('url');
var autoprefixer = require('gulp-autoprefixer');
var minifyCss = require('gulp-minify-css');
var inject = require('gulp-inject');
var concat = require('gulp-concat');
var Cachebuster = require('gulp-cachebust');
var cachebust = new Cachebuster();
var fs = require('fs');
var intervalMS = 500;
var templateObject = {};
templateObject.keenProjectId = "yoyo";
templateObject.keenWriteKey = "yolo";
var tsProjectEmily = ts.createProject({
declarationFiles: true,
noExternalResolve: false,
module: 'commonjs',
target: 'ES5',
noEmitOnError: false,
out: 'js/app.js',
typescript: typescript15
});
gulp.task('default', ['compile']);
gulp.task('ts', function () {
intervalMS = process.argv.indexOf('--highcpu') !== -1 ? 200 : intervalMS;
var live = process.argv.indexOf('--live') !== -1;
var baseIdx = process.argv.indexOf('--base');
var production = process.argv.indexOf('--production');
var baseUrl = '';
if (baseIdx !== -1) {
baseUrl = process.argv[baseIdx + 1];
}
if(production !== -1) {
live = true;
baseIdx = 1;
baseUrl = '/api/v1';
}
templateObject.live = live || '';
templateObject.basePath = baseUrl || 'http://localhost:3001/api/v1';
var realtimeUrl = url.parse(templateObject.basePath);
var port = parseInt(realtimeUrl.port, 10) + 1;
if(baseIdx === -1) {
templateObject.basePathRealtime = url.parse(realtimeUrl.protocol + '//' + realtimeUrl.hostname + ':' + port + realtimeUrl.path + '/r').href;
} else {
templateObject.basePathRealtime = templateObject.basePath + '/r';
}
console.log(templateObject);
var tsResult = gulp.src(['./www-develop/**/*.ts', '!./www-develop/lib/components/**/*.ts'])
.pipe(template(templateObject).on('error', console.error.bind(console)))
.pipe(sourcemaps.init())
.pipe(ts(tsProjectEmily));
return merge([
tsResult.dts.pipe(gulp.dest('./www/definitions')),
tsResult.js.pipe(gulp.dest('./www'))
]);
});
gulp.task('serve', function () {
return gulp.src('www')
.pipe(server({
livereload: {
enable: false,
filter: function (filePath, cb) {
cb(!(/lib/.test(filePath)));
},
port: 3003
},
directoryListing: false,
open: true
}));
});
gulp.task('locale', function () {
gulp.src('./www-develop/locale/**/*').pipe(gulp.dest('./www/locale'));
});
gulp.task('sounds', function () {
gulp.src('./www-develop/sounds/**/*').pipe(gulp.dest('./www/sounds'));
});
gulp.task('css', function () {
var cssmin = process.argv.indexOf('--cssmin') !== -1;
if(cssmin) {
return gulp.src('./www-develop/**/*.css')
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(minifyCss({compatibility: 'ie8'}))
.pipe(gulp.dest('./www'));
} else {
return gulp.src('./www-develop/**/*.css')
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(gulp.dest('./www'));
}
});
gulp.task('html', function () {
return gulp.src('./www-develop/**/*.html').pipe(gulp.dest('./www'));
});
gulp.task('lib', function () {
return gulp.src('./www-develop/lib/**/*').pipe(gulp.dest('./www/lib'));
});
gulp.task('img', function () {
return gulp.src('./www-develop/images/**/*').pipe(gulp.dest('./www/images'));
});
gulp.task('watch', ['ts', 'html', 'lib', 'img', 'css', 'locale', 'sounds'], function () {
gulp.watch('./www-develop/**/*.ts', { interval: intervalMS }, ['ts']);
gulp.watch('./www-develop/**/*.css', { interval: intervalMS }, ['css']);
gulp.watch('./www-develop/**/*.html', { interval: intervalMS }, ['html']);
gulp.watch('./www-develop/locale/**/*', { interval: intervalMS }, ['locale']);
gulp.watch('./www-develop/images/**/*', { interval: intervalMS }, ['img']);
gulp.start('serve');
});
gulp.task('responsiveCss', function () {
return gulp.src('./www-develop/css/responsive.css').pipe(gulp.dest('./www/css'));
});
gulp.task('install', function () {
return bower.commands.install()
.on('log', function (data) {
gutil.log('bower', gutil.colors.cyan(data.id), data.message);
});
});
gulp.task('compile', ['ts', 'html', 'lib', 'img', 'locale', 'responsiveCss', 'sounds'], function() {
var target = gulp.src('./www-develop/index.html');
var sources1 = gulp.src(['./www-develop/css/**/*.css', '!./www-develop/css/response.css'])
.pipe(concat('css/all.css'))
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(minifyCss({compatibility: 'ie8'}))
.pipe(cachebust.resources())
.pipe(gulp.dest('./www'));
return target.pipe(inject(sources1, {ignorePath: 'www', addRootSlash: false})).pipe(gulp.dest('./www'));
});