-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-css.js
More file actions
executable file
·65 lines (54 loc) · 1.57 KB
/
build-css.js
File metadata and controls
executable file
·65 lines (54 loc) · 1.57 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
64
65
#!/usr/bin/env node
import * as esbuild from 'esbuild';
import fs from 'fs';
import path from 'path';
// CSS file index for bundle
const indexCSS = 'source/css/_index.css';
// Get target application/deployment from the arguments
const deployTier = process.argv[2] || 'unspecified';
// Verify valid application/deployment
if (!['dev', 'prod'].includes(deployTier)) {
console.log(
`\x1b[33mWarning:\x1b[0m Invalid deployTier "\x1b[31m${deployTier}\x1b[0m\n".
\t Use: \x1b[1mnpm run build:css -- <dev|prod>\x1b[0m\n`,
);
process.exit(1);
}
// Set the destination for the CSS output
const deployDir = path.join('docs/', deployTier, '/css/');
function verifyDeployDir(dir) {
fs.mkdirSync(dir, { recursive: true });
}
/**
* Build the formatted and minified CSS files
*/
async function buildCSS(deployDir) {
try {
verifyDeployDir(deployDir);
const cssFormatted = path.join(deployDir, 'main.css');
const cssMinified = path.join(deployDir, 'main.min.css');
await Promise.all([
// Formatted CSS
esbuild.build({
entryPoints: [indexCSS],
bundle: true,
outfile: cssFormatted,
minify: false,
write: true,
}),
// Minified CSS
esbuild.build({
entryPoints: [indexCSS],
bundle: true,
outfile: cssMinified,
minify: true,
write: true,
}),
]);
console.log(`\n\x1b[32m\t\u2713 CSS for ${deployTier} written to ${deployDir}\x1b[0m\n`);
} catch (error) {
console.error('\x1b[31mBuild failed\x1b[0m]', error);
process.exit(1);
}
}
buildCSS(deployDir);