create-export 0.0.0 → 0.0.1
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/index.js +124 -0
- package/package.json +20 -7
- package/template-javascript/package.json +16 -0
- package/template-javascript/src/index.js +30 -0
- package/template-javascript/wrangler.toml +6 -0
- package/template-typescript/package.json +18 -0
- package/template-typescript/src/index.ts +30 -0
- package/template-typescript/tsconfig.json +12 -0
- package/template-typescript/wrangler.toml +6 -0
- package/LICENSE +0 -21
package/index.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import * as p from "@clack/prompts";
|
|
4
|
+
import mri from "mri";
|
|
5
|
+
import { cpSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
6
|
+
import { dirname, join, resolve } from "node:path";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
|
|
9
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
10
|
+
|
|
11
|
+
const argv = mri(process.argv.slice(2), {
|
|
12
|
+
alias: {
|
|
13
|
+
t: "template",
|
|
14
|
+
h: "help",
|
|
15
|
+
},
|
|
16
|
+
string: ["template"],
|
|
17
|
+
boolean: ["help"],
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
if (argv.help) {
|
|
21
|
+
console.log(`
|
|
22
|
+
Usage: npm create export [project-name] [options]
|
|
23
|
+
|
|
24
|
+
Options:
|
|
25
|
+
-t, --template <type> Template type: typescript | javascript
|
|
26
|
+
-h, --help Show this help message
|
|
27
|
+
|
|
28
|
+
Examples:
|
|
29
|
+
npm create export my-app
|
|
30
|
+
npm create export my-app --template typescript
|
|
31
|
+
npm create export my-app -t javascript
|
|
32
|
+
`);
|
|
33
|
+
process.exit(0);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
p.intro("create-export");
|
|
37
|
+
|
|
38
|
+
let projectName = argv._[0];
|
|
39
|
+
let template = argv.template;
|
|
40
|
+
|
|
41
|
+
if (!projectName) {
|
|
42
|
+
const result = await p.text({
|
|
43
|
+
message: "Project name:",
|
|
44
|
+
placeholder: "my-export-app",
|
|
45
|
+
defaultValue: "my-export-app",
|
|
46
|
+
validate: (value) => {
|
|
47
|
+
if (!value) return "Project name is required";
|
|
48
|
+
if (existsSync(resolve(process.cwd(), value))) {
|
|
49
|
+
return `Directory "${value}" already exists`;
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
if (p.isCancel(result)) {
|
|
55
|
+
p.cancel("Operation cancelled.");
|
|
56
|
+
process.exit(0);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
projectName = result || "my-export-app";
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const targetDir = resolve(process.cwd(), projectName);
|
|
63
|
+
|
|
64
|
+
if (existsSync(targetDir)) {
|
|
65
|
+
p.cancel(`Directory "${projectName}" already exists.`);
|
|
66
|
+
process.exit(1);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (!template) {
|
|
70
|
+
const result = await p.select({
|
|
71
|
+
message: "Select a template:",
|
|
72
|
+
options: [
|
|
73
|
+
{ value: "typescript", label: "TypeScript", hint: "recommended" },
|
|
74
|
+
{ value: "javascript", label: "JavaScript" },
|
|
75
|
+
],
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
if (p.isCancel(result)) {
|
|
79
|
+
p.cancel("Operation cancelled.");
|
|
80
|
+
process.exit(0);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
template = result;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (template !== "typescript" && template !== "javascript") {
|
|
87
|
+
p.cancel(`Invalid template: ${template}. Use "typescript" or "javascript".`);
|
|
88
|
+
process.exit(1);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const s = p.spinner();
|
|
92
|
+
s.start("Creating project...");
|
|
93
|
+
|
|
94
|
+
const templateDir = join(__dirname, `template-${template}`);
|
|
95
|
+
|
|
96
|
+
mkdirSync(targetDir, { recursive: true });
|
|
97
|
+
cpSync(templateDir, targetDir, { recursive: true });
|
|
98
|
+
|
|
99
|
+
// Update project package.json
|
|
100
|
+
const pkgPath = join(targetDir, "package.json");
|
|
101
|
+
const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
|
|
102
|
+
pkg.name = projectName;
|
|
103
|
+
writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n");
|
|
104
|
+
|
|
105
|
+
// Update wrangler.toml
|
|
106
|
+
const wranglerPath = join(targetDir, "wrangler.toml");
|
|
107
|
+
const wranglerContent = readFileSync(wranglerPath, "utf-8");
|
|
108
|
+
writeFileSync(wranglerPath, wranglerContent.replace('name = "my-export-app"', `name = "${projectName}"`));
|
|
109
|
+
|
|
110
|
+
s.stop("Project created!");
|
|
111
|
+
|
|
112
|
+
p.note(
|
|
113
|
+
`cd ${projectName}
|
|
114
|
+
npm install
|
|
115
|
+
npm run dev # Start local development
|
|
116
|
+
npm run export # Deploy to Cloudflare Workers`,
|
|
117
|
+
"Next steps"
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
p.outro(`Import from your Worker URL:
|
|
121
|
+
|
|
122
|
+
import { greet, add } from "https://${projectName}.workers.dev/";
|
|
123
|
+
const message = await greet("World");
|
|
124
|
+
`);
|
package/package.json
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-export",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Cloudflare Workers ESM Export Framework",
|
|
5
5
|
"keywords": [
|
|
6
|
-
"
|
|
6
|
+
"cloudflare",
|
|
7
|
+
"workers",
|
|
8
|
+
"esm",
|
|
9
|
+
"rpc",
|
|
10
|
+
"websocket"
|
|
7
11
|
],
|
|
8
12
|
"homepage": "https://github.com/ihasq/export#readme",
|
|
9
13
|
"bugs": {
|
|
@@ -11,13 +15,22 @@
|
|
|
11
15
|
},
|
|
12
16
|
"repository": {
|
|
13
17
|
"type": "git",
|
|
14
|
-
"url": "git+https://github.com/ihasq/export.git"
|
|
18
|
+
"url": "git+https://github.com/ihasq/export.git",
|
|
19
|
+
"directory": "packages/create-export"
|
|
15
20
|
},
|
|
16
21
|
"license": "MIT",
|
|
17
22
|
"author": "ihasq",
|
|
18
23
|
"type": "module",
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
24
|
+
"bin": {
|
|
25
|
+
"create-export": "./index.js"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"index.js",
|
|
29
|
+
"template-typescript",
|
|
30
|
+
"template-javascript"
|
|
31
|
+
],
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@clack/prompts": "^0.8.2",
|
|
34
|
+
"mri": "^1.2.0"
|
|
22
35
|
}
|
|
23
36
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "my-export-app",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "wrangler dev",
|
|
8
|
+
"export": "wrangler deploy"
|
|
9
|
+
},
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"export-runtime": "^0.0.1"
|
|
12
|
+
},
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"wrangler": "^3.93.0"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Define your exports here - these will be available to clients
|
|
2
|
+
|
|
3
|
+
export async function greet(name) {
|
|
4
|
+
return `Hello, ${name}!`;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export async function add(a, b) {
|
|
8
|
+
return a + b;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// AsyncIterator example - streaming data
|
|
12
|
+
export async function* countUp(start, end) {
|
|
13
|
+
for (let i = start; i <= end; i++) {
|
|
14
|
+
await new Promise((r) => setTimeout(r, 100));
|
|
15
|
+
yield i;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Nested object with methods
|
|
20
|
+
export const math = {
|
|
21
|
+
async multiply(a, b) {
|
|
22
|
+
return a * b;
|
|
23
|
+
},
|
|
24
|
+
async factorial(n) {
|
|
25
|
+
if (n <= 1) return 1;
|
|
26
|
+
let result = 1;
|
|
27
|
+
for (let i = 2; i <= n; i++) result *= i;
|
|
28
|
+
return result;
|
|
29
|
+
},
|
|
30
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "my-export-app",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "wrangler dev",
|
|
8
|
+
"export": "wrangler deploy"
|
|
9
|
+
},
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"export-runtime": "^0.0.1"
|
|
12
|
+
},
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"@cloudflare/workers-types": "^4.20241127.0",
|
|
15
|
+
"typescript": "^5.7.0",
|
|
16
|
+
"wrangler": "^3.93.0"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Define your exports here - these will be available to clients
|
|
2
|
+
|
|
3
|
+
export async function greet(name: string): Promise<string> {
|
|
4
|
+
return `Hello, ${name}!`;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export async function add(a: number, b: number): Promise<number> {
|
|
8
|
+
return a + b;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// AsyncIterator example - streaming data
|
|
12
|
+
export async function* countUp(start: number, end: number): AsyncGenerator<number> {
|
|
13
|
+
for (let i = start; i <= end; i++) {
|
|
14
|
+
await new Promise((r) => setTimeout(r, 100));
|
|
15
|
+
yield i;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Nested object with methods
|
|
20
|
+
export const math = {
|
|
21
|
+
async multiply(a: number, b: number): Promise<number> {
|
|
22
|
+
return a * b;
|
|
23
|
+
},
|
|
24
|
+
async factorial(n: number): Promise<number> {
|
|
25
|
+
if (n <= 1) return 1;
|
|
26
|
+
let result = 1;
|
|
27
|
+
for (let i = 2; i <= n; i++) result *= i;
|
|
28
|
+
return result;
|
|
29
|
+
},
|
|
30
|
+
};
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 ihasq
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|