nextlove 2.1.5 → 2.1.6

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/bin.js ADDED
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env node
2
+
3
+ const argv = require("minimist")(process.argv.slice(2))
4
+ const { register } = require("esbuild-register/dist/node")
5
+
6
+ const { unregister } = register({
7
+ target: `node${process.version.slice(1)}`,
8
+ })
9
+
10
+ if (argv.help || argv.h) {
11
+ console.log(
12
+ `
13
+ nextlove (generate-openapi | generate-route-types) [options]
14
+
15
+ --packageDir <path> Path to the package directory containing the Next.js app
16
+ --outputFile <path> Path to the output file
17
+ --pathGlob <glob> Glob pattern to find API route files
18
+ --apiPrefix <path> Prefix for API routes, default: "/api"
19
+
20
+ `.trim()
21
+ )
22
+ process.exit(0)
23
+ }
24
+
25
+ if (argv._[0] === "generate-openapi") {
26
+ if (argv._.length === 2) {
27
+ argv.packageDir = argv._[1]
28
+ }
29
+ if (argv["package-dir"]) {
30
+ argv.packageDir = argv["package-dir"]
31
+ }
32
+ if (!argv["packageDir"]) throw new Error("Missing --packageDir")
33
+
34
+ require("./dist/generators")
35
+ .generateOpenAPI(argv)
36
+ .then((result) => {
37
+ if (!argv.outputFile) {
38
+ console.log(result)
39
+ }
40
+ })
41
+ } else if (argv._[0] === "generate-route-types") {
42
+ if (argv._.length === 2) {
43
+ argv.packageDir = argv._[1]
44
+ }
45
+ if (argv["package-dir"]) {
46
+ argv.packageDir = argv["package-dir"]
47
+ }
48
+ if (!argv["packageDir"]) throw new Error("Missing --packageDir")
49
+
50
+ require("./dist/generators")
51
+ .generateRouteTypes(argv)
52
+ .then((result) => {
53
+ if (!argv.outputFile) {
54
+ console.log(result)
55
+ }
56
+ })
57
+ }
@@ -0,0 +1,45 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
8
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
9
+ }) : x)(function(x) {
10
+ if (typeof require !== "undefined")
11
+ return require.apply(this, arguments);
12
+ throw new Error('Dynamic require of "' + x + '" is not supported');
13
+ });
14
+ var __esm = (fn, res) => function __init() {
15
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
16
+ };
17
+ var __commonJS = (cb, mod) => function __require2() {
18
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
19
+ };
20
+ var __copyProps = (to, from, except, desc) => {
21
+ if (from && typeof from === "object" || typeof from === "function") {
22
+ for (let key of __getOwnPropNames(from))
23
+ if (!__hasOwnProp.call(to, key) && key !== except)
24
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
25
+ }
26
+ return to;
27
+ };
28
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
29
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
30
+ mod
31
+ ));
32
+
33
+ // ../../node_modules/tsup/assets/esm_shims.js
34
+ var init_esm_shims = __esm({
35
+ "../../node_modules/tsup/assets/esm_shims.js"() {
36
+ }
37
+ });
38
+
39
+ export {
40
+ __require,
41
+ __commonJS,
42
+ __toESM,
43
+ init_esm_shims
44
+ };
45
+ //# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vLi4vLi4vbm9kZV9tb2R1bGVzL3RzdXAvYXNzZXRzL2VzbV9zaGltcy5qcyJdLAogICJzb3VyY2VzQ29udGVudCI6IFsiLy8gU2hpbSBnbG9iYWxzIGluIGVzbSBidW5kbGVcbmltcG9ydCB7IGZpbGVVUkxUb1BhdGggfSBmcm9tICd1cmwnXG5pbXBvcnQgcGF0aCBmcm9tICdwYXRoJ1xuXG5jb25zdCBnZXRGaWxlbmFtZSA9ICgpID0+IGZpbGVVUkxUb1BhdGgoaW1wb3J0Lm1ldGEudXJsKVxuY29uc3QgZ2V0RGlybmFtZSA9ICgpID0+IHBhdGguZGlybmFtZShnZXRGaWxlbmFtZSgpKVxuXG5leHBvcnQgY29uc3QgX19kaXJuYW1lID0gLyogQF9fUFVSRV9fICovIGdldERpcm5hbWUoKVxuZXhwb3J0IGNvbnN0IF9fZmlsZW5hbWUgPSAvKiBAX19QVVJFX18gKi8gZ2V0RmlsZW5hbWUoKVxuIl0sCiAgIm1hcHBpbmdzIjogIjs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O0FBQUE7QUFBQTtBQUFBO0FBQUE7IiwKICAibmFtZXMiOiBbXQp9Cg==
@@ -0,0 +1,35 @@
1
+ interface TagOption {
2
+ name: string;
3
+ description: string;
4
+ doesRouteHaveTag?: (route: string) => boolean;
5
+ }
6
+ interface GenerateOpenAPIOpts {
7
+ packageDir: string;
8
+ outputFile?: string;
9
+ pathGlob?: string;
10
+ tags?: Array<TagOption>;
11
+ apiPrefix?: string;
12
+ mapFilePathToHTTPRoute?: (file_path: string) => string;
13
+ }
14
+ /**
15
+ * This function generates an OpenAPI spec from the Next.js API routes.
16
+ *
17
+ * You normally invoke this with `nextapi generate-openapi` in a
18
+ * "build:openapi" package.json script.
19
+ */
20
+ declare function generateOpenAPI(opts: GenerateOpenAPIOpts): Promise<string>;
21
+
22
+ interface GenerateRouteTypesOpts {
23
+ packageDir: string;
24
+ outputFile?: string;
25
+ pathGlob?: string;
26
+ apiPrefix?: string;
27
+ mapFilePathToHTTPRoute?: (file_path: string) => string;
28
+ /**
29
+ * If provided, only routes that return true will be included in the generated types.
30
+ */
31
+ filterRoutes?: (route: string) => boolean;
32
+ }
33
+ declare const generateRouteTypes: (opts: GenerateRouteTypesOpts) => Promise<string>;
34
+
35
+ export { generateOpenAPI, generateRouteTypes };