exportc 0.0.5 → 0.0.7
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/README.md +2 -3
- package/commands/deploy.js +13 -33
- package/commands/dev.js +9 -25
- package/commands/init.js +36 -138
- package/index.js +8 -13
- package/package.json +1 -2
package/README.md
CHANGED
|
@@ -8,9 +8,6 @@ Add [export](https://github.com/ihasq/export) to existing Vite projects. One com
|
|
|
8
8
|
# In your existing Vite project
|
|
9
9
|
npx exportc init
|
|
10
10
|
|
|
11
|
-
# Install export dependencies
|
|
12
|
-
cd export && npm install && cd ..
|
|
13
|
-
|
|
14
11
|
# Start development (Wrangler starts automatically!)
|
|
15
12
|
npm run dev
|
|
16
13
|
|
|
@@ -18,6 +15,8 @@ npm run dev
|
|
|
18
15
|
npm run export
|
|
19
16
|
```
|
|
20
17
|
|
|
18
|
+
That's it. Dependencies are installed automatically.
|
|
19
|
+
|
|
21
20
|
## What You Get
|
|
22
21
|
|
|
23
22
|
- **Single command dev** -- `npm run dev` starts both Vite and Wrangler
|
package/commands/deploy.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as p from "@clack/prompts";
|
|
2
1
|
import pc from "picocolors";
|
|
3
2
|
import fs from "node:fs";
|
|
4
3
|
import path from "node:path";
|
|
@@ -10,49 +9,44 @@ export async function deploy(argv) {
|
|
|
10
9
|
|
|
11
10
|
// Check if export directory exists
|
|
12
11
|
if (!fs.existsSync(exportDir)) {
|
|
13
|
-
|
|
12
|
+
console.error(pc.red("✗") + ` No export/ directory found. Run ${pc.cyan("exportc init")} first.`);
|
|
14
13
|
process.exit(1);
|
|
15
14
|
}
|
|
16
15
|
|
|
17
16
|
// Check if dependencies are installed
|
|
18
17
|
const nodeModules = path.join(exportDir, "node_modules");
|
|
19
18
|
if (!fs.existsSync(nodeModules)) {
|
|
20
|
-
|
|
19
|
+
console.error(pc.red("✗") + ` Dependencies not installed. Run ${pc.cyan("cd export && npm install")} first.`);
|
|
21
20
|
process.exit(1);
|
|
22
21
|
}
|
|
23
22
|
|
|
24
|
-
|
|
23
|
+
console.log(pc.cyan("exportc deploy"));
|
|
24
|
+
console.log();
|
|
25
25
|
|
|
26
26
|
// Step 1: Build Vite
|
|
27
|
-
|
|
28
|
-
s1.start("Building with Vite...");
|
|
27
|
+
console.log("Building with Vite...");
|
|
29
28
|
|
|
30
29
|
const viteBuild = spawn("npm", ["run", "build"], {
|
|
31
30
|
cwd,
|
|
32
|
-
stdio:
|
|
31
|
+
stdio: "inherit",
|
|
33
32
|
shell: true,
|
|
34
33
|
});
|
|
35
34
|
|
|
36
|
-
let viteBuildOutput = "";
|
|
37
|
-
viteBuild.stdout.on("data", (data) => { viteBuildOutput += data.toString(); });
|
|
38
|
-
viteBuild.stderr.on("data", (data) => { viteBuildOutput += data.toString(); });
|
|
39
|
-
|
|
40
35
|
const viteExitCode = await new Promise((resolve) => {
|
|
41
36
|
viteBuild.on("close", resolve);
|
|
42
37
|
viteBuild.on("error", () => resolve(1));
|
|
43
38
|
});
|
|
44
39
|
|
|
45
40
|
if (viteExitCode !== 0) {
|
|
46
|
-
|
|
47
|
-
console.error(viteBuildOutput);
|
|
41
|
+
console.error(pc.red("✗") + " Vite build failed");
|
|
48
42
|
process.exit(1);
|
|
49
43
|
}
|
|
50
44
|
|
|
51
|
-
|
|
45
|
+
console.log(pc.green("✓") + " Vite build complete");
|
|
46
|
+
console.log();
|
|
52
47
|
|
|
53
48
|
// Step 2: Deploy to Cloudflare Workers
|
|
54
|
-
|
|
55
|
-
s2.start("Deploying to Cloudflare Workers...");
|
|
49
|
+
console.log("Deploying to Cloudflare Workers...");
|
|
56
50
|
|
|
57
51
|
const wranglerDeploy = spawn("npm", ["run", "deploy"], {
|
|
58
52
|
cwd: exportDir,
|
|
@@ -66,29 +60,15 @@ export async function deploy(argv) {
|
|
|
66
60
|
});
|
|
67
61
|
|
|
68
62
|
if (wranglerExitCode !== 0) {
|
|
69
|
-
|
|
63
|
+
console.error(pc.red("✗") + " Deployment failed");
|
|
70
64
|
process.exit(1);
|
|
71
65
|
}
|
|
72
66
|
|
|
73
|
-
s2.stop("Deployed successfully!");
|
|
74
|
-
|
|
75
67
|
// Read worker name from export/package.json
|
|
76
68
|
const exportPkgPath = path.join(exportDir, "package.json");
|
|
77
69
|
const exportPkg = JSON.parse(fs.readFileSync(exportPkgPath, "utf8"));
|
|
78
70
|
const workerName = exportPkg.name;
|
|
79
71
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
${pc.cyan(`https://${workerName}.workers.dev/`)}
|
|
83
|
-
|
|
84
|
-
${pc.bold("What was deployed:")}
|
|
85
|
-
- Static assets (Vite build output)
|
|
86
|
-
- Server exports (export/ directory)
|
|
87
|
-
|
|
88
|
-
${pc.bold("Client imports will resolve to:")}
|
|
89
|
-
${pc.cyan(`https://${workerName}.workers.dev/`)}`,
|
|
90
|
-
"Workers Sites"
|
|
91
|
-
);
|
|
92
|
-
|
|
93
|
-
p.outro("Done!");
|
|
72
|
+
console.log();
|
|
73
|
+
console.log(pc.green("✓") + " Deployed to " + pc.cyan(`https://${workerName}.workers.dev/`));
|
|
94
74
|
}
|
package/commands/dev.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as p from "@clack/prompts";
|
|
2
1
|
import pc from "picocolors";
|
|
3
2
|
import fs from "node:fs";
|
|
4
3
|
import path from "node:path";
|
|
@@ -10,48 +9,33 @@ export async function dev(argv) {
|
|
|
10
9
|
|
|
11
10
|
// Check if export directory exists
|
|
12
11
|
if (!fs.existsSync(exportDir)) {
|
|
13
|
-
|
|
12
|
+
console.error(pc.red("✗") + ` No export/ directory found. Run ${pc.cyan("exportc init")} first.`);
|
|
14
13
|
process.exit(1);
|
|
15
14
|
}
|
|
16
15
|
|
|
17
16
|
// Check if dependencies are installed
|
|
18
17
|
const nodeModules = path.join(exportDir, "node_modules");
|
|
19
18
|
if (!fs.existsSync(nodeModules)) {
|
|
20
|
-
|
|
19
|
+
console.error(pc.red("✗") + ` Dependencies not installed. Run ${pc.cyan("cd export && npm install")} first.`);
|
|
21
20
|
process.exit(1);
|
|
22
21
|
}
|
|
23
22
|
|
|
24
|
-
|
|
23
|
+
console.log(pc.cyan("exportc dev"));
|
|
24
|
+
console.log();
|
|
25
|
+
console.log("Starting Wrangler dev server...");
|
|
25
26
|
|
|
26
|
-
const
|
|
27
|
-
s.start("Starting export dev server...");
|
|
28
|
-
|
|
29
|
-
// Generate types first
|
|
30
|
-
const generateTypes = spawn("npm", ["run", "dev"], {
|
|
27
|
+
const wrangler = spawn("npm", ["run", "dev"], {
|
|
31
28
|
cwd: exportDir,
|
|
32
29
|
stdio: "inherit",
|
|
33
30
|
shell: true,
|
|
34
31
|
});
|
|
35
32
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
console.error(
|
|
33
|
+
wrangler.on("error", (err) => {
|
|
34
|
+
console.error(pc.red("✗") + " Failed to start dev server");
|
|
35
|
+
console.error(err.message);
|
|
39
36
|
process.exit(1);
|
|
40
37
|
});
|
|
41
38
|
|
|
42
|
-
s.stop("Export dev server started!");
|
|
43
|
-
|
|
44
|
-
p.note(
|
|
45
|
-
`Wrangler dev server is running at ${pc.cyan("http://localhost:8787")}
|
|
46
|
-
|
|
47
|
-
${pc.bold("In your Vite app:")}
|
|
48
|
-
${pc.cyan(`import { hello } from "export/";`)}
|
|
49
|
-
${pc.cyan(`const message = await hello("World");`)}
|
|
50
|
-
|
|
51
|
-
${pc.dim("Press Ctrl+C to stop")}`,
|
|
52
|
-
"Running"
|
|
53
|
-
);
|
|
54
|
-
|
|
55
39
|
// Keep the process running
|
|
56
40
|
await new Promise(() => {});
|
|
57
41
|
}
|
package/commands/init.js
CHANGED
|
@@ -1,105 +1,53 @@
|
|
|
1
|
-
import * as p from "@clack/prompts";
|
|
2
1
|
import pc from "picocolors";
|
|
3
2
|
import fs from "node:fs";
|
|
4
3
|
import path from "node:path";
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
4
|
+
import { execSync } from "node:child_process";
|
|
8
5
|
|
|
9
6
|
export async function init(argv) {
|
|
10
7
|
const cwd = process.cwd();
|
|
11
|
-
const isNonInteractive = argv.yes || argv.y || process.env.CI === "true";
|
|
12
8
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
9
|
+
console.log(pc.cyan("exportc init"));
|
|
10
|
+
console.log();
|
|
16
11
|
|
|
17
12
|
// Check for Vite project
|
|
18
13
|
const viteConfigFiles = ["vite.config.ts", "vite.config.js", "vite.config.mts", "vite.config.mjs"];
|
|
19
14
|
const viteConfig = viteConfigFiles.find((f) => fs.existsSync(path.join(cwd, f)));
|
|
20
15
|
|
|
21
16
|
if (!viteConfig) {
|
|
22
|
-
|
|
23
|
-
console.error("Error: No Vite config found. exportc currently only supports Vite projects.");
|
|
24
|
-
process.exit(1);
|
|
25
|
-
}
|
|
26
|
-
p.cancel("No Vite config found. exportc currently only supports Vite projects.");
|
|
17
|
+
console.error(pc.red("✗") + " No Vite config found. exportc only supports Vite projects.");
|
|
27
18
|
process.exit(1);
|
|
28
19
|
}
|
|
29
20
|
|
|
30
21
|
// Check for package.json
|
|
31
22
|
const pkgPath = path.join(cwd, "package.json");
|
|
32
23
|
if (!fs.existsSync(pkgPath)) {
|
|
33
|
-
|
|
34
|
-
console.error("Error: No package.json found.");
|
|
35
|
-
process.exit(1);
|
|
36
|
-
}
|
|
37
|
-
p.cancel("No package.json found.");
|
|
24
|
+
console.error(pc.red("✗") + " No package.json found.");
|
|
38
25
|
process.exit(1);
|
|
39
26
|
}
|
|
40
27
|
|
|
41
28
|
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
|
|
42
29
|
|
|
43
|
-
//
|
|
44
|
-
const
|
|
45
|
-
if (fs.existsSync(exportDir) && !isNonInteractive) {
|
|
46
|
-
const overwrite = await p.confirm({
|
|
47
|
-
message: "export/ directory already exists. Continue and overwrite?",
|
|
48
|
-
initialValue: false,
|
|
49
|
-
});
|
|
50
|
-
if (p.isCancel(overwrite) || !overwrite) {
|
|
51
|
-
p.cancel("Operation cancelled.");
|
|
52
|
-
process.exit(0);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// Get worker name (use default in non-interactive mode)
|
|
57
|
-
const defaultWorkerName = pkg.name ? `${pkg.name}-api` : "my-api";
|
|
58
|
-
let workerName;
|
|
59
|
-
|
|
60
|
-
if (isNonInteractive) {
|
|
61
|
-
workerName = argv.name || defaultWorkerName;
|
|
62
|
-
} else {
|
|
63
|
-
workerName = await p.text({
|
|
64
|
-
message: "Worker name:",
|
|
65
|
-
placeholder: defaultWorkerName,
|
|
66
|
-
defaultValue: defaultWorkerName,
|
|
67
|
-
validate: (v) => {
|
|
68
|
-
if (!v) return "Worker name is required";
|
|
69
|
-
if (!/^[a-z0-9-]+$/.test(v)) return "Use lowercase letters, numbers, and hyphens only";
|
|
70
|
-
},
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
if (p.isCancel(workerName)) {
|
|
74
|
-
p.cancel("Operation cancelled.");
|
|
75
|
-
process.exit(0);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
30
|
+
// Auto-generate worker name from package name
|
|
31
|
+
const workerName = argv.name || (pkg.name ? `${pkg.name}-api` : "my-api");
|
|
78
32
|
|
|
79
33
|
// Check for TypeScript
|
|
80
34
|
const isTypeScript = viteConfig.endsWith(".ts") || viteConfig.endsWith(".mts") ||
|
|
81
35
|
fs.existsSync(path.join(cwd, "tsconfig.json"));
|
|
82
36
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
s = p.spinner();
|
|
86
|
-
s.start("Initializing export...");
|
|
87
|
-
} else {
|
|
88
|
-
console.log("Initializing export...");
|
|
89
|
-
}
|
|
37
|
+
const exportDir = path.join(cwd, "export");
|
|
38
|
+
const ext = isTypeScript ? "ts" : "js";
|
|
90
39
|
|
|
91
40
|
// Create export directory
|
|
41
|
+
console.log(pc.gray("Creating export directory..."));
|
|
92
42
|
if (!fs.existsSync(exportDir)) {
|
|
93
43
|
fs.mkdirSync(exportDir, { recursive: true });
|
|
94
44
|
}
|
|
95
45
|
|
|
96
46
|
// Create export/index.ts or index.js
|
|
97
|
-
const ext = isTypeScript ? "ts" : "js";
|
|
98
47
|
const indexPath = path.join(exportDir, `index.${ext}`);
|
|
99
48
|
if (!fs.existsSync(indexPath)) {
|
|
100
49
|
const template = isTypeScript
|
|
101
|
-
? `// Server-side exports -
|
|
102
|
-
// Import from "export/" in your client code
|
|
50
|
+
? `// Server-side exports - import from "export/" in your client code
|
|
103
51
|
|
|
104
52
|
export async function hello(name: string): Promise<string> {
|
|
105
53
|
return \`Hello, \${name}!\`;
|
|
@@ -125,8 +73,7 @@ export class Counter {
|
|
|
125
73
|
}
|
|
126
74
|
}
|
|
127
75
|
`
|
|
128
|
-
: `// Server-side exports -
|
|
129
|
-
// Import from "export/" in your client code
|
|
76
|
+
: `// Server-side exports - import from "export/" in your client code
|
|
130
77
|
|
|
131
78
|
export async function hello(name) {
|
|
132
79
|
return \`Hello, \${name}!\`;
|
|
@@ -155,8 +102,8 @@ export class Counter {
|
|
|
155
102
|
fs.writeFileSync(indexPath, template);
|
|
156
103
|
}
|
|
157
104
|
|
|
158
|
-
// Detect Vite build output directory
|
|
159
|
-
let viteBuildOutDir = "dist";
|
|
105
|
+
// Detect Vite build output directory
|
|
106
|
+
let viteBuildOutDir = "dist";
|
|
160
107
|
const viteConfigPath = path.join(cwd, viteConfig);
|
|
161
108
|
let viteConfigContent = fs.readFileSync(viteConfigPath, "utf8");
|
|
162
109
|
const outDirMatch = viteConfigContent.match(/outDir:\s*['"]([^'"]+)['"]/);
|
|
@@ -171,7 +118,7 @@ export class Counter {
|
|
|
171
118
|
private: true,
|
|
172
119
|
type: "module",
|
|
173
120
|
exports: "./",
|
|
174
|
-
main: `../${viteBuildOutDir}`,
|
|
121
|
+
main: `../${viteBuildOutDir}`,
|
|
175
122
|
scripts: {
|
|
176
123
|
dev: "generate-export-types && wrangler dev",
|
|
177
124
|
deploy: "generate-export-types && wrangler deploy",
|
|
@@ -192,28 +139,21 @@ export class Counter {
|
|
|
192
139
|
|
|
193
140
|
// Update main package.json
|
|
194
141
|
pkg.scripts = pkg.scripts || {};
|
|
195
|
-
|
|
196
|
-
// Add export script: build + deploy as Workers Sites
|
|
197
142
|
if (!pkg.scripts["export"]) {
|
|
198
143
|
pkg.scripts["export"] = "vite build && cd export && npm run deploy";
|
|
199
144
|
}
|
|
200
145
|
|
|
201
|
-
// Add exportc to devDependencies
|
|
202
146
|
pkg.devDependencies = pkg.devDependencies || {};
|
|
203
147
|
if (!pkg.devDependencies.exportc) {
|
|
204
|
-
pkg.devDependencies.exportc = "^0.0.
|
|
148
|
+
pkg.devDependencies.exportc = "^0.0.6";
|
|
205
149
|
}
|
|
206
150
|
|
|
207
151
|
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n");
|
|
208
152
|
|
|
209
153
|
// Update vite.config
|
|
210
|
-
|
|
211
|
-
// Check if export plugin is already added
|
|
212
154
|
if (!viteConfigContent.includes("exportc/vite")) {
|
|
213
|
-
// Add import at the top
|
|
214
155
|
const importStatement = `import { exportPlugin } from "exportc/vite";\n`;
|
|
215
156
|
|
|
216
|
-
// Find the first import or the start of the file
|
|
217
157
|
const importMatch = viteConfigContent.match(/^(import\s+.+\s+from\s+['"].+['"];?\s*\n?)+/m);
|
|
218
158
|
if (importMatch) {
|
|
219
159
|
const insertPos = importMatch.index + importMatch[0].length;
|
|
@@ -225,16 +165,12 @@ export class Counter {
|
|
|
225
165
|
viteConfigContent = importStatement + viteConfigContent;
|
|
226
166
|
}
|
|
227
167
|
|
|
228
|
-
// Add plugin to defineConfig
|
|
229
|
-
// Look for plugins array
|
|
230
168
|
if (viteConfigContent.includes("plugins:")) {
|
|
231
|
-
// Add to existing plugins array
|
|
232
169
|
viteConfigContent = viteConfigContent.replace(
|
|
233
170
|
/plugins:\s*\[/,
|
|
234
171
|
"plugins: [exportPlugin(), "
|
|
235
172
|
);
|
|
236
173
|
} else {
|
|
237
|
-
// Add plugins array to defineConfig
|
|
238
174
|
viteConfigContent = viteConfigContent.replace(
|
|
239
175
|
/defineConfig\(\s*\{/,
|
|
240
176
|
"defineConfig({\n plugins: [exportPlugin()],"
|
|
@@ -244,7 +180,7 @@ export class Counter {
|
|
|
244
180
|
fs.writeFileSync(viteConfigPath, viteConfigContent);
|
|
245
181
|
}
|
|
246
182
|
|
|
247
|
-
// Create .gitignore
|
|
183
|
+
// Create .gitignore
|
|
248
184
|
const exportGitignorePath = path.join(exportDir, ".gitignore");
|
|
249
185
|
const gitignoreContent = `# Generated files
|
|
250
186
|
.export-*.js
|
|
@@ -256,15 +192,11 @@ wrangler.toml
|
|
|
256
192
|
`;
|
|
257
193
|
fs.writeFileSync(exportGitignorePath, gitignoreContent);
|
|
258
194
|
|
|
259
|
-
// Create export-env.d.ts
|
|
195
|
+
// Create export-env.d.ts for TypeScript
|
|
260
196
|
if (isTypeScript) {
|
|
261
197
|
const envDtsPath = path.join(cwd, "export-env.d.ts");
|
|
262
198
|
if (!fs.existsSync(envDtsPath)) {
|
|
263
|
-
const envDtsContent = `//
|
|
264
|
-
// This file is auto-generated by exportc. You can modify it to add custom types.
|
|
265
|
-
|
|
266
|
-
// Re-export types from your export directory
|
|
267
|
-
// Update this when you add new exports
|
|
199
|
+
const envDtsContent = `// Auto-generated by exportc - types are updated when you run npm run dev
|
|
268
200
|
|
|
269
201
|
declare module "export/" {
|
|
270
202
|
export function hello(name: string): Promise<string>;
|
|
@@ -276,17 +208,11 @@ declare module "export/" {
|
|
|
276
208
|
[Symbol.dispose](): Promise<void>;
|
|
277
209
|
}
|
|
278
210
|
}
|
|
279
|
-
|
|
280
|
-
// Add more module declarations for subpaths:
|
|
281
|
-
// declare module "export/utils" {
|
|
282
|
-
// export function myUtil(): Promise<void>;
|
|
283
|
-
// }
|
|
284
211
|
`;
|
|
285
212
|
fs.writeFileSync(envDtsPath, envDtsContent);
|
|
286
213
|
}
|
|
287
214
|
|
|
288
|
-
// Update tsconfig
|
|
289
|
-
// Modern Vite uses tsconfig.app.json for app code, older uses tsconfig.json directly
|
|
215
|
+
// Update tsconfig
|
|
290
216
|
const tsconfigAppPath = path.join(cwd, "tsconfig.app.json");
|
|
291
217
|
const tsconfigPath = path.join(cwd, "tsconfig.json");
|
|
292
218
|
const targetTsconfig = fs.existsSync(tsconfigAppPath) ? tsconfigAppPath : tsconfigPath;
|
|
@@ -295,60 +221,32 @@ declare module "export/" {
|
|
|
295
221
|
try {
|
|
296
222
|
const tsconfigContent = fs.readFileSync(targetTsconfig, "utf8");
|
|
297
223
|
const tsconfig = JSON.parse(tsconfigContent);
|
|
298
|
-
|
|
299
|
-
// Add export-env.d.ts to include if not already present
|
|
300
224
|
tsconfig.include = tsconfig.include || [];
|
|
301
225
|
if (!tsconfig.include.includes("export-env.d.ts")) {
|
|
302
226
|
tsconfig.include.push("export-env.d.ts");
|
|
303
227
|
fs.writeFileSync(targetTsconfig, JSON.stringify(tsconfig, null, 2) + "\n");
|
|
304
228
|
}
|
|
305
229
|
} catch {
|
|
306
|
-
// Ignore JSON parse errors
|
|
230
|
+
// Ignore JSON parse errors
|
|
307
231
|
}
|
|
308
232
|
}
|
|
309
233
|
}
|
|
310
234
|
|
|
311
|
-
|
|
312
|
-
s.stop("Export initialized!");
|
|
313
|
-
|
|
314
|
-
const filesCreated = isTypeScript
|
|
315
|
-
? `${pc.cyan("export/")}
|
|
316
|
-
├── index.${ext} ${pc.dim("# Your server exports")}
|
|
317
|
-
├── package.json ${pc.dim("# Worker configuration")}
|
|
318
|
-
└── .gitignore
|
|
319
|
-
|
|
320
|
-
${pc.cyan("export-env.d.ts")} ${pc.dim("# Type declarations for export/ imports")}`
|
|
321
|
-
: `${pc.cyan("export/")}
|
|
322
|
-
├── index.${ext} ${pc.dim("# Your server exports")}
|
|
323
|
-
├── package.json ${pc.dim("# Worker configuration")}
|
|
324
|
-
└── .gitignore`;
|
|
235
|
+
console.log(pc.green("✓") + " Created export/");
|
|
325
236
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
2. Start development (Vite + Wrangler auto-start):
|
|
335
|
-
${pc.cyan("npm run dev")}
|
|
336
|
-
|
|
337
|
-
3. Import in your client code:
|
|
338
|
-
${pc.cyan(`import { hello } from "export/";`)}
|
|
339
|
-
${pc.cyan(`const message = await hello("World");`)}
|
|
340
|
-
|
|
341
|
-
4. Deploy to Cloudflare Workers Sites:
|
|
342
|
-
${pc.cyan("npm run export")}
|
|
343
|
-
${pc.dim("# Builds Vite + deploys everything to Workers")}`,
|
|
344
|
-
"Created"
|
|
345
|
-
);
|
|
346
|
-
|
|
347
|
-
p.outro(`Run ${pc.cyan("cd export && npm install")} to get started!`);
|
|
348
|
-
} else {
|
|
349
|
-
console.log("Export initialized successfully!");
|
|
350
|
-
console.log("\nNext steps:");
|
|
351
|
-
console.log(" cd export && npm install && cd ..");
|
|
352
|
-
console.log(" npm run dev");
|
|
237
|
+
// Install dependencies
|
|
238
|
+
console.log(pc.gray("Installing dependencies..."));
|
|
239
|
+
try {
|
|
240
|
+
execSync("npm install", { cwd: exportDir, stdio: "pipe" });
|
|
241
|
+
console.log(pc.green("✓") + " Installed dependencies");
|
|
242
|
+
} catch {
|
|
243
|
+
console.log(pc.yellow("!") + " Failed to install. Run: cd export && npm install");
|
|
353
244
|
}
|
|
245
|
+
|
|
246
|
+
// Done
|
|
247
|
+
console.log();
|
|
248
|
+
console.log(pc.green("Done!") + " Run " + pc.cyan("npm run dev") + " to start.");
|
|
249
|
+
console.log();
|
|
250
|
+
console.log(pc.gray(" import { hello } from \"export/\";"));
|
|
251
|
+
console.log(pc.gray(" await hello(\"World\");"));
|
|
354
252
|
}
|
package/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import mri from "mri";
|
|
4
|
-
import * as p from "@clack/prompts";
|
|
5
4
|
import pc from "picocolors";
|
|
6
5
|
import { init } from "./commands/init.js";
|
|
7
6
|
import { dev } from "./commands/dev.js";
|
|
@@ -11,36 +10,32 @@ const argv = mri(process.argv.slice(2), {
|
|
|
11
10
|
alias: {
|
|
12
11
|
h: "help",
|
|
13
12
|
v: "version",
|
|
13
|
+
y: "yes",
|
|
14
14
|
},
|
|
15
|
-
boolean: ["help", "version"],
|
|
15
|
+
boolean: ["help", "version", "yes"],
|
|
16
16
|
});
|
|
17
17
|
|
|
18
18
|
const command = argv._[0];
|
|
19
19
|
|
|
20
20
|
const HELP = `
|
|
21
|
-
${pc.bold("exportc")} - Add export to existing projects
|
|
21
|
+
${pc.bold("exportc")} - Add export to existing Vite projects
|
|
22
22
|
|
|
23
23
|
${pc.bold("Usage:")}
|
|
24
24
|
exportc <command> [options]
|
|
25
25
|
|
|
26
26
|
${pc.bold("Commands:")}
|
|
27
|
-
init Initialize export in
|
|
28
|
-
dev Start
|
|
27
|
+
init Initialize export in a Vite project
|
|
28
|
+
dev Start Wrangler dev server
|
|
29
29
|
deploy Deploy to Cloudflare Workers
|
|
30
30
|
|
|
31
31
|
${pc.bold("Options:")}
|
|
32
32
|
-h, --help Show this help message
|
|
33
33
|
-v, --version Show version number
|
|
34
34
|
|
|
35
|
-
${pc.bold("
|
|
35
|
+
${pc.bold("Example:")}
|
|
36
36
|
${pc.dim("# Add export to your Vite project")}
|
|
37
37
|
npx exportc init
|
|
38
|
-
|
|
39
|
-
${pc.dim("# Start development")}
|
|
40
|
-
npx exportc dev
|
|
41
|
-
|
|
42
|
-
${pc.dim("# Deploy to Cloudflare")}
|
|
43
|
-
npx exportc deploy
|
|
38
|
+
npm run dev
|
|
44
39
|
`;
|
|
45
40
|
|
|
46
41
|
if (argv.help || !command) {
|
|
@@ -70,6 +65,6 @@ if (!handler) {
|
|
|
70
65
|
try {
|
|
71
66
|
await handler(argv);
|
|
72
67
|
} catch (err) {
|
|
73
|
-
|
|
68
|
+
console.error(pc.red("Error:"), err.message);
|
|
74
69
|
process.exit(1);
|
|
75
70
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "exportc",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "CLI to add export to existing projects",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "node --test test/init.test.mjs",
|
|
@@ -39,7 +39,6 @@
|
|
|
39
39
|
"commands"
|
|
40
40
|
],
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@clack/prompts": "^0.8.2",
|
|
43
42
|
"mri": "^1.2.0",
|
|
44
43
|
"picocolors": "^1.1.1"
|
|
45
44
|
},
|