create-faas-app 8.0.0-beta.5 → 8.0.0-beta.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/dist/index.cjs +182 -159
- package/dist/index.d.ts +4 -22
- package/dist/index.mjs +152 -156
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,90 +1,102 @@
|
|
|
1
|
-
'
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
12
|
+
key = keys[i];
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
14
|
+
__defProp(to, key, {
|
|
15
|
+
get: ((k) => from[k]).bind(null, key),
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
24
|
+
value: mod,
|
|
25
|
+
enumerable: true
|
|
26
|
+
}) : target, mod));
|
|
2
27
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
28
|
+
//#endregion
|
|
29
|
+
let commander = require("commander");
|
|
30
|
+
let node_child_process = require("node:child_process");
|
|
31
|
+
let node_fs = require("node:fs");
|
|
32
|
+
let node_path = require("node:path");
|
|
33
|
+
let enquirer = require("enquirer");
|
|
34
|
+
enquirer = __toESM(enquirer);
|
|
8
35
|
|
|
9
|
-
|
|
36
|
+
//#region package.json
|
|
37
|
+
var version = "8.0.0-beta.6";
|
|
10
38
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
function writeFile(path$1, content) {
|
|
24
|
-
fs.mkdirSync(path.dirname(path$1), {
|
|
25
|
-
recursive: true
|
|
26
|
-
});
|
|
27
|
-
fs.writeFileSync(path$1, content);
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region src/action.ts
|
|
41
|
+
const prompt = enquirer.default.prompt;
|
|
42
|
+
const Validator = { name(input) {
|
|
43
|
+
const match = /^[a-z0-9-_]+$/i.test(input) ? true : "Must be a-z, 0-9 or -_";
|
|
44
|
+
if (match !== true) return match;
|
|
45
|
+
if ((0, node_fs.existsSync)(input)) return `${input} folder exists, please try another name`;
|
|
46
|
+
return true;
|
|
47
|
+
} };
|
|
48
|
+
function writeFile(path, content) {
|
|
49
|
+
(0, node_fs.mkdirSync)((0, node_path.dirname)(path), { recursive: true });
|
|
50
|
+
(0, node_fs.writeFileSync)(path, content);
|
|
28
51
|
}
|
|
29
52
|
function buildPackageJSON(name) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
},
|
|
65
|
-
null,
|
|
66
|
-
2
|
|
67
|
-
)}
|
|
53
|
+
return `${JSON.stringify({
|
|
54
|
+
name,
|
|
55
|
+
private: true,
|
|
56
|
+
type: "module",
|
|
57
|
+
version: "1.0.0",
|
|
58
|
+
scripts: {
|
|
59
|
+
dev: "vite",
|
|
60
|
+
build: "vite build",
|
|
61
|
+
start: "node server.ts",
|
|
62
|
+
check: "tsc --noEmit && biome check .",
|
|
63
|
+
test: "vitest run"
|
|
64
|
+
},
|
|
65
|
+
dependencies: {
|
|
66
|
+
"@faasjs/core": "*",
|
|
67
|
+
pg: "*",
|
|
68
|
+
react: "*",
|
|
69
|
+
"react-dom": "*"
|
|
70
|
+
},
|
|
71
|
+
devDependencies: {
|
|
72
|
+
"@biomejs/biome": "*",
|
|
73
|
+
"@electric-sql/pglite": "*",
|
|
74
|
+
"@faasjs/dev": "*",
|
|
75
|
+
"@faasjs/lint": "*",
|
|
76
|
+
"@types/node": "*",
|
|
77
|
+
"@types/react": "*",
|
|
78
|
+
"@types/react-dom": "*",
|
|
79
|
+
"@vitejs/plugin-react": "*",
|
|
80
|
+
jsdom: "*",
|
|
81
|
+
"knex-pglite": "*",
|
|
82
|
+
typescript: "*",
|
|
83
|
+
vite: "*",
|
|
84
|
+
vitest: "*"
|
|
85
|
+
}
|
|
86
|
+
}, null, 2)}
|
|
68
87
|
`;
|
|
69
88
|
}
|
|
70
89
|
function scaffold(rootPath) {
|
|
71
|
-
|
|
72
|
-
path.join(rootPath, ".gitignore"),
|
|
73
|
-
`node_modules/
|
|
90
|
+
writeFile((0, node_path.join)(rootPath, ".gitignore"), `node_modules/
|
|
74
91
|
dist/
|
|
75
92
|
coverage/
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
path.join(rootPath, "biome.json"),
|
|
80
|
-
`{
|
|
93
|
+
.pglite_dev/
|
|
94
|
+
`);
|
|
95
|
+
writeFile((0, node_path.join)(rootPath, "biome.json"), `{
|
|
81
96
|
"extends": ["@faasjs/lint/biome"]
|
|
82
97
|
}
|
|
83
|
-
`
|
|
84
|
-
|
|
85
|
-
writeFile(
|
|
86
|
-
path.join(rootPath, "tsconfig.json"),
|
|
87
|
-
`{
|
|
98
|
+
`);
|
|
99
|
+
writeFile((0, node_path.join)(rootPath, "tsconfig.json"), `{
|
|
88
100
|
"compilerOptions": {
|
|
89
101
|
"target": "ES2022",
|
|
90
102
|
"module": "ESNext",
|
|
@@ -95,11 +107,8 @@ coverage/
|
|
|
95
107
|
},
|
|
96
108
|
"include": ["src", "vite.config.ts", "server.ts"]
|
|
97
109
|
}
|
|
98
|
-
`
|
|
99
|
-
|
|
100
|
-
writeFile(
|
|
101
|
-
path.join(rootPath, "index.html"),
|
|
102
|
-
`<!doctype html>
|
|
110
|
+
`);
|
|
111
|
+
writeFile((0, node_path.join)(rootPath, "index.html"), `<!doctype html>
|
|
103
112
|
<html lang="en">
|
|
104
113
|
<head>
|
|
105
114
|
<meta charset="UTF-8" />
|
|
@@ -108,14 +117,11 @@ coverage/
|
|
|
108
117
|
</head>
|
|
109
118
|
<body>
|
|
110
119
|
<div id="root"></div>
|
|
111
|
-
<script type="module" src="/src/main.tsx"
|
|
120
|
+
<script type="module" src="/src/main.tsx"><\/script>
|
|
112
121
|
</body>
|
|
113
122
|
</html>
|
|
114
|
-
`
|
|
115
|
-
|
|
116
|
-
writeFile(
|
|
117
|
-
path.join(rootPath, "vite.config.ts"),
|
|
118
|
-
`import { viteFaasJsServer } from '@faasjs/dev'
|
|
123
|
+
`);
|
|
124
|
+
writeFile((0, node_path.join)(rootPath, "vite.config.ts"), `import { viteFaasJsServer } from '@faasjs/dev'
|
|
119
125
|
import react from '@vitejs/plugin-react'
|
|
120
126
|
import { defineConfig } from 'vite'
|
|
121
127
|
|
|
@@ -125,11 +131,8 @@ export default defineConfig({
|
|
|
125
131
|
},
|
|
126
132
|
plugins: [react(), viteFaasJsServer()],
|
|
127
133
|
})
|
|
128
|
-
`
|
|
129
|
-
|
|
130
|
-
writeFile(
|
|
131
|
-
path.join(rootPath, "server.ts"),
|
|
132
|
-
`import { dirname, join } from 'node:path'
|
|
134
|
+
`);
|
|
135
|
+
writeFile((0, node_path.join)(rootPath, "server.ts"), `import { dirname, join } from 'node:path'
|
|
133
136
|
import { fileURLToPath } from 'node:url'
|
|
134
137
|
import { Server, staticHandler } from '@faasjs/server'
|
|
135
138
|
|
|
@@ -154,11 +157,11 @@ new Server(join(__dirname, 'src'), {
|
|
|
154
157
|
await distHandler(req, res, ctx)
|
|
155
158
|
},
|
|
156
159
|
}).listen()
|
|
157
|
-
`
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
160
|
+
`);
|
|
161
|
+
writeFile((0, node_path.join)(rootPath, "src", "faas.yaml"), `defaults:
|
|
162
|
+
server:
|
|
163
|
+
root: .
|
|
164
|
+
base: /
|
|
162
165
|
plugins:
|
|
163
166
|
http:
|
|
164
167
|
config:
|
|
@@ -166,22 +169,35 @@ new Server(join(__dirname, 'src'), {
|
|
|
166
169
|
secure: false
|
|
167
170
|
session:
|
|
168
171
|
secret: secret
|
|
172
|
+
knex:
|
|
173
|
+
config:
|
|
174
|
+
client: pg
|
|
175
|
+
pool:
|
|
176
|
+
min: 0
|
|
177
|
+
max: 10
|
|
169
178
|
development:
|
|
179
|
+
plugins:
|
|
180
|
+
knex:
|
|
181
|
+
config:
|
|
182
|
+
client: pglite
|
|
183
|
+
connection: ./.pglite_dev
|
|
170
184
|
testing:
|
|
185
|
+
plugins:
|
|
186
|
+
knex:
|
|
187
|
+
config:
|
|
188
|
+
client: pglite
|
|
171
189
|
production:
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
190
|
+
plugins:
|
|
191
|
+
knex:
|
|
192
|
+
config:
|
|
193
|
+
client: pg
|
|
194
|
+
`);
|
|
195
|
+
writeFile((0, node_path.join)(rootPath, "src", "main.tsx"), `import { createRoot } from 'react-dom/client'
|
|
177
196
|
import HomePage from './pages/home'
|
|
178
197
|
|
|
179
198
|
createRoot(document.getElementById('root') as HTMLElement).render(<HomePage />)
|
|
180
|
-
`
|
|
181
|
-
|
|
182
|
-
writeFile(
|
|
183
|
-
path.join(rootPath, "src", "pages", "home", "index.tsx"),
|
|
184
|
-
`import { useState } from 'react'
|
|
199
|
+
`);
|
|
200
|
+
writeFile((0, node_path.join)(rootPath, "src", "pages", "home", "index.tsx"), `import { useState } from 'react'
|
|
185
201
|
|
|
186
202
|
type ApiResponse = {
|
|
187
203
|
ok: boolean
|
|
@@ -227,12 +243,8 @@ export default function HomePage() {
|
|
|
227
243
|
</main>
|
|
228
244
|
)
|
|
229
245
|
}
|
|
230
|
-
`
|
|
231
|
-
|
|
232
|
-
writeFile(
|
|
233
|
-
path.join(rootPath, "src", "pages", "home", "api", "hello.func.ts"),
|
|
234
|
-
`import { defineFunc } from '@faasjs/func'
|
|
235
|
-
import { z } from 'zod'
|
|
246
|
+
`);
|
|
247
|
+
writeFile((0, node_path.join)(rootPath, "src", "pages", "home", "api", "hello.func.ts"), `import { defineFunc, z } from '@faasjs/core'
|
|
236
248
|
|
|
237
249
|
const schema = z
|
|
238
250
|
.object({
|
|
@@ -240,22 +252,18 @@ const schema = z
|
|
|
240
252
|
})
|
|
241
253
|
.required()
|
|
242
254
|
|
|
243
|
-
export const func = defineFunc
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
255
|
+
export const func = defineFunc({
|
|
256
|
+
schema,
|
|
257
|
+
async handler({ params }) {
|
|
247
258
|
return {
|
|
248
259
|
ok: true,
|
|
249
|
-
data: \`Hello, \${
|
|
260
|
+
data: \`Hello, \${params.name || 'FaasJS'}\`,
|
|
250
261
|
error: null,
|
|
251
262
|
}
|
|
252
|
-
}
|
|
253
|
-
)
|
|
254
|
-
`
|
|
255
|
-
|
|
256
|
-
writeFile(
|
|
257
|
-
path.join(rootPath, "src", "pages", "home", "api", "__tests__", "hello.test.ts"),
|
|
258
|
-
`import { test } from '@faasjs/dev'
|
|
263
|
+
},
|
|
264
|
+
})
|
|
265
|
+
`);
|
|
266
|
+
writeFile((0, node_path.join)(rootPath, "src", "pages", "home", "api", "__tests__", "hello.test.ts"), `import { test } from '@faasjs/dev'
|
|
259
267
|
import { func } from '../hello.func'
|
|
260
268
|
|
|
261
269
|
describe('home/api/hello', () => {
|
|
@@ -272,47 +280,62 @@ describe('home/api/hello', () => {
|
|
|
272
280
|
})
|
|
273
281
|
})
|
|
274
282
|
})
|
|
275
|
-
`
|
|
276
|
-
);
|
|
283
|
+
`);
|
|
277
284
|
}
|
|
278
285
|
async function action(options = {}) {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
scaffold(answers.name);
|
|
296
|
-
child_process.execSync(`cd ${answers.name} && ${runtime} install`, { stdio: "inherit" });
|
|
297
|
-
if (runtime === "bun") {
|
|
298
|
-
child_process.execSync(`cd ${answers.name} && bun test`, { stdio: "inherit" });
|
|
299
|
-
} else child_process.execSync(`cd ${answers.name} && npm run test`, { stdio: "inherit" });
|
|
286
|
+
const answers = Object.assign(options, {});
|
|
287
|
+
if (!options.name || Validator.name(options.name) !== true) answers.name = await prompt({
|
|
288
|
+
type: "input",
|
|
289
|
+
name: "value",
|
|
290
|
+
message: "Project name",
|
|
291
|
+
initial: "faasjs",
|
|
292
|
+
validate: Validator.name
|
|
293
|
+
}).then((res) => res.value);
|
|
294
|
+
if (!answers.name) return;
|
|
295
|
+
const runtime = process.versions.bun ? "bun" : "npm";
|
|
296
|
+
(0, node_fs.mkdirSync)(answers.name);
|
|
297
|
+
(0, node_fs.writeFileSync)((0, node_path.join)(answers.name, "package.json"), buildPackageJSON(answers.name));
|
|
298
|
+
scaffold(answers.name);
|
|
299
|
+
(0, node_child_process.execSync)(`cd ${answers.name} && ${runtime} install`, { stdio: "inherit" });
|
|
300
|
+
if (runtime === "bun") (0, node_child_process.execSync)(`cd ${answers.name} && bun test`, { stdio: "inherit" });
|
|
301
|
+
else (0, node_child_process.execSync)(`cd ${answers.name} && npm run test`, { stdio: "inherit" });
|
|
300
302
|
}
|
|
301
303
|
function action_default(program) {
|
|
302
|
-
|
|
304
|
+
program.description("Create a new faas app").on("--help", () => console.log("Examples:\nnpx create-faas-app")).option("--name <name>", "Project name").action(action);
|
|
303
305
|
}
|
|
304
306
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
307
|
+
//#endregion
|
|
308
|
+
//#region src/index.ts
|
|
309
|
+
/**
|
|
310
|
+
* [](https://github.com/faasjs/faasjs/blob/main/packages/create-faas-app/LICENSE)
|
|
311
|
+
* [](https://www.npmjs.com/package/create-faas-app)
|
|
312
|
+
*
|
|
313
|
+
* Quick way to create a FaasJS project.
|
|
314
|
+
*
|
|
315
|
+
* ## Usage
|
|
316
|
+
*
|
|
317
|
+
* ```bash
|
|
318
|
+
* # use npm
|
|
319
|
+
* npx create-faas-app --name faasjs
|
|
320
|
+
*
|
|
321
|
+
* # use bun
|
|
322
|
+
* bunx create-faas-app --name faasjs
|
|
323
|
+
* ```
|
|
324
|
+
*
|
|
325
|
+
* @packageDocumentation
|
|
326
|
+
*/
|
|
327
|
+
const commander$1 = new commander.Command();
|
|
328
|
+
commander$1.storeOptionsAsProperties(false).allowUnknownOption(true).version(version).name("create-faas-app").exitOverride();
|
|
329
|
+
action_default(commander$1);
|
|
309
330
|
async function main(argv) {
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
331
|
+
try {
|
|
332
|
+
await commander$1.parseAsync(argv);
|
|
333
|
+
} catch (error) {
|
|
334
|
+
if (typeof error === "object" && error !== null && "code" in error && error.code === "commander.helpDisplayed") return commander$1;
|
|
335
|
+
console.error(error);
|
|
336
|
+
}
|
|
337
|
+
return commander$1;
|
|
316
338
|
}
|
|
317
339
|
|
|
318
|
-
|
|
340
|
+
//#endregion
|
|
341
|
+
exports.main = main;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,24 +1,6 @@
|
|
|
1
|
-
import { Command } from
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* [](https://github.com/faasjs/faasjs/blob/main/packages/create-faas-app/LICENSE)
|
|
5
|
-
* [](https://www.npmjs.com/package/create-faas-app)
|
|
6
|
-
*
|
|
7
|
-
* Quick way to create a FaasJS project.
|
|
8
|
-
*
|
|
9
|
-
* ## Usage
|
|
10
|
-
*
|
|
11
|
-
* ```bash
|
|
12
|
-
* # use npm
|
|
13
|
-
* npx create-faas-app --name faasjs
|
|
14
|
-
*
|
|
15
|
-
* # use bun
|
|
16
|
-
* bunx create-faas-app --name faasjs
|
|
17
|
-
* ```
|
|
18
|
-
*
|
|
19
|
-
* @packageDocumentation
|
|
20
|
-
*/
|
|
1
|
+
import { Command } from "commander";
|
|
21
2
|
|
|
3
|
+
//#region src/index.d.ts
|
|
22
4
|
declare function main(argv: string[]): Promise<Command>;
|
|
23
|
-
|
|
24
|
-
export { main };
|
|
5
|
+
//#endregion
|
|
6
|
+
export { main };
|
package/dist/index.mjs
CHANGED
|
@@ -1,88 +1,73 @@
|
|
|
1
|
-
import { Command } from
|
|
2
|
-
import { execSync } from
|
|
3
|
-
import { mkdirSync, writeFileSync
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { execSync } from "node:child_process";
|
|
3
|
+
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
5
|
+
import enquirer from "enquirer";
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
//#region package.json
|
|
8
|
+
var version = "8.0.0-beta.6";
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return true;
|
|
19
|
-
}
|
|
20
|
-
};
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/action.ts
|
|
12
|
+
const prompt = enquirer.prompt;
|
|
13
|
+
const Validator = { name(input) {
|
|
14
|
+
const match = /^[a-z0-9-_]+$/i.test(input) ? true : "Must be a-z, 0-9 or -_";
|
|
15
|
+
if (match !== true) return match;
|
|
16
|
+
if (existsSync(input)) return `${input} folder exists, please try another name`;
|
|
17
|
+
return true;
|
|
18
|
+
} };
|
|
21
19
|
function writeFile(path, content) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
});
|
|
25
|
-
writeFileSync(path, content);
|
|
20
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
21
|
+
writeFileSync(path, content);
|
|
26
22
|
}
|
|
27
23
|
function buildPackageJSON(name) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
},
|
|
63
|
-
null,
|
|
64
|
-
2
|
|
65
|
-
)}
|
|
24
|
+
return `${JSON.stringify({
|
|
25
|
+
name,
|
|
26
|
+
private: true,
|
|
27
|
+
type: "module",
|
|
28
|
+
version: "1.0.0",
|
|
29
|
+
scripts: {
|
|
30
|
+
dev: "vite",
|
|
31
|
+
build: "vite build",
|
|
32
|
+
start: "node server.ts",
|
|
33
|
+
check: "tsc --noEmit && biome check .",
|
|
34
|
+
test: "vitest run"
|
|
35
|
+
},
|
|
36
|
+
dependencies: {
|
|
37
|
+
"@faasjs/core": "*",
|
|
38
|
+
pg: "*",
|
|
39
|
+
react: "*",
|
|
40
|
+
"react-dom": "*"
|
|
41
|
+
},
|
|
42
|
+
devDependencies: {
|
|
43
|
+
"@biomejs/biome": "*",
|
|
44
|
+
"@electric-sql/pglite": "*",
|
|
45
|
+
"@faasjs/dev": "*",
|
|
46
|
+
"@faasjs/lint": "*",
|
|
47
|
+
"@types/node": "*",
|
|
48
|
+
"@types/react": "*",
|
|
49
|
+
"@types/react-dom": "*",
|
|
50
|
+
"@vitejs/plugin-react": "*",
|
|
51
|
+
jsdom: "*",
|
|
52
|
+
"knex-pglite": "*",
|
|
53
|
+
typescript: "*",
|
|
54
|
+
vite: "*",
|
|
55
|
+
vitest: "*"
|
|
56
|
+
}
|
|
57
|
+
}, null, 2)}
|
|
66
58
|
`;
|
|
67
59
|
}
|
|
68
60
|
function scaffold(rootPath) {
|
|
69
|
-
|
|
70
|
-
join(rootPath, ".gitignore"),
|
|
71
|
-
`node_modules/
|
|
61
|
+
writeFile(join(rootPath, ".gitignore"), `node_modules/
|
|
72
62
|
dist/
|
|
73
63
|
coverage/
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
join(rootPath, "biome.json"),
|
|
78
|
-
`{
|
|
64
|
+
.pglite_dev/
|
|
65
|
+
`);
|
|
66
|
+
writeFile(join(rootPath, "biome.json"), `{
|
|
79
67
|
"extends": ["@faasjs/lint/biome"]
|
|
80
68
|
}
|
|
81
|
-
`
|
|
82
|
-
|
|
83
|
-
writeFile(
|
|
84
|
-
join(rootPath, "tsconfig.json"),
|
|
85
|
-
`{
|
|
69
|
+
`);
|
|
70
|
+
writeFile(join(rootPath, "tsconfig.json"), `{
|
|
86
71
|
"compilerOptions": {
|
|
87
72
|
"target": "ES2022",
|
|
88
73
|
"module": "ESNext",
|
|
@@ -93,11 +78,8 @@ coverage/
|
|
|
93
78
|
},
|
|
94
79
|
"include": ["src", "vite.config.ts", "server.ts"]
|
|
95
80
|
}
|
|
96
|
-
`
|
|
97
|
-
|
|
98
|
-
writeFile(
|
|
99
|
-
join(rootPath, "index.html"),
|
|
100
|
-
`<!doctype html>
|
|
81
|
+
`);
|
|
82
|
+
writeFile(join(rootPath, "index.html"), `<!doctype html>
|
|
101
83
|
<html lang="en">
|
|
102
84
|
<head>
|
|
103
85
|
<meta charset="UTF-8" />
|
|
@@ -106,14 +88,11 @@ coverage/
|
|
|
106
88
|
</head>
|
|
107
89
|
<body>
|
|
108
90
|
<div id="root"></div>
|
|
109
|
-
<script type="module" src="/src/main.tsx"
|
|
91
|
+
<script type="module" src="/src/main.tsx"><\/script>
|
|
110
92
|
</body>
|
|
111
93
|
</html>
|
|
112
|
-
`
|
|
113
|
-
|
|
114
|
-
writeFile(
|
|
115
|
-
join(rootPath, "vite.config.ts"),
|
|
116
|
-
`import { viteFaasJsServer } from '@faasjs/dev'
|
|
94
|
+
`);
|
|
95
|
+
writeFile(join(rootPath, "vite.config.ts"), `import { viteFaasJsServer } from '@faasjs/dev'
|
|
117
96
|
import react from '@vitejs/plugin-react'
|
|
118
97
|
import { defineConfig } from 'vite'
|
|
119
98
|
|
|
@@ -123,11 +102,8 @@ export default defineConfig({
|
|
|
123
102
|
},
|
|
124
103
|
plugins: [react(), viteFaasJsServer()],
|
|
125
104
|
})
|
|
126
|
-
`
|
|
127
|
-
|
|
128
|
-
writeFile(
|
|
129
|
-
join(rootPath, "server.ts"),
|
|
130
|
-
`import { dirname, join } from 'node:path'
|
|
105
|
+
`);
|
|
106
|
+
writeFile(join(rootPath, "server.ts"), `import { dirname, join } from 'node:path'
|
|
131
107
|
import { fileURLToPath } from 'node:url'
|
|
132
108
|
import { Server, staticHandler } from '@faasjs/server'
|
|
133
109
|
|
|
@@ -152,11 +128,11 @@ new Server(join(__dirname, 'src'), {
|
|
|
152
128
|
await distHandler(req, res, ctx)
|
|
153
129
|
},
|
|
154
130
|
}).listen()
|
|
155
|
-
`
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
131
|
+
`);
|
|
132
|
+
writeFile(join(rootPath, "src", "faas.yaml"), `defaults:
|
|
133
|
+
server:
|
|
134
|
+
root: .
|
|
135
|
+
base: /
|
|
160
136
|
plugins:
|
|
161
137
|
http:
|
|
162
138
|
config:
|
|
@@ -164,22 +140,35 @@ new Server(join(__dirname, 'src'), {
|
|
|
164
140
|
secure: false
|
|
165
141
|
session:
|
|
166
142
|
secret: secret
|
|
143
|
+
knex:
|
|
144
|
+
config:
|
|
145
|
+
client: pg
|
|
146
|
+
pool:
|
|
147
|
+
min: 0
|
|
148
|
+
max: 10
|
|
167
149
|
development:
|
|
150
|
+
plugins:
|
|
151
|
+
knex:
|
|
152
|
+
config:
|
|
153
|
+
client: pglite
|
|
154
|
+
connection: ./.pglite_dev
|
|
168
155
|
testing:
|
|
156
|
+
plugins:
|
|
157
|
+
knex:
|
|
158
|
+
config:
|
|
159
|
+
client: pglite
|
|
169
160
|
production:
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
161
|
+
plugins:
|
|
162
|
+
knex:
|
|
163
|
+
config:
|
|
164
|
+
client: pg
|
|
165
|
+
`);
|
|
166
|
+
writeFile(join(rootPath, "src", "main.tsx"), `import { createRoot } from 'react-dom/client'
|
|
175
167
|
import HomePage from './pages/home'
|
|
176
168
|
|
|
177
169
|
createRoot(document.getElementById('root') as HTMLElement).render(<HomePage />)
|
|
178
|
-
`
|
|
179
|
-
|
|
180
|
-
writeFile(
|
|
181
|
-
join(rootPath, "src", "pages", "home", "index.tsx"),
|
|
182
|
-
`import { useState } from 'react'
|
|
170
|
+
`);
|
|
171
|
+
writeFile(join(rootPath, "src", "pages", "home", "index.tsx"), `import { useState } from 'react'
|
|
183
172
|
|
|
184
173
|
type ApiResponse = {
|
|
185
174
|
ok: boolean
|
|
@@ -225,12 +214,8 @@ export default function HomePage() {
|
|
|
225
214
|
</main>
|
|
226
215
|
)
|
|
227
216
|
}
|
|
228
|
-
`
|
|
229
|
-
|
|
230
|
-
writeFile(
|
|
231
|
-
join(rootPath, "src", "pages", "home", "api", "hello.func.ts"),
|
|
232
|
-
`import { defineFunc } from '@faasjs/func'
|
|
233
|
-
import { z } from 'zod'
|
|
217
|
+
`);
|
|
218
|
+
writeFile(join(rootPath, "src", "pages", "home", "api", "hello.func.ts"), `import { defineFunc, z } from '@faasjs/core'
|
|
234
219
|
|
|
235
220
|
const schema = z
|
|
236
221
|
.object({
|
|
@@ -238,22 +223,18 @@ const schema = z
|
|
|
238
223
|
})
|
|
239
224
|
.required()
|
|
240
225
|
|
|
241
|
-
export const func = defineFunc
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
226
|
+
export const func = defineFunc({
|
|
227
|
+
schema,
|
|
228
|
+
async handler({ params }) {
|
|
245
229
|
return {
|
|
246
230
|
ok: true,
|
|
247
|
-
data: \`Hello, \${
|
|
231
|
+
data: \`Hello, \${params.name || 'FaasJS'}\`,
|
|
248
232
|
error: null,
|
|
249
233
|
}
|
|
250
|
-
}
|
|
251
|
-
)
|
|
252
|
-
`
|
|
253
|
-
|
|
254
|
-
writeFile(
|
|
255
|
-
join(rootPath, "src", "pages", "home", "api", "__tests__", "hello.test.ts"),
|
|
256
|
-
`import { test } from '@faasjs/dev'
|
|
234
|
+
},
|
|
235
|
+
})
|
|
236
|
+
`);
|
|
237
|
+
writeFile(join(rootPath, "src", "pages", "home", "api", "__tests__", "hello.test.ts"), `import { test } from '@faasjs/dev'
|
|
257
238
|
import { func } from '../hello.func'
|
|
258
239
|
|
|
259
240
|
describe('home/api/hello', () => {
|
|
@@ -270,47 +251,62 @@ describe('home/api/hello', () => {
|
|
|
270
251
|
})
|
|
271
252
|
})
|
|
272
253
|
})
|
|
273
|
-
`
|
|
274
|
-
);
|
|
254
|
+
`);
|
|
275
255
|
}
|
|
276
256
|
async function action(options = {}) {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
scaffold(answers.name);
|
|
294
|
-
execSync(`cd ${answers.name} && ${runtime} install`, { stdio: "inherit" });
|
|
295
|
-
if (runtime === "bun") {
|
|
296
|
-
execSync(`cd ${answers.name} && bun test`, { stdio: "inherit" });
|
|
297
|
-
} else execSync(`cd ${answers.name} && npm run test`, { stdio: "inherit" });
|
|
257
|
+
const answers = Object.assign(options, {});
|
|
258
|
+
if (!options.name || Validator.name(options.name) !== true) answers.name = await prompt({
|
|
259
|
+
type: "input",
|
|
260
|
+
name: "value",
|
|
261
|
+
message: "Project name",
|
|
262
|
+
initial: "faasjs",
|
|
263
|
+
validate: Validator.name
|
|
264
|
+
}).then((res) => res.value);
|
|
265
|
+
if (!answers.name) return;
|
|
266
|
+
const runtime = process.versions.bun ? "bun" : "npm";
|
|
267
|
+
mkdirSync(answers.name);
|
|
268
|
+
writeFileSync(join(answers.name, "package.json"), buildPackageJSON(answers.name));
|
|
269
|
+
scaffold(answers.name);
|
|
270
|
+
execSync(`cd ${answers.name} && ${runtime} install`, { stdio: "inherit" });
|
|
271
|
+
if (runtime === "bun") execSync(`cd ${answers.name} && bun test`, { stdio: "inherit" });
|
|
272
|
+
else execSync(`cd ${answers.name} && npm run test`, { stdio: "inherit" });
|
|
298
273
|
}
|
|
299
274
|
function action_default(program) {
|
|
300
|
-
|
|
275
|
+
program.description("Create a new faas app").on("--help", () => console.log("Examples:\nnpx create-faas-app")).option("--name <name>", "Project name").action(action);
|
|
301
276
|
}
|
|
302
277
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
278
|
+
//#endregion
|
|
279
|
+
//#region src/index.ts
|
|
280
|
+
/**
|
|
281
|
+
* [](https://github.com/faasjs/faasjs/blob/main/packages/create-faas-app/LICENSE)
|
|
282
|
+
* [](https://www.npmjs.com/package/create-faas-app)
|
|
283
|
+
*
|
|
284
|
+
* Quick way to create a FaasJS project.
|
|
285
|
+
*
|
|
286
|
+
* ## Usage
|
|
287
|
+
*
|
|
288
|
+
* ```bash
|
|
289
|
+
* # use npm
|
|
290
|
+
* npx create-faas-app --name faasjs
|
|
291
|
+
*
|
|
292
|
+
* # use bun
|
|
293
|
+
* bunx create-faas-app --name faasjs
|
|
294
|
+
* ```
|
|
295
|
+
*
|
|
296
|
+
* @packageDocumentation
|
|
297
|
+
*/
|
|
298
|
+
const commander = new Command();
|
|
299
|
+
commander.storeOptionsAsProperties(false).allowUnknownOption(true).version(version).name("create-faas-app").exitOverride();
|
|
306
300
|
action_default(commander);
|
|
307
301
|
async function main(argv) {
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
302
|
+
try {
|
|
303
|
+
await commander.parseAsync(argv);
|
|
304
|
+
} catch (error) {
|
|
305
|
+
if (typeof error === "object" && error !== null && "code" in error && error.code === "commander.helpDisplayed") return commander;
|
|
306
|
+
console.error(error);
|
|
307
|
+
}
|
|
308
|
+
return commander;
|
|
314
309
|
}
|
|
315
310
|
|
|
316
|
-
|
|
311
|
+
//#endregion
|
|
312
|
+
export { main };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-faas-app",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.0-beta.7",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"funding": "https://github.com/sponsors/faasjs",
|
|
29
29
|
"scripts": {
|
|
30
|
-
"build": "
|
|
30
|
+
"build": "tsdown src/index.ts --config ../../tsdown.config.ts"
|
|
31
31
|
},
|
|
32
32
|
"files": [
|
|
33
33
|
"dist",
|