-
Notifications
You must be signed in to change notification settings - Fork 14
/
gulpfile.js
106 lines (93 loc) · 2.83 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
/* eslint-env node */
const path = require('path');
const {task, src, dest, series, parallel} = require('gulp');
const sass = require('gulp-dart-sass');
const replace = require('gulp-replace');
const alias = require('gulp-ts-alias');
const ts = require('gulp-typescript');
const rimraf = require('rimraf');
const BUILD_CLIENT_DIR = path.resolve('build');
const ESM_DIR = 'esm';
const CJS_DIR = 'cjs';
task('clean', (done) => {
rimraf.sync(BUILD_CLIENT_DIR);
rimraf.sync('styles/**/*.css');
done();
});
function compileTs(modules = false) {
const tsProject = ts.createProject('tsconfig.json', {
declaration: true,
module: modules ? 'esnext' : 'commonjs',
});
return src([
'src/**/*.{ts,tsx}',
'!src/stories/**/*',
'!src/**/__stories__/**/*',
'!src/**/__tests__/**/*',
'!src/server.ts',
'!src/configure.ts',
'!src/widget/**/*',
'!test-utils/**/*',
])
.pipe(
replace(/import '.+\.scss';/g, (match) =>
modules ? match.replace('.scss', '.css') : '',
),
)
.pipe(alias(tsProject.config))
.pipe(tsProject())
.pipe(dest(path.resolve(BUILD_CLIENT_DIR, modules ? ESM_DIR : CJS_DIR)));
}
task('compile-to-esm', () => {
return compileTs(true);
});
task('compile-to-cjs', () => {
return compileTs();
});
task('copy-js-declarations', () => {
return src([
'src/**/*.d.ts',
'!src/stories/**/*.d.ts',
'!src/**/__stories__/**/*.d.ts',
'!src/**/__tests__/**/*.d.ts',
'!test-utils/**/*.d.ts',
'!src/widget/**/*',
])
.pipe(dest(path.resolve(BUILD_CLIENT_DIR, ESM_DIR)))
.pipe(dest(path.resolve(BUILD_CLIENT_DIR, CJS_DIR)));
});
task('copy-json', () => {
return src(['src/**/i18n/*.json', `src/**/templates/*.json`])
.pipe(dest(path.resolve(BUILD_CLIENT_DIR, ESM_DIR)))
.pipe(dest(path.resolve(BUILD_CLIENT_DIR, CJS_DIR)));
});
task('styles-global', () => {
return src('styles/styles.scss')
.pipe(
sass({
includePaths: ['node_modules'],
}).on('error', sass.logError),
)
.pipe(dest('styles'));
});
task('styles-components', () => {
return src([`src/**/*.scss`, `!src/**/__stories__/**/*.scss`, '!src/widget/**/*.scss'])
.pipe(
sass({
includePaths: ['node_modules'],
}).on('error', sass.logError),
)
.pipe(dest(path.resolve(BUILD_CLIENT_DIR, ESM_DIR)))
.pipe(dest(path.resolve(BUILD_CLIENT_DIR, CJS_DIR)));
});
task(
'build',
series([
'clean',
parallel(['compile-to-esm', 'compile-to-cjs']),
'copy-js-declarations',
'copy-json',
parallel(['styles-global', 'styles-components']),
]),
);
task('default', series(['build']));