@vercube/cli 0.0.40 → 0.0.42

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