@styleframe/cli 1.0.2 → 1.0.4
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 +15 -0
- package/dist/build-DMySNOvV.js +7087 -0
- package/dist/index-B2xSBfiT.js +10 -0
- package/dist/index-DxmWvPof.js +15735 -0
- package/dist/index.cjs +25024 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +21 -0
- package/dist/init-8BBfDuR2.js +137 -0
- package/dist/json5-6vwJhlCT.js +732 -0
- package/dist/jsonc-Be26CKXt.js +4 -0
- package/dist/multipart-parser-BGQrSLK7.js +191 -0
- package/dist/toml-CV1I6ukt.js +517 -0
- package/dist/yaml-CGqHMamv.js +686 -0
- package/package.json +12 -6
- package/.tsbuildinfo +0 -1
- package/playground/build.ts +0 -14
- package/playground/init.ts +0 -20
- package/playground/package.template.json +0 -12
- package/playground/styleframe.config.ts +0 -7
- package/playground/vite.config.template.ts +0 -5
- package/scripts/prebuild.ts +0 -24
- package/src/commands/build.ts +0 -51
- package/src/commands/init/nuxt.ts +0 -27
- package/src/commands/init/vite.ts +0 -33
- package/src/commands/init.ts +0 -88
- package/src/constants.ts +0 -7
- package/src/index.ts +0 -18
- package/src/package.ts +0 -2
- package/src/utils.ts +0 -11
- package/src/vite-env.d.ts +0 -1
- package/tsconfig.json +0 -12
- package/vite.config.ts +0 -13
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { defineCommand, runMain } from "citty";
|
|
3
|
+
const version = "1.0.4";
|
|
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-8BBfDuR2.js").then((m) => m.default),
|
|
13
|
+
build: () => import("./build-DMySNOvV.js").then((n) => n.e).then((m) => m.default)
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
function run() {
|
|
17
|
+
runMain(main);
|
|
18
|
+
}
|
|
19
|
+
export {
|
|
20
|
+
run as default
|
|
21
|
+
};
|
|
@@ -0,0 +1,137 @@
|
|
|
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
|
+
const HOMEPAGE_URL = "https://styleframe.dev";
|
|
18
|
+
const DOCS_URL = `${HOMEPAGE_URL}/docs`;
|
|
19
|
+
const DOCS_MANUAL_INSTALLATION_VITE_URL = `${DOCS_URL}/getting-started/installation/manual/vite`;
|
|
20
|
+
const DOCS_MANUAL_INSTALLATION_NUXT_URL = `${DOCS_URL}/getting-started/installation/manual/nuxt`;
|
|
21
|
+
const DOCS_INSTALLATION_CUSTOM_URL = `${DOCS_URL}/getting-started/installation/custom`;
|
|
22
|
+
async function initializeViteFrameworkFile(cwd) {
|
|
23
|
+
consola.success("Vite environment detected.");
|
|
24
|
+
const configFilePath = sysPath.join(cwd, "vite.config.ts");
|
|
25
|
+
try {
|
|
26
|
+
const mod = await loadFile(configFilePath);
|
|
27
|
+
addVitePlugin(mod, {
|
|
28
|
+
from: "styleframe/plugin/vite",
|
|
29
|
+
constructor: "styleframe",
|
|
30
|
+
imported: "default"
|
|
31
|
+
});
|
|
32
|
+
await writeFile(mod, configFilePath);
|
|
33
|
+
consola.success(`Updated Vite config file.`);
|
|
34
|
+
} catch (error) {
|
|
35
|
+
consola.error(`Failed to update Vite config file.`);
|
|
36
|
+
consola.log(error);
|
|
37
|
+
console.log("");
|
|
38
|
+
console.log(
|
|
39
|
+
"Please read the documentation for manually installing styleframe for Vite."
|
|
40
|
+
);
|
|
41
|
+
console.log(DOCS_MANUAL_INSTALLATION_VITE_URL);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async function initializeNuxtFrameworkFile(cwd) {
|
|
45
|
+
consola.success("Nuxt environment detected.");
|
|
46
|
+
const configFilePath = sysPath.join(cwd, "nuxt.config.ts");
|
|
47
|
+
try {
|
|
48
|
+
const mod = await loadFile(configFilePath);
|
|
49
|
+
addNuxtModule(mod, "styleframe/plugin/nuxt", "styleframe");
|
|
50
|
+
await writeFile(mod, configFilePath);
|
|
51
|
+
consola.success(`Updated Nuxt config file.`);
|
|
52
|
+
} catch (error) {
|
|
53
|
+
consola.error(`Failed to update Nuxt config file.`);
|
|
54
|
+
consola.log(error);
|
|
55
|
+
console.log("");
|
|
56
|
+
console.log(
|
|
57
|
+
"Please read the documentation for manually installing styleframe for Nuxt."
|
|
58
|
+
);
|
|
59
|
+
console.log(DOCS_MANUAL_INSTALLATION_NUXT_URL);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const styleframeConfigTemplate = `import { styleframe } from "styleframe";
|
|
63
|
+
|
|
64
|
+
const s = styleframe();
|
|
65
|
+
|
|
66
|
+
s.variable("color--primary", "blue");
|
|
67
|
+
|
|
68
|
+
export default s;
|
|
69
|
+
`;
|
|
70
|
+
async function initializeConfigFile(cwd) {
|
|
71
|
+
const styleframeConfigPath = sysPath.join(cwd, "styleframe.config.ts");
|
|
72
|
+
if (await fileExists(styleframeConfigPath)) {
|
|
73
|
+
consola.warn(
|
|
74
|
+
`Skipped creating "styleframe.config.ts" because it already exists.`
|
|
75
|
+
);
|
|
76
|
+
} else {
|
|
77
|
+
await writeFile$1(styleframeConfigPath, styleframeConfigTemplate);
|
|
78
|
+
consola.success(`Created "styleframe.config.ts".`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
async function addPackageJsonDependencies(cwd) {
|
|
82
|
+
const packageJsonPath = sysPath.join(cwd, "package.json");
|
|
83
|
+
if (await fileExists(packageJsonPath)) {
|
|
84
|
+
const packageJson = JSON.parse(await readFile(packageJsonPath, "utf8"));
|
|
85
|
+
if (!packageJson.devDependencies) packageJson.devDependencies = {};
|
|
86
|
+
packageJson.devDependencies["styleframe"] = "^1.0.0";
|
|
87
|
+
packageJson.devDependencies["@styleframe/theme"] = "^1.0.0";
|
|
88
|
+
packageJson.devDependencies["@styleframe/pro"] = "^1.0.0";
|
|
89
|
+
await writeFile$1(packageJsonPath, JSON.stringify(packageJson, null, 2));
|
|
90
|
+
consola.success(`Added dependencies to "package.json".`);
|
|
91
|
+
} else {
|
|
92
|
+
consola.warn(
|
|
93
|
+
`Skipped adding styleframe to dependencies because package.json could not be found.`
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
async function initializeFrameworkFile(cwd) {
|
|
98
|
+
if (await fileExists(sysPath.join(cwd, "vite.config.ts"))) {
|
|
99
|
+
await initializeViteFrameworkFile(cwd);
|
|
100
|
+
} else if (await fileExists(sysPath.join(cwd, "nuxt.config.ts"))) {
|
|
101
|
+
await initializeNuxtFrameworkFile(cwd);
|
|
102
|
+
} else {
|
|
103
|
+
consola.warn(
|
|
104
|
+
"No framework file detected. Read more about setting up styleframe manually.",
|
|
105
|
+
DOCS_INSTALLATION_CUSTOM_URL
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
const init = defineCommand({
|
|
110
|
+
meta: {
|
|
111
|
+
name: "init",
|
|
112
|
+
description: "Initialize a new styleframe project."
|
|
113
|
+
},
|
|
114
|
+
args: {
|
|
115
|
+
cwd: {
|
|
116
|
+
type: "string",
|
|
117
|
+
required: false,
|
|
118
|
+
default: process.cwd(),
|
|
119
|
+
description: "The directory where the project will be initialized",
|
|
120
|
+
alias: ["d", "dir"],
|
|
121
|
+
valueHint: "path"
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
async run({ args }) {
|
|
125
|
+
const { cwd } = args;
|
|
126
|
+
consola.info("Initializing...");
|
|
127
|
+
await initializeConfigFile(cwd);
|
|
128
|
+
await addPackageJsonDependencies(cwd);
|
|
129
|
+
await initializeFrameworkFile(cwd);
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
export {
|
|
133
|
+
addPackageJsonDependencies,
|
|
134
|
+
init as default,
|
|
135
|
+
initializeConfigFile,
|
|
136
|
+
initializeFrameworkFile
|
|
137
|
+
};
|