create-export 0.0.0 → 0.0.2

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 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.0",
4
- "description": "npm create export",
3
+ "version": "0.0.2",
4
+ "description": "Cloudflare Workers ESM Export Framework",
5
5
  "keywords": [
6
- "export"
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
- "main": "index.js",
20
- "scripts": {
21
- "test": "echo \"Error: no test specified\" && exit 1"
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,56 @@
1
+ // Define your exports here - these will be available to clients
2
+
3
+ // Async function
4
+ export async function greet(name) {
5
+ return `Hello, ${name}!`;
6
+ }
7
+
8
+ // Sync function (will be async on client)
9
+ export function add(a, b) {
10
+ return a + b;
11
+ }
12
+
13
+ // AsyncIterator for streaming
14
+ export async function* countUp(start, end) {
15
+ for (let i = start; i <= end; i++) {
16
+ await new Promise((r) => setTimeout(r, 100));
17
+ yield i;
18
+ }
19
+ }
20
+
21
+ // Nested object with methods
22
+ export const math = {
23
+ multiply(a, b) {
24
+ return a * b;
25
+ },
26
+ factorial(n) {
27
+ if (n <= 1) return 1;
28
+ let result = 1;
29
+ for (let i = 2; i <= n; i++) result *= i;
30
+ return result;
31
+ },
32
+ };
33
+
34
+ // Class export (Comlink-style)
35
+ export class Counter {
36
+ constructor(initial = 0) {
37
+ this.count = initial;
38
+ }
39
+
40
+ increment() {
41
+ return ++this.count;
42
+ }
43
+
44
+ decrement() {
45
+ return --this.count;
46
+ }
47
+
48
+ getCount() {
49
+ return this.count;
50
+ }
51
+
52
+ async asyncIncrement() {
53
+ await new Promise((r) => setTimeout(r, 100));
54
+ return ++this.count;
55
+ }
56
+ }
@@ -0,0 +1,6 @@
1
+ name = "my-export-app"
2
+ main = "node_modules/export-runtime/entry.js"
3
+ compatibility_date = "2024-11-01"
4
+
5
+ [alias]
6
+ "__USER_MODULE__" = "./src/index.js"
@@ -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,58 @@
1
+ // Define your exports here - these will be available to clients
2
+
3
+ // Async function
4
+ export async function greet(name: string): Promise<string> {
5
+ return `Hello, ${name}!`;
6
+ }
7
+
8
+ // Sync function (will be async on client)
9
+ export function add(a: number, b: number): number {
10
+ return a + b;
11
+ }
12
+
13
+ // AsyncIterator for streaming
14
+ export async function* countUp(start: number, end: number): AsyncGenerator<number> {
15
+ for (let i = start; i <= end; i++) {
16
+ await new Promise((r) => setTimeout(r, 100));
17
+ yield i;
18
+ }
19
+ }
20
+
21
+ // Nested object with methods
22
+ export const math = {
23
+ multiply(a: number, b: number): number {
24
+ return a * b;
25
+ },
26
+ factorial(n: number): number {
27
+ if (n <= 1) return 1;
28
+ let result = 1;
29
+ for (let i = 2; i <= n; i++) result *= i;
30
+ return result;
31
+ },
32
+ };
33
+
34
+ // Class export (Comlink-style)
35
+ export class Counter {
36
+ private count: number;
37
+
38
+ constructor(initial: number = 0) {
39
+ this.count = initial;
40
+ }
41
+
42
+ increment(): number {
43
+ return ++this.count;
44
+ }
45
+
46
+ decrement(): number {
47
+ return --this.count;
48
+ }
49
+
50
+ getCount(): number {
51
+ return this.count;
52
+ }
53
+
54
+ async asyncIncrement(): Promise<number> {
55
+ await new Promise((r) => setTimeout(r, 100));
56
+ return ++this.count;
57
+ }
58
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ESNext",
4
+ "module": "ESNext",
5
+ "moduleResolution": "bundler",
6
+ "strict": true,
7
+ "skipLibCheck": true,
8
+ "lib": ["ESNext"],
9
+ "types": ["@cloudflare/workers-types"]
10
+ },
11
+ "include": ["src"]
12
+ }
@@ -0,0 +1,6 @@
1
+ name = "my-export-app"
2
+ main = "node_modules/export-runtime/entry.js"
3
+ compatibility_date = "2024-11-01"
4
+
5
+ [alias]
6
+ "__USER_MODULE__" = "./src/index.ts"
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.