-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathgulpfile.js
More file actions
69 lines (61 loc) · 1.67 KB
/
Copy pathgulpfile.js
File metadata and controls
69 lines (61 loc) · 1.67 KB
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
'use strict';
var gulp = require('gulp');
var concat = require('gulp-concat');
var browserify = require('browserify');
var replace = require('gulp-replace');
var fs = require('fs');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var del = require('del');
/**
* Concatenate all dictionaries
*/
gulp.task('concat', function() {
return gulp.src('./data/*.txt')
.pipe(concat('data.txt'))
.pipe(gulp.dest('./dist/tmp/'));
});
/**
* Copy all files in libs
*/
gulp.task('copy', function() {
return gulp.src(['./lib/*.js'])
.pipe(gulp.dest('./dist/tmp'));
});
/**
* Replace the dynamic files path of dictionaries with the static concatenated file
*/
gulp.task('replace', ['copy'], function() {
return gulp.src('./dist/tmp/dict.js')
.pipe(replace(/files = this\.sortuniq\(this\.flatten\(files\.map\(function\(x\)\{return glob\.sync\(x\)\}\)\)\)/, ''))
.pipe(replace(/files.length/, 1))
.pipe(replace(/files\[i\]/, '"./dist/tmp/data.txt"'))
.pipe(gulp.dest('./dist/tmp'));
});
/**
* Browserify the wordcut.js and export it as "wordcut"
*/
gulp.task('brfs', ['copy', 'concat', 'replace'], function() {
var file = './dist/tmp/wordcut.js';
return browserify(file)
.transform('brfs')
.require(file, {expose: 'wordcut'})
.bundle()
.pipe(fs.createWriteStream('./dist/wordcut.js'));
});
/**
* Minify
*/
gulp.task('min', ['brfs'], function() {
return gulp.src('./dist/wordcut.js')
.pipe(uglify())
.pipe(rename('wordcut.min.js'))
.pipe(gulp.dest('./dist'));
});
/**
* Remove tmp files
*/
gulp.task('rm', ['brfs'], function() {
return del(['./dist/tmp']);
});
gulp.task('build', ['copy', 'concat', 'replace', 'brfs', 'min', 'rm']);