-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathbuild.ts
78 lines (70 loc) · 2.17 KB
/
build.ts
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
import { from as observableFrom, forkJoin as observableForkJoin, Observable } from 'rxjs';
import { switchMap, tap } from 'rxjs/operators';
import { copy, outputFile } from 'fs-extra';
import { render } from 'sass';
const pkg = require(`${process.cwd()}/package.json`);
const cssProcessConfig = {
inputPath: `${process.cwd()}/src/lib/ui-switch/`,
outputPath: `${process.cwd()}/dist/`,
filename: 'ui-switch.component',
};
function getVersions() {
const paths = [`${process.cwd()}/dist/package.json`];
return paths.map(path => require(path)).map(pkgs => pkgs.version);
}
function verifyVersions() {
const versions = getVersions();
console.log(versions);
versions.map(version => {
if (version !== pkg.version) {
throw new Error('Versions mismatch');
}
});
}
function copyFiles() {
console.log('copying files');
return observableForkJoin([
observableFrom(copy(`${process.cwd()}/LICENSE`, `${process.cwd()}/dist/LICENSE`)),
observableFrom(copy(`${process.cwd()}/README.md`, `${process.cwd()}/dist/README.md`)),
observableFrom(copy(`${process.cwd()}/logo.png`, `${process.cwd()}/dist/logo.png`)),
observableFrom(
copy(
`${cssProcessConfig.inputPath}${cssProcessConfig.filename}.scss`,
`${cssProcessConfig.outputPath}${cssProcessConfig.filename}.scss`
)
),
]);
}
function compileCss() {
console.log('compiling css');
return new Observable(observer => {
render(
{ file: `${cssProcessConfig.inputPath}${cssProcessConfig.filename}.scss` },
(error, compiled) => {
if (error) {
observer.error(error);
} else {
observer.next(compiled);
}
}
);
});
}
function saveCss(compiled) {
return observableFrom(
outputFile(`${cssProcessConfig.outputPath}${cssProcessConfig.filename}.css`, compiled.css)
);
}
function buildLibrary() {
const copyFiles$ = copyFiles();
return copyFiles$.pipe(
switchMap(() => compileCss()),
switchMap(result => saveCss(result)),
tap(() => verifyVersions())
);
}
buildLibrary().subscribe({
next: () => console.log('success'),
error: err => console.log('err', err),
complete: () => console.log('complete'),
});