@styleframe/cli 3.0.0 → 4.1.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.
Files changed (64) hide show
  1. package/CHANGELOG.md +124 -0
  2. package/dist/build-CBdsifMN.js +47 -0
  3. package/dist/build-D7cinF0l.cjs +50 -0
  4. package/dist/build-dtcg-BpbjBRCf.js +429 -0
  5. package/dist/build-dtcg-vuGHy-Sl.cjs +434 -0
  6. package/dist/chunk-D6vf50IK.cjs +28 -0
  7. package/dist/commands/build.d.ts +22 -0
  8. package/dist/commands/build.d.ts.map +1 -0
  9. package/dist/commands/dtcg/build-dtcg.d.ts +36 -0
  10. package/dist/commands/dtcg/build-dtcg.d.ts.map +1 -0
  11. package/dist/commands/dtcg/build-dtcg.test.d.ts +2 -0
  12. package/dist/commands/dtcg/build-dtcg.test.d.ts.map +1 -0
  13. package/dist/commands/dtcg/evaluate.d.ts +30 -0
  14. package/dist/commands/dtcg/evaluate.d.ts.map +1 -0
  15. package/dist/commands/dtcg/evaluate.test.d.ts +2 -0
  16. package/dist/commands/dtcg/evaluate.test.d.ts.map +1 -0
  17. package/dist/commands/dtcg/export.d.ts +24 -0
  18. package/dist/commands/dtcg/export.d.ts.map +1 -0
  19. package/dist/commands/dtcg/import.d.ts +38 -0
  20. package/dist/commands/dtcg/import.d.ts.map +1 -0
  21. package/dist/commands/dtcg/index.d.ts +3 -0
  22. package/dist/commands/dtcg/index.d.ts.map +1 -0
  23. package/dist/commands/figma/export.d.ts +24 -0
  24. package/dist/commands/figma/export.d.ts.map +1 -0
  25. package/dist/commands/figma/import.d.ts +38 -0
  26. package/dist/commands/figma/import.d.ts.map +1 -0
  27. package/dist/commands/figma/index.d.ts +3 -0
  28. package/dist/commands/figma/index.d.ts.map +1 -0
  29. package/dist/commands/init/nuxt.d.ts +2 -0
  30. package/dist/commands/init/nuxt.d.ts.map +1 -0
  31. package/dist/commands/init/vite.d.ts +2 -0
  32. package/dist/commands/init/vite.d.ts.map +1 -0
  33. package/dist/commands/init.d.ts +26 -0
  34. package/dist/commands/init.d.ts.map +1 -0
  35. package/dist/constants.d.ts +8 -0
  36. package/dist/constants.d.ts.map +1 -0
  37. package/dist/dtcg-D1-iITOr.js +14 -0
  38. package/dist/dtcg-D84AfyzO.cjs +13 -0
  39. package/dist/export-CBdPGGEq.js +66 -0
  40. package/dist/export-DmPAU9Wh.cjs +69 -0
  41. package/dist/export-ONk9eKoZ.cjs +86 -0
  42. package/dist/export-suUS16eO.js +83 -0
  43. package/dist/figma-BvXoqRPU.cjs +13 -0
  44. package/dist/figma-D2RJh56T.js +14 -0
  45. package/dist/import-BQrcHNjK.cjs +126 -0
  46. package/dist/import-Bll_uBvJ.js +123 -0
  47. package/dist/import-MqLYxb8d.js +114 -0
  48. package/dist/import-ibQc_GXm.cjs +117 -0
  49. package/dist/index.cjs +21 -8669
  50. package/dist/index.d.ts +3 -4
  51. package/dist/index.d.ts.map +1 -0
  52. package/dist/index.js +16 -18
  53. package/dist/init-CAO0mA_w.js +262 -0
  54. package/dist/init-CaJoUVv2.cjs +265 -0
  55. package/dist/utils.d.ts +7 -0
  56. package/dist/utils.d.ts.map +1 -0
  57. package/package.json +14 -17
  58. package/dist/build-BFZSJ2Zh.js +0 -49
  59. package/dist/export-SH70kD-5.js +0 -139
  60. package/dist/import-CwuwczM7.js +0 -90
  61. package/dist/index-C3Gqfamh.js +0 -3689
  62. package/dist/index-DH3Hm47n.js +0 -14
  63. package/dist/index-DtEAy_us.js +0 -4475
  64. package/dist/init-DnrkQJYO.js +0 -234
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- declare function run(): void;
2
- export default run;
3
-
4
- export { }
1
+ #!/usr/bin/env node
2
+ export default function run(): void;
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAiBA,MAAM,CAAC,OAAO,UAAU,GAAG,SAE1B"}
package/dist/index.js CHANGED
@@ -1,23 +1,21 @@
1
1
  #!/usr/bin/env node
2
2
  import { defineCommand, runMain } from "citty";
3
- const version = "3.0.0";
4
- const description = "A command-line interface for styleframe.";
5
- const main = defineCommand({
6
- meta: {
7
- name: "styleframe",
8
- version,
9
- description
10
- },
11
- subCommands: {
12
- init: () => import("./init-DnrkQJYO.js").then((m) => m.default),
13
- build: () => import("./build-BFZSJ2Zh.js").then((m) => m.default),
14
- figma: () => import("./index-DH3Hm47n.js").then((m) => m.default)
15
- }
3
+ //#region src/index.ts
4
+ var main = defineCommand({
5
+ meta: {
6
+ name: "styleframe",
7
+ version: "4.1.0",
8
+ description: "A command-line interface for styleframe."
9
+ },
10
+ subCommands: {
11
+ init: () => import("./init-CAO0mA_w.js").then((m) => m.default),
12
+ build: () => import("./build-CBdsifMN.js").then((m) => m.default),
13
+ dtcg: () => import("./dtcg-D1-iITOr.js").then((m) => m.default),
14
+ figma: () => import("./figma-D2RJh56T.js").then((m) => m.default)
15
+ }
16
16
  });
17
17
  function run() {
18
- runMain(main);
18
+ runMain(main);
19
19
  }
20
- run();
21
- export {
22
- run as default
23
- };
20
+ //#endregion
21
+ export { run as default };
@@ -0,0 +1,262 @@
1
+ import { defineCommand } from "citty";
2
+ import consola from "consola";
3
+ import { access } from "node:fs/promises";
4
+ import { readFile as readFile$1, writeFile as writeFile$1 } from "fs/promises";
5
+ import path from "path";
6
+ import { constants } from "node:fs";
7
+ import { loadFile, writeFile as writeFile$2 } from "magicast";
8
+ import { addNuxtModule, addVitePlugin } from "magicast/helpers";
9
+ //#region src/utils.ts
10
+ async function fileExists(path) {
11
+ try {
12
+ await access(path, constants.F_OK);
13
+ return true;
14
+ } catch {
15
+ return false;
16
+ }
17
+ }
18
+ /**
19
+ * Parse a JSONC string (JSON with comments and trailing commas).
20
+ * Handles single-line comments, multi-line comments, and trailing commas.
21
+ */
22
+ function parseJsonc(text) {
23
+ let result = "";
24
+ let i = 0;
25
+ let inString = false;
26
+ while (i < text.length) {
27
+ const char = text[i];
28
+ const next = text[i + 1];
29
+ if (inString) {
30
+ if (char === "\\" && i + 1 < text.length) {
31
+ result += char + next;
32
+ i += 2;
33
+ continue;
34
+ }
35
+ if (char === "\"") inString = false;
36
+ result += char;
37
+ i++;
38
+ } else if (char === "\"") {
39
+ inString = true;
40
+ result += char;
41
+ i++;
42
+ } else if (char === "/" && next === "/") while (i < text.length && text[i] !== "\n") i++;
43
+ else if (char === "/" && next === "*") {
44
+ i += 2;
45
+ while (i < text.length && !(text[i] === "*" && text[i + 1] === "/")) i++;
46
+ i += 2;
47
+ } else {
48
+ result += char;
49
+ i++;
50
+ }
51
+ }
52
+ result = result.replace(/,(\s*[}\]])/g, "$1");
53
+ return JSON.parse(result);
54
+ }
55
+ var DOCS_URL = `https://styleframe.dev/docs`;
56
+ `${DOCS_URL}`;
57
+ var DOCS_MANUAL_INSTALLATION_VITE_URL = `${DOCS_URL}/getting-started/installation/manual/vite`;
58
+ `${DOCS_URL}`;
59
+ var DOCS_MANUAL_INSTALLATION_NUXT_URL = `${DOCS_URL}/getting-started/installation/manual/nuxt`;
60
+ var DOCS_INSTALLATION_CUSTOM_URL = `${DOCS_URL}/getting-started/installation/custom`;
61
+ //#endregion
62
+ //#region src/commands/init/vite.ts
63
+ async function initializeViteFrameworkFile(cwd) {
64
+ consola.success("Vite environment detected.");
65
+ const configFilePath = path.join(cwd, "vite.config.ts");
66
+ try {
67
+ const mod = await loadFile(configFilePath);
68
+ addVitePlugin(mod, {
69
+ from: "styleframe/plugin/vite",
70
+ constructor: "styleframe",
71
+ imported: "default"
72
+ });
73
+ await writeFile$2(mod, configFilePath);
74
+ consola.success(`Updated Vite config file.`);
75
+ } catch (error) {
76
+ consola.error(`Failed to update Vite config file.`);
77
+ consola.log(error);
78
+ console.log("");
79
+ console.log("Please read the documentation for manually installing styleframe for Vite.");
80
+ console.log(DOCS_MANUAL_INSTALLATION_VITE_URL);
81
+ }
82
+ }
83
+ //#endregion
84
+ //#region src/commands/init/nuxt.ts
85
+ async function initializeNuxtFrameworkFile(cwd) {
86
+ consola.success("Nuxt environment detected.");
87
+ const configFilePath = path.join(cwd, "nuxt.config.ts");
88
+ try {
89
+ const mod = await loadFile(configFilePath);
90
+ addNuxtModule(mod, "styleframe/plugin/nuxt", "styleframe");
91
+ await writeFile$2(mod, configFilePath);
92
+ consola.success(`Updated Nuxt config file.`);
93
+ } catch (error) {
94
+ consola.error(`Failed to update Nuxt config file.`);
95
+ consola.log(error);
96
+ console.log("");
97
+ console.log("Please read the documentation for manually installing styleframe for Nuxt.");
98
+ console.log(DOCS_MANUAL_INSTALLATION_NUXT_URL);
99
+ }
100
+ }
101
+ //#endregion
102
+ //#region src/commands/init.ts
103
+ var styleframeConfigTemplate = `import { styleframe } from "styleframe";
104
+
105
+ const s = styleframe();
106
+
107
+ s.variable("color--primary", "blue");
108
+
109
+ export default s;
110
+ `;
111
+ var VIRTUAL_STYLEFRAME_MODULE = "virtual:styleframe";
112
+ var STYLEFRAME_TYPES_PATH = "./.styleframe/styleframe.d.ts";
113
+ var styleframePaths = { [VIRTUAL_STYLEFRAME_MODULE]: [STYLEFRAME_TYPES_PATH] };
114
+ var styleframeIncludes = [
115
+ "styleframe.config.ts",
116
+ "*.styleframe.ts",
117
+ ".styleframe/**/*.d.ts"
118
+ ];
119
+ function buildTsconfigTemplate(options) {
120
+ return {
121
+ compilerOptions: {
122
+ target: "ES2022",
123
+ module: "ESNext",
124
+ moduleResolution: "bundler",
125
+ strict: true,
126
+ noEmit: true,
127
+ skipLibCheck: true,
128
+ esModuleInterop: true,
129
+ ...options.paths ? { paths: styleframePaths } : {}
130
+ },
131
+ include: styleframeIncludes
132
+ };
133
+ }
134
+ /**
135
+ * Detects whether the project at `cwd` uses a type-checker that requires a
136
+ * `compilerOptions.paths` entry for the `virtual:styleframe` virtual module.
137
+ *
138
+ * Currently this means Vue (`vue-tsc` won't resolve a bare-specifier ambient
139
+ * `declare module` imported inside a `.vue` SFC). Detection checks for `vue` in
140
+ * package.json dependencies and excludes Nuxt: the Nuxt module already injects
141
+ * the mapping into Nuxt's generated tsconfig via `prepare:types`, and writing
142
+ * `paths` into an `extends`-based root tsconfig would replace (not merge) Nuxt's
143
+ * inherited aliases.
144
+ */
145
+ async function needsExplicitPaths(cwd) {
146
+ const packageJsonPath = path.join(cwd, "package.json");
147
+ if (!await fileExists(packageJsonPath)) return false;
148
+ try {
149
+ const packageJson = JSON.parse(await readFile$1(packageJsonPath, "utf8"));
150
+ const deps = {
151
+ ...packageJson.dependencies,
152
+ ...packageJson.devDependencies
153
+ };
154
+ return "vue" in deps && !("nuxt" in deps);
155
+ } catch {
156
+ return false;
157
+ }
158
+ }
159
+ async function initializeConfigFile(cwd) {
160
+ const styleframeConfigPath = path.join(cwd, "styleframe.config.ts");
161
+ if (await fileExists(styleframeConfigPath)) consola.warn(`Skipped creating "styleframe.config.ts" because it already exists.`);
162
+ else {
163
+ await writeFile$1(styleframeConfigPath, styleframeConfigTemplate);
164
+ consola.success(`Created "styleframe.config.ts".`);
165
+ }
166
+ }
167
+ /**
168
+ * Merges the `virtual:styleframe` paths entry into `compilerOptions.paths`,
169
+ * creating `compilerOptions`/`paths` if absent and preserving existing entries.
170
+ * Returns true if the entry was added, false if it was already mapped (so a
171
+ * user's own override is never clobbered).
172
+ */
173
+ function addStyleframePaths(config) {
174
+ const compilerOptions = config.compilerOptions ??= {};
175
+ const paths = compilerOptions.paths ??= {};
176
+ if (VIRTUAL_STYLEFRAME_MODULE in paths) return false;
177
+ paths[VIRTUAL_STYLEFRAME_MODULE] = [STYLEFRAME_TYPES_PATH];
178
+ return true;
179
+ }
180
+ async function initializeTsConfig(cwd, options) {
181
+ const tsconfigPath = path.join(cwd, "tsconfig.json");
182
+ if (await fileExists(tsconfigPath)) {
183
+ const existingConfig = parseJsonc(await readFile$1(tsconfigPath, "utf8"));
184
+ const added = [];
185
+ if (options.paths && addStyleframePaths(existingConfig)) added.push(`paths "${VIRTUAL_STYLEFRAME_MODULE}"`);
186
+ const includes = existingConfig.include ??= [];
187
+ for (const pattern of styleframeIncludes) if (!includes.includes(pattern)) {
188
+ includes.push(pattern);
189
+ added.push(`"${pattern}"`);
190
+ }
191
+ if (added.length > 0) {
192
+ await writeFile$1(tsconfigPath, JSON.stringify(existingConfig, null, " "));
193
+ consola.success(`Added ${added.join(", ")} to tsconfig.json.`);
194
+ }
195
+ } else {
196
+ await writeFile$1(tsconfigPath, JSON.stringify(buildTsconfigTemplate(options), null, " "));
197
+ consola.success(`Created "tsconfig.json".`);
198
+ }
199
+ }
200
+ async function addPackageJsonDependencies(cwd) {
201
+ const packageJsonPath = path.join(cwd, "package.json");
202
+ if (await fileExists(packageJsonPath)) {
203
+ const packageJson = JSON.parse(await readFile$1(packageJsonPath, "utf8"));
204
+ if (!packageJson.devDependencies) packageJson.devDependencies = {};
205
+ Object.assign(packageJson.devDependencies, {
206
+ "devDependencies": {
207
+ "styleframe": "^3.0.0",
208
+ "@styleframe/cli": "^4.0.0",
209
+ "@styleframe/core": "^3.0.0",
210
+ "@styleframe/loader": "^3.0.0",
211
+ "@styleframe/plugin": "^3.0.0",
212
+ "@styleframe/theme": "^3.0.0",
213
+ "@styleframe/transpiler": "^3.0.0"
214
+ },
215
+ "dependencies": { "@styleframe/runtime": "^3.0.0" }
216
+ }.devDependencies);
217
+ if (!packageJson.dependencies) packageJson.dependencies = {};
218
+ Object.assign(packageJson.dependencies, {
219
+ "devDependencies": {
220
+ "styleframe": "^3.0.0",
221
+ "@styleframe/cli": "^4.0.0",
222
+ "@styleframe/core": "^3.0.0",
223
+ "@styleframe/loader": "^3.0.0",
224
+ "@styleframe/plugin": "^3.0.0",
225
+ "@styleframe/theme": "^3.0.0",
226
+ "@styleframe/transpiler": "^3.0.0"
227
+ },
228
+ "dependencies": { "@styleframe/runtime": "^3.0.0" }
229
+ }.dependencies);
230
+ await writeFile$1(packageJsonPath, JSON.stringify(packageJson, null, 2));
231
+ consola.success(`Added dependencies to "package.json".`);
232
+ } else consola.warn(`Skipped adding styleframe to dependencies because package.json could not be found.`);
233
+ }
234
+ async function initializeFrameworkFile(cwd) {
235
+ if (await fileExists(path.join(cwd, "vite.config.ts"))) await initializeViteFrameworkFile(cwd);
236
+ else if (await fileExists(path.join(cwd, "nuxt.config.ts"))) await initializeNuxtFrameworkFile(cwd);
237
+ else consola.warn("No framework file detected. Read more about setting up styleframe manually.", DOCS_INSTALLATION_CUSTOM_URL);
238
+ }
239
+ var init_default = defineCommand({
240
+ meta: {
241
+ name: "init",
242
+ description: "Initialize a new styleframe project."
243
+ },
244
+ args: { cwd: {
245
+ type: "string",
246
+ required: false,
247
+ default: process.cwd(),
248
+ description: "The directory where the project will be initialized",
249
+ alias: ["d", "dir"],
250
+ valueHint: "path"
251
+ } },
252
+ async run({ args }) {
253
+ const { cwd } = args;
254
+ consola.info("Initializing...");
255
+ await initializeConfigFile(cwd);
256
+ await initializeTsConfig(cwd, { paths: await needsExplicitPaths(cwd) });
257
+ await addPackageJsonDependencies(cwd);
258
+ await initializeFrameworkFile(cwd);
259
+ }
260
+ });
261
+ //#endregion
262
+ export { init_default as default };
@@ -0,0 +1,265 @@
1
+ const require_chunk = require("./chunk-D6vf50IK.cjs");
2
+ let citty = require("citty");
3
+ let consola = require("consola");
4
+ consola = require_chunk.__toESM(consola, 1);
5
+ let node_fs_promises = require("node:fs/promises");
6
+ let fs_promises = require("fs/promises");
7
+ let path = require("path");
8
+ path = require_chunk.__toESM(path, 1);
9
+ let node_fs = require("node:fs");
10
+ let magicast = require("magicast");
11
+ let magicast_helpers = require("magicast/helpers");
12
+ //#region src/utils.ts
13
+ async function fileExists(path) {
14
+ try {
15
+ await (0, node_fs_promises.access)(path, node_fs.constants.F_OK);
16
+ return true;
17
+ } catch {
18
+ return false;
19
+ }
20
+ }
21
+ /**
22
+ * Parse a JSONC string (JSON with comments and trailing commas).
23
+ * Handles single-line comments, multi-line comments, and trailing commas.
24
+ */
25
+ function parseJsonc(text) {
26
+ let result = "";
27
+ let i = 0;
28
+ let inString = false;
29
+ while (i < text.length) {
30
+ const char = text[i];
31
+ const next = text[i + 1];
32
+ if (inString) {
33
+ if (char === "\\" && i + 1 < text.length) {
34
+ result += char + next;
35
+ i += 2;
36
+ continue;
37
+ }
38
+ if (char === "\"") inString = false;
39
+ result += char;
40
+ i++;
41
+ } else if (char === "\"") {
42
+ inString = true;
43
+ result += char;
44
+ i++;
45
+ } else if (char === "/" && next === "/") while (i < text.length && text[i] !== "\n") i++;
46
+ else if (char === "/" && next === "*") {
47
+ i += 2;
48
+ while (i < text.length && !(text[i] === "*" && text[i + 1] === "/")) i++;
49
+ i += 2;
50
+ } else {
51
+ result += char;
52
+ i++;
53
+ }
54
+ }
55
+ result = result.replace(/,(\s*[}\]])/g, "$1");
56
+ return JSON.parse(result);
57
+ }
58
+ var DOCS_URL = `https://styleframe.dev/docs`;
59
+ `${DOCS_URL}`;
60
+ var DOCS_MANUAL_INSTALLATION_VITE_URL = `${DOCS_URL}/getting-started/installation/manual/vite`;
61
+ `${DOCS_URL}`;
62
+ var DOCS_MANUAL_INSTALLATION_NUXT_URL = `${DOCS_URL}/getting-started/installation/manual/nuxt`;
63
+ var DOCS_INSTALLATION_CUSTOM_URL = `${DOCS_URL}/getting-started/installation/custom`;
64
+ //#endregion
65
+ //#region src/commands/init/vite.ts
66
+ async function initializeViteFrameworkFile(cwd) {
67
+ consola.default.success("Vite environment detected.");
68
+ const configFilePath = path.default.join(cwd, "vite.config.ts");
69
+ try {
70
+ const mod = await (0, magicast.loadFile)(configFilePath);
71
+ (0, magicast_helpers.addVitePlugin)(mod, {
72
+ from: "styleframe/plugin/vite",
73
+ constructor: "styleframe",
74
+ imported: "default"
75
+ });
76
+ await (0, magicast.writeFile)(mod, configFilePath);
77
+ consola.default.success(`Updated Vite config file.`);
78
+ } catch (error) {
79
+ consola.default.error(`Failed to update Vite config file.`);
80
+ consola.default.log(error);
81
+ console.log("");
82
+ console.log("Please read the documentation for manually installing styleframe for Vite.");
83
+ console.log(DOCS_MANUAL_INSTALLATION_VITE_URL);
84
+ }
85
+ }
86
+ //#endregion
87
+ //#region src/commands/init/nuxt.ts
88
+ async function initializeNuxtFrameworkFile(cwd) {
89
+ consola.default.success("Nuxt environment detected.");
90
+ const configFilePath = path.default.join(cwd, "nuxt.config.ts");
91
+ try {
92
+ const mod = await (0, magicast.loadFile)(configFilePath);
93
+ (0, magicast_helpers.addNuxtModule)(mod, "styleframe/plugin/nuxt", "styleframe");
94
+ await (0, magicast.writeFile)(mod, configFilePath);
95
+ consola.default.success(`Updated Nuxt config file.`);
96
+ } catch (error) {
97
+ consola.default.error(`Failed to update Nuxt config file.`);
98
+ consola.default.log(error);
99
+ console.log("");
100
+ console.log("Please read the documentation for manually installing styleframe for Nuxt.");
101
+ console.log(DOCS_MANUAL_INSTALLATION_NUXT_URL);
102
+ }
103
+ }
104
+ //#endregion
105
+ //#region src/commands/init.ts
106
+ var styleframeConfigTemplate = `import { styleframe } from "styleframe";
107
+
108
+ const s = styleframe();
109
+
110
+ s.variable("color--primary", "blue");
111
+
112
+ export default s;
113
+ `;
114
+ var VIRTUAL_STYLEFRAME_MODULE = "virtual:styleframe";
115
+ var STYLEFRAME_TYPES_PATH = "./.styleframe/styleframe.d.ts";
116
+ var styleframePaths = { [VIRTUAL_STYLEFRAME_MODULE]: [STYLEFRAME_TYPES_PATH] };
117
+ var styleframeIncludes = [
118
+ "styleframe.config.ts",
119
+ "*.styleframe.ts",
120
+ ".styleframe/**/*.d.ts"
121
+ ];
122
+ function buildTsconfigTemplate(options) {
123
+ return {
124
+ compilerOptions: {
125
+ target: "ES2022",
126
+ module: "ESNext",
127
+ moduleResolution: "bundler",
128
+ strict: true,
129
+ noEmit: true,
130
+ skipLibCheck: true,
131
+ esModuleInterop: true,
132
+ ...options.paths ? { paths: styleframePaths } : {}
133
+ },
134
+ include: styleframeIncludes
135
+ };
136
+ }
137
+ /**
138
+ * Detects whether the project at `cwd` uses a type-checker that requires a
139
+ * `compilerOptions.paths` entry for the `virtual:styleframe` virtual module.
140
+ *
141
+ * Currently this means Vue (`vue-tsc` won't resolve a bare-specifier ambient
142
+ * `declare module` imported inside a `.vue` SFC). Detection checks for `vue` in
143
+ * package.json dependencies and excludes Nuxt: the Nuxt module already injects
144
+ * the mapping into Nuxt's generated tsconfig via `prepare:types`, and writing
145
+ * `paths` into an `extends`-based root tsconfig would replace (not merge) Nuxt's
146
+ * inherited aliases.
147
+ */
148
+ async function needsExplicitPaths(cwd) {
149
+ const packageJsonPath = path.default.join(cwd, "package.json");
150
+ if (!await fileExists(packageJsonPath)) return false;
151
+ try {
152
+ const packageJson = JSON.parse(await (0, fs_promises.readFile)(packageJsonPath, "utf8"));
153
+ const deps = {
154
+ ...packageJson.dependencies,
155
+ ...packageJson.devDependencies
156
+ };
157
+ return "vue" in deps && !("nuxt" in deps);
158
+ } catch {
159
+ return false;
160
+ }
161
+ }
162
+ async function initializeConfigFile(cwd) {
163
+ const styleframeConfigPath = path.default.join(cwd, "styleframe.config.ts");
164
+ if (await fileExists(styleframeConfigPath)) consola.default.warn(`Skipped creating "styleframe.config.ts" because it already exists.`);
165
+ else {
166
+ await (0, fs_promises.writeFile)(styleframeConfigPath, styleframeConfigTemplate);
167
+ consola.default.success(`Created "styleframe.config.ts".`);
168
+ }
169
+ }
170
+ /**
171
+ * Merges the `virtual:styleframe` paths entry into `compilerOptions.paths`,
172
+ * creating `compilerOptions`/`paths` if absent and preserving existing entries.
173
+ * Returns true if the entry was added, false if it was already mapped (so a
174
+ * user's own override is never clobbered).
175
+ */
176
+ function addStyleframePaths(config) {
177
+ const compilerOptions = config.compilerOptions ??= {};
178
+ const paths = compilerOptions.paths ??= {};
179
+ if (VIRTUAL_STYLEFRAME_MODULE in paths) return false;
180
+ paths[VIRTUAL_STYLEFRAME_MODULE] = [STYLEFRAME_TYPES_PATH];
181
+ return true;
182
+ }
183
+ async function initializeTsConfig(cwd, options) {
184
+ const tsconfigPath = path.default.join(cwd, "tsconfig.json");
185
+ if (await fileExists(tsconfigPath)) {
186
+ const existingConfig = parseJsonc(await (0, fs_promises.readFile)(tsconfigPath, "utf8"));
187
+ const added = [];
188
+ if (options.paths && addStyleframePaths(existingConfig)) added.push(`paths "${VIRTUAL_STYLEFRAME_MODULE}"`);
189
+ const includes = existingConfig.include ??= [];
190
+ for (const pattern of styleframeIncludes) if (!includes.includes(pattern)) {
191
+ includes.push(pattern);
192
+ added.push(`"${pattern}"`);
193
+ }
194
+ if (added.length > 0) {
195
+ await (0, fs_promises.writeFile)(tsconfigPath, JSON.stringify(existingConfig, null, " "));
196
+ consola.default.success(`Added ${added.join(", ")} to tsconfig.json.`);
197
+ }
198
+ } else {
199
+ await (0, fs_promises.writeFile)(tsconfigPath, JSON.stringify(buildTsconfigTemplate(options), null, " "));
200
+ consola.default.success(`Created "tsconfig.json".`);
201
+ }
202
+ }
203
+ async function addPackageJsonDependencies(cwd) {
204
+ const packageJsonPath = path.default.join(cwd, "package.json");
205
+ if (await fileExists(packageJsonPath)) {
206
+ const packageJson = JSON.parse(await (0, fs_promises.readFile)(packageJsonPath, "utf8"));
207
+ if (!packageJson.devDependencies) packageJson.devDependencies = {};
208
+ Object.assign(packageJson.devDependencies, {
209
+ "devDependencies": {
210
+ "styleframe": "^3.0.0",
211
+ "@styleframe/cli": "^4.0.0",
212
+ "@styleframe/core": "^3.0.0",
213
+ "@styleframe/loader": "^3.0.0",
214
+ "@styleframe/plugin": "^3.0.0",
215
+ "@styleframe/theme": "^3.0.0",
216
+ "@styleframe/transpiler": "^3.0.0"
217
+ },
218
+ "dependencies": { "@styleframe/runtime": "^3.0.0" }
219
+ }.devDependencies);
220
+ if (!packageJson.dependencies) packageJson.dependencies = {};
221
+ Object.assign(packageJson.dependencies, {
222
+ "devDependencies": {
223
+ "styleframe": "^3.0.0",
224
+ "@styleframe/cli": "^4.0.0",
225
+ "@styleframe/core": "^3.0.0",
226
+ "@styleframe/loader": "^3.0.0",
227
+ "@styleframe/plugin": "^3.0.0",
228
+ "@styleframe/theme": "^3.0.0",
229
+ "@styleframe/transpiler": "^3.0.0"
230
+ },
231
+ "dependencies": { "@styleframe/runtime": "^3.0.0" }
232
+ }.dependencies);
233
+ await (0, fs_promises.writeFile)(packageJsonPath, JSON.stringify(packageJson, null, 2));
234
+ consola.default.success(`Added dependencies to "package.json".`);
235
+ } else consola.default.warn(`Skipped adding styleframe to dependencies because package.json could not be found.`);
236
+ }
237
+ async function initializeFrameworkFile(cwd) {
238
+ if (await fileExists(path.default.join(cwd, "vite.config.ts"))) await initializeViteFrameworkFile(cwd);
239
+ else if (await fileExists(path.default.join(cwd, "nuxt.config.ts"))) await initializeNuxtFrameworkFile(cwd);
240
+ else consola.default.warn("No framework file detected. Read more about setting up styleframe manually.", DOCS_INSTALLATION_CUSTOM_URL);
241
+ }
242
+ var init_default = (0, citty.defineCommand)({
243
+ meta: {
244
+ name: "init",
245
+ description: "Initialize a new styleframe project."
246
+ },
247
+ args: { cwd: {
248
+ type: "string",
249
+ required: false,
250
+ default: process.cwd(),
251
+ description: "The directory where the project will be initialized",
252
+ alias: ["d", "dir"],
253
+ valueHint: "path"
254
+ } },
255
+ async run({ args }) {
256
+ const { cwd } = args;
257
+ consola.default.info("Initializing...");
258
+ await initializeConfigFile(cwd);
259
+ await initializeTsConfig(cwd, { paths: await needsExplicitPaths(cwd) });
260
+ await addPackageJsonDependencies(cwd);
261
+ await initializeFrameworkFile(cwd);
262
+ }
263
+ });
264
+ //#endregion
265
+ exports.default = init_default;
@@ -0,0 +1,7 @@
1
+ export declare function fileExists(path: string): Promise<boolean>;
2
+ /**
3
+ * Parse a JSONC string (JSON with comments and trailing commas).
4
+ * Handles single-line comments, multi-line comments, and trailing commas.
5
+ */
6
+ export declare function parseJsonc(text: string): unknown;
7
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAGA,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,oBAO5C;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAgDhD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@styleframe/cli",
3
- "version": "3.0.0",
3
+ "version": "4.1.0",
4
4
  "description": "A command-line interface for styleframe.",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",
@@ -20,28 +20,29 @@
20
20
  "README.md"
21
21
  ],
22
22
  "dependencies": {
23
- "@styleframe/figma": "^1.0.1",
23
+ "@styleframe/dtcg": "^1.1.0",
24
+ "@styleframe/figma": "^2.1.0",
24
25
  "citty": "^0.1.6",
25
26
  "consola": "^3.0.0-2",
26
27
  "magicast": "^0.5.0"
27
28
  },
28
29
  "peerDependencies": {
29
- "@styleframe/loader": "^3.0.0"
30
+ "@styleframe/loader": "^3.0.2"
30
31
  },
31
32
  "devDependencies": {
32
33
  "@styleframe/config-typescript": "^3.0.0",
33
- "@styleframe/config-vite": "^3.0.0",
34
- "@styleframe/core": "^3.0.0",
34
+ "@styleframe/config-vite": "^3.0.1",
35
+ "@styleframe/core": "^3.6.0",
35
36
  "@styleframe/license": "^2.0.2",
36
- "@styleframe/theme": "^3.0.0",
37
- "@styleframe/loader": "^3.0.0",
38
- "@vitest/coverage-v8": "^3.2.4",
37
+ "@styleframe/theme": "^3.7.1",
38
+ "@styleframe/loader": "^3.0.2",
39
+ "@vitest/coverage-v8": "^4.1.7",
39
40
  "tsx": "^4.20.6",
40
41
  "typescript": "^5.8.3",
41
- "vite": "^7.0.6",
42
- "vite-plugin-dts": "^4.5.4",
43
- "vite-plugin-node": "^7.0.0",
44
- "vitest": "^3.2.4"
42
+ "vite": "^8.0.14",
43
+ "vite-plugin-dts": "^5.0.1",
44
+ "vite-plugin-node": "^8.0.0",
45
+ "vitest": "^4.1.7"
45
46
  },
46
47
  "homepage": "https://github.com/styleframe-dev/styleframe#readme",
47
48
  "bugs": {
@@ -52,13 +53,9 @@
52
53
  "url": "git+https://github.com/styleframe-dev/styleframe.git"
53
54
  },
54
55
  "author": "Alex Grozav <alex@styleframe.dev>",
55
- "overrides": {
56
- "vite": "npm:rolldown-vite@latest"
57
- },
58
56
  "scripts": {
59
57
  "dev": "vite build --watch",
60
- "prebuild": "tsx ./scripts/prebuild.ts",
61
- "build": "pnpm run prebuild && pnpm typecheck && vite build",
58
+ "build": "pnpm typecheck && vite build",
62
59
  "typecheck": "tsc --noEmit",
63
60
  "test": "vitest run --passWithNoTests",
64
61
  "test:dev": "vitest --watch",