-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathbuild-repository.ts
71 lines (63 loc) · 2.15 KB
/
build-repository.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
#!/usr/bin/env ts-node
/*!
* Script to build additional assets for portal.
* Copyright 2020-2024 Chocolatey Software
* Licensed under Apache License (https://github.com/chocolatey/choco-theme/blob/main/LICENSE)
*/
import * as esbuild from 'esbuild';
import * as fs from 'fs/promises';
import { purgeCss } from './functions/purge-css';
import { repository } from './functions/determine-repository';
import { repositoryConfig } from './data/repository-config';
const init = async () => {
console.log('🚀 Compiling and minifying repository JS...');
let esbuildOptions: esbuild.BuildOptions = {
entryPoints: [''],
target: 'es2015',
bundle: true,
outdir: '',
minify: true,
outExtension: { '.js': '.min.js' }
}
switch (repository.name) {
case repositoryConfig.ccm.name:
esbuildOptions = {
...esbuildOptions,
external: ['popper.js'],
banner: {
js: `
if (typeof window !== 'undefined') {
window.require = function(module) {
if (module === 'popper.js') return window.Popper;
throw new Error('Cannot find module ' + module);
};
}
`,
},
entryPoints: [
`${repository.js}src/views/**/*.js`,
`${repository.js}src/account.js`
],
outdir: `${repository.js}dist/`
};
break;
case repositoryConfig.portal.name:
esbuildOptions = {
...esbuildOptions,
entryPoints: [`${repository.js}src/*.js`],
outdir: repository.js
};
break;
}
await esbuild.build({
...esbuildOptions
}).then(async () => {
console.log('✅ Repository JS compiled and minified');
// PurgeCSS
await purgeCss({
source: `${repository.css}${repository.name}.min.css`,
repository: repository
});
});
};
init();