@vc-shell/create-vc-app 2.4.0-pr302.b052b38 → 2.4.0-pr303.f20ea90
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/commands/add-module.d.ts.map +1 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/engine/codegen.d.ts +2 -5
- package/dist/engine/codegen.d.ts.map +1 -1
- package/dist/index.js +233 -330
- package/dist/templates/dynamic-module/tsconfig.json +5 -1
- package/dist/templates/module/composables/useDetails.ts.ejs +0 -1
- package/dist/templates/module/composables/useList.ts.ejs +1 -2
- package/dist/templates/module/pages/list.vue.ejs +4 -24
- package/dist/templates/sample-module/composables/useList/index.ts +1 -1
- package/dist/templates/sample-module/pages/index.ts +1 -1
- package/dist/templates/sample-module/pages/list.vue +1 -9
- package/dist/templates/sample-module/sample-data/index.ts +2 -2
- package/dist/templates/standalone/_github/COMMIT_CONVENTION.md +12 -12
- package/dist/templates/standalone/_github/PULL_REQUEST_TEMPLATE.md +0 -3
- package/dist/templates/standalone/_vscode/extensions.json +3 -1
- package/dist/templates/standalone/_vscode/settings.json +8 -3
- package/dist/templates/standalone/eslint.config.mjs +0 -20
- package/dist/templates/standalone/src/api_client/README.md +37 -38
- package/dist/templates/standalone/src/bootstrap.ts.ejs +2 -1
- package/dist/templates/standalone/src/components/dashboard-widgets/Welcome.vue +2 -1
- package/dist/templates/standalone/src/pages/App.vue.ejs +0 -1
- package/dist/templates/standalone/src/pages/Dashboard.vue.ejs +1 -1
- package/dist/templates/standalone/src/router/routes.ts.ejs +15 -12
- package/dist/templates/standalone/tsconfig.json +9 -2
- package/package.json +3 -3
- package/dist/engine/codegen.test.d.ts +0 -2
- package/dist/engine/codegen.test.d.ts.map +0 -1
- package/dist/engine/format.d.ts +0 -13
- package/dist/engine/format.d.ts.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,54 +1,53 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import { exit as
|
|
6
|
-
import { fileURLToPath as
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
version: q
|
|
2
|
+
import z from "mri";
|
|
3
|
+
import n from "picocolors";
|
|
4
|
+
import c from "node:path";
|
|
5
|
+
import { exit as L, argv as B } from "node:process";
|
|
6
|
+
import { fileURLToPath as F } from "node:url";
|
|
7
|
+
import A from "prompts";
|
|
8
|
+
import r from "node:fs";
|
|
9
|
+
import E from "ejs";
|
|
10
|
+
const O = "2.4.0-pr303.f20ea90", V = {
|
|
11
|
+
version: O
|
|
13
12
|
};
|
|
14
|
-
function
|
|
13
|
+
function h(e) {
|
|
15
14
|
return e.trim().replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[\s_]+/g, "-").toLowerCase().replace(/[^a-z0-9-]/g, "");
|
|
16
15
|
}
|
|
17
|
-
function
|
|
18
|
-
return e.replace(/[-_\s]+(.)?/g, (
|
|
16
|
+
function x(e) {
|
|
17
|
+
return e.replace(/[-_\s]+(.)?/g, (a, t) => t ? t.toUpperCase() : "").replace(/^(.)/, (a, t) => t.toUpperCase());
|
|
19
18
|
}
|
|
20
|
-
function
|
|
21
|
-
const
|
|
22
|
-
return
|
|
19
|
+
function Z(e) {
|
|
20
|
+
const a = x(e);
|
|
21
|
+
return a.charAt(0).toLowerCase() + a.slice(1);
|
|
23
22
|
}
|
|
24
|
-
function
|
|
23
|
+
function D(e) {
|
|
25
24
|
return e.replace(/[-\s]+/g, "_").replace(/([a-z])([A-Z])/g, "$1_$2").toUpperCase();
|
|
26
25
|
}
|
|
27
|
-
function
|
|
28
|
-
return e.replace(/[-_]+/g, " ").replace(/\b\w/g, (
|
|
26
|
+
function S(e) {
|
|
27
|
+
return e.replace(/[-_]+/g, " ").replace(/\b\w/g, (a) => a.toUpperCase());
|
|
29
28
|
}
|
|
30
|
-
function
|
|
29
|
+
function k(e) {
|
|
31
30
|
return /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.test(e);
|
|
32
31
|
}
|
|
33
|
-
function
|
|
32
|
+
function C(e) {
|
|
34
33
|
return e.trim().toLowerCase().replace(/\s+/g, "-").replace(/^[._]/, "").replace(/[^a-z0-9-~]+/g, "-");
|
|
35
34
|
}
|
|
36
|
-
function
|
|
35
|
+
function _(e) {
|
|
37
36
|
return e.trim().toLowerCase().replace(/\/+/g, "/").replace(/[^a-z0-9/-]+/g, "/").replace(/\/?$/, "/");
|
|
38
37
|
}
|
|
39
|
-
function
|
|
40
|
-
const
|
|
38
|
+
function R(e) {
|
|
39
|
+
const a = e.moduleName || "", t = a ? h(a) : "", s = {
|
|
41
40
|
hasModule: !!e.moduleName,
|
|
42
|
-
ModuleName:
|
|
43
|
-
ModuleNamePascalCase:
|
|
44
|
-
ModuleNameCamelCase:
|
|
45
|
-
ModuleNameUppercase:
|
|
46
|
-
ModuleNameScreamingSnake:
|
|
47
|
-
ModuleNameSentenceCase:
|
|
41
|
+
ModuleName: t,
|
|
42
|
+
ModuleNamePascalCase: a ? x(a) : "",
|
|
43
|
+
ModuleNameCamelCase: a ? Z(a) : "",
|
|
44
|
+
ModuleNameUppercase: t.toUpperCase(),
|
|
45
|
+
ModuleNameScreamingSnake: a ? D(a) : "",
|
|
46
|
+
ModuleNameSentenceCase: a ? S(a) : ""
|
|
48
47
|
};
|
|
49
|
-
return e.projectName && (
|
|
48
|
+
return e.projectName && (s.AppName = h(e.projectName), s.AppNameSentenceCase = S(e.projectName)), e.packageName !== void 0 && (s.PackageName = e.packageName || "", s.BasePath = e.basePath || "", s.tenantRoutes = e.tenantRoutes || !1, s.aiAgent = e.aiAgent || !1, s.dashboard = e.dashboard || !1, s.mocks = e.mocks || !1), s;
|
|
50
49
|
}
|
|
51
|
-
const
|
|
50
|
+
const J = /* @__PURE__ */ new Set([".png", ".jpg", ".jpeg", ".gif", ".bmp", ".ico", ".pdf", ".zip"]), K = {
|
|
52
51
|
_gitignore: ".gitignore",
|
|
53
52
|
"_yarnrc.yml": ".yarnrc.yml",
|
|
54
53
|
_browserslistrc: ".browserslistrc",
|
|
@@ -63,177 +62,155 @@ const H = /* @__PURE__ */ new Set([".png", ".jpg", ".jpeg", ".gif", ".bmp", ".ic
|
|
|
63
62
|
_yarn: ".yarn",
|
|
64
63
|
"_package.json": "package.json"
|
|
65
64
|
};
|
|
66
|
-
function
|
|
67
|
-
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
const
|
|
71
|
-
if (
|
|
72
|
-
|
|
65
|
+
function Y(e, a, t) {
|
|
66
|
+
a.endsWith(".ejs") && (a = a.slice(0, -4));
|
|
67
|
+
const s = c.dirname(a);
|
|
68
|
+
r.existsSync(s) || r.mkdirSync(s, { recursive: !0 });
|
|
69
|
+
const o = c.extname(e.replace(/\.ejs$/, "")).toLowerCase();
|
|
70
|
+
if (J.has(o))
|
|
71
|
+
r.copyFileSync(e, a);
|
|
73
72
|
else {
|
|
74
|
-
const
|
|
75
|
-
|
|
73
|
+
const d = r.readFileSync(e, "utf-8"), p = E.render(d, t, { filename: e });
|
|
74
|
+
r.writeFileSync(a, p);
|
|
76
75
|
}
|
|
77
76
|
}
|
|
78
|
-
function j(e,
|
|
79
|
-
if (!
|
|
80
|
-
const
|
|
81
|
-
for (const
|
|
82
|
-
const
|
|
83
|
-
let
|
|
77
|
+
function j(e, a, t) {
|
|
78
|
+
if (!r.existsSync(e)) return;
|
|
79
|
+
const s = r.readdirSync(e);
|
|
80
|
+
for (const o of s) {
|
|
81
|
+
const d = c.join(e, o), p = o.endsWith(".ejs") ? o.slice(0, -4) : o;
|
|
82
|
+
let m = K[p] ?? p;
|
|
84
83
|
try {
|
|
85
|
-
|
|
84
|
+
m = E.render(m, t);
|
|
86
85
|
} catch {
|
|
87
86
|
}
|
|
88
|
-
const
|
|
89
|
-
|
|
87
|
+
const l = c.join(a, m);
|
|
88
|
+
r.statSync(d).isDirectory() ? (r.existsSync(l) || r.mkdirSync(l, { recursive: !0 }), j(d, l, t)) : Y(d, l, t);
|
|
90
89
|
}
|
|
91
90
|
}
|
|
92
|
-
function
|
|
93
|
-
if (
|
|
94
|
-
for (const
|
|
95
|
-
if (
|
|
96
|
-
const
|
|
97
|
-
|
|
91
|
+
function q(e) {
|
|
92
|
+
if (r.existsSync(e))
|
|
93
|
+
for (const a of r.readdirSync(e)) {
|
|
94
|
+
if (a === ".git") continue;
|
|
95
|
+
const t = c.join(e, a);
|
|
96
|
+
r.statSync(t).isDirectory() ? r.rmSync(t, { recursive: !0, force: !0 }) : r.unlinkSync(t);
|
|
98
97
|
}
|
|
99
98
|
}
|
|
100
|
-
function
|
|
101
|
-
if (!
|
|
102
|
-
const
|
|
103
|
-
return
|
|
104
|
-
}
|
|
105
|
-
const te = /* @__PURE__ */ new Set(["node_modules", ".git", ".yarn", "dist"]);
|
|
106
|
-
function L(e, t = []) {
|
|
107
|
-
if (!i.existsSync(e)) return t;
|
|
108
|
-
if (!i.statSync(e).isDirectory())
|
|
109
|
-
return t.push(e), t;
|
|
110
|
-
for (const n of i.readdirSync(e))
|
|
111
|
-
te.has(n) || L(m.join(e, n), t);
|
|
112
|
-
return t;
|
|
113
|
-
}
|
|
114
|
-
async function z(e) {
|
|
115
|
-
const t = e.flatMap((o) => L(o));
|
|
116
|
-
let n = 0;
|
|
117
|
-
for (const o of t)
|
|
118
|
-
try {
|
|
119
|
-
const a = await I.getFileInfo(o, { resolveConfig: !0 });
|
|
120
|
-
if (!a.inferredParser || a.ignored) continue;
|
|
121
|
-
const l = i.readFileSync(o, "utf-8"), s = await I.resolveConfig(o, { editorconfig: !0 }), c = await I.format(l, { ...s, filepath: o });
|
|
122
|
-
c !== l && (i.writeFileSync(o, c), n++);
|
|
123
|
-
} catch {
|
|
124
|
-
}
|
|
125
|
-
return n;
|
|
99
|
+
function I(e) {
|
|
100
|
+
if (!r.existsSync(e)) return !0;
|
|
101
|
+
const a = r.readdirSync(e);
|
|
102
|
+
return a.length === 0 || a.length === 1 && a[0] === ".git";
|
|
126
103
|
}
|
|
127
|
-
const
|
|
104
|
+
const W = {
|
|
128
105
|
standalone: "Standalone App",
|
|
129
106
|
"dynamic-module": "Dynamic Module"
|
|
130
107
|
};
|
|
131
|
-
function
|
|
132
|
-
const
|
|
108
|
+
function H(e) {
|
|
109
|
+
const a = W[e.projectType] ?? e.projectType, t = !!e.moduleName;
|
|
133
110
|
console.log(`
|
|
134
|
-
${
|
|
135
|
-
${
|
|
136
|
-
${
|
|
137
|
-
${
|
|
138
|
-
${
|
|
139
|
-
${
|
|
140
|
-
${
|
|
141
|
-
` : ""} ${
|
|
142
|
-
${
|
|
111
|
+
${n.green("╭─────────────────────────────────────────╮")}
|
|
112
|
+
${n.green("│")} ${n.green("│")}
|
|
113
|
+
${n.green("│")} ${n.bold("VC Shell App created successfully!")} ${n.green("│")}
|
|
114
|
+
${n.green("│")} ${n.green("│")}
|
|
115
|
+
${n.green("│")} Project: ${n.cyan(e.projectName.padEnd(28))}${n.green("│")}
|
|
116
|
+
${n.green("│")} Type: ${n.cyan(a.padEnd(28))}${n.green("│")}
|
|
117
|
+
${t && e.moduleName ? ` ${n.green("│")} Module: ${n.cyan(e.moduleName.padEnd(28))}${n.green("│")}
|
|
118
|
+
` : ""} ${n.green("│")} ${n.green("│")}
|
|
119
|
+
${n.green("╰─────────────────────────────────────────╯")}
|
|
143
120
|
|
|
144
|
-
${
|
|
121
|
+
${n.bold("Next steps:")}
|
|
145
122
|
|
|
146
123
|
1. cd ${e.projectName}
|
|
147
124
|
2. yarn install
|
|
148
125
|
3. yarn serve
|
|
149
|
-
${
|
|
126
|
+
${t && e.moduleName ? `
|
|
150
127
|
Module is ready at:
|
|
151
|
-
src/modules/${
|
|
128
|
+
src/modules/${X(e.moduleName)}/
|
|
152
129
|
` : ""}
|
|
153
|
-
${
|
|
130
|
+
${n.dim("Docs: https://docs.virtocommerce.org/platform/developer-guide/latest/custom-apps-development/vc-shell/vc-shell-overview/")}
|
|
154
131
|
`);
|
|
155
132
|
}
|
|
156
|
-
function
|
|
133
|
+
function X(e) {
|
|
157
134
|
return e.trim().replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[\s_]+/g, "-").toLowerCase().replace(/[^a-z0-9-]/g, "");
|
|
158
135
|
}
|
|
159
|
-
const
|
|
136
|
+
const P = [
|
|
160
137
|
{ title: "Standalone App — full application with bundled modules", value: "standalone" },
|
|
161
138
|
{ title: "Dynamic Module — remote module loaded by host via Module Federation", value: "dynamic-module" }
|
|
162
139
|
];
|
|
163
|
-
function
|
|
164
|
-
return typeof e == "string" &&
|
|
140
|
+
function G(e) {
|
|
141
|
+
return typeof e == "string" && P.some((a) => a.value === e);
|
|
165
142
|
}
|
|
166
|
-
async function
|
|
167
|
-
const
|
|
168
|
-
let
|
|
169
|
-
const
|
|
170
|
-
let
|
|
171
|
-
if (
|
|
172
|
-
|
|
173
|
-
const
|
|
174
|
-
if (!
|
|
175
|
-
const
|
|
176
|
-
console.error(
|
|
143
|
+
async function Q(e, a) {
|
|
144
|
+
const t = process.cwd();
|
|
145
|
+
let o = e._?.[0] || e.name || e["app-name"];
|
|
146
|
+
const d = o || "vc-app", p = () => o === "." ? c.basename(c.resolve()) : o, m = !!(o && e.type);
|
|
147
|
+
let l;
|
|
148
|
+
if (m) {
|
|
149
|
+
o = o || d;
|
|
150
|
+
const f = c.resolve(t, o);
|
|
151
|
+
if (!G(e.type)) {
|
|
152
|
+
const b = P.map(($) => $.value).join(", ");
|
|
153
|
+
console.error(n.red(`Unknown project type: "${e.type}". Valid types: ${b}`)), process.exit(1);
|
|
177
154
|
}
|
|
178
|
-
|
|
179
|
-
const
|
|
180
|
-
|
|
181
|
-
projectName:
|
|
182
|
-
packageName: e["package-name"] || (
|
|
183
|
-
projectType:
|
|
184
|
-
moduleName:
|
|
185
|
-
basePath: e["base-path"] ||
|
|
155
|
+
r.existsSync(f) && !I(f) && !e.overwrite && (console.error(n.red(`Target directory "${o}" is not empty. Use --overwrite to overwrite.`)), process.exit(1));
|
|
156
|
+
const u = p(), y = e.type, g = e["module-name"], N = y === "dynamic-module" ? g || S(u) : g || void 0;
|
|
157
|
+
l = {
|
|
158
|
+
projectName: h(u),
|
|
159
|
+
packageName: e["package-name"] || (k(u) ? u : C(u)),
|
|
160
|
+
projectType: y,
|
|
161
|
+
moduleName: N,
|
|
162
|
+
basePath: e["base-path"] || _(`/apps/${h(u)}/`),
|
|
186
163
|
tenantRoutes: e["tenant-routes"] || !1,
|
|
187
164
|
aiAgent: e["ai-agent"] || !1,
|
|
188
165
|
dashboard: e.dashboard || !1,
|
|
189
166
|
mocks: e.mocks || !1
|
|
190
167
|
};
|
|
191
168
|
} else {
|
|
192
|
-
const
|
|
193
|
-
throw new Error(
|
|
169
|
+
const f = () => {
|
|
170
|
+
throw new Error(n.red("✖") + " Creation cancelled");
|
|
194
171
|
};
|
|
195
172
|
try {
|
|
196
|
-
const
|
|
173
|
+
const u = await A(
|
|
197
174
|
[
|
|
198
175
|
{
|
|
199
176
|
name: "projectName",
|
|
200
|
-
type:
|
|
201
|
-
message:
|
|
202
|
-
initial:
|
|
177
|
+
type: o ? null : "text",
|
|
178
|
+
message: n.reset("Project name:"),
|
|
179
|
+
initial: d,
|
|
203
180
|
onState: (w) => {
|
|
204
|
-
|
|
181
|
+
o = h(String(w.value).trim()) || d;
|
|
205
182
|
},
|
|
206
|
-
format: (w) =>
|
|
183
|
+
format: (w) => h(String(w).trim())
|
|
207
184
|
},
|
|
208
185
|
{
|
|
209
|
-
type: () => !
|
|
186
|
+
type: () => !r.existsSync(c.resolve(t, o)) || I(c.resolve(t, o)) ? null : "confirm",
|
|
210
187
|
name: "overwrite",
|
|
211
|
-
message: () => (
|
|
188
|
+
message: () => (o === "." ? "Current directory" : `Target directory "${o}"`) + " is not empty. Remove existing files and continue?"
|
|
212
189
|
},
|
|
213
190
|
{
|
|
214
|
-
type: (w, { overwrite:
|
|
215
|
-
if (
|
|
216
|
-
throw new Error(
|
|
191
|
+
type: (w, { overwrite: M }) => {
|
|
192
|
+
if (M === !1)
|
|
193
|
+
throw new Error(n.red("✖") + " Operation cancelled");
|
|
217
194
|
return null;
|
|
218
195
|
},
|
|
219
196
|
name: "overwriteChecker"
|
|
220
197
|
},
|
|
221
198
|
{
|
|
222
199
|
name: "packageName",
|
|
223
|
-
type: () =>
|
|
224
|
-
message:
|
|
225
|
-
initial: () =>
|
|
226
|
-
validate: (w) =>
|
|
200
|
+
type: () => k(p()) ? null : "text",
|
|
201
|
+
message: n.reset("Package name:"),
|
|
202
|
+
initial: () => C(p()),
|
|
203
|
+
validate: (w) => k(w) || "Invalid package.json name"
|
|
227
204
|
},
|
|
228
205
|
{
|
|
229
206
|
type: "select",
|
|
230
207
|
name: "projectType",
|
|
231
|
-
message:
|
|
232
|
-
choices:
|
|
208
|
+
message: n.reset("Project type:"),
|
|
209
|
+
choices: P
|
|
233
210
|
}
|
|
234
211
|
],
|
|
235
|
-
{ onCancel:
|
|
236
|
-
),
|
|
212
|
+
{ onCancel: f }
|
|
213
|
+
), y = o ? h(o) : u.projectName, g = u.projectType || "standalone", N = S(y), b = "/apps/" + h(y) + "/", $ = await A(
|
|
237
214
|
[
|
|
238
215
|
{
|
|
239
216
|
name: "includeModule",
|
|
@@ -243,17 +220,17 @@ async function se(e, t) {
|
|
|
243
220
|
},
|
|
244
221
|
{
|
|
245
222
|
name: "moduleName",
|
|
246
|
-
type: (w,
|
|
247
|
-
message:
|
|
248
|
-
initial:
|
|
223
|
+
type: (w, M) => g === "standalone" && !M.includeModule ? null : "text",
|
|
224
|
+
message: n.reset("Module name:"),
|
|
225
|
+
initial: N,
|
|
249
226
|
format: (w) => String(w).trim()
|
|
250
227
|
},
|
|
251
228
|
{
|
|
252
229
|
name: "basePath",
|
|
253
230
|
type: g === "dynamic-module" ? null : "text",
|
|
254
|
-
message:
|
|
255
|
-
initial:
|
|
256
|
-
format: (w) =>
|
|
231
|
+
message: n.reset("Base path:"),
|
|
232
|
+
initial: b,
|
|
233
|
+
format: (w) => _(String(w).trim())
|
|
257
234
|
},
|
|
258
235
|
{
|
|
259
236
|
type: g === "dynamic-module" ? null : "confirm",
|
|
@@ -280,213 +257,139 @@ async function se(e, t) {
|
|
|
280
257
|
initial: !1
|
|
281
258
|
}
|
|
282
259
|
],
|
|
283
|
-
{ onCancel:
|
|
260
|
+
{ onCancel: f }
|
|
284
261
|
);
|
|
285
|
-
|
|
286
|
-
projectName:
|
|
287
|
-
packageName:
|
|
262
|
+
l = {
|
|
263
|
+
projectName: y,
|
|
264
|
+
packageName: u.packageName || (k(y) ? y : C(y)),
|
|
288
265
|
projectType: g,
|
|
289
|
-
moduleName: $.moduleName || ($.includeModule !== !1 ?
|
|
290
|
-
basePath: $.basePath ||
|
|
266
|
+
moduleName: $.moduleName || ($.includeModule !== !1 ? N : void 0),
|
|
267
|
+
basePath: $.basePath || _(b),
|
|
291
268
|
tenantRoutes: $.tenantRoutes || !1,
|
|
292
269
|
aiAgent: $.aiAgent || !1,
|
|
293
270
|
dashboard: $.dashboard ?? !0,
|
|
294
271
|
mocks: $.mocks || !1
|
|
295
272
|
};
|
|
296
|
-
} catch (
|
|
297
|
-
console.log(
|
|
273
|
+
} catch (u) {
|
|
274
|
+
console.log(u.message), process.exit(1);
|
|
298
275
|
}
|
|
299
276
|
}
|
|
300
|
-
const
|
|
301
|
-
|
|
302
|
-
Scaffolding ${
|
|
277
|
+
const i = c.resolve(t, o);
|
|
278
|
+
r.existsSync(i) && !I(i) ? q(i) : r.existsSync(i) || r.mkdirSync(i, { recursive: !0 }), console.log(`
|
|
279
|
+
Scaffolding ${n.cyan(l.projectType)} in ${n.green(i)}...
|
|
303
280
|
`);
|
|
304
|
-
const
|
|
305
|
-
if (j(
|
|
306
|
-
const
|
|
307
|
-
j(
|
|
281
|
+
const v = R(l);
|
|
282
|
+
if (j(c.join(a, l.projectType), i, v), l.moduleName) {
|
|
283
|
+
const f = h(l.moduleName), u = l.projectType === "dynamic-module" ? c.join(i, "src/modules") : c.join(i, "src/modules", f);
|
|
284
|
+
j(c.join(a, "module"), u, v);
|
|
308
285
|
}
|
|
309
|
-
|
|
286
|
+
l.mocks && j(c.join(a, "sample-module"), c.join(i, "src/modules/sample"), v), H(l);
|
|
310
287
|
}
|
|
311
|
-
function
|
|
312
|
-
const
|
|
313
|
-
let
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
const l = e[o];
|
|
321
|
-
if (l === "/" && e[o + 1] === "/") {
|
|
322
|
-
const s = e.indexOf(`
|
|
323
|
-
`, o), c = s === -1 ? e.length : s;
|
|
324
|
-
a(o, c), o = c;
|
|
325
|
-
continue;
|
|
326
|
-
}
|
|
327
|
-
if (l === "/" && e[o + 1] === "*") {
|
|
328
|
-
const s = e.indexOf("*/", o + 2), c = s === -1 ? e.length : s + 2;
|
|
329
|
-
a(o, c), o = c;
|
|
330
|
-
continue;
|
|
331
|
-
}
|
|
332
|
-
if (l === '"' || l === "'" || l === "`") {
|
|
333
|
-
let s = o + 1;
|
|
334
|
-
for (; s < e.length; ) {
|
|
335
|
-
if (e[s] === "\\") {
|
|
336
|
-
s += 2;
|
|
337
|
-
continue;
|
|
338
|
-
}
|
|
339
|
-
if (e[s] === l) break;
|
|
340
|
-
s++;
|
|
341
|
-
}
|
|
342
|
-
t && a(o + 1, s), o = s + 1;
|
|
343
|
-
continue;
|
|
344
|
-
}
|
|
345
|
-
o++;
|
|
346
|
-
}
|
|
347
|
-
return n.join("");
|
|
348
|
-
}
|
|
349
|
-
function ie(e, t) {
|
|
350
|
-
let n = 0;
|
|
351
|
-
for (let o = t; o < e.length; o++) {
|
|
352
|
-
const a = e[o];
|
|
353
|
-
if (a === "(" || a === "[" || a === "{")
|
|
354
|
-
n++;
|
|
355
|
-
else if ((a === ")" || a === "]" || a === "}") && (n--, n === 0))
|
|
356
|
-
return e[o + 1] === ";" ? o + 2 : o + 1;
|
|
288
|
+
function U(e, a) {
|
|
289
|
+
const t = /^import\s.+$/gm;
|
|
290
|
+
let s = null, o;
|
|
291
|
+
for (; (o = t.exec(e)) !== null; )
|
|
292
|
+
s = o;
|
|
293
|
+
if (s) {
|
|
294
|
+
const d = s.index + s[0].length;
|
|
295
|
+
return e.slice(0, d) + `
|
|
296
|
+
` + a + e.slice(d);
|
|
357
297
|
}
|
|
358
|
-
return
|
|
298
|
+
return a + `
|
|
299
|
+
` + e;
|
|
359
300
|
}
|
|
360
|
-
function
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
301
|
+
function ee(e, a) {
|
|
302
|
+
let t = r.readFileSync(e, "utf-8");
|
|
303
|
+
const s = x(a), o = h(a);
|
|
304
|
+
t = U(t, `import ${s} from "./modules/${o}";`);
|
|
305
|
+
const d = /\.use\([A-Z]\w+,\s*\{\s*router\s*\}\)/g;
|
|
306
|
+
let p = null, m;
|
|
307
|
+
for (; (m = d.exec(t)) !== null; )
|
|
308
|
+
p = m;
|
|
309
|
+
if (p) {
|
|
310
|
+
const l = p.index + p[0].length, i = `
|
|
311
|
+
.use(${s}, { router })`;
|
|
312
|
+
t = t.slice(0, l) + i + t.slice(l);
|
|
369
313
|
}
|
|
370
|
-
|
|
314
|
+
r.writeFileSync(e, t);
|
|
371
315
|
}
|
|
372
|
-
function
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
const
|
|
377
|
-
if (
|
|
378
|
-
|
|
316
|
+
function te(e, a) {
|
|
317
|
+
let t = r.readFileSync(e, "utf-8");
|
|
318
|
+
const s = h(a), o = D(a);
|
|
319
|
+
if (!t.includes("addMenuItem")) {
|
|
320
|
+
const v = /import\s*\{([^}]+)\}\s*from\s*["']@vc-shell\/framework["']/.exec(t);
|
|
321
|
+
if (v) {
|
|
322
|
+
const f = v[1].trim() + ", addMenuItem";
|
|
323
|
+
t = t.replace(v[0], `import { ${f} } from "@vc-shell/framework"`);
|
|
324
|
+
} else
|
|
325
|
+
t = U(t, 'import { addMenuItem } from "@vc-shell/framework";');
|
|
379
326
|
}
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
e,
|
|
400
|
-
C(n, [
|
|
401
|
-
{ at: c, text: `
|
|
402
|
-
import ${a} from "./modules/${l}";` },
|
|
403
|
-
{ at: s.index, text: `${d}app.use(${a});
|
|
404
|
-
` }
|
|
405
|
-
])
|
|
406
|
-
);
|
|
407
|
-
}
|
|
408
|
-
function me(e) {
|
|
409
|
-
const t = k(e);
|
|
410
|
-
if (/\baddMenuItem\b/.test(t)) return e;
|
|
411
|
-
const n = /import\s*\{([^}]*)\}\s*from\s*["']@vc-shell\/framework["']/.exec(
|
|
412
|
-
k(e, { strings: !1 })
|
|
413
|
-
);
|
|
414
|
-
if (n) {
|
|
415
|
-
const l = n[1].trim().replace(/,$/, ""), s = n.index + n[0].length;
|
|
416
|
-
return e.slice(0, n.index) + `import { ${l}, addMenuItem } from "@vc-shell/framework"` + e.slice(s);
|
|
417
|
-
}
|
|
418
|
-
const o = 'import { addMenuItem } from "@vc-shell/framework";', a = B(t);
|
|
419
|
-
return a === -1 ? `${o}
|
|
420
|
-
${e}` : C(e, [{ at: a, text: `
|
|
421
|
-
${o}` }]);
|
|
422
|
-
}
|
|
423
|
-
function de(e, t) {
|
|
424
|
-
const n = v(t), o = O(t), a = me(i.readFileSync(e, "utf-8")), l = k(a), s = (u) => [
|
|
425
|
-
`${u}addMenuItem({`,
|
|
426
|
-
`${u} title: "${o}.MENU.TITLE",`,
|
|
427
|
-
`${u} icon: "lucide-box",`,
|
|
428
|
-
`${u} priority: 10,`,
|
|
429
|
-
`${u} url: "/${n}",`,
|
|
430
|
-
`${u}});`
|
|
431
|
-
].join(`
|
|
432
|
-
`), c = ce(l, "addMenuItem"), d = c[c.length - 1];
|
|
433
|
-
if (d) {
|
|
434
|
-
const u = V(a, d.start);
|
|
435
|
-
i.writeFileSync(e, C(a, [{ at: d.end, text: `
|
|
436
|
-
|
|
437
|
-
${s(u)}` }]));
|
|
438
|
-
return;
|
|
327
|
+
const d = /addMenuItem\(\{[\s\S]*?\}\);/g;
|
|
328
|
+
let p = null, m;
|
|
329
|
+
for (; (m = d.exec(t)) !== null; )
|
|
330
|
+
p = m;
|
|
331
|
+
const l = `
|
|
332
|
+
addMenuItem({
|
|
333
|
+
title: "${o}.MENU.TITLE",
|
|
334
|
+
icon: "lucide-box",
|
|
335
|
+
priority: 10,
|
|
336
|
+
url: "/${s}",
|
|
337
|
+
});`;
|
|
338
|
+
if (p) {
|
|
339
|
+
const i = p.index + p[0].length;
|
|
340
|
+
t = t.slice(0, i) + `
|
|
341
|
+
` + l + t.slice(i);
|
|
342
|
+
} else {
|
|
343
|
+
const i = t.lastIndexOf("}");
|
|
344
|
+
i !== -1 && (t = t.slice(0, i) + l + `
|
|
345
|
+
` + t.slice(i));
|
|
439
346
|
}
|
|
440
|
-
|
|
441
|
-
if (p === -1)
|
|
442
|
-
throw new Error("Could not find the bootstrap function body in bootstrap.ts");
|
|
443
|
-
i.writeFileSync(e, C(a, [{ at: p, text: `${s(" ")}
|
|
444
|
-
` }]));
|
|
347
|
+
r.writeFileSync(e, t);
|
|
445
348
|
}
|
|
446
|
-
async function
|
|
447
|
-
const
|
|
448
|
-
|
|
449
|
-
const
|
|
450
|
-
({ ...
|
|
451
|
-
let
|
|
452
|
-
|
|
349
|
+
async function ae(e, a) {
|
|
350
|
+
const t = process.cwd(), s = e._?.[1], o = c.join(t, "package.json");
|
|
351
|
+
r.existsSync(o) || (console.error(n.red("Error: No package.json found. Run this command from a vc-shell project root.")), process.exit(1));
|
|
352
|
+
const d = JSON.parse(r.readFileSync(o, "utf-8"));
|
|
353
|
+
({ ...d.dependencies, ...d.devDependencies })["@vc-shell/framework"] || (console.error(n.red("Error: Not a vc-shell project (@vc-shell/framework not found in dependencies).")), process.exit(1));
|
|
354
|
+
let m = s;
|
|
355
|
+
m || (m = (await A({
|
|
453
356
|
type: "text",
|
|
454
357
|
name: "moduleName",
|
|
455
358
|
message: "Module name:",
|
|
456
|
-
validate: (
|
|
457
|
-
})).moduleName),
|
|
458
|
-
const
|
|
459
|
-
|
|
460
|
-
const
|
|
461
|
-
j(
|
|
462
|
-
const
|
|
463
|
-
if (
|
|
359
|
+
validate: (b) => b.trim().length > 0 || "Module name is required"
|
|
360
|
+
})).moduleName), m || (console.error(n.red("Module name is required.")), process.exit(1));
|
|
361
|
+
const l = h(m), i = x(m), v = c.join(t, "src/modules"), f = c.join(v, l);
|
|
362
|
+
r.existsSync(v) || r.mkdirSync(v, { recursive: !0 }), r.existsSync(f) && (console.error(n.red(`Error: Module "${l}" already exists at ${c.relative(t, f)}`)), process.exit(1));
|
|
363
|
+
const u = R({ moduleName: m, projectName: c.basename(t) });
|
|
364
|
+
j(c.join(a, "module"), f, u), console.log(n.green(` ✔ Created ${c.relative(t, f)}/`));
|
|
365
|
+
const y = c.join(t, "src/main.ts");
|
|
366
|
+
if (r.existsSync(y))
|
|
464
367
|
try {
|
|
465
|
-
|
|
368
|
+
ee(y, m), console.log(n.green(` ✔ Updated src/main.ts — added import & app.use(${i})`));
|
|
466
369
|
} catch {
|
|
467
|
-
console.warn(
|
|
370
|
+
console.warn(n.yellow(" ⚠ Could not auto-update src/main.ts. Add manually:")), console.warn(n.yellow(` import ${i} from "./modules/${l}";`)), console.warn(n.yellow(` app.use(${i}, { router });`));
|
|
468
371
|
}
|
|
469
|
-
const g =
|
|
470
|
-
if (
|
|
372
|
+
const g = c.join(t, "src/bootstrap.ts");
|
|
373
|
+
if (r.existsSync(g))
|
|
471
374
|
try {
|
|
472
|
-
|
|
375
|
+
te(g, m), console.log(n.green(` ✔ Updated src/bootstrap.ts — added menu item "${S(m)}"`));
|
|
473
376
|
} catch {
|
|
474
|
-
console.warn(
|
|
377
|
+
console.warn(n.yellow(" ⚠ Could not auto-update src/bootstrap.ts. Add addMenuItem() manually."));
|
|
475
378
|
}
|
|
476
|
-
|
|
477
|
-
Module "${
|
|
379
|
+
console.log(`
|
|
380
|
+
Module "${l}" is ready! Run ${n.bold(n.green("yarn serve"))} to see it.
|
|
478
381
|
`);
|
|
479
382
|
}
|
|
480
|
-
const
|
|
481
|
-
function
|
|
383
|
+
const T = c.resolve(F(import.meta.url), "..", "templates");
|
|
384
|
+
function ne() {
|
|
482
385
|
console.log(`
|
|
483
|
-
${
|
|
386
|
+
${n.bold(n.green("create-vc-app"))} — Create VC Shell applications and modules
|
|
484
387
|
|
|
485
|
-
${
|
|
388
|
+
${n.bold("Usage:")}
|
|
486
389
|
create-vc-app [project-name] [options] Create a new project
|
|
487
390
|
create-vc-app add-module <module-name> Add a module to existing project
|
|
488
391
|
|
|
489
|
-
${
|
|
392
|
+
${n.bold("Options (create):")}
|
|
490
393
|
--type <type> Project type: standalone | dynamic-module
|
|
491
394
|
--name, --app-name <name> Application name
|
|
492
395
|
--package-name <name> npm package name
|
|
@@ -500,31 +403,31 @@ ${r.bold("Options (create):")}
|
|
|
500
403
|
--help, -h Show this help
|
|
501
404
|
--version, -v Show version
|
|
502
405
|
|
|
503
|
-
${
|
|
406
|
+
${n.bold("Examples:")}
|
|
504
407
|
create-vc-app my-app
|
|
505
408
|
create-vc-app my-app --type standalone --dashboard --mocks
|
|
506
409
|
create-vc-app my-module --type dynamic-module --module-name "Reviews"
|
|
507
410
|
create-vc-app add-module orders
|
|
508
411
|
|
|
509
|
-
${
|
|
412
|
+
${n.bold("Docs:")} https://docs.virtocommerce.org/platform/developer-guide/latest/custom-apps-development/vc-shell/vc-shell-overview/
|
|
510
413
|
`);
|
|
511
414
|
}
|
|
512
|
-
async function
|
|
513
|
-
const e =
|
|
415
|
+
async function oe() {
|
|
416
|
+
const e = z(B.slice(2), {
|
|
514
417
|
alias: { h: "help", v: "version" },
|
|
515
418
|
boolean: ["help", "version", "mocks", "overwrite", "tenant-routes", "ai-agent", "dashboard"],
|
|
516
419
|
string: ["type", "name", "app-name", "package-name", "module-name", "base-path"]
|
|
517
420
|
});
|
|
518
421
|
if (e.help) {
|
|
519
|
-
|
|
422
|
+
ne();
|
|
520
423
|
return;
|
|
521
424
|
}
|
|
522
425
|
if (e.version) {
|
|
523
|
-
console.log(`create-vc-app v${
|
|
426
|
+
console.log(`create-vc-app v${V.version}`);
|
|
524
427
|
return;
|
|
525
428
|
}
|
|
526
|
-
e._[0] === "add-module" ? await
|
|
429
|
+
e._[0] === "add-module" ? await ae(e, T) : await Q(e, T);
|
|
527
430
|
}
|
|
528
|
-
|
|
529
|
-
console.error(
|
|
431
|
+
oe().catch((e) => {
|
|
432
|
+
console.error(n.red(e.message || String(e))), L(1);
|
|
530
433
|
});
|