@faasjs/dev 8.0.0-beta.10
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/LICENSE +21 -0
- package/README.md +141 -0
- package/configs/oxlint.base.json +5 -0
- package/dist/chunk-D8kEL_kv.mjs +38 -0
- package/dist/cli/index.cjs +292 -0
- package/dist/cli/index.d.ts +5 -0
- package/dist/cli/index.mjs +290 -0
- package/dist/index.cjs +318 -0
- package/dist/index.d.ts +105 -0
- package/dist/index.mjs +272 -0
- package/dist/typegen-BNWmP5Qp.mjs +165 -0
- package/dist/typegen-HX5QyuhP.cjs +182 -0
- package/faas.mjs +7 -0
- package/package.json +59 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019-present, Zhu Feng
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# @faasjs/dev
|
|
2
|
+
|
|
3
|
+
FaasJS development toolkit for local development and testing.
|
|
4
|
+
|
|
5
|
+
[](https://github.com/faasjs/faasjs/blob/main/packages/dev/LICENSE)
|
|
6
|
+
[](https://www.npmjs.com/package/@faasjs/dev)
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
npm install @faasjs/dev
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Features
|
|
15
|
+
|
|
16
|
+
- Vite integration for in-process FaasJS API during local development.
|
|
17
|
+
- Test helpers to invoke and assert FaasJS functions.
|
|
18
|
+
|
|
19
|
+
## Usage: Vite integration
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { viteFaasJsServer } from '@faasjs/dev'
|
|
23
|
+
|
|
24
|
+
export default defineConfig({
|
|
25
|
+
plugins: [viteFaasJsServer()],
|
|
26
|
+
})
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Usage: Test helpers
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import { test } from '@faasjs/dev'
|
|
33
|
+
import Func from '../demo.func.ts'
|
|
34
|
+
|
|
35
|
+
const func = test(Func)
|
|
36
|
+
const response = await func.JSONhandler({ name: 'FaasJS' })
|
|
37
|
+
|
|
38
|
+
expect(response.statusCode).toBe(200)
|
|
39
|
+
expect(response.data).toEqual({ message: 'Hello, FaasJS' })
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## API
|
|
43
|
+
|
|
44
|
+
- Vite: [viteFaasJsServer](functions/viteFaasJsServer.md)
|
|
45
|
+
- Test: [test](functions/test.md), [FuncWarper](classes/FuncWarper.md), [streamToText](functions/streamToText.md), [streamToObject](functions/streamToObject.md), [streamToString](variables/streamToString.md)
|
|
46
|
+
|
|
47
|
+
## Functions
|
|
48
|
+
|
|
49
|
+
- [closeAll](functions/closeAll.md)
|
|
50
|
+
- [createCronJob](functions/createCronJob.md)
|
|
51
|
+
- [createPgliteKnex](functions/createPgliteKnex.md)
|
|
52
|
+
- [defineApi](functions/defineApi.md)
|
|
53
|
+
- [generateFaasTypes](functions/generateFaasTypes.md)
|
|
54
|
+
- [getAll](functions/getAll.md)
|
|
55
|
+
- [initPostgresTypeParsers](functions/initPostgresTypeParsers.md)
|
|
56
|
+
- [isTypegenSourceFile](functions/isTypegenSourceFile.md)
|
|
57
|
+
- [listCronJobs](functions/listCronJobs.md)
|
|
58
|
+
- [mountFaasKnex](functions/mountFaasKnex.md)
|
|
59
|
+
- [nameFunc](functions/nameFunc.md)
|
|
60
|
+
- [parseFuncFilenameFromStack](functions/parseFuncFilenameFromStack.md)
|
|
61
|
+
- [query](functions/query.md)
|
|
62
|
+
- [raw](functions/raw.md)
|
|
63
|
+
- [removeCronJob](functions/removeCronJob.md)
|
|
64
|
+
- [staticHandler](functions/staticHandler.md)
|
|
65
|
+
- [streamToObject](functions/streamToObject.md)
|
|
66
|
+
- [streamToText](functions/streamToText.md)
|
|
67
|
+
- [test](functions/test.md)
|
|
68
|
+
- [transaction](functions/transaction.md)
|
|
69
|
+
- [unmountFaasKnex](functions/unmountFaasKnex.md)
|
|
70
|
+
- [useFunc](functions/useFunc.md)
|
|
71
|
+
- [useHttp](functions/useHttp.md)
|
|
72
|
+
- [useKnex](functions/useKnex.md)
|
|
73
|
+
- [useMiddleware](functions/useMiddleware.md)
|
|
74
|
+
- [useMiddlewares](functions/useMiddlewares.md)
|
|
75
|
+
- [usePlugin](functions/usePlugin.md)
|
|
76
|
+
- [viteFaasJsServer](functions/viteFaasJsServer.md)
|
|
77
|
+
|
|
78
|
+
## Classes
|
|
79
|
+
|
|
80
|
+
- [Cookie](classes/Cookie.md)
|
|
81
|
+
- [CronJob](classes/CronJob.md)
|
|
82
|
+
- [Func](classes/Func.md)
|
|
83
|
+
- [FuncWarper](classes/FuncWarper.md)
|
|
84
|
+
- [Http](classes/Http.md)
|
|
85
|
+
- [HttpError](classes/HttpError.md)
|
|
86
|
+
- [Knex](classes/Knex.md)
|
|
87
|
+
- [KnexSchema](classes/KnexSchema.md)
|
|
88
|
+
- [Server](classes/Server.md)
|
|
89
|
+
- [Session](classes/Session.md)
|
|
90
|
+
|
|
91
|
+
## Interfaces
|
|
92
|
+
|
|
93
|
+
- [FaasPluginEventMap](interfaces/FaasPluginEventMap.md)
|
|
94
|
+
|
|
95
|
+
## Type Aliases
|
|
96
|
+
|
|
97
|
+
- [Config](type-aliases/Config.md)
|
|
98
|
+
- [CookieOptions](type-aliases/CookieOptions.md)
|
|
99
|
+
- [CronJobContext](type-aliases/CronJobContext.md)
|
|
100
|
+
- [CronJobErrorHandler](type-aliases/CronJobErrorHandler.md)
|
|
101
|
+
- [CronJobHandler](type-aliases/CronJobHandler.md)
|
|
102
|
+
- [CronJobOptions](type-aliases/CronJobOptions.md)
|
|
103
|
+
- [DefineApiData](type-aliases/DefineApiData.md)
|
|
104
|
+
- [DefineApiOptions](type-aliases/DefineApiOptions.md)
|
|
105
|
+
- [ExportedHandler](type-aliases/ExportedHandler.md)
|
|
106
|
+
- [FuncConfig](type-aliases/FuncConfig.md)
|
|
107
|
+
- [FuncEventType](type-aliases/FuncEventType.md)
|
|
108
|
+
- [FuncReturnType](type-aliases/FuncReturnType.md)
|
|
109
|
+
- [GenerateFaasTypesOptions](type-aliases/GenerateFaasTypesOptions.md)
|
|
110
|
+
- [GenerateFaasTypesResult](type-aliases/GenerateFaasTypesResult.md)
|
|
111
|
+
- [Handler](type-aliases/Handler.md)
|
|
112
|
+
- [HttpConfig](type-aliases/HttpConfig.md)
|
|
113
|
+
- [InferPluginEvent](type-aliases/InferPluginEvent.md)
|
|
114
|
+
- [InvokeData](type-aliases/InvokeData.md)
|
|
115
|
+
- [KnexConfig](type-aliases/KnexConfig.md)
|
|
116
|
+
- [LifeCycleKey](type-aliases/LifeCycleKey.md)
|
|
117
|
+
- [Middleware](type-aliases/Middleware.md)
|
|
118
|
+
- [MiddlewareContext](type-aliases/MiddlewareContext.md)
|
|
119
|
+
- [MiddlewareEvent](type-aliases/MiddlewareEvent.md)
|
|
120
|
+
- [MountData](type-aliases/MountData.md)
|
|
121
|
+
- [MountedKnexAdapter](type-aliases/MountedKnexAdapter.md)
|
|
122
|
+
- [MountFaasKnexOptions](type-aliases/MountFaasKnexOptions.md)
|
|
123
|
+
- [Next](type-aliases/Next.md)
|
|
124
|
+
- [NormalizePluginType](type-aliases/NormalizePluginType.md)
|
|
125
|
+
- [Plugin](type-aliases/Plugin.md)
|
|
126
|
+
- [ResolvePluginEvent](type-aliases/ResolvePluginEvent.md)
|
|
127
|
+
- [Response](type-aliases/Response.md)
|
|
128
|
+
- [ServerHandlerOptions](type-aliases/ServerHandlerOptions.md)
|
|
129
|
+
- [ServerOptions](type-aliases/ServerOptions.md)
|
|
130
|
+
- [SessionContent](type-aliases/SessionContent.md)
|
|
131
|
+
- [SessionOptions](type-aliases/SessionOptions.md)
|
|
132
|
+
- [Simplify](type-aliases/Simplify.md)
|
|
133
|
+
- [StaticHandlerOptions](type-aliases/StaticHandlerOptions.md)
|
|
134
|
+
- [UnionToIntersection](type-aliases/UnionToIntersection.md)
|
|
135
|
+
- [UseifyPlugin](type-aliases/UseifyPlugin.md)
|
|
136
|
+
|
|
137
|
+
## Variables
|
|
138
|
+
|
|
139
|
+
- [ContentType](variables/ContentType.md)
|
|
140
|
+
- [originKnex](variables/originKnex.md)
|
|
141
|
+
- [streamToString](variables/streamToString.md)
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
|
|
3
|
+
//#region \0rolldown/runtime.js
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __exportAll = (all, no_symbols) => {
|
|
9
|
+
let target = {};
|
|
10
|
+
for (var name in all) {
|
|
11
|
+
__defProp(target, name, {
|
|
12
|
+
get: all[name],
|
|
13
|
+
enumerable: true
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
if (!no_symbols) {
|
|
17
|
+
__defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
18
|
+
}
|
|
19
|
+
return target;
|
|
20
|
+
};
|
|
21
|
+
var __copyProps = (to, from, except, desc) => {
|
|
22
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
23
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
24
|
+
key = keys[i];
|
|
25
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
26
|
+
__defProp(to, key, {
|
|
27
|
+
get: ((k) => from[k]).bind(null, key),
|
|
28
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return to;
|
|
34
|
+
};
|
|
35
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
export { __reExport as n, __exportAll as t };
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_typegen = require('../typegen-HX5QyuhP.cjs');
|
|
3
|
+
let _faasjs_core = require("@faasjs/core");
|
|
4
|
+
let _faasjs_node_utils = require("@faasjs/node-utils");
|
|
5
|
+
let node_fs = require("node:fs");
|
|
6
|
+
let node_path = require("node:path");
|
|
7
|
+
let node_child_process = require("node:child_process");
|
|
8
|
+
let node_module = require("node:module");
|
|
9
|
+
|
|
10
|
+
//#region package.json
|
|
11
|
+
var version = "8.0.0-beta.9";
|
|
12
|
+
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/cli/shared.ts
|
|
15
|
+
function parseCommonCliArgs(args, scope) {
|
|
16
|
+
const options = {};
|
|
17
|
+
const rest = [];
|
|
18
|
+
for (let i = 0; i < args.length; i++) {
|
|
19
|
+
const arg = args[i];
|
|
20
|
+
if (arg === "-h" || arg === "--help") return {
|
|
21
|
+
mode: "help",
|
|
22
|
+
options,
|
|
23
|
+
rest
|
|
24
|
+
};
|
|
25
|
+
if (arg === "-v" || arg === "--version") return {
|
|
26
|
+
mode: "version",
|
|
27
|
+
options,
|
|
28
|
+
rest
|
|
29
|
+
};
|
|
30
|
+
if (arg === "--root") {
|
|
31
|
+
const value = args[i + 1];
|
|
32
|
+
if (!value || value.startsWith("-")) throw Error(`[${scope}] Missing value for ${arg}`);
|
|
33
|
+
options.root = value;
|
|
34
|
+
i += 1;
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (arg.startsWith("-")) throw Error(`[${scope}] Unknown option: ${arg}`);
|
|
38
|
+
rest.push(arg);
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
mode: "run",
|
|
42
|
+
options,
|
|
43
|
+
rest
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function printVersion() {
|
|
47
|
+
console.log(version);
|
|
48
|
+
return 0;
|
|
49
|
+
}
|
|
50
|
+
async function runCli(handler) {
|
|
51
|
+
try {
|
|
52
|
+
return await handler();
|
|
53
|
+
} catch (error) {
|
|
54
|
+
console.error(error?.message || error);
|
|
55
|
+
return 1;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function createMain(run) {
|
|
59
|
+
return async (argv = process.argv) => runCli(() => run(argv.slice(2)));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region src/cli/knex.ts
|
|
64
|
+
const MigrateActions = [
|
|
65
|
+
"latest",
|
|
66
|
+
"rollback",
|
|
67
|
+
"status",
|
|
68
|
+
"current",
|
|
69
|
+
"make"
|
|
70
|
+
];
|
|
71
|
+
function isMigrateAction(value) {
|
|
72
|
+
return MigrateActions.includes(value);
|
|
73
|
+
}
|
|
74
|
+
const ActionHandlers = {
|
|
75
|
+
latest: (schema) => schema.migrateLatest(),
|
|
76
|
+
rollback: (schema) => schema.migrateRollback(),
|
|
77
|
+
status: async (schema) => {
|
|
78
|
+
console.log(await schema.migrateStatus());
|
|
79
|
+
},
|
|
80
|
+
current: async (schema) => {
|
|
81
|
+
console.log(await schema.migrateCurrentVersion());
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
const HelpText$3 = `Run FaasJS knex migrations.
|
|
85
|
+
|
|
86
|
+
Usage:
|
|
87
|
+
faas knex <action> [name] [options]
|
|
88
|
+
|
|
89
|
+
Actions:
|
|
90
|
+
latest Run all pending migrations
|
|
91
|
+
rollback Roll back the last migration batch
|
|
92
|
+
status Print pending migration count
|
|
93
|
+
current Print current migration version
|
|
94
|
+
make <name> Create a new migration file
|
|
95
|
+
|
|
96
|
+
Options:
|
|
97
|
+
--root <path> Project root path (default: process.cwd())
|
|
98
|
+
-h, --help Show help
|
|
99
|
+
-v, --version Show version
|
|
100
|
+
`;
|
|
101
|
+
function parseCliArgs(args) {
|
|
102
|
+
const { mode, options, rest } = parseCommonCliArgs(args, "faas knex");
|
|
103
|
+
if (mode !== "run") return {
|
|
104
|
+
mode,
|
|
105
|
+
options
|
|
106
|
+
};
|
|
107
|
+
const [action, name, extra] = rest;
|
|
108
|
+
if (!action) throw Error("[faas knex] Missing action. Usage: faas knex <latest|rollback|status|current|make>");
|
|
109
|
+
if (!isMigrateAction(action)) throw Error(`[faas knex] Unknown action: ${action}`);
|
|
110
|
+
if (action !== "make") {
|
|
111
|
+
if (name) throw Error(`[faas knex] Unexpected argument: ${name}`);
|
|
112
|
+
return {
|
|
113
|
+
mode: "run",
|
|
114
|
+
action,
|
|
115
|
+
options
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
if (!name) throw Error("[faas knex] Missing migration name. Usage: faas knex make create_users");
|
|
119
|
+
if (extra) throw Error(`[faas knex] Unexpected argument: ${extra}`);
|
|
120
|
+
return {
|
|
121
|
+
mode: "run",
|
|
122
|
+
action: "make",
|
|
123
|
+
name,
|
|
124
|
+
options
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
async function run$3(args) {
|
|
128
|
+
const parsed = parseCliArgs(args);
|
|
129
|
+
if (parsed.mode === "help") {
|
|
130
|
+
console.log(HelpText$3);
|
|
131
|
+
return 0;
|
|
132
|
+
}
|
|
133
|
+
if (parsed.mode === "version") return printVersion();
|
|
134
|
+
const envRoot = parsed.options.root ?? process.cwd();
|
|
135
|
+
(0, _faasjs_node_utils.loadEnvFileIfExists)({ cwd: envRoot });
|
|
136
|
+
const { root: projectRoot, staging } = require_typegen.resolveServerConfig(envRoot);
|
|
137
|
+
const srcRoot = (0, node_path.join)(projectRoot, "src");
|
|
138
|
+
const knex = (0, _faasjs_core.useKnex)({ config: (0, _faasjs_node_utils.loadConfig)(srcRoot, (0, node_path.join)(srcRoot, "index.func.ts"), staging).plugins?.knex?.config });
|
|
139
|
+
await knex.mount();
|
|
140
|
+
const schema = new _faasjs_core.KnexSchema(knex);
|
|
141
|
+
try {
|
|
142
|
+
if (parsed.action === "make") console.log(await schema.migrateMake(parsed.name));
|
|
143
|
+
else await ActionHandlers[parsed.action](schema);
|
|
144
|
+
} finally {
|
|
145
|
+
await knex.quit();
|
|
146
|
+
}
|
|
147
|
+
return 0;
|
|
148
|
+
}
|
|
149
|
+
const main$3 = createMain(run$3);
|
|
150
|
+
|
|
151
|
+
//#endregion
|
|
152
|
+
//#region src/cli/lint.ts
|
|
153
|
+
const HelpText$2 = `Run formatter and lint checks with Oxc shared configs.
|
|
154
|
+
|
|
155
|
+
Usage:
|
|
156
|
+
faas lint [options]
|
|
157
|
+
|
|
158
|
+
Options:
|
|
159
|
+
--root <path> Project root path (default: process.cwd())
|
|
160
|
+
-h, --help Show help
|
|
161
|
+
-v, --version Show version
|
|
162
|
+
`;
|
|
163
|
+
function resolvePackageJsonPath(projectRoot, packageName) {
|
|
164
|
+
const requireFromProject = (0, node_module.createRequire)((0, node_path.resolve)(projectRoot, "package.json"));
|
|
165
|
+
let packageEntryPath = "";
|
|
166
|
+
try {
|
|
167
|
+
packageEntryPath = requireFromProject.resolve(packageName);
|
|
168
|
+
} catch {
|
|
169
|
+
throw Error(`[faas lint] Missing dependency: ${packageName}. Please install ${packageName} in your project.`);
|
|
170
|
+
}
|
|
171
|
+
let currentPath = (0, node_path.dirname)(packageEntryPath);
|
|
172
|
+
let packageJsonPath = "";
|
|
173
|
+
while (true) {
|
|
174
|
+
const candidate = (0, node_path.join)(currentPath, "package.json");
|
|
175
|
+
if ((0, node_fs.existsSync)(candidate)) {
|
|
176
|
+
packageJsonPath = candidate;
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
const parentPath = (0, node_path.dirname)(currentPath);
|
|
180
|
+
if (parentPath === currentPath) break;
|
|
181
|
+
currentPath = parentPath;
|
|
182
|
+
}
|
|
183
|
+
if (!packageJsonPath) throw Error(`[faas lint] Invalid dependency: Cannot find package.json for ${packageName}.`);
|
|
184
|
+
return packageJsonPath;
|
|
185
|
+
}
|
|
186
|
+
function resolveBinPath(projectRoot, packageName, binName) {
|
|
187
|
+
const packageJsonPath = resolvePackageJsonPath(projectRoot, packageName);
|
|
188
|
+
const packageJSON = JSON.parse((0, node_fs.readFileSync)(packageJsonPath, "utf8"));
|
|
189
|
+
const bin = typeof packageJSON.bin === "string" ? packageJSON.bin : packageJSON.bin?.[binName];
|
|
190
|
+
if (!bin) throw Error(`[faas lint] Invalid dependency: ${packageName} does not expose "${binName}" bin.`);
|
|
191
|
+
return (0, node_path.resolve)((0, node_path.dirname)(packageJsonPath), bin);
|
|
192
|
+
}
|
|
193
|
+
function resolveSharedConfigPath(projectRoot, configFileName) {
|
|
194
|
+
const configPath = (0, node_path.resolve)((0, node_path.dirname)(resolvePackageJsonPath(projectRoot, "@faasjs/dev")), "configs", configFileName);
|
|
195
|
+
if (!(0, node_fs.existsSync)(configPath)) throw Error(`[faas lint] Missing shared config: ${configPath}`);
|
|
196
|
+
return configPath;
|
|
197
|
+
}
|
|
198
|
+
function runNodeBin(projectRoot, command, binPath, args) {
|
|
199
|
+
try {
|
|
200
|
+
(0, node_child_process.execFileSync)(process.execPath, [binPath, ...args], {
|
|
201
|
+
cwd: projectRoot,
|
|
202
|
+
stdio: "inherit"
|
|
203
|
+
});
|
|
204
|
+
} catch {
|
|
205
|
+
throw Error(`[faas lint] ${command} failed`);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
async function run$2(args) {
|
|
209
|
+
const { mode, options, rest } = parseCommonCliArgs(args, "faas lint");
|
|
210
|
+
if (mode === "help") {
|
|
211
|
+
console.log(HelpText$2);
|
|
212
|
+
return 0;
|
|
213
|
+
}
|
|
214
|
+
if (mode === "version") return printVersion();
|
|
215
|
+
if (rest.length) throw Error(`[faas lint] Unexpected argument: ${rest[0]}`);
|
|
216
|
+
const projectRoot = options.root ?? process.cwd();
|
|
217
|
+
(0, _faasjs_node_utils.loadEnvFileIfExists)({ cwd: projectRoot });
|
|
218
|
+
runNodeBin(projectRoot, "oxlint", resolveBinPath(projectRoot, "oxlint", "oxlint"), [
|
|
219
|
+
"-c",
|
|
220
|
+
resolveSharedConfigPath(projectRoot, "oxlint.base.json"),
|
|
221
|
+
"--fix",
|
|
222
|
+
"."
|
|
223
|
+
]);
|
|
224
|
+
console.log("[faas lint] Done");
|
|
225
|
+
return 0;
|
|
226
|
+
}
|
|
227
|
+
const main$2 = createMain(run$2);
|
|
228
|
+
|
|
229
|
+
//#endregion
|
|
230
|
+
//#region src/cli/types.ts
|
|
231
|
+
const HelpText$1 = `Generate FaasJS API/event type declarations.
|
|
232
|
+
|
|
233
|
+
Usage:
|
|
234
|
+
faas types [options]
|
|
235
|
+
|
|
236
|
+
Options:
|
|
237
|
+
--root <path> Project root path (default: process.cwd())
|
|
238
|
+
-h, --help Show help
|
|
239
|
+
-v, --version Show version
|
|
240
|
+
`;
|
|
241
|
+
async function run$1(args) {
|
|
242
|
+
const { mode, options, rest } = parseCommonCliArgs(args, "faas types");
|
|
243
|
+
if (mode === "help") {
|
|
244
|
+
console.log(HelpText$1);
|
|
245
|
+
return 0;
|
|
246
|
+
}
|
|
247
|
+
if (mode === "version") return printVersion();
|
|
248
|
+
if (rest.length) throw Error(`[faas types] Unknown option: ${rest[0]}`);
|
|
249
|
+
(0, _faasjs_node_utils.loadEnvFileIfExists)({ cwd: options.root ?? process.cwd() });
|
|
250
|
+
const result = await require_typegen.generateFaasTypes(options);
|
|
251
|
+
console.log(`[faas types] ${result.changed ? "Generated" : "Up to date"} ${result.output} (${result.routeCount} routes from ${result.fileCount} files)`);
|
|
252
|
+
return 0;
|
|
253
|
+
}
|
|
254
|
+
const main$1 = createMain(run$1);
|
|
255
|
+
|
|
256
|
+
//#endregion
|
|
257
|
+
//#region src/cli/index.ts
|
|
258
|
+
const HelpText = `FaasJS CLI.
|
|
259
|
+
|
|
260
|
+
Usage:
|
|
261
|
+
faas <command> [...args]
|
|
262
|
+
|
|
263
|
+
Commands:
|
|
264
|
+
types [options] Generate FaasJS API/event type declarations
|
|
265
|
+
knex <action> [name] [options] Run FaasJS knex migrations
|
|
266
|
+
lint [options] Run formatter and lint with Oxc
|
|
267
|
+
|
|
268
|
+
Options:
|
|
269
|
+
-h, --help Show help
|
|
270
|
+
-v, --version Show version
|
|
271
|
+
`;
|
|
272
|
+
const Commands = {
|
|
273
|
+
types: run$1,
|
|
274
|
+
knex: run$3,
|
|
275
|
+
lint: run$2
|
|
276
|
+
};
|
|
277
|
+
async function run(args) {
|
|
278
|
+
const command = args[0];
|
|
279
|
+
if (!command || command === "-h" || command === "--help") {
|
|
280
|
+
console.log(HelpText);
|
|
281
|
+
return 0;
|
|
282
|
+
}
|
|
283
|
+
if (command === "-v" || command === "--version") return printVersion();
|
|
284
|
+
const handler = Commands[command];
|
|
285
|
+
if (!handler) throw Error(`[faas] Unknown command: ${command}`);
|
|
286
|
+
return await handler(args.slice(1));
|
|
287
|
+
}
|
|
288
|
+
const main = createMain(run);
|
|
289
|
+
|
|
290
|
+
//#endregion
|
|
291
|
+
exports.main = main;
|
|
292
|
+
exports.run = run;
|