generated from gravity-ui/package-example
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgulpfile.mjs
90 lines (78 loc) · 2.69 KB
/
gulpfile.mjs
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
import path from 'node:path';
import {addVirtualFile, createTypescriptProject} from '@gravity-ui/gulp-utils';
import {dest, parallel, series, src, task} from 'gulp';
import gulpSass from 'gulp-sass';
import sourcemaps from 'gulp-sourcemaps';
import * as rimraf from 'rimraf';
import * as sass from 'sass';
const BUILD_DIR = path.resolve('dist');
const sassLoader = gulpSass(sass);
task('clean', (done) => {
rimraf.sync(BUILD_DIR);
done();
});
async function compileTs(modules = false) {
const tsProject = await createTypescriptProject({
compilerOptions: {
declaration: true,
...(modules ? undefined : {verbatimModuleSyntax: false}),
module: modules ? 'esnext' : 'NodeNext',
moduleResolution: modules ? 'bundler' : 'NodeNext',
},
});
const transformers = [
tsProject.customTransformers.transformScssImports,
tsProject.customTransformers.transformLocalModules,
];
return new Promise((resolve) => {
src([
'src/**/*.{ts,tsx}',
'!src/demo/**/*',
'!src/**/__stories__/**/*',
'!src/**/__tests__/**/*',
'!src/**/*.test.{ts,tsx}',
])
.pipe(sourcemaps.init())
.pipe(
tsProject({
customTransformers: {
before: transformers,
afterDeclarations: transformers,
},
}),
)
.pipe(sourcemaps.write('.', {includeContent: true, sourceRoot: '../../src'}))
.pipe(
addVirtualFile({
fileName: 'package.json',
text: JSON.stringify({type: modules ? 'module' : 'commonjs'}),
}),
)
.pipe(dest(path.resolve(BUILD_DIR, modules ? 'esm' : 'cjs')))
.on('end', resolve);
});
}
task('compile-to-esm', () => {
return compileTs(true);
});
task('compile-to-cjs', () => {
return compileTs();
});
task('copy-i18n', () => {
return src(['src/**/i18n/*.json'])
.pipe(dest(path.resolve(BUILD_DIR, 'esm')))
.pipe(dest(path.resolve(BUILD_DIR, 'cjs')));
});
task('styles', () => {
return src(['src/**/*.scss', '!src/demo/**/*', '!src/**/__stories__/**/*'])
.pipe(sourcemaps.init())
.pipe(sassLoader({loadPaths: ['./node_modules/']}).on('error', sassLoader.logError))
.pipe(sourcemaps.write('.'))
.pipe(dest(path.resolve(BUILD_DIR, 'esm')))
.pipe(dest(path.resolve(BUILD_DIR, 'cjs')));
});
task(
'build',
series(['clean', parallel(['compile-to-esm', 'compile-to-cjs']), 'copy-i18n', 'styles']),
);
task('default', series(['build']));