create-faas-app 8.0.0-beta.43 → 8.0.0-beta.45
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 +4 -3
- package/dist/index.mjs +21 -6
- package/index.mjs +24 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Command } from "commander";
|
|
2
|
-
|
|
3
2
|
//#region src/index.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* Run the `create-faas-app` CLI with a provided argv array.
|
|
@@ -7,11 +6,13 @@ import { Command } from "commander";
|
|
|
7
6
|
* The array should use the same shape as `process.argv`, including executable
|
|
8
7
|
* and script slots. Parsing may prompt for a project name, create files, install
|
|
9
8
|
* dependencies, generate FaasJS action types, and run template tests. Commander
|
|
10
|
-
* help exits are swallowed and return the shared program
|
|
11
|
-
*
|
|
9
|
+
* help exits are swallowed and return the shared program. Parsing and action
|
|
10
|
+
* failures are rethrown so library callers and the executable entry point can
|
|
11
|
+
* handle them without duplicate error output.
|
|
12
12
|
*
|
|
13
13
|
* @param {string[]} argv - CLI arguments forwarded to Commander.
|
|
14
14
|
* @returns {Promise<Command>} Commander program instance after parsing.
|
|
15
|
+
* @throws The original Commander or action error when parsing or scaffolding fails.
|
|
15
16
|
*
|
|
16
17
|
* @example
|
|
17
18
|
* ```ts
|
package/dist/index.mjs
CHANGED
|
@@ -6,12 +6,25 @@ import { dirname, join } from "node:path";
|
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
7
|
import enquirer from "enquirer";
|
|
8
8
|
//#region package.json
|
|
9
|
-
var version = "8.0.0-beta.
|
|
9
|
+
var version = "8.0.0-beta.44";
|
|
10
10
|
//#endregion
|
|
11
11
|
//#region src/action/index.ts
|
|
12
12
|
const prompt = enquirer.prompt;
|
|
13
13
|
const validateName = (input) => Validator.name(input);
|
|
14
|
-
|
|
14
|
+
function resolveTemplateRoot() {
|
|
15
|
+
let currentPath = dirname(fileURLToPath(import.meta.url));
|
|
16
|
+
while (true) {
|
|
17
|
+
if (existsSync(join(currentPath, "package.json"))) {
|
|
18
|
+
const templatePath = join(currentPath, "template");
|
|
19
|
+
if (existsSync(templatePath)) return templatePath;
|
|
20
|
+
throw new Error(`Template directory is missing from create-faas-app at ${templatePath}`);
|
|
21
|
+
}
|
|
22
|
+
const parentPath = dirname(currentPath);
|
|
23
|
+
if (parentPath === currentPath) throw new Error("Unable to locate the create-faas-app package directory");
|
|
24
|
+
currentPath = parentPath;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const templateRoot = resolveTemplateRoot();
|
|
15
28
|
const ignoredTemplateEntries = /* @__PURE__ */ new Set(["node_modules"]);
|
|
16
29
|
const Validator = { name(input) {
|
|
17
30
|
const match = /^[a-z0-9-_]+$/i.test(input) ? true : "Must be a-z, 0-9 or -_";
|
|
@@ -133,7 +146,7 @@ ${getTemplateNames().join(", ")}`)).option("--name <name>", "Project name").opti
|
|
|
133
146
|
* @packageDocumentation
|
|
134
147
|
*/
|
|
135
148
|
const commander = new Command();
|
|
136
|
-
commander.storeOptionsAsProperties(false).
|
|
149
|
+
commander.storeOptionsAsProperties(false).configureOutput({ writeErr: () => void 0 }).version(version).name("create-faas-app").exitOverride();
|
|
137
150
|
registerCreateFaasApp(commander);
|
|
138
151
|
/**
|
|
139
152
|
* Run the `create-faas-app` CLI with a provided argv array.
|
|
@@ -141,11 +154,13 @@ registerCreateFaasApp(commander);
|
|
|
141
154
|
* The array should use the same shape as `process.argv`, including executable
|
|
142
155
|
* and script slots. Parsing may prompt for a project name, create files, install
|
|
143
156
|
* dependencies, generate FaasJS action types, and run template tests. Commander
|
|
144
|
-
* help exits are swallowed and return the shared program
|
|
145
|
-
*
|
|
157
|
+
* help exits are swallowed and return the shared program. Parsing and action
|
|
158
|
+
* failures are rethrown so library callers and the executable entry point can
|
|
159
|
+
* handle them without duplicate error output.
|
|
146
160
|
*
|
|
147
161
|
* @param {string[]} argv - CLI arguments forwarded to Commander.
|
|
148
162
|
* @returns {Promise<Command>} Commander program instance after parsing.
|
|
163
|
+
* @throws The original Commander or action error when parsing or scaffolding fails.
|
|
149
164
|
*
|
|
150
165
|
* @example
|
|
151
166
|
* ```ts
|
|
@@ -159,7 +174,7 @@ async function main(argv) {
|
|
|
159
174
|
await commander.parseAsync(argv);
|
|
160
175
|
} catch (error) {
|
|
161
176
|
if (typeof error === "object" && error !== null && "code" in error && error.code === "commander.helpDisplayed") return commander;
|
|
162
|
-
|
|
177
|
+
throw error;
|
|
163
178
|
}
|
|
164
179
|
return commander;
|
|
165
180
|
}
|
package/index.mjs
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { realpathSync } from 'node:fs'
|
|
4
|
+
import { pathToFileURL } from 'node:url'
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
export async function runCli(argv = process.argv, mainFunction) {
|
|
7
|
+
try {
|
|
8
|
+
const run = mainFunction ?? (await import('./dist/index.mjs')).main
|
|
9
|
+
|
|
10
|
+
await run(argv)
|
|
11
|
+
} catch (error) {
|
|
12
|
+
console.error(error)
|
|
13
|
+
process.exitCode = 1
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function isEntrypoint() {
|
|
18
|
+
if (!process.argv[1]) return false
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
return import.meta.url === pathToFileURL(realpathSync(process.argv[1])).href
|
|
22
|
+
} catch {
|
|
23
|
+
return false
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (isEntrypoint()) await runCli()
|