-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·39 lines (36 loc) · 1.02 KB
/
index.js
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
#!/usr/bin/env node
import { pipeline } from 'node:stream/promises';
import { Transform, Readable } from 'node:stream';
import yargs from 'yargs';
import { generateCss } from './primo-style.js';
const argv = yargs(process.argv.slice(2))
.option('server', {
alias: 's',
describe: 'Primo VE server (e.g. panda.primo.exlibrisgroup.com)'
})
.option('file', {
alias: 'f',
describe: 'Custom colors JSON file'
})
.demandOption(['server', 'file'])
.argv;
const colorHookFilter = () => {
let inColorHook = false;
const isHookStart = chunk => chunk.includes('/* primary color hook */');
const isHookEnd = chunk => chunk.includes('/* primary color hook end*/');
return new Transform({
transform(chunk, _, next) {
if (inColorHook ||= isHookStart(chunk)) {
this.push(chunk + "\n");
inColorHook = !isHookEnd(chunk);
}
next();
}
})
}
const css = await generateCss(argv.server, argv.file);
await pipeline(
Readable.from(css.split("\n")),
colorHookFilter(),
process.stdout,
)