-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
142 lines (122 loc) · 3.52 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
/* jshint node: true */
const gulp = require('gulp');
const clean = require('gulp-clean');
const gulpConcat = require('gulp-concat');
const gulpConnect = require('gulp-connect');
const replace = require('gulp-replace');
const babel = require('gulp-babel');
const argv = require('yargs').argv;
const pkg = require('./package.json');
const fs = require('fs');
const replaceString = require('replace-string');
const NAME_TOKEN = '%%DRIVERNAME%%';
const BASE = 'component/';
const DIST = 'dist/';
const TMP = 'tmp/';
const ASSETS = 'assets/';
const DRIVER_NAME = argv.name || pkg.name.replace(/^ui-driver-/, '');
console.log('Driver Name:', DRIVER_NAME);
if (!DRIVER_NAME) {
console.log('Please include a driver name with the --name flag');
process.exit(1);
}
gulp.task('watch', function () {
gulp.watch(['./component/*.js', './component/*.hbs', './component/*.css'], gulp.parallel('build'));
});
gulp.task('clean', function () {
return gulp.src([`${DIST}*.js`, `${DIST}*.css`, `${DIST}*.hbs`, `${TMP}*.js`, `${TMP}*.css`, `${TMP}*.hbs`,], { read: false })
.pipe(clean());
});
gulp.task('styles', gulp.series('clean', function () {
return gulp.src([
BASE + '**.css'
])
.pipe(replace(NAME_TOKEN, DRIVER_NAME))
.pipe(gulpConcat(`component.css`, { newLine: ';\n' }))
.pipe(gulp.dest(DIST));
}));
gulp.task('assets', gulp.series('styles', function () {
return gulp.src(ASSETS + '*')
.pipe(gulp.dest(DIST));
}));
gulp.task('babel', gulp.series('assets', function () {
const babelOpts = {
presets: [
[
"@babel/preset-env", {
targets: {
browsers: ["> 1%"]
}
}]
],
plugins: [
"add-module-exports",
[
"transform-es2015-modules-amd", {
"noInterop": true,
}
]
],
comments: false,
moduleId: `nodes/components/driver-${DRIVER_NAME}/component`
};
let hbs = fs.readFileSync(`${BASE}template.hbs`, 'utf8');
hbs = replaceString(hbs, NAME_TOKEN, DRIVER_NAME);
hbs = Buffer.from(hbs).toString('base64');
return gulp.src([
`${BASE}component.js`
])
.pipe(replace('const LAYOUT;', `const LAYOUT = "${hbs}";`))
.pipe(replace(NAME_TOKEN, DRIVER_NAME))
.pipe(babel(babelOpts))
.pipe(gulpConcat(`component.js`, { newLine: ';\n' }))
.pipe(gulp.dest(TMP));
}));
gulp.task('rexport', gulp.series('babel', function () {
const babelOpts = {
presets: [
[
"@babel/preset-env", {
targets: {
browsers: ["> 1%"]
}
}]
],
plugins: [
"add-module-exports",
[
"transform-es2015-modules-amd", {
"noInterop": true,
}
]
],
comments: false,
moduleId: `ui/components/driver-${DRIVER_NAME}/component`
};
return gulp.src([
`${BASE}rexport.js`
])
.pipe(replace(NAME_TOKEN, DRIVER_NAME))
.pipe(babel(babelOpts))
.pipe(gulpConcat(`rexport.js`, { newLine: ';\n' }))
.pipe(gulp.dest(TMP));
}));
gulp.task('compile', gulp.series('rexport', function () {
return gulp.src([
`${TMP}**.js`
])
.pipe(gulpConcat(`component.js`, { newLine: ';\n' }))
.pipe(gulp.dest(DIST));
}));
gulp.task('build', gulp.series('compile'));
gulp.task('server', gulp.parallel(['build', 'watch'], function () {
return gulpConnect.server({
root: [DIST],
port: process.env.PORT || 3000,
https: false,
});
}));
gulp.task('default', gulp.series('build'));
gulp.task('watch', function () {
gulp.watch(['./component/*.js', './component/*.hbs', './component/*.css'], gulp.parallel('build'));
});