@code-id-labs/cli 0.0.0-stage → 1.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/dist/index.d.ts +2 -0
- package/dist/index.js +592 -0
- package/package.json +33 -3
- package/README.md +0 -3
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,592 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { execSync } from "node:child_process";
|
|
5
|
+
import { Command } from "commander";
|
|
6
|
+
import prompts from "prompts";
|
|
7
|
+
import pc from "picocolors";
|
|
8
|
+
import { loadConfig } from "c12";
|
|
9
|
+
//#region src/utils/config.ts
|
|
10
|
+
const DEFAULT_CONFIG = {
|
|
11
|
+
prefix: "cui",
|
|
12
|
+
ui: {
|
|
13
|
+
colors: {
|
|
14
|
+
primary: "#10b981",
|
|
15
|
+
neutral: "#737373",
|
|
16
|
+
danger: "#ef4444"
|
|
17
|
+
},
|
|
18
|
+
radius: {
|
|
19
|
+
sm: "8rpx",
|
|
20
|
+
md: "12rpx",
|
|
21
|
+
lg: "16rpx"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
components: {}
|
|
25
|
+
};
|
|
26
|
+
const CONFIG_FILE_NAMES = [
|
|
27
|
+
"cui.config.ts",
|
|
28
|
+
"cui.config.js",
|
|
29
|
+
"cui.config.mjs"
|
|
30
|
+
];
|
|
31
|
+
function getProjectRoot() {
|
|
32
|
+
return process.cwd();
|
|
33
|
+
}
|
|
34
|
+
function getConfigPath(cwd = getProjectRoot()) {
|
|
35
|
+
for (const name of CONFIG_FILE_NAMES) {
|
|
36
|
+
const p = path.resolve(cwd, name);
|
|
37
|
+
if (fs.existsSync(p)) return p;
|
|
38
|
+
}
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
async function readConfigAsync(cwd = getProjectRoot()) {
|
|
42
|
+
try {
|
|
43
|
+
const { config } = await loadConfig({
|
|
44
|
+
name: "cui",
|
|
45
|
+
configFile: "cui.config",
|
|
46
|
+
cwd,
|
|
47
|
+
rcFile: false
|
|
48
|
+
});
|
|
49
|
+
if (config) return {
|
|
50
|
+
...DEFAULT_CONFIG,
|
|
51
|
+
...config
|
|
52
|
+
};
|
|
53
|
+
} catch (err) {
|
|
54
|
+
console.warn("Failed to load cui.config via c12:", err);
|
|
55
|
+
}
|
|
56
|
+
return getConfigPath(cwd) ? DEFAULT_CONFIG : null;
|
|
57
|
+
}
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region src/utils/logger.ts
|
|
60
|
+
const logger = {
|
|
61
|
+
info(...args) {
|
|
62
|
+
console.log(pc.cyan("ℹ"), ...args);
|
|
63
|
+
},
|
|
64
|
+
success(...args) {
|
|
65
|
+
console.log(pc.green("✔"), ...args);
|
|
66
|
+
},
|
|
67
|
+
warn(...args) {
|
|
68
|
+
console.log(pc.yellow("⚠"), ...args);
|
|
69
|
+
},
|
|
70
|
+
error(...args) {
|
|
71
|
+
console.log(pc.red("✖"), ...args);
|
|
72
|
+
},
|
|
73
|
+
highlight(text) {
|
|
74
|
+
return pc.bold(pc.cyan(text));
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
//#endregion
|
|
78
|
+
//#region src/utils/pm.ts
|
|
79
|
+
function detectPackageManager(cwd = process.cwd()) {
|
|
80
|
+
if (fs.existsSync(path.resolve(cwd, "pnpm-lock.yaml"))) return "pnpm";
|
|
81
|
+
if (fs.existsSync(path.resolve(cwd, "yarn.lock"))) return "yarn";
|
|
82
|
+
if (fs.existsSync(path.resolve(cwd, "package-lock.json"))) return "npm";
|
|
83
|
+
return "npm";
|
|
84
|
+
}
|
|
85
|
+
function installDependencies(dependencies, options = {}) {
|
|
86
|
+
if (!dependencies || dependencies.length === 0) return;
|
|
87
|
+
const cwd = options.cwd || process.cwd();
|
|
88
|
+
const pm = detectPackageManager(cwd);
|
|
89
|
+
const isDev = options.dev ? pm === "yarn" ? "--dev" : "-D" : "";
|
|
90
|
+
let command = "";
|
|
91
|
+
if (pm === "pnpm") command = `pnpm add ${isDev} ${dependencies.join(" ")}`;
|
|
92
|
+
else if (pm === "yarn") command = `yarn add ${isDev} ${dependencies.join(" ")}`;
|
|
93
|
+
else command = `npm install ${isDev} ${dependencies.join(" ")}`;
|
|
94
|
+
try {
|
|
95
|
+
execSync(command, {
|
|
96
|
+
cwd,
|
|
97
|
+
stdio: "inherit"
|
|
98
|
+
});
|
|
99
|
+
} catch (error) {
|
|
100
|
+
throw new Error(`Failed to install dependencies: ${command}`, { cause: error });
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
//#endregion
|
|
104
|
+
//#region src/template.ts
|
|
105
|
+
function getCodeUiDepRange() {
|
|
106
|
+
try {
|
|
107
|
+
const pkgPath = new URL("../package.json", import.meta.url);
|
|
108
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
|
|
109
|
+
if (pkg.version) return `^${pkg.version}`;
|
|
110
|
+
} catch {}
|
|
111
|
+
return "^1.0.0";
|
|
112
|
+
}
|
|
113
|
+
function generateStarterFiles(options) {
|
|
114
|
+
const { projectName, appId, primaryColor, iconCollection, prefix } = options;
|
|
115
|
+
const codeUiRange = getCodeUiDepRange();
|
|
116
|
+
return {
|
|
117
|
+
".gitignore": [
|
|
118
|
+
"node_modules",
|
|
119
|
+
"dist",
|
|
120
|
+
".weapp-vite",
|
|
121
|
+
".DS_Store",
|
|
122
|
+
"*.log",
|
|
123
|
+
""
|
|
124
|
+
].join("\n"),
|
|
125
|
+
"package.json": JSON.stringify({
|
|
126
|
+
name: projectName,
|
|
127
|
+
type: "module",
|
|
128
|
+
version: "0.1.0",
|
|
129
|
+
private: true,
|
|
130
|
+
scripts: {
|
|
131
|
+
dev: "wv dev",
|
|
132
|
+
"dev:open": "wv dev -o",
|
|
133
|
+
build: "wv build",
|
|
134
|
+
clean: "rm -rf dist",
|
|
135
|
+
open: "wv open",
|
|
136
|
+
postinstall: "wv prepare"
|
|
137
|
+
},
|
|
138
|
+
dependencies: {
|
|
139
|
+
"@code-id-labs/components": codeUiRange,
|
|
140
|
+
"@code-id-labs/plugin-vite": codeUiRange
|
|
141
|
+
},
|
|
142
|
+
devDependencies: {
|
|
143
|
+
...iconCollection !== "lucide" ? { [`@iconify-json/${iconCollection}`]: "^1.2.0" } : {},
|
|
144
|
+
"@types/node": "^22.0.0",
|
|
145
|
+
"miniprogram-api-typings": "^5.2.3",
|
|
146
|
+
typescript: "^5.8.0",
|
|
147
|
+
"weapp-vite": "^7.5.0"
|
|
148
|
+
}
|
|
149
|
+
}, null, 2) + "\n",
|
|
150
|
+
"tsconfig.json": JSON.stringify({
|
|
151
|
+
references: [
|
|
152
|
+
{ path: "./.weapp-vite/tsconfig.app.json" },
|
|
153
|
+
{ path: "./.weapp-vite/tsconfig.server.json" },
|
|
154
|
+
{ path: "./.weapp-vite/tsconfig.node.json" },
|
|
155
|
+
{ path: "./.weapp-vite/tsconfig.shared.json" }
|
|
156
|
+
],
|
|
157
|
+
files: []
|
|
158
|
+
}, null, 2) + "\n",
|
|
159
|
+
"project.config.json": JSON.stringify({
|
|
160
|
+
description: "WeChat MiniProgram project powered by weapp-vite & Code UI",
|
|
161
|
+
miniprogramRoot: "dist/",
|
|
162
|
+
srcMiniprogramRoot: "dist/",
|
|
163
|
+
compileType: "miniprogram",
|
|
164
|
+
setting: {
|
|
165
|
+
coverView: false,
|
|
166
|
+
postcss: false,
|
|
167
|
+
minified: false,
|
|
168
|
+
enhance: false,
|
|
169
|
+
showShadowRootInWxmlPanel: false,
|
|
170
|
+
packNpmRelationList: [],
|
|
171
|
+
ignoreUploadUnusedFiles: true,
|
|
172
|
+
compileHotReLoad: false,
|
|
173
|
+
skylineRenderEnable: false,
|
|
174
|
+
packNpmManually: false,
|
|
175
|
+
es6: true,
|
|
176
|
+
minifyWXML: true,
|
|
177
|
+
newFeature: true,
|
|
178
|
+
urlCheck: false,
|
|
179
|
+
nodeModules: true,
|
|
180
|
+
autoAudits: false,
|
|
181
|
+
uploadWithSourceMap: true,
|
|
182
|
+
uglifyFileName: true,
|
|
183
|
+
remoteDebugLogEnable: true,
|
|
184
|
+
prefetch: false
|
|
185
|
+
},
|
|
186
|
+
simulatorType: "wechat",
|
|
187
|
+
simulatorPluginLibVersion: {},
|
|
188
|
+
editorSetting: {
|
|
189
|
+
tabIndent: "insertSpaces",
|
|
190
|
+
tabSize: 2
|
|
191
|
+
},
|
|
192
|
+
libVersion: "3.13.2",
|
|
193
|
+
packOptions: {
|
|
194
|
+
ignore: [],
|
|
195
|
+
include: []
|
|
196
|
+
},
|
|
197
|
+
appid: appId,
|
|
198
|
+
projectname: projectName,
|
|
199
|
+
condition: {}
|
|
200
|
+
}, null, 2) + "\n",
|
|
201
|
+
"weapp-vite.config.ts": `import { defineConfig } from "weapp-vite";
|
|
202
|
+
import { codeUI } from "@code-id-labs/plugin-vite";
|
|
203
|
+
|
|
204
|
+
export default defineConfig(({ mode }) => ({
|
|
205
|
+
weapp: {
|
|
206
|
+
srcRoot: "src",
|
|
207
|
+
platform: "weapp",
|
|
208
|
+
tailwindcss: {
|
|
209
|
+
cssEntries: ["src/app.css"],
|
|
210
|
+
cssOptions: {
|
|
211
|
+
rem2rpx: true,
|
|
212
|
+
autoprefixer: true,
|
|
213
|
+
},
|
|
214
|
+
},
|
|
215
|
+
hmr: {
|
|
216
|
+
runtime: "classic",
|
|
217
|
+
},
|
|
218
|
+
generate: {
|
|
219
|
+
extensions: {
|
|
220
|
+
js: "ts",
|
|
221
|
+
},
|
|
222
|
+
dirs: {
|
|
223
|
+
component: "src/components",
|
|
224
|
+
page: "src/pages",
|
|
225
|
+
},
|
|
226
|
+
},
|
|
227
|
+
},
|
|
228
|
+
plugins: [
|
|
229
|
+
codeUI({
|
|
230
|
+
autoImport: true,
|
|
231
|
+
treeShake: mode === "production",
|
|
232
|
+
}),
|
|
233
|
+
],
|
|
234
|
+
build: {
|
|
235
|
+
minify: mode === "production",
|
|
236
|
+
cssMinify: mode === "production" ? "lightningcss" : false,
|
|
237
|
+
},
|
|
238
|
+
}));
|
|
239
|
+
`,
|
|
240
|
+
"cui.config.ts": `import { defineConfig } from "@code-id-labs/plugin-vite";
|
|
241
|
+
|
|
242
|
+
export default defineConfig({
|
|
243
|
+
prefix: "${prefix}",
|
|
244
|
+
ui: {
|
|
245
|
+
colors: {
|
|
246
|
+
primary: "${primaryColor}",
|
|
247
|
+
secondary: "stone",
|
|
248
|
+
neutral: "zinc",
|
|
249
|
+
danger: "red",
|
|
250
|
+
success: "green",
|
|
251
|
+
warning: "amber",
|
|
252
|
+
info: "blue",
|
|
253
|
+
},
|
|
254
|
+
colorMode: "system",
|
|
255
|
+
},
|
|
256
|
+
icons: {
|
|
257
|
+
collections: ["${iconCollection}"],
|
|
258
|
+
},
|
|
259
|
+
components: {},
|
|
260
|
+
});
|
|
261
|
+
`,
|
|
262
|
+
"src/app.css": `@import "tailwindcss";
|
|
263
|
+
@import "@code-id-labs/components";
|
|
264
|
+
|
|
265
|
+
* {
|
|
266
|
+
box-sizing: border-box;
|
|
267
|
+
}
|
|
268
|
+
`,
|
|
269
|
+
"src/app.ts": `App({
|
|
270
|
+
globalData: {},
|
|
271
|
+
onLaunch() {},
|
|
272
|
+
});
|
|
273
|
+
`,
|
|
274
|
+
"src/app.json": JSON.stringify({
|
|
275
|
+
$schema: "https://vite.weapp.dev/app.json",
|
|
276
|
+
pages: ["pages/index/index"],
|
|
277
|
+
window: {
|
|
278
|
+
navigationBarTitleText: "Code UI",
|
|
279
|
+
navigationBarBackgroundColor: "@navBgColor",
|
|
280
|
+
navigationBarTextStyle: "@navTxtStyle",
|
|
281
|
+
backgroundColor: "@bgColor"
|
|
282
|
+
},
|
|
283
|
+
style: "v2",
|
|
284
|
+
componentFramework: "glass-easel",
|
|
285
|
+
sitemapLocation: "sitemap.json",
|
|
286
|
+
darkmode: true,
|
|
287
|
+
themeLocation: "theme.json"
|
|
288
|
+
}, null, 2) + "\n",
|
|
289
|
+
"src/theme.json": JSON.stringify({
|
|
290
|
+
light: {
|
|
291
|
+
navBgColor: "#ffffff",
|
|
292
|
+
navTxtStyle: "black",
|
|
293
|
+
bgColor: "#fafafa"
|
|
294
|
+
},
|
|
295
|
+
dark: {
|
|
296
|
+
navBgColor: "#18181b",
|
|
297
|
+
navTxtStyle: "white",
|
|
298
|
+
bgColor: "#09090b"
|
|
299
|
+
}
|
|
300
|
+
}, null, 2) + "\n",
|
|
301
|
+
"src/sitemap.json": JSON.stringify({
|
|
302
|
+
desc: "WeChat MiniProgram Sitemap",
|
|
303
|
+
rules: [{
|
|
304
|
+
action: "allow",
|
|
305
|
+
page: "*"
|
|
306
|
+
}]
|
|
307
|
+
}, null, 2) + "\n",
|
|
308
|
+
"src/pages/index/index.json": JSON.stringify({
|
|
309
|
+
$schema: "https://vite.weapp.dev/page.json",
|
|
310
|
+
navigationBarTitleText: "Code UI Starter"
|
|
311
|
+
}, null, 2) + "\n",
|
|
312
|
+
"src/pages/index/index.ts": `Page({
|
|
313
|
+
data: {
|
|
314
|
+
count: 0,
|
|
315
|
+
},
|
|
316
|
+
handleIncrement() {
|
|
317
|
+
this.setData({
|
|
318
|
+
count: this.data.count + 1,
|
|
319
|
+
});
|
|
320
|
+
},
|
|
321
|
+
});
|
|
322
|
+
`,
|
|
323
|
+
"src/pages/index/index.wxml": `<view class="min-h-screen bg-muted p-4 flex flex-col justify-center">
|
|
324
|
+
<${prefix}-card
|
|
325
|
+
title="Welcome to Code UI"
|
|
326
|
+
description="Headless + Tailwind-styled WeChat MiniProgram components."
|
|
327
|
+
>
|
|
328
|
+
<view class="flex items-center justify-between py-2">
|
|
329
|
+
<text class="text-sm text-default">Interactive counter</text>
|
|
330
|
+
<${prefix}-badge label="Count: {{count}}" color="primary" variant="soft" />
|
|
331
|
+
</view>
|
|
332
|
+
|
|
333
|
+
<view slot="footer" class="flex justify-end gap-2">
|
|
334
|
+
<${prefix}-button
|
|
335
|
+
label="Increment"
|
|
336
|
+
color="primary"
|
|
337
|
+
leading-icon="i-${iconCollection}-plus"
|
|
338
|
+
bind:click="handleIncrement"
|
|
339
|
+
/>
|
|
340
|
+
</view>
|
|
341
|
+
</${prefix}-card>
|
|
342
|
+
</view>
|
|
343
|
+
`
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
function writeStarterProject(targetDir, options) {
|
|
347
|
+
const files = generateStarterFiles(options);
|
|
348
|
+
for (const [relPath, content] of Object.entries(files)) {
|
|
349
|
+
const fullPath = path.resolve(targetDir, relPath);
|
|
350
|
+
fs.mkdirSync(path.dirname(fullPath), { recursive: true });
|
|
351
|
+
fs.writeFileSync(fullPath, content, "utf-8");
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
//#endregion
|
|
355
|
+
//#region src/index.ts
|
|
356
|
+
const program = new Command();
|
|
357
|
+
program.name("code-ui").description("Code UI — WeChat MiniProgram Component Library CLI").version("0.0.1");
|
|
358
|
+
program.command("create [project-name]").description("Create a new WeChat MiniProgram starter project with weapp-vite, Tailwind CSS v4, and Code UI").option("-y, --yes", "Use default options without interactive prompts").option("--appid <appid>", "WeChat MiniProgram AppID", "touristappid").option("--primary <color>", "Primary semantic color palette", "red").option("--icons <collection>", "Default Iconify collection", "lucide").option("--prefix <prefix>", "Component tag prefix", "c").option("--pm <manager>", "Package manager (pnpm | npm | yarn)").option("--skip-install", "Skip automatic dependency installation").action(async (projectNameArg, cmdOpts) => {
|
|
359
|
+
console.log(pc.bold(pc.cyan("\n✨ Code UI — WeChat MiniProgram Starter (weapp-vite + Tailwind v4)\n")));
|
|
360
|
+
let projectName = projectNameArg || "my-code-ui-app";
|
|
361
|
+
let appId = cmdOpts.appid || "touristappid";
|
|
362
|
+
let primaryColor = cmdOpts.primary || "red";
|
|
363
|
+
let iconCollection = cmdOpts.icons || "lucide";
|
|
364
|
+
let prefix = cmdOpts.prefix || "c";
|
|
365
|
+
let pm = cmdOpts.pm || "pnpm";
|
|
366
|
+
let runInstall = !cmdOpts.skipInstall;
|
|
367
|
+
if (!cmdOpts.yes) {
|
|
368
|
+
const response = await prompts([
|
|
369
|
+
{
|
|
370
|
+
type: projectNameArg ? null : "text",
|
|
371
|
+
name: "projectName",
|
|
372
|
+
message: "Project folder name:",
|
|
373
|
+
initial: projectName,
|
|
374
|
+
validate: (val) => val.trim().length > 0 ? true : "Project name cannot be empty"
|
|
375
|
+
},
|
|
376
|
+
{
|
|
377
|
+
type: "text",
|
|
378
|
+
name: "appId",
|
|
379
|
+
message: "WeChat MiniProgram AppID:",
|
|
380
|
+
initial: appId
|
|
381
|
+
},
|
|
382
|
+
{
|
|
383
|
+
type: "select",
|
|
384
|
+
name: "primaryColor",
|
|
385
|
+
message: "Primary brand color palette:",
|
|
386
|
+
choices: [
|
|
387
|
+
{
|
|
388
|
+
title: "Red (Code.id Crimson)",
|
|
389
|
+
value: "red"
|
|
390
|
+
},
|
|
391
|
+
{
|
|
392
|
+
title: "Emerald",
|
|
393
|
+
value: "emerald"
|
|
394
|
+
},
|
|
395
|
+
{
|
|
396
|
+
title: "Blue",
|
|
397
|
+
value: "blue"
|
|
398
|
+
},
|
|
399
|
+
{
|
|
400
|
+
title: "Indigo",
|
|
401
|
+
value: "indigo"
|
|
402
|
+
},
|
|
403
|
+
{
|
|
404
|
+
title: "Stone",
|
|
405
|
+
value: "stone"
|
|
406
|
+
},
|
|
407
|
+
{
|
|
408
|
+
title: "Violet",
|
|
409
|
+
value: "violet"
|
|
410
|
+
}
|
|
411
|
+
],
|
|
412
|
+
initial: 0
|
|
413
|
+
},
|
|
414
|
+
{
|
|
415
|
+
type: "select",
|
|
416
|
+
name: "iconCollection",
|
|
417
|
+
message: "Default Iconify icon collection:",
|
|
418
|
+
choices: [
|
|
419
|
+
{
|
|
420
|
+
title: "Lucide (i-lucide-*)",
|
|
421
|
+
value: "lucide"
|
|
422
|
+
},
|
|
423
|
+
{
|
|
424
|
+
title: "Tabler (i-tabler-*)",
|
|
425
|
+
value: "tabler"
|
|
426
|
+
},
|
|
427
|
+
{
|
|
428
|
+
title: "Heroicons (i-heroicons-*)",
|
|
429
|
+
value: "heroicons"
|
|
430
|
+
},
|
|
431
|
+
{
|
|
432
|
+
title: "Material Design Icons (i-mdi-*)",
|
|
433
|
+
value: "mdi"
|
|
434
|
+
}
|
|
435
|
+
],
|
|
436
|
+
initial: 0
|
|
437
|
+
},
|
|
438
|
+
{
|
|
439
|
+
type: "text",
|
|
440
|
+
name: "prefix",
|
|
441
|
+
message: "Component tag prefix (e.g. 'c' for <c-button>):",
|
|
442
|
+
initial: prefix
|
|
443
|
+
},
|
|
444
|
+
{
|
|
445
|
+
type: cmdOpts.pm ? null : "select",
|
|
446
|
+
name: "pm",
|
|
447
|
+
message: "Package manager:",
|
|
448
|
+
choices: [
|
|
449
|
+
{
|
|
450
|
+
title: "pnpm (Recommended)",
|
|
451
|
+
value: "pnpm"
|
|
452
|
+
},
|
|
453
|
+
{
|
|
454
|
+
title: "npm",
|
|
455
|
+
value: "npm"
|
|
456
|
+
},
|
|
457
|
+
{
|
|
458
|
+
title: "yarn",
|
|
459
|
+
value: "yarn"
|
|
460
|
+
}
|
|
461
|
+
],
|
|
462
|
+
initial: 0
|
|
463
|
+
},
|
|
464
|
+
{
|
|
465
|
+
type: cmdOpts.skipInstall ? null : "confirm",
|
|
466
|
+
name: "runInstall",
|
|
467
|
+
message: "Install dependencies now?",
|
|
468
|
+
initial: true
|
|
469
|
+
}
|
|
470
|
+
], { onCancel: () => {
|
|
471
|
+
logger.warn("Project creation cancelled.");
|
|
472
|
+
process.exit(0);
|
|
473
|
+
} });
|
|
474
|
+
if (response.projectName) projectName = String(response.projectName).trim();
|
|
475
|
+
if (response.appId) appId = String(response.appId).trim();
|
|
476
|
+
if (response.primaryColor) primaryColor = String(response.primaryColor);
|
|
477
|
+
if (response.iconCollection) iconCollection = String(response.iconCollection);
|
|
478
|
+
if (response.prefix) prefix = String(response.prefix).trim();
|
|
479
|
+
if (response.pm) pm = response.pm;
|
|
480
|
+
if (typeof response.runInstall === "boolean") runInstall = response.runInstall;
|
|
481
|
+
}
|
|
482
|
+
const targetDir = path.resolve(process.cwd(), projectName);
|
|
483
|
+
if (fs.existsSync(targetDir) && fs.readdirSync(targetDir).length > 0 && !cmdOpts.yes) {
|
|
484
|
+
const { overwrite } = await prompts({
|
|
485
|
+
type: "confirm",
|
|
486
|
+
name: "overwrite",
|
|
487
|
+
message: `Directory "${projectName}" is not empty. Continue and overwrite matching files?`,
|
|
488
|
+
initial: false
|
|
489
|
+
});
|
|
490
|
+
if (!overwrite) {
|
|
491
|
+
logger.warn("Aborted.");
|
|
492
|
+
process.exit(0);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
writeStarterProject(targetDir, {
|
|
496
|
+
projectName: path.basename(targetDir),
|
|
497
|
+
appId,
|
|
498
|
+
primaryColor,
|
|
499
|
+
iconCollection,
|
|
500
|
+
prefix
|
|
501
|
+
});
|
|
502
|
+
logger.success(`Scaffolded Code UI project in ${pc.green(targetDir)}`);
|
|
503
|
+
if (runInstall) {
|
|
504
|
+
logger.info(`Installing dependencies with ${pc.cyan(pm)}...`);
|
|
505
|
+
const installCmd = pm === "yarn" ? "yarn" : `${pm} install`;
|
|
506
|
+
try {
|
|
507
|
+
execSync(installCmd, {
|
|
508
|
+
cwd: targetDir,
|
|
509
|
+
stdio: "inherit"
|
|
510
|
+
});
|
|
511
|
+
logger.success("Dependencies installed.");
|
|
512
|
+
} catch {
|
|
513
|
+
logger.warn(`Automatic install failed. You can install manually inside ${pc.cyan(projectName)} via "${installCmd}".`);
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
const relDir = path.relative(process.cwd(), targetDir) || ".";
|
|
517
|
+
console.log(`\n${pc.bold("Next steps:")}`);
|
|
518
|
+
if (relDir !== ".") console.log(` ${pc.cyan(`cd ${relDir}`)}`);
|
|
519
|
+
if (!runInstall) console.log(` ${pc.cyan(`${pm} install`)}`);
|
|
520
|
+
console.log(` ${pc.cyan(`${pm === "npm" ? "npm run" : pm} dev`)}`);
|
|
521
|
+
console.log(` Open WeChat DevTools and import ${pc.green(path.join(relDir, "dist"))} (or project root).\n`);
|
|
522
|
+
});
|
|
523
|
+
program.command("init").description("Initialize Code UI configuration (cui.config.ts, weapp-vite.config.ts, and src/app.css) in an existing weapp-vite project").option("-y, --yes", "Skip prompts and use defaults").option("--primary <color>", "Primary semantic color palette", "red").option("--icons <collection>", "Default Iconify collection", "lucide").option("--prefix <prefix>", "Component tag prefix", "c").option("--install", "Install @code-ui packages automatically").action(async (cmdOpts) => {
|
|
524
|
+
const cwd = process.cwd();
|
|
525
|
+
const files = generateStarterFiles({
|
|
526
|
+
projectName: path.basename(cwd),
|
|
527
|
+
appId: "touristappid",
|
|
528
|
+
primaryColor: cmdOpts.primary || "red",
|
|
529
|
+
iconCollection: cmdOpts.icons || "lucide",
|
|
530
|
+
prefix: cmdOpts.prefix || "c"
|
|
531
|
+
});
|
|
532
|
+
const cuiConfigPath = path.resolve(cwd, "cui.config.ts");
|
|
533
|
+
if (!fs.existsSync(cuiConfigPath)) {
|
|
534
|
+
fs.writeFileSync(cuiConfigPath, files["cui.config.ts"] ?? "", "utf-8");
|
|
535
|
+
logger.success(`Created ${pc.green("cui.config.ts")}`);
|
|
536
|
+
} else logger.info(`${pc.cyan("cui.config.ts")} already exists, skipping.`);
|
|
537
|
+
const weappViteConfigPath = path.resolve(cwd, "weapp-vite.config.ts");
|
|
538
|
+
const viteConfigPath = path.resolve(cwd, "vite.config.ts");
|
|
539
|
+
if (!fs.existsSync(weappViteConfigPath) && !fs.existsSync(viteConfigPath)) {
|
|
540
|
+
fs.writeFileSync(weappViteConfigPath, files["weapp-vite.config.ts"] ?? "", "utf-8");
|
|
541
|
+
logger.success(`Created ${pc.green("weapp-vite.config.ts")}`);
|
|
542
|
+
} else logger.info(`Vite config already exists. Ensure ${pc.cyan("codeUI({ autoImport: true, treeShake: mode === 'production' })")} is registered in plugins.`);
|
|
543
|
+
const appCssPath = path.resolve(cwd, "src/app.css");
|
|
544
|
+
if (!fs.existsSync(appCssPath)) {
|
|
545
|
+
fs.mkdirSync(path.dirname(appCssPath), { recursive: true });
|
|
546
|
+
fs.writeFileSync(appCssPath, files["src/app.css"] ?? "", "utf-8");
|
|
547
|
+
logger.success(`Created ${pc.green("src/app.css")}`);
|
|
548
|
+
} else {
|
|
549
|
+
const currentCss = fs.readFileSync(appCssPath, "utf-8");
|
|
550
|
+
if (!currentCss.includes("@code-id-labs/components")) {
|
|
551
|
+
const updatedCss = `@import "tailwindcss";\n@import "@code-id-labs/components";\n\n${currentCss.replace(/@import\s+["']tailwindcss["'];?\s*/g, "")}`;
|
|
552
|
+
fs.writeFileSync(appCssPath, updatedCss, "utf-8");
|
|
553
|
+
logger.success(`Added ${pc.green("@import \"@code-id-labs/components\";")} to ${pc.green("src/app.css")}`);
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
if (cmdOpts.install) {
|
|
557
|
+
const iconCol = cmdOpts.icons || "lucide";
|
|
558
|
+
installDependencies(["@code-id-labs/components", "@code-id-labs/plugin-vite"], { cwd });
|
|
559
|
+
if (iconCol !== "lucide") installDependencies([`@iconify-json/${iconCol}`], {
|
|
560
|
+
cwd,
|
|
561
|
+
dev: true
|
|
562
|
+
});
|
|
563
|
+
logger.success("Installed Code UI dependencies.");
|
|
564
|
+
} else {
|
|
565
|
+
const pm = detectPackageManager(cwd);
|
|
566
|
+
const addCmd = pm === "npm" ? "npm i" : `${pm} add`;
|
|
567
|
+
const iconCol = cmdOpts.icons || "lucide";
|
|
568
|
+
console.log(`\n${pc.bold("Install required packages:")}`);
|
|
569
|
+
console.log(` ${pc.cyan(`${addCmd} @code-id-labs/components @code-id-labs/plugin-vite`)}`);
|
|
570
|
+
if (iconCol !== "lucide") console.log(` ${pc.cyan(`${addCmd} -D @iconify-json/${iconCol}`)}\n`);
|
|
571
|
+
else console.log("");
|
|
572
|
+
}
|
|
573
|
+
});
|
|
574
|
+
program.command("info").description("Show current Code UI configuration and environment status").action(async () => {
|
|
575
|
+
const configPath = getConfigPath();
|
|
576
|
+
console.log(pc.bold(pc.cyan("\nCode UI Component Library\n")));
|
|
577
|
+
if (configPath) {
|
|
578
|
+
console.log(`Config file: ${pc.green(configPath)}`);
|
|
579
|
+
const config = await readConfigAsync();
|
|
580
|
+
if (config) {
|
|
581
|
+
console.log(`Prefix: ${pc.yellow(config.prefix || "cui")}`);
|
|
582
|
+
console.log(`Components: ${pc.yellow(Object.keys(config.components || {}).join(", ") || "none configured")}`);
|
|
583
|
+
}
|
|
584
|
+
} else {
|
|
585
|
+
console.log(pc.yellow("No cui.config.ts found in current directory."));
|
|
586
|
+
console.log(`Run ${pc.cyan("npx @code-id-labs/cli init")} or create a ${pc.cyan("cui.config.ts")} to customize global component styling.`);
|
|
587
|
+
}
|
|
588
|
+
console.log("");
|
|
589
|
+
});
|
|
590
|
+
program.parse(process.argv);
|
|
591
|
+
//#endregion
|
|
592
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@code-id-labs/cli",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "CLI tool for code-ui prebuilt WeChat MiniProgram component library",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"code-ui": "./dist/index.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"main": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"c12": "^2.0.4",
|
|
19
|
+
"commander": "^12.1.0",
|
|
20
|
+
"picocolors": "^1.1.1",
|
|
21
|
+
"prompts": "^2.4.2"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@types/node": "^26.2.0",
|
|
25
|
+
"@types/prompts": "^2.4.9",
|
|
26
|
+
"tsdown": "^0.23.0",
|
|
27
|
+
"typescript": "^5.5.4",
|
|
28
|
+
"@code-id-labs/core": "0.0.1"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "tsdown",
|
|
32
|
+
"dev": "tsdown --watch",
|
|
33
|
+
"typecheck": "tsc --noEmit",
|
|
34
|
+
"clean": "rm -rf dist"
|
|
35
|
+
}
|
|
6
36
|
}
|
package/README.md
DELETED