@styleframe/cli 2.4.0 → 4.0.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/CHANGELOG.md +102 -0
- package/dist/build-BIWOTFZD.cjs +49 -0
- package/dist/{build-ur0w63-6.js → build-CANA04j1.js} +1 -1
- package/dist/export-BMneJTdq.cjs +517 -0
- package/dist/export-Cx6awh55.js +517 -0
- package/dist/import-BLbc2zWU.cjs +90 -0
- package/dist/{import-CwuwczM7.js → import-a5DtGEAY.js} +1 -1
- package/dist/index-BTHfb82h.js +14 -0
- package/dist/index-jMzviwjD.cjs +14 -0
- package/dist/index.cjs +21 -8396
- package/dist/index.js +4 -5
- package/dist/{init-iaRyWohK.js → init-CKeTXHp5.js} +99 -10
- package/dist/init-CO7VnQKe.cjs +234 -0
- package/package.json +9 -8
- package/dist/export-DbajI91o.js +0 -139
- package/dist/index-BX6dI2z2.js +0 -4291
- package/dist/index-C3Gqfamh.js +0 -3689
- package/dist/index-D1u8JN2Q.js +0 -14
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { defineCommand, runMain } from "citty";
|
|
3
|
-
const version = "
|
|
3
|
+
const version = "4.0.0";
|
|
4
4
|
const description = "A command-line interface for styleframe.";
|
|
5
5
|
const main = defineCommand({
|
|
6
6
|
meta: {
|
|
@@ -9,15 +9,14 @@ const main = defineCommand({
|
|
|
9
9
|
description
|
|
10
10
|
},
|
|
11
11
|
subCommands: {
|
|
12
|
-
init: () => import("./init-
|
|
13
|
-
build: () => import("./build-
|
|
14
|
-
|
|
12
|
+
init: () => import("./init-CKeTXHp5.js").then((m) => m.default),
|
|
13
|
+
build: () => import("./build-CANA04j1.js").then((m) => m.default),
|
|
14
|
+
dtcg: () => import("./index-BTHfb82h.js").then((m) => m.default)
|
|
15
15
|
}
|
|
16
16
|
});
|
|
17
17
|
function run() {
|
|
18
18
|
runMain(main);
|
|
19
19
|
}
|
|
20
|
-
run();
|
|
21
20
|
export {
|
|
22
21
|
run as default
|
|
23
22
|
};
|
|
@@ -1,19 +1,61 @@
|
|
|
1
1
|
import consola from "consola";
|
|
2
2
|
import { defineCommand } from "citty";
|
|
3
3
|
import { writeFile as writeFile$1, readFile } from "fs/promises";
|
|
4
|
-
import
|
|
4
|
+
import path from "path";
|
|
5
5
|
import { access } from "node:fs/promises";
|
|
6
6
|
import { constants } from "node:fs";
|
|
7
7
|
import { loadFile, writeFile } from "magicast";
|
|
8
8
|
import { addVitePlugin, addNuxtModule } from "magicast/helpers";
|
|
9
|
-
async function fileExists(
|
|
9
|
+
async function fileExists(path2) {
|
|
10
10
|
try {
|
|
11
|
-
await access(
|
|
11
|
+
await access(path2, constants.F_OK);
|
|
12
12
|
return true;
|
|
13
13
|
} catch {
|
|
14
14
|
return false;
|
|
15
15
|
}
|
|
16
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
|
+
}
|
|
17
59
|
const HOMEPAGE_URL = "https://styleframe.dev";
|
|
18
60
|
const DOCS_URL = `${HOMEPAGE_URL}/docs`;
|
|
19
61
|
const DOCS_MANUAL_INSTALLATION_VITE_URL = `${DOCS_URL}/getting-started/installation/manual/vite`;
|
|
@@ -21,7 +63,7 @@ const DOCS_MANUAL_INSTALLATION_NUXT_URL = `${DOCS_URL}/getting-started/installat
|
|
|
21
63
|
const DOCS_INSTALLATION_CUSTOM_URL = `${DOCS_URL}/getting-started/installation/custom`;
|
|
22
64
|
async function initializeViteFrameworkFile(cwd) {
|
|
23
65
|
consola.success("Vite environment detected.");
|
|
24
|
-
const configFilePath =
|
|
66
|
+
const configFilePath = path.join(cwd, "vite.config.ts");
|
|
25
67
|
try {
|
|
26
68
|
const mod = await loadFile(configFilePath);
|
|
27
69
|
addVitePlugin(mod, {
|
|
@@ -43,7 +85,7 @@ async function initializeViteFrameworkFile(cwd) {
|
|
|
43
85
|
}
|
|
44
86
|
async function initializeNuxtFrameworkFile(cwd) {
|
|
45
87
|
consola.success("Nuxt environment detected.");
|
|
46
|
-
const configFilePath =
|
|
88
|
+
const configFilePath = path.join(cwd, "nuxt.config.ts");
|
|
47
89
|
try {
|
|
48
90
|
const mod = await loadFile(configFilePath);
|
|
49
91
|
addNuxtModule(mod, "styleframe/plugin/nuxt", "styleframe");
|
|
@@ -67,8 +109,25 @@ s.variable("color--primary", "blue");
|
|
|
67
109
|
|
|
68
110
|
export default s;
|
|
69
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
|
+
};
|
|
70
129
|
async function initializeConfigFile(cwd) {
|
|
71
|
-
const styleframeConfigPath =
|
|
130
|
+
const styleframeConfigPath = path.join(cwd, "styleframe.config.ts");
|
|
72
131
|
if (await fileExists(styleframeConfigPath)) {
|
|
73
132
|
consola.warn(
|
|
74
133
|
`Skipped creating "styleframe.config.ts" because it already exists.`
|
|
@@ -78,8 +137,36 @@ async function initializeConfigFile(cwd) {
|
|
|
78
137
|
consola.success(`Created "styleframe.config.ts".`);
|
|
79
138
|
}
|
|
80
139
|
}
|
|
140
|
+
async function initializeTsConfig(cwd) {
|
|
141
|
+
const tsconfigPath = path.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
|
+
}
|
|
81
168
|
async function addPackageJsonDependencies(cwd) {
|
|
82
|
-
const packageJsonPath =
|
|
169
|
+
const packageJsonPath = path.join(cwd, "package.json");
|
|
83
170
|
if (await fileExists(packageJsonPath)) {
|
|
84
171
|
const packageJson = JSON.parse(await readFile(packageJsonPath, "utf8"));
|
|
85
172
|
if (!packageJson.devDependencies) packageJson.devDependencies = {};
|
|
@@ -103,9 +190,9 @@ async function addPackageJsonDependencies(cwd) {
|
|
|
103
190
|
}
|
|
104
191
|
}
|
|
105
192
|
async function initializeFrameworkFile(cwd) {
|
|
106
|
-
if (await fileExists(
|
|
193
|
+
if (await fileExists(path.join(cwd, "vite.config.ts"))) {
|
|
107
194
|
await initializeViteFrameworkFile(cwd);
|
|
108
|
-
} else if (await fileExists(
|
|
195
|
+
} else if (await fileExists(path.join(cwd, "nuxt.config.ts"))) {
|
|
109
196
|
await initializeNuxtFrameworkFile(cwd);
|
|
110
197
|
} else {
|
|
111
198
|
consola.warn(
|
|
@@ -133,6 +220,7 @@ const init = defineCommand({
|
|
|
133
220
|
const { cwd } = args;
|
|
134
221
|
consola.info("Initializing...");
|
|
135
222
|
await initializeConfigFile(cwd);
|
|
223
|
+
await initializeTsConfig(cwd);
|
|
136
224
|
await addPackageJsonDependencies(cwd);
|
|
137
225
|
await initializeFrameworkFile(cwd);
|
|
138
226
|
}
|
|
@@ -141,5 +229,6 @@ export {
|
|
|
141
229
|
addPackageJsonDependencies,
|
|
142
230
|
init as default,
|
|
143
231
|
initializeConfigFile,
|
|
144
|
-
initializeFrameworkFile
|
|
232
|
+
initializeFrameworkFile,
|
|
233
|
+
initializeTsConfig
|
|
145
234
|
};
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const consola = require("consola");
|
|
4
|
+
const citty = require("citty");
|
|
5
|
+
const promises$1 = require("fs/promises");
|
|
6
|
+
const path = require("path");
|
|
7
|
+
const promises = require("node:fs/promises");
|
|
8
|
+
const node_fs = require("node:fs");
|
|
9
|
+
const magicast = require("magicast");
|
|
10
|
+
const helpers = require("magicast/helpers");
|
|
11
|
+
async function fileExists(path2) {
|
|
12
|
+
try {
|
|
13
|
+
await promises.access(path2, node_fs.constants.F_OK);
|
|
14
|
+
return true;
|
|
15
|
+
} catch {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function parseJsonc(text) {
|
|
20
|
+
let result = "";
|
|
21
|
+
let i = 0;
|
|
22
|
+
let inString = false;
|
|
23
|
+
while (i < text.length) {
|
|
24
|
+
const char = text[i];
|
|
25
|
+
const next = text[i + 1];
|
|
26
|
+
if (inString) {
|
|
27
|
+
if (char === "\\" && i + 1 < text.length) {
|
|
28
|
+
result += char + next;
|
|
29
|
+
i += 2;
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (char === '"') {
|
|
33
|
+
inString = false;
|
|
34
|
+
}
|
|
35
|
+
result += char;
|
|
36
|
+
i++;
|
|
37
|
+
} else {
|
|
38
|
+
if (char === '"') {
|
|
39
|
+
inString = true;
|
|
40
|
+
result += char;
|
|
41
|
+
i++;
|
|
42
|
+
} else if (char === "/" && next === "/") {
|
|
43
|
+
while (i < text.length && text[i] !== "\n") {
|
|
44
|
+
i++;
|
|
45
|
+
}
|
|
46
|
+
} else if (char === "/" && next === "*") {
|
|
47
|
+
i += 2;
|
|
48
|
+
while (i < text.length && !(text[i] === "*" && text[i + 1] === "/")) {
|
|
49
|
+
i++;
|
|
50
|
+
}
|
|
51
|
+
i += 2;
|
|
52
|
+
} else {
|
|
53
|
+
result += char;
|
|
54
|
+
i++;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
result = result.replace(/,(\s*[}\]])/g, "$1");
|
|
59
|
+
return JSON.parse(result);
|
|
60
|
+
}
|
|
61
|
+
const HOMEPAGE_URL = "https://styleframe.dev";
|
|
62
|
+
const DOCS_URL = `${HOMEPAGE_URL}/docs`;
|
|
63
|
+
const DOCS_MANUAL_INSTALLATION_VITE_URL = `${DOCS_URL}/getting-started/installation/manual/vite`;
|
|
64
|
+
const DOCS_MANUAL_INSTALLATION_NUXT_URL = `${DOCS_URL}/getting-started/installation/manual/nuxt`;
|
|
65
|
+
const DOCS_INSTALLATION_CUSTOM_URL = `${DOCS_URL}/getting-started/installation/custom`;
|
|
66
|
+
async function initializeViteFrameworkFile(cwd) {
|
|
67
|
+
consola.success("Vite environment detected.");
|
|
68
|
+
const configFilePath = path.join(cwd, "vite.config.ts");
|
|
69
|
+
try {
|
|
70
|
+
const mod = await magicast.loadFile(configFilePath);
|
|
71
|
+
helpers.addVitePlugin(mod, {
|
|
72
|
+
from: "styleframe/plugin/vite",
|
|
73
|
+
constructor: "styleframe",
|
|
74
|
+
imported: "default"
|
|
75
|
+
});
|
|
76
|
+
await magicast.writeFile(mod, configFilePath);
|
|
77
|
+
consola.success(`Updated Vite config file.`);
|
|
78
|
+
} catch (error) {
|
|
79
|
+
consola.error(`Failed to update Vite config file.`);
|
|
80
|
+
consola.log(error);
|
|
81
|
+
console.log("");
|
|
82
|
+
console.log(
|
|
83
|
+
"Please read the documentation for manually installing styleframe for Vite."
|
|
84
|
+
);
|
|
85
|
+
console.log(DOCS_MANUAL_INSTALLATION_VITE_URL);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
async function initializeNuxtFrameworkFile(cwd) {
|
|
89
|
+
consola.success("Nuxt environment detected.");
|
|
90
|
+
const configFilePath = path.join(cwd, "nuxt.config.ts");
|
|
91
|
+
try {
|
|
92
|
+
const mod = await magicast.loadFile(configFilePath);
|
|
93
|
+
helpers.addNuxtModule(mod, "styleframe/plugin/nuxt", "styleframe");
|
|
94
|
+
await magicast.writeFile(mod, configFilePath);
|
|
95
|
+
consola.success(`Updated Nuxt config file.`);
|
|
96
|
+
} catch (error) {
|
|
97
|
+
consola.error(`Failed to update Nuxt config file.`);
|
|
98
|
+
consola.log(error);
|
|
99
|
+
console.log("");
|
|
100
|
+
console.log(
|
|
101
|
+
"Please read the documentation for manually installing styleframe for Nuxt."
|
|
102
|
+
);
|
|
103
|
+
console.log(DOCS_MANUAL_INSTALLATION_NUXT_URL);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const styleframeConfigTemplate = `import { styleframe } from "styleframe";
|
|
107
|
+
|
|
108
|
+
const s = styleframe();
|
|
109
|
+
|
|
110
|
+
s.variable("color--primary", "blue");
|
|
111
|
+
|
|
112
|
+
export default s;
|
|
113
|
+
`;
|
|
114
|
+
const styleframeIncludes = [
|
|
115
|
+
"styleframe.config.ts",
|
|
116
|
+
"*.styleframe.ts",
|
|
117
|
+
".styleframe/**/*.d.ts"
|
|
118
|
+
];
|
|
119
|
+
const tsconfigTemplate = {
|
|
120
|
+
compilerOptions: {
|
|
121
|
+
target: "ES2022",
|
|
122
|
+
module: "ESNext",
|
|
123
|
+
moduleResolution: "bundler",
|
|
124
|
+
strict: true,
|
|
125
|
+
noEmit: true,
|
|
126
|
+
skipLibCheck: true,
|
|
127
|
+
esModuleInterop: true
|
|
128
|
+
},
|
|
129
|
+
include: styleframeIncludes
|
|
130
|
+
};
|
|
131
|
+
async function initializeConfigFile(cwd) {
|
|
132
|
+
const styleframeConfigPath = path.join(cwd, "styleframe.config.ts");
|
|
133
|
+
if (await fileExists(styleframeConfigPath)) {
|
|
134
|
+
consola.warn(
|
|
135
|
+
`Skipped creating "styleframe.config.ts" because it already exists.`
|
|
136
|
+
);
|
|
137
|
+
} else {
|
|
138
|
+
await promises$1.writeFile(styleframeConfigPath, styleframeConfigTemplate);
|
|
139
|
+
consola.success(`Created "styleframe.config.ts".`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
async function initializeTsConfig(cwd) {
|
|
143
|
+
const tsconfigPath = path.join(cwd, "tsconfig.json");
|
|
144
|
+
if (await fileExists(tsconfigPath)) {
|
|
145
|
+
const existingConfig = parseJsonc(
|
|
146
|
+
await promises$1.readFile(tsconfigPath, "utf8")
|
|
147
|
+
);
|
|
148
|
+
if (!existingConfig.include) {
|
|
149
|
+
existingConfig.include = [];
|
|
150
|
+
}
|
|
151
|
+
const includes = existingConfig.include;
|
|
152
|
+
const added = [];
|
|
153
|
+
for (const pattern of styleframeIncludes) {
|
|
154
|
+
if (!includes.includes(pattern)) {
|
|
155
|
+
includes.push(pattern);
|
|
156
|
+
added.push(pattern);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (added.length > 0) {
|
|
160
|
+
await promises$1.writeFile(tsconfigPath, JSON.stringify(existingConfig, null, " "));
|
|
161
|
+
consola.success(
|
|
162
|
+
`Added ${added.map((p) => `"${p}"`).join(", ")} to tsconfig.json includes.`
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
} else {
|
|
166
|
+
await promises$1.writeFile(tsconfigPath, JSON.stringify(tsconfigTemplate, null, " "));
|
|
167
|
+
consola.success(`Created "tsconfig.json".`);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
async function addPackageJsonDependencies(cwd) {
|
|
171
|
+
const packageJsonPath = path.join(cwd, "package.json");
|
|
172
|
+
if (await fileExists(packageJsonPath)) {
|
|
173
|
+
const packageJson = JSON.parse(await promises$1.readFile(packageJsonPath, "utf8"));
|
|
174
|
+
if (!packageJson.devDependencies) packageJson.devDependencies = {};
|
|
175
|
+
packageJson.devDependencies["styleframe"] = "^2.0.0";
|
|
176
|
+
packageJson.devDependencies["@styleframe/cli"] = "^2.0.0";
|
|
177
|
+
packageJson.devDependencies["@styleframe/core"] = "^2.0.0";
|
|
178
|
+
packageJson.devDependencies["@styleframe/license"] = "^2.0.0";
|
|
179
|
+
packageJson.devDependencies["@styleframe/loader"] = "^2.0.0";
|
|
180
|
+
packageJson.devDependencies["@styleframe/plugin"] = "^2.0.0";
|
|
181
|
+
packageJson.devDependencies["@styleframe/pro"] = "^2.0.0";
|
|
182
|
+
packageJson.devDependencies["@styleframe/theme"] = "^2.0.0";
|
|
183
|
+
packageJson.devDependencies["@styleframe/transpiler"] = "^2.0.0";
|
|
184
|
+
if (!packageJson.dependencies) packageJson.dependencies = {};
|
|
185
|
+
packageJson.dependencies["@styleframe/runtime"] = "^2.0.0";
|
|
186
|
+
await promises$1.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2));
|
|
187
|
+
consola.success(`Added dependencies to "package.json".`);
|
|
188
|
+
} else {
|
|
189
|
+
consola.warn(
|
|
190
|
+
`Skipped adding styleframe to dependencies because package.json could not be found.`
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
async function initializeFrameworkFile(cwd) {
|
|
195
|
+
if (await fileExists(path.join(cwd, "vite.config.ts"))) {
|
|
196
|
+
await initializeViteFrameworkFile(cwd);
|
|
197
|
+
} else if (await fileExists(path.join(cwd, "nuxt.config.ts"))) {
|
|
198
|
+
await initializeNuxtFrameworkFile(cwd);
|
|
199
|
+
} else {
|
|
200
|
+
consola.warn(
|
|
201
|
+
"No framework file detected. Read more about setting up styleframe manually.",
|
|
202
|
+
DOCS_INSTALLATION_CUSTOM_URL
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
const init = citty.defineCommand({
|
|
207
|
+
meta: {
|
|
208
|
+
name: "init",
|
|
209
|
+
description: "Initialize a new styleframe project."
|
|
210
|
+
},
|
|
211
|
+
args: {
|
|
212
|
+
cwd: {
|
|
213
|
+
type: "string",
|
|
214
|
+
required: false,
|
|
215
|
+
default: process.cwd(),
|
|
216
|
+
description: "The directory where the project will be initialized",
|
|
217
|
+
alias: ["d", "dir"],
|
|
218
|
+
valueHint: "path"
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
async run({ args }) {
|
|
222
|
+
const { cwd } = args;
|
|
223
|
+
consola.info("Initializing...");
|
|
224
|
+
await initializeConfigFile(cwd);
|
|
225
|
+
await initializeTsConfig(cwd);
|
|
226
|
+
await addPackageJsonDependencies(cwd);
|
|
227
|
+
await initializeFrameworkFile(cwd);
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
exports.addPackageJsonDependencies = addPackageJsonDependencies;
|
|
231
|
+
exports.default = init;
|
|
232
|
+
exports.initializeConfigFile = initializeConfigFile;
|
|
233
|
+
exports.initializeFrameworkFile = initializeFrameworkFile;
|
|
234
|
+
exports.initializeTsConfig = initializeTsConfig;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@styleframe/cli",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "A command-line interface for styleframe.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -20,21 +20,22 @@
|
|
|
20
20
|
"README.md"
|
|
21
21
|
],
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@styleframe/
|
|
23
|
+
"@styleframe/dtcg": "^1.1.0",
|
|
24
|
+
"@styleframe/figma": "^2.0.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": "^
|
|
30
|
+
"@styleframe/loader": "^3.0.0"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
32
|
-
"@styleframe/config-typescript": "^
|
|
33
|
-
"@styleframe/config-vite": "^
|
|
34
|
-
"@styleframe/core": "^
|
|
33
|
+
"@styleframe/config-typescript": "^3.0.0",
|
|
34
|
+
"@styleframe/config-vite": "^3.0.0",
|
|
35
|
+
"@styleframe/core": "^3.4.0",
|
|
35
36
|
"@styleframe/license": "^2.0.2",
|
|
36
|
-
"@styleframe/theme": "^
|
|
37
|
-
"@styleframe/loader": "^
|
|
37
|
+
"@styleframe/theme": "^3.6.0",
|
|
38
|
+
"@styleframe/loader": "^3.0.0",
|
|
38
39
|
"@vitest/coverage-v8": "^3.2.4",
|
|
39
40
|
"tsx": "^4.20.6",
|
|
40
41
|
"typescript": "^5.8.3",
|
package/dist/export-DbajI91o.js
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import { writeFile } from "node:fs/promises";
|
|
3
|
-
import { l as loadConfiguration } from "./index-BX6dI2z2.js";
|
|
4
|
-
import { defineCommand } from "citty";
|
|
5
|
-
import consola from "consola";
|
|
6
|
-
import { d as detectFigmaType, s as styleframeValueToFigma, a as styleframeToFigmaName, t as toDTCG } from "./index-C3Gqfamh.js";
|
|
7
|
-
const _export = defineCommand({
|
|
8
|
-
meta: {
|
|
9
|
-
name: "export",
|
|
10
|
-
description: "Export Styleframe variables to DTCG format JSON"
|
|
11
|
-
},
|
|
12
|
-
args: {
|
|
13
|
-
config: {
|
|
14
|
-
type: "string",
|
|
15
|
-
description: "Path to the Styleframe config file",
|
|
16
|
-
default: "styleframe.config.ts",
|
|
17
|
-
alias: ["c"],
|
|
18
|
-
valueHint: "path"
|
|
19
|
-
},
|
|
20
|
-
output: {
|
|
21
|
-
type: "string",
|
|
22
|
-
description: "Output JSON file path",
|
|
23
|
-
default: "tokens.json",
|
|
24
|
-
alias: ["o"],
|
|
25
|
-
valueHint: "path"
|
|
26
|
-
},
|
|
27
|
-
collection: {
|
|
28
|
-
type: "string",
|
|
29
|
-
description: "Name for the Figma collection",
|
|
30
|
-
default: "Design Tokens",
|
|
31
|
-
alias: ["n", "name"]
|
|
32
|
-
},
|
|
33
|
-
baseFontSize: {
|
|
34
|
-
type: "string",
|
|
35
|
-
description: "Base font size for rem conversion (in pixels)",
|
|
36
|
-
default: "16"
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
async run({ args }) {
|
|
40
|
-
const configPath = path.resolve(args.config);
|
|
41
|
-
const outputPath = path.resolve(args.output);
|
|
42
|
-
const baseFontSize = Number.parseInt(args.baseFontSize, 10) || 16;
|
|
43
|
-
consola.info(
|
|
44
|
-
`Loading configuration from "${path.relative(process.cwd(), configPath)}"...`
|
|
45
|
-
);
|
|
46
|
-
const instance = await loadConfiguration({ entry: configPath });
|
|
47
|
-
const root = instance.root;
|
|
48
|
-
consola.info("Extracting variables...");
|
|
49
|
-
const modes = ["Default", ...root.themes.map((t) => capitalize(t.name))];
|
|
50
|
-
const variableMap = /* @__PURE__ */ new Map();
|
|
51
|
-
for (const variable of root.variables) {
|
|
52
|
-
if (!variableMap.has(variable.name)) {
|
|
53
|
-
variableMap.set(variable.name, /* @__PURE__ */ new Map());
|
|
54
|
-
}
|
|
55
|
-
const modeValues = variableMap.get(variable.name);
|
|
56
|
-
modeValues.set("Default", resolveValue(variable.value));
|
|
57
|
-
}
|
|
58
|
-
for (const theme of root.themes) {
|
|
59
|
-
const modeName = capitalize(theme.name);
|
|
60
|
-
for (const variable of theme.variables) {
|
|
61
|
-
if (!variableMap.has(variable.name)) {
|
|
62
|
-
variableMap.set(variable.name, /* @__PURE__ */ new Map());
|
|
63
|
-
}
|
|
64
|
-
const modeValues = variableMap.get(variable.name);
|
|
65
|
-
modeValues.set(modeName, resolveValue(variable.value));
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
const variables = [];
|
|
69
|
-
for (const [name, modeValues] of variableMap) {
|
|
70
|
-
const defaultValue = modeValues.get("Default");
|
|
71
|
-
if (defaultValue === void 0) continue;
|
|
72
|
-
const type = detectFigmaType(defaultValue);
|
|
73
|
-
const figmaValues = {};
|
|
74
|
-
for (const [modeName, value] of modeValues) {
|
|
75
|
-
const figmaValue = styleframeValueToFigma(value, type, baseFontSize);
|
|
76
|
-
if (figmaValue !== null) {
|
|
77
|
-
figmaValues[modeName] = figmaValue;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
const rawDefaultValue = getRawValue(
|
|
81
|
-
root.variables.find((v) => v.name === name)?.value
|
|
82
|
-
);
|
|
83
|
-
const isReference = isReferenceValue(rawDefaultValue);
|
|
84
|
-
const aliasTo = isReference ? getReferenceName(rawDefaultValue) : void 0;
|
|
85
|
-
variables.push({
|
|
86
|
-
name: styleframeToFigmaName(name),
|
|
87
|
-
styleframeName: name,
|
|
88
|
-
type,
|
|
89
|
-
values: figmaValues,
|
|
90
|
-
aliasTo
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
const intermediateData = {
|
|
94
|
-
collection: args.collection,
|
|
95
|
-
modes,
|
|
96
|
-
variables
|
|
97
|
-
};
|
|
98
|
-
const themeNames = root.themes.map((t) => capitalize(t.name));
|
|
99
|
-
const dtcgData = toDTCG(intermediateData, { themeNames });
|
|
100
|
-
consola.info(
|
|
101
|
-
`Writing ${variables.length} variables to "${path.relative(process.cwd(), outputPath)}"...`
|
|
102
|
-
);
|
|
103
|
-
await writeFile(outputPath, JSON.stringify(dtcgData, null, 2));
|
|
104
|
-
consola.success(
|
|
105
|
-
`Exported ${variables.length} variables in DTCG format to "${path.relative(process.cwd(), outputPath)}"`
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
function capitalize(str) {
|
|
110
|
-
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
111
|
-
}
|
|
112
|
-
function resolveValue(value) {
|
|
113
|
-
if (value === null || value === void 0) return value;
|
|
114
|
-
if (typeof value !== "object") return value;
|
|
115
|
-
if ("type" in value) {
|
|
116
|
-
if (value.type === "reference") {
|
|
117
|
-
return value.fallback ?? "";
|
|
118
|
-
}
|
|
119
|
-
if (value.type === "css") {
|
|
120
|
-
return value.value.map((v) => resolveValue(v)).join("");
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
if (Array.isArray(value)) {
|
|
124
|
-
return value.map((v) => resolveValue(v)).join("");
|
|
125
|
-
}
|
|
126
|
-
return String(value);
|
|
127
|
-
}
|
|
128
|
-
function getRawValue(value) {
|
|
129
|
-
return value ?? "";
|
|
130
|
-
}
|
|
131
|
-
function isReferenceValue(value) {
|
|
132
|
-
return typeof value === "object" && value !== null && "type" in value && value.type === "reference";
|
|
133
|
-
}
|
|
134
|
-
function getReferenceName(value) {
|
|
135
|
-
return value.name;
|
|
136
|
-
}
|
|
137
|
-
export {
|
|
138
|
-
_export as default
|
|
139
|
-
};
|