@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
@@ -1,234 +0,0 @@
1
- import consola from "consola";
2
- import { defineCommand } from "citty";
3
- import { writeFile as writeFile$1, readFile } from "fs/promises";
4
- import sysPath from "path";
5
- import { access } from "node:fs/promises";
6
- import { constants } from "node:fs";
7
- import { loadFile, writeFile } from "magicast";
8
- import { addVitePlugin, addNuxtModule } from "magicast/helpers";
9
- async function fileExists(path) {
10
- try {
11
- await access(path, constants.F_OK);
12
- return true;
13
- } catch {
14
- return false;
15
- }
16
- }
17
- function parseJsonc(text) {
18
- let result = "";
19
- let i = 0;
20
- let inString = false;
21
- while (i < text.length) {
22
- const char = text[i];
23
- const next = text[i + 1];
24
- if (inString) {
25
- if (char === "\\" && i + 1 < text.length) {
26
- result += char + next;
27
- i += 2;
28
- continue;
29
- }
30
- if (char === '"') {
31
- inString = false;
32
- }
33
- result += char;
34
- i++;
35
- } else {
36
- if (char === '"') {
37
- inString = true;
38
- result += char;
39
- i++;
40
- } else if (char === "/" && next === "/") {
41
- while (i < text.length && text[i] !== "\n") {
42
- i++;
43
- }
44
- } else if (char === "/" && next === "*") {
45
- i += 2;
46
- while (i < text.length && !(text[i] === "*" && text[i + 1] === "/")) {
47
- i++;
48
- }
49
- i += 2;
50
- } else {
51
- result += char;
52
- i++;
53
- }
54
- }
55
- }
56
- result = result.replace(/,(\s*[}\]])/g, "$1");
57
- return JSON.parse(result);
58
- }
59
- const HOMEPAGE_URL = "https://styleframe.dev";
60
- const DOCS_URL = `${HOMEPAGE_URL}/docs`;
61
- const DOCS_MANUAL_INSTALLATION_VITE_URL = `${DOCS_URL}/getting-started/installation/manual/vite`;
62
- const DOCS_MANUAL_INSTALLATION_NUXT_URL = `${DOCS_URL}/getting-started/installation/manual/nuxt`;
63
- const DOCS_INSTALLATION_CUSTOM_URL = `${DOCS_URL}/getting-started/installation/custom`;
64
- async function initializeViteFrameworkFile(cwd) {
65
- consola.success("Vite environment detected.");
66
- const configFilePath = sysPath.join(cwd, "vite.config.ts");
67
- try {
68
- const mod = await loadFile(configFilePath);
69
- addVitePlugin(mod, {
70
- from: "styleframe/plugin/vite",
71
- constructor: "styleframe",
72
- imported: "default"
73
- });
74
- await writeFile(mod, configFilePath);
75
- consola.success(`Updated Vite config file.`);
76
- } catch (error) {
77
- consola.error(`Failed to update Vite config file.`);
78
- consola.log(error);
79
- console.log("");
80
- console.log(
81
- "Please read the documentation for manually installing styleframe for Vite."
82
- );
83
- console.log(DOCS_MANUAL_INSTALLATION_VITE_URL);
84
- }
85
- }
86
- async function initializeNuxtFrameworkFile(cwd) {
87
- consola.success("Nuxt environment detected.");
88
- const configFilePath = sysPath.join(cwd, "nuxt.config.ts");
89
- try {
90
- const mod = await loadFile(configFilePath);
91
- addNuxtModule(mod, "styleframe/plugin/nuxt", "styleframe");
92
- await writeFile(mod, configFilePath);
93
- consola.success(`Updated Nuxt config file.`);
94
- } catch (error) {
95
- consola.error(`Failed to update Nuxt config file.`);
96
- consola.log(error);
97
- console.log("");
98
- console.log(
99
- "Please read the documentation for manually installing styleframe for Nuxt."
100
- );
101
- console.log(DOCS_MANUAL_INSTALLATION_NUXT_URL);
102
- }
103
- }
104
- const styleframeConfigTemplate = `import { styleframe } from "styleframe";
105
-
106
- const s = styleframe();
107
-
108
- s.variable("color--primary", "blue");
109
-
110
- export default s;
111
- `;
112
- const styleframeIncludes = [
113
- "styleframe.config.ts",
114
- "*.styleframe.ts",
115
- ".styleframe/**/*.d.ts"
116
- ];
117
- const tsconfigTemplate = {
118
- compilerOptions: {
119
- target: "ES2022",
120
- module: "ESNext",
121
- moduleResolution: "bundler",
122
- strict: true,
123
- noEmit: true,
124
- skipLibCheck: true,
125
- esModuleInterop: true
126
- },
127
- include: styleframeIncludes
128
- };
129
- async function initializeConfigFile(cwd) {
130
- const styleframeConfigPath = sysPath.join(cwd, "styleframe.config.ts");
131
- if (await fileExists(styleframeConfigPath)) {
132
- consola.warn(
133
- `Skipped creating "styleframe.config.ts" because it already exists.`
134
- );
135
- } else {
136
- await writeFile$1(styleframeConfigPath, styleframeConfigTemplate);
137
- consola.success(`Created "styleframe.config.ts".`);
138
- }
139
- }
140
- async function initializeTsConfig(cwd) {
141
- const tsconfigPath = sysPath.join(cwd, "tsconfig.json");
142
- if (await fileExists(tsconfigPath)) {
143
- const existingConfig = parseJsonc(
144
- await readFile(tsconfigPath, "utf8")
145
- );
146
- if (!existingConfig.include) {
147
- existingConfig.include = [];
148
- }
149
- const includes = existingConfig.include;
150
- const added = [];
151
- for (const pattern of styleframeIncludes) {
152
- if (!includes.includes(pattern)) {
153
- includes.push(pattern);
154
- added.push(pattern);
155
- }
156
- }
157
- if (added.length > 0) {
158
- await writeFile$1(tsconfigPath, JSON.stringify(existingConfig, null, " "));
159
- consola.success(
160
- `Added ${added.map((p) => `"${p}"`).join(", ")} to tsconfig.json includes.`
161
- );
162
- }
163
- } else {
164
- await writeFile$1(tsconfigPath, JSON.stringify(tsconfigTemplate, null, " "));
165
- consola.success(`Created "tsconfig.json".`);
166
- }
167
- }
168
- async function addPackageJsonDependencies(cwd) {
169
- const packageJsonPath = sysPath.join(cwd, "package.json");
170
- if (await fileExists(packageJsonPath)) {
171
- const packageJson = JSON.parse(await readFile(packageJsonPath, "utf8"));
172
- if (!packageJson.devDependencies) packageJson.devDependencies = {};
173
- packageJson.devDependencies["styleframe"] = "^2.0.0";
174
- packageJson.devDependencies["@styleframe/cli"] = "^2.0.0";
175
- packageJson.devDependencies["@styleframe/core"] = "^2.0.0";
176
- packageJson.devDependencies["@styleframe/license"] = "^2.0.0";
177
- packageJson.devDependencies["@styleframe/loader"] = "^2.0.0";
178
- packageJson.devDependencies["@styleframe/plugin"] = "^2.0.0";
179
- packageJson.devDependencies["@styleframe/pro"] = "^2.0.0";
180
- packageJson.devDependencies["@styleframe/theme"] = "^2.0.0";
181
- packageJson.devDependencies["@styleframe/transpiler"] = "^2.0.0";
182
- if (!packageJson.dependencies) packageJson.dependencies = {};
183
- packageJson.dependencies["@styleframe/runtime"] = "^2.0.0";
184
- await writeFile$1(packageJsonPath, JSON.stringify(packageJson, null, 2));
185
- consola.success(`Added dependencies to "package.json".`);
186
- } else {
187
- consola.warn(
188
- `Skipped adding styleframe to dependencies because package.json could not be found.`
189
- );
190
- }
191
- }
192
- async function initializeFrameworkFile(cwd) {
193
- if (await fileExists(sysPath.join(cwd, "vite.config.ts"))) {
194
- await initializeViteFrameworkFile(cwd);
195
- } else if (await fileExists(sysPath.join(cwd, "nuxt.config.ts"))) {
196
- await initializeNuxtFrameworkFile(cwd);
197
- } else {
198
- consola.warn(
199
- "No framework file detected. Read more about setting up styleframe manually.",
200
- DOCS_INSTALLATION_CUSTOM_URL
201
- );
202
- }
203
- }
204
- const init = defineCommand({
205
- meta: {
206
- name: "init",
207
- description: "Initialize a new styleframe project."
208
- },
209
- args: {
210
- cwd: {
211
- type: "string",
212
- required: false,
213
- default: process.cwd(),
214
- description: "The directory where the project will be initialized",
215
- alias: ["d", "dir"],
216
- valueHint: "path"
217
- }
218
- },
219
- async run({ args }) {
220
- const { cwd } = args;
221
- consola.info("Initializing...");
222
- await initializeConfigFile(cwd);
223
- await initializeTsConfig(cwd);
224
- await addPackageJsonDependencies(cwd);
225
- await initializeFrameworkFile(cwd);
226
- }
227
- });
228
- export {
229
- addPackageJsonDependencies,
230
- init as default,
231
- initializeConfigFile,
232
- initializeFrameworkFile,
233
- initializeTsConfig
234
- };