@vercube/cli 0.0.41 → 0.0.43

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.
@@ -0,0 +1,21 @@
1
+ import { defineCommand } from "citty";
2
+ import { build, createVercube } from "@vercube/devkit";
3
+
4
+ //#region src/commands/build.ts
5
+ const buildCommand = defineCommand({
6
+ meta: {
7
+ name: "build",
8
+ description: "Build the project"
9
+ },
10
+ args: { entry: {
11
+ type: "string",
12
+ description: "Entry file",
13
+ default: void 0
14
+ } },
15
+ run: async (ctx) => {
16
+ await build(await createVercube({ build: { entry: ctx?.args?.entry ?? void 0 } }));
17
+ }
18
+ });
19
+
20
+ //#endregion
21
+ export { buildCommand };
@@ -0,0 +1,18 @@
1
+ import { defineCommand } from "citty";
2
+ import { createDevServer, createVercube, watch } from "@vercube/devkit";
3
+
4
+ //#region src/commands/dev.ts
5
+ const devCommand = defineCommand({
6
+ meta: {
7
+ name: "dev",
8
+ description: "Start development server"
9
+ },
10
+ async run() {
11
+ const app = await createVercube();
12
+ createDevServer(app);
13
+ await watch(app);
14
+ }
15
+ });
16
+
17
+ //#endregion
18
+ export { devCommand };
@@ -0,0 +1,62 @@
1
+ import { defineCommand } from "citty";
2
+ import { build, createVercube } from "@vercube/devkit";
3
+ import { cliFetch } from "srvx/cli";
4
+
5
+ //#region src/commands/fetch.ts
6
+ const fetchCommand = defineCommand({
7
+ meta: {
8
+ name: "fetch",
9
+ description: "Fetch a request from the application"
10
+ },
11
+ args: {
12
+ url: {
13
+ type: "positional",
14
+ description: "URL to fetch",
15
+ default: "/"
16
+ },
17
+ entry: {
18
+ type: "string",
19
+ description: "Entry point for the application",
20
+ default: "index.mjs"
21
+ },
22
+ method: {
23
+ type: "string",
24
+ description: "HTTP method (default: GET, or POST if body is provided)",
25
+ default: "GET",
26
+ alias: "X",
27
+ valueHint: "GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS"
28
+ },
29
+ headers: {
30
+ type: "string",
31
+ description: "Add header (format: \"Name: Value, Name: Value, ...\")",
32
+ alias: "H"
33
+ },
34
+ data: {
35
+ type: "string",
36
+ description: "Request body (use @- for stdin, @file for file)",
37
+ alias: "d"
38
+ },
39
+ verbose: {
40
+ type: "boolean",
41
+ description: "Show request and response headers",
42
+ alias: "v",
43
+ default: false
44
+ }
45
+ },
46
+ async run(ctx) {
47
+ const app = await createVercube({ build: { dts: false } });
48
+ await build(app);
49
+ await cliFetch({
50
+ verbose: ctx.args.verbose,
51
+ dir: app.config.build?.output?.dir ?? "dist",
52
+ entry: ctx.args.entry,
53
+ url: ctx.args.url,
54
+ method: ctx.args.method,
55
+ header: ctx.args.headers?.split(",") ?? [],
56
+ data: ctx.args.data
57
+ });
58
+ }
59
+ });
60
+
61
+ //#endregion
62
+ export { fetchCommand };
package/dist/index.mjs CHANGED
@@ -1,279 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  import { defineCommand, runMain } from "citty";
3
- import { build, createDevServer, createVercube, watch } from "@vercube/devkit";
4
- import { cliFetch } from "srvx/cli";
5
- import { existsSync } from "node:fs";
6
- import { consola } from "consola";
7
- import { colors } from "consola/utils";
8
- import { downloadTemplate, startShell } from "giget";
9
- import { installDependencies } from "nypm";
10
- import { relative, resolve } from "pathe";
11
- import { hasTTY } from "std-env";
12
- import { x } from "tinyexec";
13
3
 
14
4
  //#region package.json
15
- var version = "0.0.41";
16
-
17
- //#endregion
18
- //#region src/commands/build.ts
19
- const buildCommand = defineCommand({
20
- meta: {
21
- name: "build",
22
- description: "Build the project"
23
- },
24
- args: { entry: {
25
- type: "string",
26
- description: "Entry file",
27
- default: void 0
28
- } },
29
- run: async (ctx) => {
30
- await build(await createVercube({ build: { entry: ctx?.args?.entry ?? void 0 } }));
31
- }
32
- });
33
-
34
- //#endregion
35
- //#region src/commands/dev.ts
36
- const devCommand = defineCommand({
37
- meta: {
38
- name: "dev",
39
- description: "Start development server"
40
- },
41
- async run() {
42
- const app = await createVercube();
43
- createDevServer(app);
44
- await watch(app);
45
- }
46
- });
47
-
48
- //#endregion
49
- //#region src/commands/fetch.ts
50
- const fetchCommand = defineCommand({
51
- meta: {
52
- name: "fetch",
53
- description: "Fetch a request from the application"
54
- },
55
- args: {
56
- url: {
57
- type: "positional",
58
- description: "URL to fetch",
59
- default: "/"
60
- },
61
- entry: {
62
- type: "string",
63
- description: "Entry point for the application",
64
- default: "index.mjs"
65
- },
66
- method: {
67
- type: "string",
68
- description: "HTTP method (default: GET, or POST if body is provided)",
69
- default: "GET",
70
- alias: "X",
71
- valueHint: "GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS"
72
- },
73
- headers: {
74
- type: "string",
75
- description: "Add header (format: \"Name: Value, Name: Value, ...\")",
76
- alias: "H"
77
- },
78
- data: {
79
- type: "string",
80
- description: "Request body (use @- for stdin, @file for file)",
81
- alias: "d"
82
- },
83
- verbose: {
84
- type: "boolean",
85
- description: "Show request and response headers",
86
- alias: "v",
87
- default: false
88
- }
89
- },
90
- async run(ctx) {
91
- const app = await createVercube({ build: { dts: false } });
92
- await build(app);
93
- await cliFetch({
94
- verbose: ctx.args.verbose,
95
- dir: app.config.build?.output?.dir ?? "dist",
96
- entry: ctx.args.entry,
97
- url: ctx.args.url,
98
- method: ctx.args.method,
99
- headers: ctx.args.headers?.split(",") ?? [],
100
- data: ctx.args.data
101
- });
102
- }
103
- });
104
-
105
- //#endregion
106
- //#region src/utils/logo.ts
107
- const startColor = {
108
- r: 149,
109
- g: 100,
110
- b: 245
111
- };
112
- const endColor = {
113
- r: 111,
114
- g: 114,
115
- b: 245
116
- };
117
- const icon = [
118
- " _ ",
119
- " | | ",
120
- " __ _____ _ __ ___ _ _| |__ ___ ",
121
- " \\ \\ / / _ \\ '__/ __| | | | '_ \\ / _ \\",
122
- String.raw` \ V / __/ | | (__| |_| | |_) | __/`,
123
- String.raw` \_/ \___|_| \___|\__,_|_.__/ \___|`,
124
- " ",
125
- " "
126
- ];
127
- function interpolateColor(startColor, endColor, factor) {
128
- return `\u001B[38;2;${Math.round(startColor.r + factor * (endColor.r - startColor.r))};${Math.round(startColor.g + factor * (endColor.g - startColor.g))};${Math.round(startColor.b + factor * (endColor.b - startColor.b))}m`;
129
- }
130
- function applyGradient(icon, startColor, endColor) {
131
- const totalLines = icon.length;
132
- return icon.map((line, index) => {
133
- return interpolateColor(startColor, endColor, index / (totalLines - 1)) + line;
134
- }).join("\n");
135
- }
136
- const vercubeIcon = applyGradient(icon, startColor, endColor);
137
-
138
- //#endregion
139
- //#region src/commands/init.ts
140
- const logger = consola.withTag(colors.whiteBright(colors.bold(colors.bgGreenBright(" vercube "))));
141
- const DEFAULT_REGISTRY = "https://raw.githubusercontent.com/vercube/starter/main/templates";
142
- const DEFAULT_TEMPLATE_NAME = "vercube";
143
- const packageManagerOptions = Object.keys({
144
- npm: void 0,
145
- pnpm: void 0,
146
- yarn: void 0,
147
- bun: void 0,
148
- deno: void 0
149
- });
150
- const initCommand = defineCommand({
151
- meta: {
152
- name: "init",
153
- description: "Initialize a new Vercube app"
154
- },
155
- args: {
156
- dir: {
157
- type: "positional",
158
- description: "Project directory",
159
- default: ""
160
- },
161
- force: {
162
- type: "boolean",
163
- alias: "f",
164
- description: "Override existing directory"
165
- },
166
- install: {
167
- type: "boolean",
168
- default: true,
169
- description: "Skip installing dependencies"
170
- },
171
- gitInit: {
172
- type: "boolean",
173
- description: "Initialize git repository",
174
- default: true
175
- },
176
- packageManager: {
177
- type: "string",
178
- description: "Package manager choice (npm, pnpm, yarn, bun)",
179
- default: "pnpm"
180
- }
181
- },
182
- async run(ctx) {
183
- if (hasTTY) process.stdout.write(`\n${vercubeIcon}\n\n`);
184
- consola.info(`Welcome to ${colors.bold("Vercube")}!`);
185
- let dir = ctx.args.dir;
186
- if (ctx.args.dir === "") dir = await logger.prompt("Where would you like to create your project?", {
187
- placeholder: "./vercube-app",
188
- type: "text",
189
- default: "vercube-app",
190
- cancel: "reject"
191
- }).catch(() => process.exit(1));
192
- const cwd = resolve(process.cwd());
193
- let templateDownloadPath = resolve(cwd, dir);
194
- logger.info(`Creating a new project in ${colors.cyan(relative(cwd, templateDownloadPath) || templateDownloadPath)}.`);
195
- let shouldForce = Boolean(ctx.args.force);
196
- if (!shouldForce && existsSync(templateDownloadPath)) switch (await logger.prompt(`The directory ${colors.cyan(templateDownloadPath)} already exists. What would you like to do?`, {
197
- type: "select",
198
- options: [
199
- "Override its contents",
200
- "Select different directory",
201
- "Abort"
202
- ]
203
- })) {
204
- case "Override its contents":
205
- shouldForce = true;
206
- break;
207
- case "Select different directory":
208
- templateDownloadPath = resolve(cwd, await logger.prompt("Please specify a different directory:", {
209
- type: "text",
210
- cancel: "reject"
211
- }).catch(() => process.exit(1)));
212
- break;
213
- default: process.exit(1);
214
- }
215
- let template;
216
- try {
217
- template = await downloadTemplate(DEFAULT_TEMPLATE_NAME, {
218
- dir: templateDownloadPath,
219
- force: shouldForce,
220
- offline: Boolean(ctx.args.offline),
221
- preferOffline: Boolean(ctx.args.preferOffline),
222
- registry: DEFAULT_REGISTRY
223
- });
224
- } catch (error) {
225
- if (process.env.DEBUG) throw error;
226
- logger.error(error.toString());
227
- process.exit(1);
228
- }
229
- const packageManagerArg = ctx.args.packageManager;
230
- const selectedPackageManager = packageManagerOptions.includes(packageManagerArg) ? packageManagerArg : await logger.prompt("Which package manager would you like to use?", {
231
- type: "select",
232
- options: packageManagerOptions,
233
- cancel: "reject"
234
- }).catch(() => process.exit(1));
235
- if (ctx.args.install === false) logger.info("Skipping install dependencies step.");
236
- else {
237
- logger.start("Installing dependencies...");
238
- try {
239
- await installDependencies({
240
- cwd: template.dir,
241
- packageManager: {
242
- name: selectedPackageManager,
243
- command: selectedPackageManager
244
- }
245
- });
246
- } catch (error) {
247
- if (process.env.DEBUG) throw error;
248
- logger.error(error.toString());
249
- process.exit(1);
250
- }
251
- logger.success("Installation completed.");
252
- }
253
- let gitInit = ctx.args.gitInit;
254
- if (gitInit === void 0) gitInit = await logger.prompt("Initialize git repository?", {
255
- type: "confirm",
256
- cancel: "reject"
257
- }).catch(() => process.exit(1));
258
- if (ctx.args.gitInit) {
259
- logger.info("Initializing git repository...\n");
260
- try {
261
- await x("git", ["init", template.dir], {
262
- throwOnError: true,
263
- nodeOptions: { stdio: "inherit" }
264
- });
265
- } catch (error) {
266
- logger.warn(`Failed to initialize git repository: ${error}`);
267
- }
268
- }
269
- logger.log("\n✨ Vercube project has been created! Next steps:");
270
- const relativeTemplateDir = relative(process.cwd(), template.dir) || ".";
271
- const runCmd = selectedPackageManager === "deno" ? "task" : "run";
272
- const nextSteps = [!ctx.args.shell && relativeTemplateDir.length > 1 && `\`cd ${relativeTemplateDir}\``, `Start development server with \`${selectedPackageManager} ${runCmd} dev\``].filter(Boolean);
273
- for (const step of nextSteps) logger.log(` › ${step}`);
274
- if (ctx.args.shell) startShell(template.dir);
275
- }
276
- });
5
+ var version = "0.0.43";
277
6
 
278
7
  //#endregion
279
8
  //#region src/index.ts
@@ -284,10 +13,10 @@ runMain(defineCommand({
284
13
  description: "Vercube CLI"
285
14
  },
286
15
  subCommands: {
287
- build: buildCommand,
288
- dev: devCommand,
289
- init: initCommand,
290
- fetch: fetchCommand
16
+ build: () => import("./build-C-oLahSl.mjs").then(({ buildCommand }) => buildCommand),
17
+ dev: () => import("./dev-Bh7mSI64.mjs").then(({ devCommand }) => devCommand),
18
+ init: () => import("./init-DC0cXuj_.mjs").then(({ initCommand }) => initCommand),
19
+ fetch: () => import("./fetch-Bu_lz9cd.mjs").then(({ fetchCommand }) => fetchCommand)
291
20
  }
292
21
  }));
293
22
 
@@ -0,0 +1,184 @@
1
+ import { defineCommand } from "citty";
2
+ import { existsSync } from "node:fs";
3
+ import { consola } from "consola";
4
+ import { colors } from "consola/utils";
5
+ import { downloadTemplate, startShell } from "giget";
6
+ import { installDependencies } from "nypm";
7
+ import { relative, resolve } from "pathe";
8
+ import { hasTTY } from "std-env";
9
+ import { x } from "tinyexec";
10
+
11
+ //#region src/utils/logo.ts
12
+ const startColor = {
13
+ r: 149,
14
+ g: 100,
15
+ b: 245
16
+ };
17
+ const endColor = {
18
+ r: 111,
19
+ g: 114,
20
+ b: 245
21
+ };
22
+ const icon = [
23
+ " _ ",
24
+ " | | ",
25
+ " __ _____ _ __ ___ _ _| |__ ___ ",
26
+ " \\ \\ / / _ \\ '__/ __| | | | '_ \\ / _ \\",
27
+ String.raw` \ V / __/ | | (__| |_| | |_) | __/`,
28
+ String.raw` \_/ \___|_| \___|\__,_|_.__/ \___|`,
29
+ " ",
30
+ " "
31
+ ];
32
+ function interpolateColor(startColor, endColor, factor) {
33
+ return `\u001B[38;2;${Math.round(startColor.r + factor * (endColor.r - startColor.r))};${Math.round(startColor.g + factor * (endColor.g - startColor.g))};${Math.round(startColor.b + factor * (endColor.b - startColor.b))}m`;
34
+ }
35
+ function applyGradient(icon, startColor, endColor) {
36
+ const totalLines = icon.length;
37
+ return icon.map((line, index) => {
38
+ return interpolateColor(startColor, endColor, index / (totalLines - 1)) + line;
39
+ }).join("\n");
40
+ }
41
+ const vercubeIcon = applyGradient(icon, startColor, endColor);
42
+
43
+ //#endregion
44
+ //#region src/commands/init.ts
45
+ const logger = consola.withTag(colors.whiteBright(colors.bold(colors.bgGreenBright(" vercube "))));
46
+ const DEFAULT_REGISTRY = "https://raw.githubusercontent.com/vercube/starter/main/templates";
47
+ const DEFAULT_TEMPLATE_NAME = "vercube";
48
+ const packageManagerOptions = Object.keys({
49
+ npm: void 0,
50
+ pnpm: void 0,
51
+ yarn: void 0,
52
+ bun: void 0,
53
+ deno: void 0
54
+ });
55
+ const initCommand = defineCommand({
56
+ meta: {
57
+ name: "init",
58
+ description: "Initialize a new Vercube app"
59
+ },
60
+ args: {
61
+ dir: {
62
+ type: "positional",
63
+ description: "Project directory",
64
+ default: ""
65
+ },
66
+ force: {
67
+ type: "boolean",
68
+ alias: "f",
69
+ description: "Override existing directory"
70
+ },
71
+ install: {
72
+ type: "boolean",
73
+ default: true,
74
+ description: "Skip installing dependencies"
75
+ },
76
+ gitInit: {
77
+ type: "boolean",
78
+ description: "Initialize git repository",
79
+ default: true
80
+ },
81
+ packageManager: {
82
+ type: "string",
83
+ description: "Package manager choice (npm, pnpm, yarn, bun)",
84
+ default: "pnpm"
85
+ }
86
+ },
87
+ async run(ctx) {
88
+ if (hasTTY) process.stdout.write(`\n${vercubeIcon}\n\n`);
89
+ consola.info(`Welcome to ${colors.bold("Vercube")}!`);
90
+ let dir = ctx.args.dir;
91
+ if (ctx.args.dir === "") dir = await logger.prompt("Where would you like to create your project?", {
92
+ placeholder: "./vercube-app",
93
+ type: "text",
94
+ default: "vercube-app",
95
+ cancel: "reject"
96
+ }).catch(() => process.exit(1));
97
+ const cwd = resolve(process.cwd());
98
+ let templateDownloadPath = resolve(cwd, dir);
99
+ logger.info(`Creating a new project in ${colors.cyan(relative(cwd, templateDownloadPath) || templateDownloadPath)}.`);
100
+ let shouldForce = Boolean(ctx.args.force);
101
+ if (!shouldForce && existsSync(templateDownloadPath)) switch (await logger.prompt(`The directory ${colors.cyan(templateDownloadPath)} already exists. What would you like to do?`, {
102
+ type: "select",
103
+ options: [
104
+ "Override its contents",
105
+ "Select different directory",
106
+ "Abort"
107
+ ]
108
+ })) {
109
+ case "Override its contents":
110
+ shouldForce = true;
111
+ break;
112
+ case "Select different directory":
113
+ templateDownloadPath = resolve(cwd, await logger.prompt("Please specify a different directory:", {
114
+ type: "text",
115
+ cancel: "reject"
116
+ }).catch(() => process.exit(1)));
117
+ break;
118
+ default: process.exit(1);
119
+ }
120
+ let template;
121
+ try {
122
+ template = await downloadTemplate(DEFAULT_TEMPLATE_NAME, {
123
+ dir: templateDownloadPath,
124
+ force: shouldForce,
125
+ offline: Boolean(ctx.args.offline),
126
+ preferOffline: Boolean(ctx.args.preferOffline),
127
+ registry: DEFAULT_REGISTRY
128
+ });
129
+ } catch (error) {
130
+ if (process.env.DEBUG) throw error;
131
+ logger.error(error.toString());
132
+ process.exit(1);
133
+ }
134
+ const packageManagerArg = ctx.args.packageManager;
135
+ const selectedPackageManager = packageManagerOptions.includes(packageManagerArg) ? packageManagerArg : await logger.prompt("Which package manager would you like to use?", {
136
+ type: "select",
137
+ options: packageManagerOptions,
138
+ cancel: "reject"
139
+ }).catch(() => process.exit(1));
140
+ if (ctx.args.install === false) logger.info("Skipping install dependencies step.");
141
+ else {
142
+ logger.start("Installing dependencies...");
143
+ try {
144
+ await installDependencies({
145
+ cwd: template.dir,
146
+ packageManager: {
147
+ name: selectedPackageManager,
148
+ command: selectedPackageManager
149
+ }
150
+ });
151
+ } catch (error) {
152
+ if (process.env.DEBUG) throw error;
153
+ logger.error(error.toString());
154
+ process.exit(1);
155
+ }
156
+ logger.success("Installation completed.");
157
+ }
158
+ let gitInit = ctx.args.gitInit;
159
+ if (gitInit === void 0) gitInit = await logger.prompt("Initialize git repository?", {
160
+ type: "confirm",
161
+ cancel: "reject"
162
+ }).catch(() => process.exit(1));
163
+ if (ctx.args.gitInit) {
164
+ logger.info("Initializing git repository...\n");
165
+ try {
166
+ await x("git", ["init", template.dir], {
167
+ throwOnError: true,
168
+ nodeOptions: { stdio: "inherit" }
169
+ });
170
+ } catch (error) {
171
+ logger.warn(`Failed to initialize git repository: ${error}`);
172
+ }
173
+ }
174
+ logger.log("\n✨ Vercube project has been created! Next steps:");
175
+ const relativeTemplateDir = relative(process.cwd(), template.dir) || ".";
176
+ const runCmd = selectedPackageManager === "deno" ? "task" : "run";
177
+ const nextSteps = [!ctx.args.shell && relativeTemplateDir.length > 1 && `\`cd ${relativeTemplateDir}\``, `Start development server with \`${selectedPackageManager} ${runCmd} dev\``].filter(Boolean);
178
+ for (const step of nextSteps) logger.log(` › ${step}`);
179
+ if (ctx.args.shell) startShell(template.dir);
180
+ }
181
+ });
182
+
183
+ //#endregion
184
+ export { initCommand };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercube/cli",
3
- "version": "0.0.41",
3
+ "version": "0.0.43",
4
4
  "description": "CLI module for Vercube framework",
5
5
  "repository": {
6
6
  "type": "git",
@@ -31,10 +31,10 @@
31
31
  "nypm": "0.6.4",
32
32
  "pathe": "2.0.3",
33
33
  "std-env": "3.10.0",
34
- "srvx": "npm:srvx-nightly",
34
+ "srvx": "0.11.0",
35
35
  "tinyexec": "1.0.2",
36
- "@vercube/devkit": "0.0.41",
37
- "@vercube/logger": "0.0.41"
36
+ "@vercube/devkit": "0.0.43",
37
+ "@vercube/logger": "0.0.43"
38
38
  },
39
39
  "publishConfig": {
40
40
  "access": "public"