-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
63 lines (47 loc) · 1.76 KB
/
Copy pathgulpfile.js
File metadata and controls
63 lines (47 loc) · 1.76 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
const {readdir, writeFile, mkdir} = require('fs/promises');
const {join} = require('path');
const {spawn} = require('child_process');
const gulp = require('gulp');
const sass = require('sass');
const PROJECT_ROOT = __dirname;
const NG = `"${join(PROJECT_ROOT, 'node_modules', '.bin', 'ng')}"`;
const N_CORE = join(PROJECT_ROOT, 'projects', 'naisc-core');
const N_CORE_DEST = join(PROJECT_ROOT, 'dist', 'naisc-core');
function build() {
return new Promise(resolve => {
console.log();
const buildProc = spawn(NG, ['build', 'naisc-core'], {
cwd: PROJECT_ROOT,
shell: true,
stdio: 'inherit',
env: process.env
});
process.on('exit', () => buildProc.kill());
buildProc.on('exit', () => {
console.log();
resolve();
});
});
}
async function themesBuild() {
const sourcePath = join(N_CORE, 'src', 'resources', 'themes', 'pre-built');
const targetPath = join(N_CORE_DEST, 'themes', 'pre-built');
await mkdir(targetPath, {recursive: true});
for (const file of await readdir(sourcePath)) {
if (!/^[^_].*\.scss$/.test(file)) continue;
const source = join(sourcePath, file);
const target = join(targetPath, file.replace(/\.scss$/, '.css'));
const compiled = sass.compile(source);
await writeFile(target, compiled.css, {encoding: 'utf-8'});
}
}
function themesCopyBuilder() {
const source = join(N_CORE, 'src', 'resources', 'themes', '*.scss');
const target = join(N_CORE_DEST, 'themes');
return gulp.src(source).pipe(gulp.dest(target));
}
gulp.task('themes:build', themesBuild);
gulp.task('themes:copy-builder', themesCopyBuilder);
gulp.task('themes', gulp.series('themes:build', 'themes:copy-builder'));
gulp.task('build:compile', build);
gulp.task('build', gulp.series('build:compile', 'themes'));