forked from AlaSQL/alasql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
313 lines (290 loc) · 8.41 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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
//
// gulpfile.js
// Gulp for Alasql
// Дата: 06.08.2014
// (c) 2014-2015, Andrey Gershun
//
var exec = require('child_process').exec;
var fs = require('fs');
var gulp = require('gulp');
var jison = require('gulp-jison');
module.exports = gulp;
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var shell = require('gulp-exec');
var rename = require('gulp-rename');
var argv = require('yargs').argv || {};
var replace = require('gulp-replace');
var execSync = require('child_process').execSync;
// Identify name of the build
var packageData = require('./package.json'); // JSON.parse(fs.readFileSync('package.json', 'utf8'));
var packageVersion = packageData.version;
var branch = execSync(
'git --work-tree="' + __dirname + '" --git-dir="' + __dirname + '/.git" branch',
{encoding: 'utf8'}
)
.match(/^\*\s+(.*)/m)[1]
.trim();
var hint = execSync('git rev-parse --short HEAD', {encoding: 'utf8'});
let buildVersion = [
branch.replace(/[^0-9a-z-]/gi, '.').replace(/^\.+|\.+$/g, ''),
hint.replace(/[^0-9a-z-]/gi, ''),
]
.filter(Boolean)
.join('-');
gulp.task('js-merge-worker', function () {
return gulp
.src([
'./src/05copyright.js',
'./src/99worker-start.js',
'./src/99worker.js',
'./src/99worker-finish.js',
])
.pipe(concat('alasql-worker.js'))
.pipe(replace(/PACKAGE_VERSION/g, packageVersion))
.pipe(replace(/BUILD_VERSION/g, buildVersion))
.pipe(gulp.dest('./dist'))
.pipe(rename('alasql-worker.min.js'))
.pipe(
uglify({
output: {
comments: function (a, b) {
return 1 === b.line && /^!/.test(b.value);
},
},
})
) // leave first line of comment if starts with a "!"
.pipe(gulp.dest('./dist'));
});
gulp.task('js-merge', function () {
return gulp
.src([
'./src/05copyright.js',
'./src/10start.js',
'./src/alasqlparser.js',
'./src/12pretty.js',
'./src/15utility.js',
'./src/16comments.js',
'./src/17alasql.js',
'./src/18promise.js',
'./src/20database.js',
'./src/21transaction.js',
// './src/22store.js',
'./src/23table.js',
'./src/24view.js',
'./src/25queryclass.js',
'./src/28yy.js',
'./src/30statements.js',
'./src/35search.js',
'./src/38query.js',
'./src/39dojoin.js',
'./src/40select.js',
'./src/41exists.js',
'./src/420from.js',
'./src/421join.js',
'./src/422where.js',
'./src/423groupby.js',
'./src/424select.js',
'./src/425having.js',
'./src/426orderby.js',
'./src/427pivot.js',
'./src/43rollup.js',
'./src/44defcols.js',
'./src/45union.js',
'./src/46apply.js',
'./src/47over.js',
'./src/50expression.js',
'./src/52linq.js',
'./src/55functions.js',
// './src/56sprintf.js',
'./src/57case.js',
'./src/58json.js',
'./src/59convert.js',
'./src/60createtable.js',
'./src/61date.js',
'./src/62droptable.js',
'./src/63createvertex.js',
'./src/64altertable.js',
'./src/65createindex.js',
'./src/66dropindex.js',
'./src/67withselect.js',
'./src/68if.js',
'./src/69while.js',
'./src/70insert.js',
'./src/71trigger.js',
'./src/72delete.js',
'./src/74update.js',
// './src/74update.js',
'./src/75merge.js',
'./src/76usedatabase.js',
'./src/77declare.js',
'./src/78show.js',
'./src/79set.js',
'./src/80console.js',
'./src/81commit.js',
'./src/821tsql.js',
'./src/822mysql.js',
'./src/823postgres.js',
'./src/824oracle.js',
'./src/825sqlite.js',
'./src/830into.js',
'./src/831xls.js',
'./src/832xlsxml.js',
'./src/833xlsx.js',
// './src/839zip.js', // To be added later in XLSX plugin
'./src/84from.js',
'./src/843xml.js',
'./src/844gexf.js',
// './src/85help.js',
'./src/86print.js',
'./src/87source.js',
'./src/88require.js',
'./src/89assert.js',
'./src/91indexeddb.js',
'./src/92localstorage.js',
'./src/93sqljs.js',
'./src/94filestorage.js',
'./src/97saveas.js',
'./src/99worker.js',
'./src/FileSaver.js',
'./src/98finish.js',
])
.pipe(concat('alasql.fs.js'))
.pipe(replace(/\/\*\/\*[\S\s]+?\*\//g, '')) // Remove multiline comments starting with "/*/*"
.pipe(replace(/^\/\/[ \t]{2,}.*/gm, '')) // Remove single line comments where the // part is first thing and content does not follow imidiatly (probably a "just test" line)
.pipe(replace(/\/\/.*?console\.log\(.*/gm, '')) // Remove single line comments 'console.log(' is part of the line
.pipe(replace(/\n[\s]+\n/g, '\n\n')) // Collaps multilinebreak
.pipe(replace(/PACKAGE_VERSION/g, packageVersion))
.pipe(replace(/BUILD_VERSION/g, buildVersion))
.pipe(gulp.dest('./dist'))
.pipe(replace(/\/\/\*not-for-browser\/\*/g, '/*not-for-browser/*')) // Remove things not for browser build
.pipe(replace(/\/\*only-for-browser\/\*/g, '//*only-for-browser/*')) // Reveal things only for browser build
.pipe(
replace(
/function locateNearestErrorRecoveryRule\(state\) \{/g,
'var locateNearestErrorRecoveryRule = function (state) {'
)
) // Support "use strict" https://github.com/zaach/jison/pull/373
.pipe(rename('alasql.js'))
.pipe(gulp.dest('./dist'))
.pipe(rename('alasql.min.js'))
.pipe(
uglify({
output: {
comments: function (a, b) {
return 1 === b.line && /^!/.test(b.value);
},
},
})
) // leave first line of comment if starts with a "!"
.pipe(gulp.dest('./dist'));
});
gulp.task('jison-compile', function () {
return gulp
.src('./src/alasqlparser.jison')
.pipe(jison({moduleType: 'commonjs', moduleName: 'alasqlparser'}))
.pipe(gulp.dest('./src/'));
});
gulp.task('copy-dist-org', function () {
return gulp
.src([
'./dist/alasql.min.js',
'./dist/alasql-worker.min.js',
'/dist/alasql-echo.js',
'/dist/alasql-md.js',
])
.pipe(gulp.dest('./console/'));
});
// Additional task to update alasql.org/console directory
gulp.task('copy-console-org', function () {
return gulp.src(['./dist/*']).pipe(gulp.dest('../alasql-org/console/'));
});
/************************/
// Echo plugin
gulp.task('typescript', function () {
return gulp.src(['types/alasql.d.ts']).pipe(gulp.dest('./dist'));
});
// Echo plugin
gulp.task('plugin-plugins', function () {
return gulp
.src(['./src/echo/alasql-echo.js' /*, './src/md/alasql-md.js'*/])
.pipe(gulp.dest('./dist'));
});
// Echo plugin
gulp.task('plugin-prolog', function () {
return gulp.src(['./src/prolog/alasql-prolog.js']).pipe(gulp.dest('./dist'));
});
var toRun = ['js-merge', 'js-merge-worker', 'plugin-prolog', 'plugin-plugins', 'typescript'];
if (argv.jison) {
toRun = ['jison-compile'];
}
// Главная задача
gulp.task(
'default',
gulp.series(...toRun, function (done) {
done();
})
);
gulp.task(
'watch',
gulp.series(...toRun, function () {
gulp.watch('./src/*.js', function () {
gulp.run('js-merge');
});
gulp.watch('./src/99worker*.js', function () {
gulp.run('js-merge-worker');
});
gulp.watch('./src/alasqlparser.jison', function () {
gulp.run('jison-compile');
});
gulp.watch('types/alasql.d.ts', function () {
gulp.run('typescript');
});
gulp.watch('./src/echo/*.js', function () {
gulp.run('plugin-plugins');
});
gulp.watch('./src/md/*.js', function () {
gulp.run('plugin-plugins');
});
gulp.watch('./src/prolog/*.js', function () {
gulp.run('plugin-prolog');
});
//gulp.watch('./dist/alasql.js',function(){ gulp.run('uglify'); });
gulp.watch('./dist/alasql.min.js', function () {
// gulp.run('copy-dist');
gulp.run('copy-dist-org');
});
gulp.watch('./dist/alasql-worker.js', function () {
// gulp.run('copy-dist');
gulp.run('copy-dist-org');
});
gulp.watch('./dist/alasql.min.js', function () {
console.log('Initiating mocha test...');
exec('npm run test:only', console.log);
});
// gulp.watch('./console/*',function(){ gulp.run('copy-console-org'); });
// gulp.watch('./src/*.jison',function(){ gulp.run('jison-compile'); gulp.run('js-merge');});
// gulp.watch('./src/*.jisonlex',function(){ gulp.run('jison-lex-compile'); gulp.run('js-merge');});
})
);
gulp.task(
'fast',
gulp.series('js-merge' /*, 'jison-compile', 'jison-lex-compile' */, function (done) {
gulp.watch('./src/alasqlparser.jison', function () {
gulp.run('jison-compile');
});
gulp.watch('./src/*.js', function () {
gulp.run('js-merge');
});
done();
})
);
gulp.task('doc', function () {
return gulp
.src('./alasql.js', {read: false})
.pipe(shell('jsdoc dist/alasql.js -d ../alasql-org/api'));
});
gulp.task('console', function (done) {
gulp.run('copy-console-org');
done();
});