-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
executable file
·49 lines (40 loc) · 973 Bytes
/
cli.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
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env node
const {
ramp,
tailwindRamp,
colorAtLightness,
namedColors,
termColorString,
} = require("./index.js");
let generator = ramp;
const printPalette = (inputColor, options = {}) => {
const terminalStrings = [];
Object.entries(generator(inputColor, options)).forEach(([code, color]) => {
terminalStrings.push(
" " + termColorString(color, `"${code}" : "${color}"`)
);
});
console.log(`{\n${terminalStrings.join(",\n")}\n}`);
};
const args = process.argv.slice(2);
const colors = [];
const optionArgs = [];
const options = {};
args.forEach((arg) => {
if (arg[0] === "#" || arg in namedColors) {
colors.push(arg);
}
if (arg.substring(0, 2) === "--") {
optionArgs.push(arg.substring(2));
}
if (arg.substring(0, 2) === "-t") {
generator = tailwindRamp;
}
});
optionArgs.forEach((option) => {
const [key, value] = option.split("=");
options[key] = value;
});
colors.forEach((color) => {
printPalette(color, options);
});