@jirawatpyk/aura-react 5.1.1 → 5.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,17 +5,42 @@
5
5
  import fs from 'node:fs';
6
6
  import { createTheme } from '../dist/esm/theme.js';
7
7
 
8
+ const USAGE = 'Usage: aura-theme --brand "#0ea5e9" [--signal "#facc15"] [--primary ink|brand] [--name acme] [--selector .tenant] [--out theme.css]';
9
+ const KNOWN = ['brand', 'signal', 'primary', 'name', 'selector', 'out', 'help'];
10
+ function fail(msg) {
11
+ console.error('aura-theme: ' + msg + '\n' + USAGE);
12
+ process.exit(2);
13
+ }
14
+ /* --key value and --key=value (5.2); a value-taking option with no value is an error, not `true`. */
8
15
  const args = {};
9
16
  for (let i = 2; i < process.argv.length; i++) {
10
17
  const a = process.argv[i];
11
- if (a.startsWith('--')) { const k = a.slice(2); const v = process.argv[i + 1] && !process.argv[i + 1].startsWith('--') ? process.argv[++i] : true; args[k] = v; }
18
+ if (!a.startsWith('--')) fail('unexpected "' + a + '"');
19
+ const eq = a.indexOf('=');
20
+ const k = eq > 0 ? a.slice(2, eq) : a.slice(2);
21
+ if (KNOWN.indexOf(k) < 0) fail('unknown option --' + k);
22
+ if (k === 'help') { args.help = true; continue; }
23
+ const v = eq > 0 ? a.slice(eq + 1) : process.argv[i + 1] !== undefined && !process.argv[i + 1].startsWith('--') ? process.argv[++i] : undefined;
24
+ if (v === undefined || v === '') fail('--' + k + ' needs a value');
25
+ args[k] = v;
26
+ }
27
+ if (args.help) {
28
+ console.log(USAGE);
29
+ process.exit(0);
30
+ }
31
+ if (!args.brand) fail('--brand is required');
32
+ for (const k of ['brand', 'signal']) {
33
+ if (args[k] !== undefined && /^(?:[0-9a-f]{3}|[0-9a-f]{6})$/i.test(args[k])) args[k] = '#' + args[k]; /* a shell ate the # */
34
+ if (args[k] !== undefined && !/^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i.test(args[k])) fail('--' + k + ' must be a #rgb or #rrggbb colour (got "' + args[k] + '"; quote it in the shell: --' + k + ' "#0ea5e9")');
12
35
  }
13
- if (!args.brand || args.help) {
14
- console.log('Usage: aura-theme --brand "#0ea5e9" [--signal "#facc15"] [--primary ink|brand] [--name acme] [--selector .tenant] [--out theme.css]');
15
- process.exit(args.help ? 0 : 1);
36
+ if (args.primary !== undefined && args.primary !== 'ink' && args.primary !== 'brand') fail('--primary is ink or brand');
37
+ let t, css;
38
+ try {
39
+ t = createTheme({ brand: args.brand, signal: args.signal, primary: args.primary, name: args.name });
40
+ css = t.css(args.selector);
41
+ } catch (e) {
42
+ fail(e.message);
16
43
  }
17
- const t = createTheme({ brand: args.brand, signal: args.signal, primary: args.primary, name: args.name });
18
- const css = t.css(args.selector);
19
44
  if (args.out) fs.writeFileSync(args.out, css); else process.stdout.write(css);
20
45
  const log = args.out ? console.log : console.error;
21
46
  log(`\nContrast checks (${t.checks.filter((c) => c.pass).length}/${t.checks.length} pass):`);