@styleframe/cli 4.0.0 → 4.1.1
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 +43 -0
- package/dist/build-CBdsifMN.js +47 -0
- package/dist/build-D7cinF0l.cjs +50 -0
- package/dist/build-dtcg-BpbjBRCf.js +429 -0
- package/dist/build-dtcg-vuGHy-Sl.cjs +434 -0
- package/dist/chunk-D6vf50IK.cjs +28 -0
- package/dist/dtcg-D1-iITOr.js +14 -0
- package/dist/dtcg-D84AfyzO.cjs +13 -0
- package/dist/export-CBdPGGEq.js +66 -0
- package/dist/export-DmPAU9Wh.cjs +69 -0
- package/dist/export-ONk9eKoZ.cjs +86 -0
- package/dist/export-suUS16eO.js +83 -0
- package/dist/figma-BvXoqRPU.cjs +13 -0
- package/dist/figma-D2RJh56T.js +14 -0
- package/dist/import-BQrcHNjK.cjs +126 -0
- package/dist/import-Bll_uBvJ.js +123 -0
- package/dist/import-MqLYxb8d.js +114 -0
- package/dist/import-ibQc_GXm.cjs +117 -0
- package/dist/index.cjs +16 -16
- package/dist/index.d.cts +4 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.js +16 -17
- package/dist/init-CAO0mA_w.js +262 -0
- package/dist/init-CaJoUVv2.cjs +265 -0
- package/package.json +22 -20
- package/dist/build-BIWOTFZD.cjs +0 -49
- package/dist/build-CANA04j1.js +0 -49
- package/dist/export-BMneJTdq.cjs +0 -517
- package/dist/export-Cx6awh55.js +0 -517
- package/dist/import-BLbc2zWU.cjs +0 -90
- package/dist/import-a5DtGEAY.js +0 -90
- package/dist/index-BTHfb82h.js +0 -14
- package/dist/index-jMzviwjD.cjs +0 -14
- package/dist/init-CKeTXHp5.js +0 -234
- package/dist/init-CO7VnQKe.cjs +0 -234
package/dist/index-BTHfb82h.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { defineCommand } from "citty";
|
|
2
|
-
const index = defineCommand({
|
|
3
|
-
meta: {
|
|
4
|
-
name: "dtcg",
|
|
5
|
-
description: "Export Styleframe variables to and import them from DTCG format"
|
|
6
|
-
},
|
|
7
|
-
subCommands: {
|
|
8
|
-
export: () => import("./export-Cx6awh55.js").then((m) => m.default),
|
|
9
|
-
import: () => import("./import-a5DtGEAY.js").then((m) => m.default)
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
export {
|
|
13
|
-
index as default
|
|
14
|
-
};
|
package/dist/index-jMzviwjD.cjs
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const citty = require("citty");
|
|
4
|
-
const index = citty.defineCommand({
|
|
5
|
-
meta: {
|
|
6
|
-
name: "dtcg",
|
|
7
|
-
description: "Export Styleframe variables to and import them from DTCG format"
|
|
8
|
-
},
|
|
9
|
-
subCommands: {
|
|
10
|
-
export: () => Promise.resolve().then(() => require("./export-BMneJTdq.cjs")).then((m) => m.default),
|
|
11
|
-
import: () => Promise.resolve().then(() => require("./import-BLbc2zWU.cjs")).then((m) => m.default)
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
exports.default = index;
|
package/dist/init-CKeTXHp5.js
DELETED
|
@@ -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 path 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(path2) {
|
|
10
|
-
try {
|
|
11
|
-
await access(path2, 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 = path.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 = path.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 = path.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 = 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
|
-
}
|
|
168
|
-
async function addPackageJsonDependencies(cwd) {
|
|
169
|
-
const packageJsonPath = path.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(path.join(cwd, "vite.config.ts"))) {
|
|
194
|
-
await initializeViteFrameworkFile(cwd);
|
|
195
|
-
} else if (await fileExists(path.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
|
-
};
|
package/dist/init-CO7VnQKe.cjs
DELETED
|
@@ -1,234 +0,0 @@
|
|
|
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;
|