-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
126 lines (111 loc) · 3.55 KB
/
gulpfile.js
File metadata and controls
126 lines (111 loc) · 3.55 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
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
var gulp = require('gulp'),
gutil = require('gulp-util'),
mocha = require('gulp-mocha'),
sass = require('gulp-sass'),
webpack = require('webpack'),
uglify = require('gulp-uglify'),
documentation = require('gulp-documentation'),
rename = require('gulp-rename'),
del = require('del'),
fs = require('fs');
var HEADER = './src/header.js',
VERSION = './build/version.js',
TARGET_FILE = 'quant.js',
SRC_DIR = __dirname + '/src/',
TEST_DIR = __dirname + '/test/',
DOCS_DIR = __dirname + '/docs/',
BUILD_DIR = __dirname + '/build/',
ASSET_DIR = '/assets',
DIST_DIR = __dirname + '/dist/';
function createBanner() {
var today = gutil.date(new Date(), 'yyyy-mm-dd'); // today, formatted as yyyy-mm-dd
var version = require('./package.json').version;
var year = gutil.date(new Date(), 'yyyy');
return String(fs.readFileSync(HEADER))
.replace('@@date', today)
.replace('@@year', year)
.replace('@@version', version);
}
function updateVersionFile() {
var version = require('./package.json').version;
fs.writeFileSync(VERSION, 'module.exports = \'' + version + '\';\n' +
'// Note: This file is automatically generated when building quant.js.\n' +
'// Changes made in this file will be overwritten.\n');
}
var webpackConfig = require('./webpack.config');
webpackConfig.plugins = [
new webpack.BannerPlugin({
banner: createBanner(),
entryOnly: true,
raw: true
}),
];
var compiler = webpack(webpackConfig);
var uglifyConfig = {
sourceMap: true,
output: {
comments: /@license/
}
};
gulp.task('bundle', ['html','build'], function (cb) {
compiler.run(function (err, stats) {
if (err) {
gutil.log(err);
}
cb();
});
});
gulp.task('minify', ['bundle'], function () {
return gulp.src(DIST_DIR + TARGET_FILE)
.pipe(uglify(uglifyConfig))
.on('error', function (err) { gutil.log(gutil.colors.red('[Error]'), err.toString()); })
.pipe(rename({ extname: '.min.js' }))
.pipe(gulp.dest(DIST_DIR));
});
gulp.task('html', ['html-copy'], function() {
return gulp.src(BUILD_DIR + '**/*.html')
.pipe(gulp.dest(DIST_DIR));
});
gulp.task('html-copy', function() {
return gulp.src(SRC_DIR + '**/*.html')
.pipe(gulp.dest(BUILD_DIR));
});
gulp.task('style', function() {
return gulp.src(SRC_DIR + '**/*.scss')
.pipe(sass({outputStyle: 'expanded'}))
.pipe(gulp.dest(BUILD_DIR + ASSET_DIR));
});
gulp.task('js-copy', function() {
return gulp.src([SRC_DIR + '**/*.js', '!'+HEADER])
.pipe(gulp.dest(BUILD_DIR));
});
gulp.task('test', ['build'], function() {
return gulp.src([TEST_DIR + "**/*test.js"], {read: false})
.pipe(mocha({reporter: 'spec'}))
.on('error', function(){});
});
gulp.task('docs', function () {
return gulp.src([BUILD_DIR + '**/*.js'])
.pipe(documentation('md'))
.pipe(gulp.dest(DOCS_DIR));
});
gulp.task('watch', function () {
gulp.watch(
[ __dirname + '/app.js',
__dirname + '/main.js',
SRC_DIR + '**/*.js'
], ['bundle','test']);
gulp.watch([SRC_DIR + '**/*.scss'], ['bundle']);
gulp.watch([SRC_DIR + '**/*.html'], ['html']);
});
gulp.task('build', ['html-copy','style','js-copy'], function() {
updateVersionFile();
});
gulp.task('compile', ['build']);
gulp.task('coverage', ['test']);
gulp.task('clean', del.bind(null, [BUILD_DIR, DIST_DIR,'**/*.log']));
gulp.task('dist-clean', ['clean'], del.bind(null,
[ __dirname + '/node_modules',
__dirname + '/coverage',
]));
gulp.task('default', ['bundle','minify','docs']);