-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
159 lines (133 loc) · 4.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
var gulp = require('gulp');
var del = require('del');
var merge = require('merge-stream');
var plugins = require('gulp-load-plugins')();
var browserSync = require('browser-sync').create();
var browserify = require("browserify");
var source = require('vinyl-source-stream');
var tsify = require("tsify");
var sourcemaps = require('gulp-sourcemaps');
var buffer = require('vinyl-buffer');
/* nicer browserify errors */
var gutil = require('gulp-util');
var chalk = require('chalk');
var projectName= "odc-d3"
gulp.task('clean', function (cb) {
return del(['tmp', 'dist'], cb);
});
gulp.task('build-css', function () {
var fileName = projectName;
return gulp.src('./src/styles/*')
.pipe(plugins.plumber({ errorHandler: onError }))
.pipe(plugins.sass())
.pipe(plugins.concat(fileName+'.css'))
.pipe(gulp.dest('./dist'))
.pipe(plugins.cleanCss())
.pipe(plugins.rename({ extname: '.min.css' }))
.pipe(gulp.dest('./dist'));
});
gulp.task('build-js2', function () {
var jsFileName = projectName;
return gulp.src('./src/*.js')
.pipe(plugins.plumber({ errorHandler: onError }))
.pipe(plugins.babel({
presets: ['es2015']
}))
.pipe(plugins.concat(jsFileName+'.js'))
.pipe(gulp.dest('dist'))
.pipe(plugins.stripDebug())
.pipe(plugins.uglify())
.pipe(plugins.rename({ extname: '.min.js' }))
.pipe(gulp.dest('dist'));
});
gulp.task('copy-global-d3', function () {
return gulp.src("./src/d3_global.js")
.pipe(plugins.rename({
basename: "d3"
}))
.pipe(gulp.dest('./src/'))
});
gulp.task('do-build-js', gulp.series('copy-global-d3', function () {
return buildJs(projectName, "dist")
}));
gulp.task('build-js', gulp.series('do-build-js', function () {
return gulp.src("./src/d3_import.js")
.pipe(plugins.rename({
basename: "d3"
}))
.pipe(gulp.dest('./src/'))
}));
gulp.task('build-js-standalone', function () {
return buildJs(projectName, "dist/standalone");
});
function buildJs(jsFileName, dest) {
return browserify({
basedir: '.',
debug: true,
entries: ['src/index.js'],
cache: {},
packageCache: {},
standalone: 'ODCD3'
})
.transform("babelify", {presets: ["@babel/preset-env"], plugins: ["transform-class-properties"]})
.bundle()
.on('error', map_error)
.pipe(plugins.plumber({ errorHandler: onError }))
.pipe(source(jsFileName+'.js'))
.pipe(gulp.dest(dest))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(plugins.stripDebug())
.pipe(plugins.uglify())
.pipe(plugins.rename({ extname: '.min.js' }))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(dest));
}
gulp.task('build', gulp.parallel('build-css', 'build-js'));
gulp.task('build-clean', gulp.series('clean', 'build'));
gulp.task('watch', function() {
return gulp.watch(['./src/**/*.html', './src/styles/*.*css', 'src/**/*.js' , "!src/d3.js"], ['default']);
});
gulp.task('default', gulp.series('build-clean', 'build-js-standalone'));
gulp.task('default-watch', gulp.series('default', ()=>{ browserSync.reload() }));
gulp.task('serve', gulp.series('default', ()=>{
browserSync.init({
server: {
baseDir: "examples",
index: "index.html",
routes: {
"/bower_components": "bower_components",
"/dist": "dist"
}
},
port: 8089,
open: 'local',
browser: "google chrome"
});
gulp.watch(['i18n/**/*.json', './src/**/*.html', './src/styles/*.*css', 'src/**/*.js', "!src/d3.js", 'examples/**/*.*'], ['default-watch']);
}));
// error function for plumber
var onError = function (err) {
console.log('onError', err);
this.emit('end');
};
function map_error(err) {
if (err.fileName) {
// regular error
gutil.log(chalk.red(err.name)
+ ': '
+ chalk.yellow(err.fileName.replace(__dirname + '/src/js/', ''))
+ ': '
+ 'Line '
+ chalk.magenta(err.lineNumber)
+ ' & '
+ 'Column '
+ chalk.magenta(err.columnNumber || err.column)
+ ': '
+ chalk.blue(err.description))
} else {
// browserify error..
gutil.log(chalk.red(err))
}
this.emit('end');
}