create-faas-app 8.0.0-beta.21 → 8.0.0-beta.22
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.d.ts +2 -2
- package/dist/index.mjs +41 -6
- package/package.json +1 -1
- package/template/antd/src/faas.yaml +1 -1
- package/template/basic/src/faas.yaml +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -4,8 +4,8 @@ import { Command } from "commander";
|
|
|
4
4
|
/**
|
|
5
5
|
* Run the `create-faas-app` CLI with a provided argv array.
|
|
6
6
|
*
|
|
7
|
-
* @param argv - CLI arguments forwarded to Commander.
|
|
8
|
-
* @returns Commander program instance after parsing.
|
|
7
|
+
* @param {string[]} argv - CLI arguments forwarded to Commander.
|
|
8
|
+
* @returns {Promise<Command>} Commander program instance after parsing.
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
11
|
* ```ts
|
package/dist/index.mjs
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { Command } from "commander";
|
|
2
2
|
import { execSync } from "node:child_process";
|
|
3
|
+
import { randomBytes } from "node:crypto";
|
|
3
4
|
import { existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from "node:fs";
|
|
4
5
|
import { dirname, join } from "node:path";
|
|
5
6
|
import { fileURLToPath } from "node:url";
|
|
6
7
|
import enquirer from "enquirer";
|
|
7
8
|
//#region package.json
|
|
8
|
-
var version = "8.0.0-beta.
|
|
9
|
+
var version = "8.0.0-beta.21";
|
|
9
10
|
//#endregion
|
|
10
11
|
//#region src/action.ts
|
|
11
12
|
const prompt = enquirer.prompt;
|
|
@@ -28,6 +29,9 @@ function resolveTemplateName(template = "basic") {
|
|
|
28
29
|
function renderTemplate(content, replacements) {
|
|
29
30
|
return Object.entries(replacements).reduce((result, [key, value]) => result.replaceAll(`{{${key}}}`, value), content);
|
|
30
31
|
}
|
|
32
|
+
function generateSessionSecret() {
|
|
33
|
+
return randomBytes(32).toString("hex");
|
|
34
|
+
}
|
|
31
35
|
function copyTemplateDirectory(sourcePath, targetPath, replacements) {
|
|
32
36
|
mkdirSync(targetPath, { recursive: true });
|
|
33
37
|
for (const entry of readdirSync(sourcePath, { withFileTypes: true })) {
|
|
@@ -44,6 +48,22 @@ function scaffold(rootPath, replacements, templateName) {
|
|
|
44
48
|
mkdirSync(rootPath);
|
|
45
49
|
copyTemplateDirectory(join(templateRoot, templateName), rootPath, replacements);
|
|
46
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Scaffold a new FaasJS app from a bundled template and install its dependencies.
|
|
53
|
+
*
|
|
54
|
+
* @param {object} [options] - Optional CLI arguments used to choose the project name and template.
|
|
55
|
+
* @param {string} [options.name] - Target folder name for the generated app.
|
|
56
|
+
* @param {string} [options.template] - Template name such as `basic` or `antd`.
|
|
57
|
+
* @returns {Promise<void>} Resolves after the project is generated and its test command finishes.
|
|
58
|
+
* @throws {Error} When the selected template is unknown.
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* await action({
|
|
62
|
+
* name: 'faasjs-demo',
|
|
63
|
+
* template: 'basic',
|
|
64
|
+
* })
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
47
67
|
async function action(options = {}) {
|
|
48
68
|
const templateName = resolveTemplateName(options.template);
|
|
49
69
|
const answers = Object.assign(options, {});
|
|
@@ -56,12 +76,27 @@ async function action(options = {}) {
|
|
|
56
76
|
}).then((res) => res.value);
|
|
57
77
|
if (!answers.name) return;
|
|
58
78
|
const runtime = process.versions.bun ? "bun" : "npm";
|
|
59
|
-
scaffold(answers.name, {
|
|
79
|
+
scaffold(answers.name, {
|
|
80
|
+
name: answers.name,
|
|
81
|
+
secret: generateSessionSecret()
|
|
82
|
+
}, templateName);
|
|
60
83
|
execSync(`cd ${answers.name} && ${runtime} install`, { stdio: "inherit" });
|
|
61
84
|
if (runtime === "bun") execSync(`cd ${answers.name} && bun test`, { stdio: "inherit" });
|
|
62
85
|
else execSync(`cd ${answers.name} && npm run test`, { stdio: "inherit" });
|
|
63
86
|
}
|
|
64
|
-
|
|
87
|
+
/**
|
|
88
|
+
* Register the `create-faas-app` command on a Commander program.
|
|
89
|
+
*
|
|
90
|
+
* @param {Command} program - Commander program instance extended with the generator command.
|
|
91
|
+
* @returns {void} No return value.
|
|
92
|
+
* @example
|
|
93
|
+
* ```ts
|
|
94
|
+
* const program = new Command()
|
|
95
|
+
*
|
|
96
|
+
* registerCreateFaasApp(program)
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
function registerCreateFaasApp(program) {
|
|
65
100
|
program.description("Create a new faas app").on("--help", () => console.log(`Examples:
|
|
66
101
|
npx create-faas-app --name faasjs
|
|
67
102
|
npx create-faas-app --name faasjs-admin --template antd
|
|
@@ -91,12 +126,12 @@ ${getTemplateNames().join(", ")}`)).option("--name <name>", "Project name").opti
|
|
|
91
126
|
*/
|
|
92
127
|
const commander = new Command();
|
|
93
128
|
commander.storeOptionsAsProperties(false).allowUnknownOption(true).version(version).name("create-faas-app").exitOverride();
|
|
94
|
-
|
|
129
|
+
registerCreateFaasApp(commander);
|
|
95
130
|
/**
|
|
96
131
|
* Run the `create-faas-app` CLI with a provided argv array.
|
|
97
132
|
*
|
|
98
|
-
* @param argv - CLI arguments forwarded to Commander.
|
|
99
|
-
* @returns Commander program instance after parsing.
|
|
133
|
+
* @param {string[]} argv - CLI arguments forwarded to Commander.
|
|
134
|
+
* @returns {Promise<Command>} Commander program instance after parsing.
|
|
100
135
|
*
|
|
101
136
|
* @example
|
|
102
137
|
* ```ts
|
package/package.json
CHANGED