@zuplo/cli 2.1.0 → 2.2.0
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/.tool-versions +1 -0
- package/dist/cli.js +8 -2
- package/dist/cmds/project/import-openapi.js +2 -7
- package/dist/common/args.js +5 -0
- package/dist/common/outdated.test.js +66 -0
- package/dist/common/upgraders/package-json-upgrader.js +7 -6
- package/dist/common/upgraders/tsconfig-upgrader.js +107 -0
- package/dist/common/upgraders/tsconfig-upgrader.test.js +30 -0
- package/dist/convert/engine.test.js +302 -0
- package/dist/project/import-openapi/handler.js +2 -2
- package/dist/project/update/handler.js +13 -8
- package/package.json +4 -2
package/.tool-versions
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
nodejs 18.20.4
|
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="56d3c48c-3960-5c1d-adbd-d0a76d0ac940")}catch(e){}}();
|
|
3
3
|
import * as dotenv from "dotenv";
|
|
4
4
|
dotenv.config();
|
|
5
5
|
import * as Sentry from "@sentry/node";
|
|
@@ -42,6 +42,12 @@ if (gte(process.versions.node, MIN_NODE_VERSION)) {
|
|
|
42
42
|
});
|
|
43
43
|
const cli = yargs(hideBin(process.argv))
|
|
44
44
|
.env("ZUPLO")
|
|
45
|
+
.option("prompt", {
|
|
46
|
+
type: "boolean",
|
|
47
|
+
describe: "Bypass confirmation prompts",
|
|
48
|
+
default: true,
|
|
49
|
+
hidden: true,
|
|
50
|
+
})
|
|
45
51
|
.command(compile)
|
|
46
52
|
.command(convert)
|
|
47
53
|
.command(deleteZup)
|
|
@@ -84,4 +90,4 @@ else {
|
|
|
84
90
|
Consider using a Node.js version manager such as https://github.com/nvm-sh/nvm.`);
|
|
85
91
|
}
|
|
86
92
|
//# sourceMappingURL=cli.js.map
|
|
87
|
-
//# debugId=
|
|
93
|
+
//# debugId=56d3c48c-3960-5c1d-adbd-d0a76d0ac940
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="d280723f-9208-5c26-a757-080dd9217482")}catch(e){}}();
|
|
3
3
|
import { captureEvent } from "../../common/analytics/lib.js";
|
|
4
4
|
import setBlocking from "../../common/output.js";
|
|
5
5
|
import { ZuploProjectValidator } from "../../common/validators/file-system-validator.js";
|
|
@@ -16,11 +16,6 @@ export default {
|
|
|
16
16
|
default: ".",
|
|
17
17
|
normalize: true,
|
|
18
18
|
hidden: true,
|
|
19
|
-
})
|
|
20
|
-
.option("prompt", {
|
|
21
|
-
type: "boolean",
|
|
22
|
-
describe: "Prompt for confirmation before importing",
|
|
23
|
-
default: true,
|
|
24
19
|
})
|
|
25
20
|
.option("source", {
|
|
26
21
|
type: "string",
|
|
@@ -43,4 +38,4 @@ export default {
|
|
|
43
38
|
},
|
|
44
39
|
};
|
|
45
40
|
//# sourceMappingURL=import-openapi.js.map
|
|
46
|
-
//# debugId=
|
|
41
|
+
//# debugId=d280723f-9208-5c26-a757-080dd9217482
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="3d67c996-402a-5927-8ae6-1fb20dee5751")}catch(e){}}();
|
|
3
|
+
export {};
|
|
4
|
+
//# sourceMappingURL=args.js.map
|
|
5
|
+
//# debugId=3d67c996-402a-5927-8ae6-1fb20dee5751
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="f4a9a7b0-4a16-5eb9-b752-e61ee1acb33e")}catch(e){}}();
|
|
3
|
+
import { assert } from "chai";
|
|
4
|
+
import { rm, writeFile } from "node:fs/promises";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { beforeEach, describe, it } from "node:test";
|
|
7
|
+
import { MockAgent, setGlobalDispatcher } from "undici";
|
|
8
|
+
import { ZUPLO_VERSION_CHECK_FILE } from "./constants.js";
|
|
9
|
+
import { warnIfOutdatedVersion } from "./outdated.js";
|
|
10
|
+
import { ZUPLO_XDG_STATE_HOME } from "./xdg/lib.js";
|
|
11
|
+
const versionCheckPath = join(ZUPLO_XDG_STATE_HOME, ZUPLO_VERSION_CHECK_FILE);
|
|
12
|
+
process.env.ZUPLO_OVERRIDE_CI_TO_TEST = "true";
|
|
13
|
+
describe("Outdated CLI check", function () {
|
|
14
|
+
let mockAgent;
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
mockAgent = new MockAgent();
|
|
17
|
+
mockAgent.disableNetConnect();
|
|
18
|
+
mockAgent
|
|
19
|
+
.get("https://raw.githubusercontent.com")
|
|
20
|
+
.intercept({
|
|
21
|
+
path: "/zuplo/zuplo/main/packages/zuplo/package.json",
|
|
22
|
+
method: "GET",
|
|
23
|
+
})
|
|
24
|
+
.reply(200, {
|
|
25
|
+
name: "zuplo",
|
|
26
|
+
dependencies: {
|
|
27
|
+
"@zuplo/cli": "1.109.0",
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
setGlobalDispatcher(mockAgent);
|
|
31
|
+
});
|
|
32
|
+
it("should warn on outdated version", async function () {
|
|
33
|
+
await rm(versionCheckPath, { recursive: true, force: true });
|
|
34
|
+
const result = await warnIfOutdatedVersion("1.0.0");
|
|
35
|
+
assert.isTrue(result);
|
|
36
|
+
assert.equal(mockAgent.pendingInterceptors.length, 0);
|
|
37
|
+
});
|
|
38
|
+
it("should not warn if current version", async function () {
|
|
39
|
+
const result = await warnIfOutdatedVersion("1.109.0");
|
|
40
|
+
assert.isFalse(result);
|
|
41
|
+
});
|
|
42
|
+
it("should not warn if still has cached result", async function () {
|
|
43
|
+
const state = { lastCheck: Date.now() - 1000, latestVersion: "1.108.0" };
|
|
44
|
+
await writeFile(versionCheckPath, JSON.stringify(state), "utf-8");
|
|
45
|
+
const result = await warnIfOutdatedVersion("1.108.0");
|
|
46
|
+
assert.isFalse(result);
|
|
47
|
+
});
|
|
48
|
+
it("should warn when time expired on outdated version", async function () {
|
|
49
|
+
const state = {
|
|
50
|
+
lastCheck: Date.now() - 1000 * 60 * 60 * 24 - 100,
|
|
51
|
+
latestVersion: "1.0.0",
|
|
52
|
+
};
|
|
53
|
+
await writeFile(versionCheckPath, JSON.stringify(state), "utf-8");
|
|
54
|
+
const result = await warnIfOutdatedVersion("1.0.0");
|
|
55
|
+
assert.isTrue(result);
|
|
56
|
+
assert.equal(mockAgent.pendingInterceptors.length, 0);
|
|
57
|
+
});
|
|
58
|
+
it("should handle invalid state", async function () {
|
|
59
|
+
await writeFile(versionCheckPath, "hello", "utf-8");
|
|
60
|
+
const result = await warnIfOutdatedVersion("0.0.1");
|
|
61
|
+
assert.isTrue(result);
|
|
62
|
+
assert.equal(mockAgent.pendingInterceptors.length, 0);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
//# sourceMappingURL=outdated.test.js.map
|
|
66
|
+
//# debugId=f4a9a7b0-4a16-5eb9-b752-e61ee1acb33e
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="7f37d2ec-c9c4-5c18-a196-361f8f5e4924")}catch(e){}}();
|
|
3
3
|
import { readFile, writeFile } from "node:fs/promises";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import prettier from "prettier";
|
|
@@ -30,10 +30,11 @@ export class PackageJsonUpgrader extends StandardUpgrader {
|
|
|
30
30
|
(packageJson.scripts.build === "zup build" ||
|
|
31
31
|
packageJson.scripts.build === "zuplo build"))
|
|
32
32
|
delete packageJson.scripts.build;
|
|
33
|
-
if (packageJson.scripts.test &&
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
if (packageJson.scripts.test && packageJson.scripts.test === "zuplo test") {
|
|
34
|
+
packageJson.scripts.test = "zup test";
|
|
35
|
+
}
|
|
36
|
+
else if (!packageJson.scripts.test) {
|
|
37
|
+
packageJson.scripts.test = "zup test";
|
|
37
38
|
}
|
|
38
39
|
if (packageJson.scripts.postinstall &&
|
|
39
40
|
packageJson.scripts.postinstall === "husky install") {
|
|
@@ -64,4 +65,4 @@ export class PackageJsonUpgrader extends StandardUpgrader {
|
|
|
64
65
|
}
|
|
65
66
|
}
|
|
66
67
|
//# sourceMappingURL=package-json-upgrader.js.map
|
|
67
|
-
//# debugId=
|
|
68
|
+
//# debugId=7f37d2ec-c9c4-5c18-a196-361f8f5e4924
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="1bf2cbbf-1e6f-586b-86a8-5ce98e9e2358")}catch(e){}}();
|
|
3
|
+
import { parse } from "jsonc-parser";
|
|
4
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import prettier from "prettier";
|
|
7
|
+
import ts, { ModuleKind, ModuleResolutionKind, ScriptTarget, } from "typescript";
|
|
8
|
+
import { StandardUpgrader } from "./lib.js";
|
|
9
|
+
export class FailedToParseTSConfigJson extends Error {
|
|
10
|
+
constructor() {
|
|
11
|
+
super("Invalid tsconfig.json: Failed to parse the tsconfig.json file.");
|
|
12
|
+
Object.setPrototypeOf(this, FailedToParseTSConfigJson.prototype);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export class InvalidTSConfigJson extends Error {
|
|
16
|
+
constructor(message) {
|
|
17
|
+
super(message);
|
|
18
|
+
Object.setPrototypeOf(this, InvalidTSConfigJson.prototype);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export class TSConfigUpgrader extends StandardUpgrader {
|
|
22
|
+
async isApplicable() {
|
|
23
|
+
return { ok: true };
|
|
24
|
+
}
|
|
25
|
+
async needsUpgrade() {
|
|
26
|
+
try {
|
|
27
|
+
const tsFilePath = join(this.normalizedDir, "tsconfig.json");
|
|
28
|
+
const tsConfigRaw = await readFile(tsFilePath, "utf-8");
|
|
29
|
+
const tsConfigJson = parse(tsConfigRaw);
|
|
30
|
+
if (!(tsConfigJson &&
|
|
31
|
+
typeof tsConfigJson === "object" &&
|
|
32
|
+
"compilerOptions" in tsConfigJson)) {
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
const { options, errors } = ts.convertCompilerOptionsFromJson(tsConfigJson.compilerOptions, this.normalizedDir);
|
|
36
|
+
const libValue = ["ESNext", "WebWorker", "Webworker.Iterable"];
|
|
37
|
+
const includesAllLibs = (userLibs) => {
|
|
38
|
+
const a = libValue.map((item) => item.toLowerCase());
|
|
39
|
+
const b = userLibs.map((item) => item.toLowerCase());
|
|
40
|
+
return a.every((item) => b.includes(item));
|
|
41
|
+
};
|
|
42
|
+
return (errors.length > 0 ||
|
|
43
|
+
options.module !== ModuleKind.ESNext ||
|
|
44
|
+
options.target !== ScriptTarget.ES2022 ||
|
|
45
|
+
options.moduleResolution !== ModuleResolutionKind.Bundler ||
|
|
46
|
+
!options.lib ||
|
|
47
|
+
options.baseUrl !== undefined ||
|
|
48
|
+
!includesAllLibs(tsConfigJson.compilerOptions.lib ?? []));
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async upgrade() {
|
|
55
|
+
if (!(await this.needsUpgrade())) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const tsFilePath = join(this.normalizedDir, "tsconfig.json");
|
|
59
|
+
const tsConfig = {
|
|
60
|
+
include: ["modules/**/*", ".zuplo/**/*", "tests/**/*"],
|
|
61
|
+
exclude: ["./node_modules", "./dist"],
|
|
62
|
+
compilerOptions: {
|
|
63
|
+
module: "ESNext",
|
|
64
|
+
target: "ES2022",
|
|
65
|
+
moduleResolution: "Bundler",
|
|
66
|
+
lib: ["ESNext", "WebWorker", "Webworker.Iterable"],
|
|
67
|
+
preserveConstEnums: true,
|
|
68
|
+
useUnknownInCatchVariables: false,
|
|
69
|
+
forceConsistentCasingInFileNames: true,
|
|
70
|
+
importHelpers: true,
|
|
71
|
+
removeComments: true,
|
|
72
|
+
esModuleInterop: true,
|
|
73
|
+
strictNullChecks: true,
|
|
74
|
+
noEmit: true,
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
const formatted = await prettier.format(JSON.stringify(tsConfig), {
|
|
78
|
+
parser: "json",
|
|
79
|
+
});
|
|
80
|
+
await writeFile(tsFilePath, formatted);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
export const getZuploTsConfigTemplate = () => ({
|
|
84
|
+
include: ["modules/**/*", ".zuplo/**/*", "tests/**/*"],
|
|
85
|
+
exclude: ["./node_modules", "./dist"],
|
|
86
|
+
compilerOptions: {
|
|
87
|
+
baseUrl: ".",
|
|
88
|
+
module: ModuleKind.ESNext,
|
|
89
|
+
target: ScriptTarget.ESNext,
|
|
90
|
+
moduleResolution: ModuleResolutionKind.Bundler,
|
|
91
|
+
lib: ["ESNext", "WebWorker", "Webworker.Iterable"],
|
|
92
|
+
preserveConstEnums: true,
|
|
93
|
+
useUnknownInCatchVariables: false,
|
|
94
|
+
forceConsistentCasingInFileNames: true,
|
|
95
|
+
importHelpers: true,
|
|
96
|
+
removeComments: true,
|
|
97
|
+
esModuleInterop: true,
|
|
98
|
+
strictNullChecks: true,
|
|
99
|
+
experimentalDecorators: true,
|
|
100
|
+
noEmit: true,
|
|
101
|
+
paths: {
|
|
102
|
+
"@app/*": [".zuplo/*"],
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
//# sourceMappingURL=tsconfig-upgrader.js.map
|
|
107
|
+
//# debugId=1bf2cbbf-1e6f-586b-86a8-5ce98e9e2358
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="6067ec2f-ba9e-552d-86dc-efe5ac6410f1")}catch(e){}}();
|
|
3
|
+
import assert from "node:assert";
|
|
4
|
+
import { describe, test } from "node:test";
|
|
5
|
+
import { TSConfigUpgrader } from "./tsconfig-upgrader.js";
|
|
6
|
+
process.env.ZUPLO_OVERRIDE_CI_TO_TEST = "true";
|
|
7
|
+
describe("TSConfigUpgrader checks", async function () {
|
|
8
|
+
test("Should not run for a valid tsconfig.json", async function () {
|
|
9
|
+
const upgrader = new TSConfigUpgrader(new URL("../../../test-fixtures/tsconfig/valid", import.meta.url).pathname);
|
|
10
|
+
const needsUpgrade = await upgrader.needsUpgrade();
|
|
11
|
+
assert.equal(needsUpgrade, false);
|
|
12
|
+
});
|
|
13
|
+
test("Should run for a legacy tsconfig.json", async function () {
|
|
14
|
+
const upgrader = new TSConfigUpgrader(new URL("../../../test-fixtures/tsconfig/legacy", import.meta.url).pathname);
|
|
15
|
+
const needsUpgrade = await upgrader.needsUpgrade();
|
|
16
|
+
assert.equal(needsUpgrade, true);
|
|
17
|
+
});
|
|
18
|
+
test("Should run for a missing prop tsconfig.json", async function () {
|
|
19
|
+
const upgrader = new TSConfigUpgrader(new URL("../../../test-fixtures/tsconfig/missing-prop", import.meta.url).pathname);
|
|
20
|
+
const needsUpgrade = await upgrader.needsUpgrade();
|
|
21
|
+
assert.equal(needsUpgrade, true);
|
|
22
|
+
});
|
|
23
|
+
test("Should run when baseUrl set in tsconfig.json", async function () {
|
|
24
|
+
const upgrader = new TSConfigUpgrader(new URL("../../../test-fixtures/tsconfig/missing-prop", import.meta.url).pathname);
|
|
25
|
+
const needsUpgrade = await upgrader.needsUpgrade();
|
|
26
|
+
assert.equal(needsUpgrade, true);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
//# sourceMappingURL=tsconfig-upgrader.test.js.map
|
|
30
|
+
//# debugId=6067ec2f-ba9e-552d-86dc-efe5ac6410f1
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="ef0b2816-b9e6-501e-8d11-6961d4a8afa1")}catch(e){}}();
|
|
3
|
+
import { expect } from "chai";
|
|
4
|
+
import { describe, it } from "node:test";
|
|
5
|
+
import { convertRoutes } from "./engine.js";
|
|
6
|
+
describe("Routes.json Conversion Engine", () => {
|
|
7
|
+
it("should handle simple route conversion (no version)", () => {
|
|
8
|
+
const routesConfig = {
|
|
9
|
+
versions: [
|
|
10
|
+
{
|
|
11
|
+
name: "v1",
|
|
12
|
+
pathPrefix: "/v1",
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
name: "none",
|
|
16
|
+
pathPrefix: "",
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
routes: [
|
|
20
|
+
{
|
|
21
|
+
methods: ["GET"],
|
|
22
|
+
path: "/test",
|
|
23
|
+
summary: "Test route",
|
|
24
|
+
version: "none",
|
|
25
|
+
corsPolicy: "anything-goes",
|
|
26
|
+
description: "This is a test route",
|
|
27
|
+
operationId: "random",
|
|
28
|
+
handler: {
|
|
29
|
+
export: "urlRewriteHandler",
|
|
30
|
+
module: "$import(@zuplo/runtime)",
|
|
31
|
+
options: {
|
|
32
|
+
rewritePattern: "https://jsonplaceholder.typicode.com/todos",
|
|
33
|
+
forwardSearch: true,
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
};
|
|
39
|
+
const expected = {
|
|
40
|
+
openapi: "3.1.0",
|
|
41
|
+
info: {
|
|
42
|
+
title: "Converted from config/routes.json",
|
|
43
|
+
version: "1.0.0",
|
|
44
|
+
},
|
|
45
|
+
paths: {
|
|
46
|
+
"/test": {
|
|
47
|
+
get: {
|
|
48
|
+
summary: "Test route",
|
|
49
|
+
description: "This is a test route",
|
|
50
|
+
operationId: "random",
|
|
51
|
+
"x-zuplo-route": {
|
|
52
|
+
corsPolicy: "anything-goes",
|
|
53
|
+
handler: {
|
|
54
|
+
export: "urlRewriteHandler",
|
|
55
|
+
module: "$import(@zuplo/runtime)",
|
|
56
|
+
options: {
|
|
57
|
+
rewritePattern: "https://jsonplaceholder.typicode.com/todos",
|
|
58
|
+
forwardSearch: true,
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
"x-zuplo-path": {
|
|
64
|
+
pathMode: "url-pattern",
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
const actual = convertRoutes(routesConfig);
|
|
70
|
+
expect(actual).to.deep.equal(expected);
|
|
71
|
+
});
|
|
72
|
+
it("should handle simple route conversion (with version)", () => {
|
|
73
|
+
const routesConfig = {
|
|
74
|
+
versions: [
|
|
75
|
+
{
|
|
76
|
+
name: "v1",
|
|
77
|
+
pathPrefix: "/v1",
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
name: "none",
|
|
81
|
+
pathPrefix: "",
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
routes: [
|
|
85
|
+
{
|
|
86
|
+
methods: ["GET"],
|
|
87
|
+
path: "/test",
|
|
88
|
+
summary: "Test route",
|
|
89
|
+
version: "v1",
|
|
90
|
+
corsPolicy: "anything-goes",
|
|
91
|
+
description: "This is a test route",
|
|
92
|
+
operationId: "random",
|
|
93
|
+
handler: {
|
|
94
|
+
export: "urlRewriteHandler",
|
|
95
|
+
module: "$import(@zuplo/runtime)",
|
|
96
|
+
options: {
|
|
97
|
+
rewritePattern: "https://jsonplaceholder.typicode.com/todos",
|
|
98
|
+
forwardSearch: true,
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
],
|
|
103
|
+
};
|
|
104
|
+
const expected = {
|
|
105
|
+
openapi: "3.1.0",
|
|
106
|
+
info: {
|
|
107
|
+
title: "Converted from config/routes.json",
|
|
108
|
+
version: "1.0.0",
|
|
109
|
+
},
|
|
110
|
+
paths: {
|
|
111
|
+
"/v1/test": {
|
|
112
|
+
get: {
|
|
113
|
+
summary: "Test route",
|
|
114
|
+
description: "This is a test route",
|
|
115
|
+
operationId: "random",
|
|
116
|
+
"x-zuplo-route": {
|
|
117
|
+
corsPolicy: "anything-goes",
|
|
118
|
+
handler: {
|
|
119
|
+
export: "urlRewriteHandler",
|
|
120
|
+
module: "$import(@zuplo/runtime)",
|
|
121
|
+
options: {
|
|
122
|
+
rewritePattern: "https://jsonplaceholder.typicode.com/todos",
|
|
123
|
+
forwardSearch: true,
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
"x-zuplo-path": {
|
|
129
|
+
pathMode: "url-pattern",
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
const actual = convertRoutes(routesConfig);
|
|
135
|
+
expect(actual).to.deep.equal(expected);
|
|
136
|
+
});
|
|
137
|
+
it("should handle single route with multiple methods", () => {
|
|
138
|
+
const routesConfig = {
|
|
139
|
+
versions: [
|
|
140
|
+
{
|
|
141
|
+
name: "v1",
|
|
142
|
+
pathPrefix: "/v1",
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
name: "none",
|
|
146
|
+
pathPrefix: "",
|
|
147
|
+
},
|
|
148
|
+
],
|
|
149
|
+
routes: [
|
|
150
|
+
{
|
|
151
|
+
methods: ["GET", "POST", "HEAD"],
|
|
152
|
+
path: "/test",
|
|
153
|
+
summary: "Test route",
|
|
154
|
+
version: "v1",
|
|
155
|
+
corsPolicy: "anything-goes",
|
|
156
|
+
description: "This is a test route",
|
|
157
|
+
operationId: "random",
|
|
158
|
+
handler: {
|
|
159
|
+
export: "urlRewriteHandler",
|
|
160
|
+
module: "$import(@zuplo/runtime)",
|
|
161
|
+
options: {
|
|
162
|
+
rewritePattern: "https://jsonplaceholder.typicode.com/todos",
|
|
163
|
+
forwardSearch: true,
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
],
|
|
168
|
+
};
|
|
169
|
+
const expected = {
|
|
170
|
+
openapi: "3.1.0",
|
|
171
|
+
info: {
|
|
172
|
+
title: "Converted from config/routes.json",
|
|
173
|
+
version: "1.0.0",
|
|
174
|
+
},
|
|
175
|
+
paths: {
|
|
176
|
+
"/v1/test": {
|
|
177
|
+
"get,post,head": {
|
|
178
|
+
summary: "Test route",
|
|
179
|
+
description: "This is a test route",
|
|
180
|
+
operationId: "random",
|
|
181
|
+
"x-zuplo-route": {
|
|
182
|
+
corsPolicy: "anything-goes",
|
|
183
|
+
handler: {
|
|
184
|
+
export: "urlRewriteHandler",
|
|
185
|
+
module: "$import(@zuplo/runtime)",
|
|
186
|
+
options: {
|
|
187
|
+
rewritePattern: "https://jsonplaceholder.typicode.com/todos",
|
|
188
|
+
forwardSearch: true,
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
"x-zuplo-path": {
|
|
194
|
+
pathMode: "url-pattern",
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
},
|
|
198
|
+
};
|
|
199
|
+
const actual = convertRoutes(routesConfig);
|
|
200
|
+
expect(actual).to.deep.equal(expected);
|
|
201
|
+
});
|
|
202
|
+
it("should handle single route with different methods", () => {
|
|
203
|
+
const routesConfig = {
|
|
204
|
+
versions: [
|
|
205
|
+
{
|
|
206
|
+
name: "v1",
|
|
207
|
+
pathPrefix: "/v1",
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
name: "none",
|
|
211
|
+
pathPrefix: "",
|
|
212
|
+
},
|
|
213
|
+
],
|
|
214
|
+
routes: [
|
|
215
|
+
{
|
|
216
|
+
methods: ["GET"],
|
|
217
|
+
path: "/test",
|
|
218
|
+
summary: "Test route",
|
|
219
|
+
description: "This is a test route",
|
|
220
|
+
version: "v1",
|
|
221
|
+
corsPolicy: "anything-goes",
|
|
222
|
+
handler: {
|
|
223
|
+
export: "urlRewriteHandler",
|
|
224
|
+
module: "$import(@zuplo/runtime)",
|
|
225
|
+
options: {
|
|
226
|
+
rewritePattern: "https://welcome.zuplo.io/",
|
|
227
|
+
forwardSearch: true,
|
|
228
|
+
},
|
|
229
|
+
},
|
|
230
|
+
operationId: "random1",
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
methods: ["POST"],
|
|
234
|
+
path: "/test",
|
|
235
|
+
summary: "Test route",
|
|
236
|
+
description: "This is a test route",
|
|
237
|
+
version: "v1",
|
|
238
|
+
corsPolicy: "anything-goes",
|
|
239
|
+
handler: {
|
|
240
|
+
export: "urlRewriteHandler",
|
|
241
|
+
module: "$import(@zuplo/runtime)",
|
|
242
|
+
options: {
|
|
243
|
+
rewritePattern: "https://welcome.zuplo.io/",
|
|
244
|
+
forwardSearch: true,
|
|
245
|
+
},
|
|
246
|
+
},
|
|
247
|
+
operationId: "random2",
|
|
248
|
+
},
|
|
249
|
+
],
|
|
250
|
+
};
|
|
251
|
+
const expected = {
|
|
252
|
+
openapi: "3.1.0",
|
|
253
|
+
info: {
|
|
254
|
+
title: "Converted from config/routes.json",
|
|
255
|
+
version: "1.0.0",
|
|
256
|
+
},
|
|
257
|
+
paths: {
|
|
258
|
+
"/v1/test": {
|
|
259
|
+
get: {
|
|
260
|
+
summary: "Test route",
|
|
261
|
+
description: "This is a test route",
|
|
262
|
+
operationId: "random1",
|
|
263
|
+
"x-zuplo-route": {
|
|
264
|
+
corsPolicy: "anything-goes",
|
|
265
|
+
handler: {
|
|
266
|
+
export: "urlRewriteHandler",
|
|
267
|
+
module: "$import(@zuplo/runtime)",
|
|
268
|
+
options: {
|
|
269
|
+
rewritePattern: "https://welcome.zuplo.io/",
|
|
270
|
+
forwardSearch: true,
|
|
271
|
+
},
|
|
272
|
+
},
|
|
273
|
+
},
|
|
274
|
+
},
|
|
275
|
+
post: {
|
|
276
|
+
summary: "Test route",
|
|
277
|
+
description: "This is a test route",
|
|
278
|
+
operationId: "random2",
|
|
279
|
+
"x-zuplo-route": {
|
|
280
|
+
corsPolicy: "anything-goes",
|
|
281
|
+
handler: {
|
|
282
|
+
export: "urlRewriteHandler",
|
|
283
|
+
module: "$import(@zuplo/runtime)",
|
|
284
|
+
options: {
|
|
285
|
+
rewritePattern: "https://welcome.zuplo.io/",
|
|
286
|
+
forwardSearch: true,
|
|
287
|
+
},
|
|
288
|
+
},
|
|
289
|
+
},
|
|
290
|
+
},
|
|
291
|
+
"x-zuplo-path": {
|
|
292
|
+
pathMode: "url-pattern",
|
|
293
|
+
},
|
|
294
|
+
},
|
|
295
|
+
},
|
|
296
|
+
};
|
|
297
|
+
const actual = convertRoutes(routesConfig);
|
|
298
|
+
expect(actual).to.deep.equal(expected);
|
|
299
|
+
});
|
|
300
|
+
});
|
|
301
|
+
//# sourceMappingURL=engine.test.js.map
|
|
302
|
+
//# debugId=ef0b2816-b9e6-501e-8d11-6961d4a8afa1
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="a4e07444-c9b0-5d72-9ff0-ddd4f42e802b")}catch(e){}}();
|
|
3
3
|
import { confirm } from "@inquirer/prompts";
|
|
4
4
|
import jsYaml from "js-yaml";
|
|
5
5
|
import { existsSync, writeFileSync } from "node:fs";
|
|
@@ -142,4 +142,4 @@ export async function importOpenApi(argv) {
|
|
|
142
142
|
await printResultToConsoleAndExitGracefully(`Import successful. File written to ${destinationFilePath}`);
|
|
143
143
|
}
|
|
144
144
|
//# sourceMappingURL=handler.js.map
|
|
145
|
-
//# debugId=
|
|
145
|
+
//# debugId=a4e07444-c9b0-5d72-9ff0-ddd4f42e802b
|
|
@@ -1,29 +1,34 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="b240c7b1-8f8c-54c7-b381-3ec9bae18cd4")}catch(e){}}();
|
|
3
3
|
import { confirm } from "@inquirer/prompts";
|
|
4
4
|
import { printDiagnosticsToConsole, printResultToConsoleAndExitGracefully, } from "../../common/output.js";
|
|
5
5
|
import { PackageJsonUpgrader } from "../../common/upgraders/package-json-upgrader.js";
|
|
6
|
+
import { TSConfigUpgrader } from "../../common/upgraders/tsconfig-upgrader.js";
|
|
6
7
|
import { VsCodeSettingsJsonUpgrader } from "../../common/upgraders/vscode-settings-json-upgrader.js";
|
|
7
8
|
export async function update(argv) {
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
let answer = !!argv.prompt;
|
|
10
|
+
if (answer) {
|
|
11
|
+
printDiagnosticsToConsole("This command will make changes to your source code. Please commit your changes to version control before continuing.");
|
|
12
|
+
answer = await confirm({ message: "Continue?", default: true });
|
|
13
|
+
}
|
|
10
14
|
if (answer) {
|
|
11
15
|
const u = new PackageJsonUpgrader(argv.dir);
|
|
12
16
|
if ((await u.isApplicable()).ok) {
|
|
13
17
|
printDiagnosticsToConsole("Updating your package.json...");
|
|
14
18
|
await u.upgrade();
|
|
15
19
|
}
|
|
16
|
-
else {
|
|
17
|
-
}
|
|
18
20
|
const v = new VsCodeSettingsJsonUpgrader(argv.dir);
|
|
19
21
|
if ((await v.isApplicable()).ok) {
|
|
20
|
-
printDiagnosticsToConsole("Updating your .
|
|
22
|
+
printDiagnosticsToConsole("Updating your .vscode settings...");
|
|
21
23
|
await v.upgrade();
|
|
22
24
|
}
|
|
23
|
-
|
|
25
|
+
const t = new TSConfigUpgrader(argv.dir);
|
|
26
|
+
if ((await t.isApplicable()).ok) {
|
|
27
|
+
printDiagnosticsToConsole("Rewriting your tsconfig.json...");
|
|
28
|
+
await t.upgrade();
|
|
24
29
|
}
|
|
25
30
|
await printResultToConsoleAndExitGracefully("Update completed");
|
|
26
31
|
}
|
|
27
32
|
}
|
|
28
33
|
//# sourceMappingURL=handler.js.map
|
|
29
|
-
//# debugId=
|
|
34
|
+
//# debugId=b240c7b1-8f8c-54c7-b381-3ec9bae18cd4
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zuplo/cli",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": "https://github.com/zuplo/cli",
|
|
6
6
|
"description": "The command-line interface for Zuplo",
|
|
@@ -9,9 +9,11 @@
|
|
|
9
9
|
"scripts": {
|
|
10
10
|
"update:zuplo-dependencies-safely": "./scripts/update-zuplo-dependencies.sh",
|
|
11
11
|
"build": "tsc --build && node ./scripts/post-build.js",
|
|
12
|
+
"build:clean": "tsc --build --clean",
|
|
12
13
|
"clean": "git clean -Xfde !.env",
|
|
13
14
|
"sentry:sourcemaps": "sentry-cli sourcemaps inject --org zuplo --project zuplo-cli ./dist",
|
|
14
|
-
"test": "node --test
|
|
15
|
+
"test": "find dist -name \"*.test.js\" | xargs node --test --test-only",
|
|
16
|
+
"test:ci": "find dist -name \"*.test.js\" | xargs node --test"
|
|
15
17
|
},
|
|
16
18
|
"engines": {
|
|
17
19
|
"node": ">=18.0.0"
|