astralis-cli 0.1.0 → 0.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astralis-cli",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Setup and tooling CLI for Astralis UI — wire up a project, generate a static brand theme, connect the MCP server.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -36,7 +36,7 @@
36
36
  "node": ">=18"
37
37
  },
38
38
  "dependencies": {
39
- "astralis-ui": "^0.1.3"
39
+ "astralis-ui": "^0.2.0"
40
40
  },
41
41
  "scripts": {
42
42
  "test": "node --test"
@@ -1,58 +1,130 @@
1
1
  import { parseArgs } from "node:util";
2
2
  import { existsSync, writeFileSync } from "node:fs";
3
- import { generateBrandTokens } from "astralis-ui/color-math";
3
+ import { themeCss, validateSeed, isEmptySeed } from "astralis-ui/serialize";
4
4
  import { ok, fail, cyan, dim } from "../lib/ui.mjs";
5
5
 
6
- const HEX_PATTERN = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i;
7
-
8
- const serialize = (vars) =>
9
- Object.entries(vars)
10
- .map(([name, value]) => ` ${name}: ${value};`)
11
- .join("\n");
12
-
13
6
  /**
14
- * The static equivalent of `<AstralisProvider tokens={{ brandColor }}>` —
15
- * same OKLCH math (imported from the library, never duplicated), rendered as
16
- * a stylesheet for people who prefer build-time theming over the runtime
17
- * provider. Must be imported AFTER astralis-ui/styles.css so the cascade
18
- * lets these :root declarations win.
7
+ * Renders a theme seed as a stylesheet — the static equivalent of
8
+ * <AstralisProvider tokens={seed}>, for people who prefer build-time theming
9
+ * over the runtime provider.
10
+ *
11
+ * Both the colour maths and the serialization come from the library and are
12
+ * never duplicated here, so `astralis theme` and the provider cannot drift.
19
13
  */
20
- export function themeCss(hex) {
21
- const light = generateBrandTokens(hex, "light");
22
- const dark = generateBrandTokens(hex, "dark");
23
- return [
24
- `/* Generated by astralis-cli — brand ramp for ${hex}.`,
25
- ` * Import AFTER "astralis-ui/styles.css" so these overrides win. */`,
26
- "",
27
- ":root {",
28
- serialize(light),
29
- "}",
30
- "",
31
- ".astralis-dark {",
32
- serialize(dark),
33
- "}",
34
- "",
35
- ].join("\n");
36
- }
14
+
15
+ /** Flag -> seed field. */
16
+ const STRING_FLAGS = {
17
+ brand: "brandColor",
18
+ gray: "grayColor",
19
+ error: "errorColor",
20
+ warning: "warningColor",
21
+ success: "successColor",
22
+ info: "infoColor",
23
+ "font-heading": "fontHeading",
24
+ "font-body": "fontBody",
25
+ "font-mono": "fontMono",
26
+ };
27
+
28
+ const NUMBER_FLAGS = {
29
+ radius: "radiusScale",
30
+ spacing: "spacingScale",
31
+ "font-scale": "fontSizeScale",
32
+ motion: "motionScale",
33
+ };
34
+
35
+ const USAGE = `Usage: astralis theme [options]
36
+
37
+ Colours
38
+ --brand <hex> brand hue, e.g. "#8b5cf6"
39
+ --gray <hex> neutral hue — drives every surface, label and border,
40
+ and tints white/black so the page follows the neutral
41
+
42
+ Status (each seeds its own palette; the red/orange/green/blue hues and
43
+ their colorScheme values are never altered)
44
+ --error <hex> defaults to red
45
+ --warning <hex> defaults to orange
46
+ --success <hex> defaults to green
47
+ --info <hex> defaults to blue
48
+
49
+ Typefaces
50
+ --font-heading <stack>
51
+ --font-body <stack>
52
+ --font-mono <stack>
53
+
54
+ Scales (1 = library default; 0 is allowed)
55
+ --radius <n> border-radius multiplier
56
+ --spacing <n> spacing multiplier — the density dial
57
+ --font-scale <n> font-size multiplier
58
+ --motion <n> duration multiplier (0 disables transitions)
59
+
60
+ Output
61
+ --out <file> default: astralis-theme.css
62
+ --force overwrite an existing file
63
+
64
+ A bare hex is shorthand for --brand: astralis theme "#8b5cf6"`;
37
65
 
38
66
  export async function run(argv) {
39
- const { values, positionals } = parseArgs({
40
- args: argv,
41
- options: {
42
- out: { type: "string", default: "astralis-theme.css" },
43
- force: { type: "boolean", default: false },
44
- },
45
- allowPositionals: true,
46
- });
47
-
48
- const hex = positionals[0];
49
- if (!hex) fail('Usage: astralis theme "#8b5cf6" [--out astralis-theme.css] [--force]');
50
- if (!HEX_PATTERN.test(hex)) fail(`"${hex}" is not a hex color — expected #rgb or #rrggbb.`);
67
+ let parsed;
68
+ try {
69
+ parsed = parseArgs({
70
+ args: argv,
71
+ options: {
72
+ ...Object.fromEntries(
73
+ [...Object.keys(STRING_FLAGS), ...Object.keys(NUMBER_FLAGS)].map((f) => [f, { type: "string" }]),
74
+ ),
75
+ out: { type: "string", default: "astralis-theme.css" },
76
+ force: { type: "boolean", default: false },
77
+ help: { type: "boolean", default: false },
78
+ },
79
+ allowPositionals: true,
80
+ });
81
+ } catch (error) {
82
+ fail(`${error.message}\n\n${USAGE}`);
83
+ }
84
+
85
+ const { values, positionals } = parsed;
86
+ if (values.help) {
87
+ console.log(USAGE);
88
+ return;
89
+ }
90
+
91
+ const seed = {};
92
+ for (const [flag, field] of Object.entries(STRING_FLAGS)) {
93
+ if (values[flag] !== undefined) seed[field] = values[flag];
94
+ }
95
+ for (const [flag, field] of Object.entries(NUMBER_FLAGS)) {
96
+ if (values[flag] === undefined) continue;
97
+ const n = Number(values[flag]);
98
+ if (!Number.isFinite(n)) fail(`--${flag} expects a number, got "${values[flag]}".`);
99
+ seed[field] = n;
100
+ }
101
+
102
+ // Back-compat: `astralis theme "#8b5cf6"` still means --brand.
103
+ if (positionals[0]) {
104
+ if (seed.brandColor) fail("Pass the brand colour as a positional OR as --brand, not both.");
105
+ seed.brandColor = positionals[0].toLowerCase();
106
+ }
107
+
108
+ if (isEmptySeed(seed)) fail(`Nothing to generate — no theme options given.\n\n${USAGE}`);
109
+
110
+ const issues = validateSeed(seed);
111
+ if (issues.length) {
112
+ fail(`Invalid theme options:\n${issues.map((i) => ` ${i.field}: ${i.message}`).join("\n")}`);
113
+ }
114
+
51
115
  if (existsSync(values.out) && !values.force) {
52
116
  fail(`${values.out} already exists — pass --force to overwrite.`);
53
117
  }
54
118
 
55
- writeFileSync(values.out, themeCss(hex.toLowerCase()));
119
+ writeFileSync(values.out, themeCss(seed));
56
120
  ok(`wrote ${cyan(values.out)}`);
57
- console.log(`\nImport it after the library stylesheet:\n ${cyan('import "astralis-ui/styles.css";')}\n ${cyan(`import "./${values.out}";`)}\n${dim("(Runtime alternative: <AstralisProvider tokens={{ brandColor }}> — same math.)")}`);
121
+
122
+ const usesFont = seed.fontHeading || seed.fontBody || seed.fontMono;
123
+ console.log(
124
+ `\nImport it after the library stylesheet:\n` +
125
+ ` ${cyan('import "astralis-ui/styles.css";')}\n` +
126
+ ` ${cyan(`import "./${values.out}";`)}\n` +
127
+ (usesFont ? `${dim("Custom fonts must be loaded by your app (next/font or a <link>).")}\n` : "") +
128
+ `${dim("Runtime alternative: <AstralisProvider tokens={…}> — same math.")}`,
129
+ );
58
130
  }
package/src/index.mjs CHANGED
@@ -23,8 +23,11 @@ ${bold("Commands")}
23
23
  ${dim("--framework next|vite · extra args pass to the scaffolder")}
24
24
  ${cyan("init")} wire astralis-ui into this project (Next.js or Vite)
25
25
  ${dim("--dry-run show the changes without writing")}
26
- ${cyan("theme <hex>")} generate a static brand-theme stylesheet
27
- ${dim('--out <file> (default astralis-theme.css) · --force')}
26
+ ${cyan("theme")} generate a static theme stylesheet from a seed
27
+ ${dim("--brand/--gray <hex> · --font-heading/-body/-mono <stack>")}
28
+ ${dim("--radius/--spacing/--font-scale/--motion <n>")}
29
+ ${dim("--out <file> (default astralis-theme.css) · --force")}
30
+ ${dim("run `astralis theme --help` for the full list")}
28
31
  ${cyan("mcp")} connect AI coding agents to the Astralis docs server
29
32
  ${dim("--write add it to Claude Desktop's config")}
30
33