@zuplo/cli 1.53.0 → 1.54.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/README.md CHANGED
@@ -9,10 +9,20 @@ Commands:
9
9
  zup deploy Deploys current Git branch of the current directory
10
10
  zup dev Runs the zup locally
11
11
  zup list Lists all deployed zups
12
+ zup link Links information from your Zuplo account to your local machine
13
+ zup login Authenticates the user
12
14
  zup test Runs the tests under /tests against an endpoint
15
+ zup project Project commands
13
16
  zup tunnel Tunnel commands
14
17
  zup variable Variable commands
15
18
 
19
+ zup project
20
+
21
+ Project commands
22
+
23
+ Commands:
24
+ zup project update Updates your project structure to the latest conventions
25
+
16
26
  zup tunnel
17
27
 
18
28
  Tunnel commands
@@ -33,7 +43,6 @@ Commands:
33
43
  zup tunnel services describe Describes the services for this tunnel
34
44
  zup tunnel services update Updates the services for this tunnel
35
45
 
36
-
37
46
  zup variable
38
47
 
39
48
  Variable commands
package/dist/cli.js CHANGED
@@ -10,6 +10,7 @@ import dev from "./cmds/dev.js";
10
10
  import link from "./cmds/link.js";
11
11
  import list from "./cmds/list.js";
12
12
  import login from "./cmds/login.js";
13
+ import project from "./cmds/project/index.js";
13
14
  import test from "./cmds/test.js";
14
15
  import tunnel from "./cmds/tunnel/index.js";
15
16
  import variable from "./cmds/variable/index.js";
@@ -26,6 +27,7 @@ if (gte(process.versions.node, MIN_NODE_VERSION)) {
26
27
  .command(link)
27
28
  .command(login)
28
29
  .command(test)
30
+ .command(project)
29
31
  .command(tunnel)
30
32
  .command(variable)
31
33
  .demandCommand()
@@ -0,0 +1,12 @@
1
+ import { groupHandler } from "../../common/handler.js";
2
+ import update from "./update.js";
3
+ const commands = {
4
+ describe: "Project commands",
5
+ command: "project",
6
+ builder: (yargs) => {
7
+ return yargs.command(update).help();
8
+ },
9
+ handler: groupHandler,
10
+ };
11
+ export default commands;
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,26 @@
1
+ import setBlocking from "../../common/output.js";
2
+ import { ZuploProjectValidator } from "../../common/validators/file-system-validator.js";
3
+ import { YargsChecker } from "../../common/validators/lib.js";
4
+ import { update } from "../../project/update/handler.js";
5
+ export default {
6
+ desc: "Updates your project structure to the latest conventions",
7
+ command: "update",
8
+ builder: (yargs) => {
9
+ return yargs
10
+ .option("dir", {
11
+ type: "string",
12
+ describe: "The directory containing your zup",
13
+ default: ".",
14
+ normalize: true,
15
+ hidden: true,
16
+ })
17
+ .middleware([setBlocking])
18
+ .check(async (argv) => {
19
+ return await new YargsChecker(new ZuploProjectValidator()).check(argv);
20
+ });
21
+ },
22
+ handler: async (argv) => {
23
+ await update(argv);
24
+ },
25
+ };
26
+ //# sourceMappingURL=update.js.map
@@ -0,0 +1,13 @@
1
+ export class StandardUpgrader {
2
+ normalizedDir;
3
+ constructor(normalizedDir) {
4
+ this.normalizedDir = normalizedDir;
5
+ }
6
+ }
7
+ export class VsCodeFolderMissing extends Error {
8
+ constructor() {
9
+ super("Missing .vscode folder: The current directory does not contain a .vscode folder.");
10
+ Object.setPrototypeOf(this, VsCodeFolderMissing.prototype);
11
+ }
12
+ }
13
+ //# sourceMappingURL=lib.js.map
@@ -0,0 +1,54 @@
1
+ import { readFile, writeFile } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+ import prettier from "prettier";
4
+ import { StandardUpgrader } from "./lib.js";
5
+ export class FailedToParsePackageJson extends Error {
6
+ constructor() {
7
+ super("Invalid package.json: Failed to parse the package.json file.");
8
+ Object.setPrototypeOf(this, FailedToParsePackageJson.prototype);
9
+ }
10
+ }
11
+ export class PackageJsonUpgrader extends StandardUpgrader {
12
+ async isApplicable() {
13
+ try {
14
+ const rawPackage = await readFile(join(this.normalizedDir, "package.json"), "utf-8");
15
+ const packageJson = JSON.parse(rawPackage);
16
+ return { ok: true };
17
+ }
18
+ catch (err) {
19
+ return { ok: false, error: new FailedToParsePackageJson() };
20
+ }
21
+ }
22
+ async upgrade() {
23
+ const packageJsonFile = join(this.normalizedDir, "package.json");
24
+ const rawPackage = await readFile(packageJsonFile, "utf-8");
25
+ const packageJson = JSON.parse(rawPackage);
26
+ packageJson.scripts.dev = "zup dev";
27
+ delete packageJson.scripts.build;
28
+ if ((packageJson.scripts.test && packageJson.scripts.test === "zup test") ||
29
+ packageJson.scripts.test === "zuplo test") {
30
+ delete packageJson.scripts.test;
31
+ }
32
+ if (packageJson.scripts.postinstall &&
33
+ packageJson.scripts.postinstall === "husky install") {
34
+ delete packageJson.scripts.postinstall;
35
+ }
36
+ if (packageJson.dependencies["@zuplo/runtime"]) {
37
+ delete packageJson.dependencies["@zuplo/runtime"];
38
+ }
39
+ if (packageJson.dependencies["@zuplo/core"]) {
40
+ delete packageJson.dependencies["@zuplo/core"];
41
+ }
42
+ packageJson.dependencies["zuplo"] = "latest";
43
+ delete packageJson.devDependencies["@zuplo/test"];
44
+ delete packageJson.devDependencies["husky"];
45
+ delete packageJson.devDependencies["chai"];
46
+ delete packageJson.devDependencies["@types/chai"];
47
+ const formatted = prettier.format(JSON.stringify(packageJson), {
48
+ parser: "json-stringify",
49
+ quoteProps: "as-needed",
50
+ });
51
+ await writeFile(packageJsonFile, formatted);
52
+ }
53
+ }
54
+ //# sourceMappingURL=package-json-upgrader.js.map
@@ -0,0 +1,93 @@
1
+ import { parse } from "jsonc-parser";
2
+ import { existsSync } from "node:fs";
3
+ import { readFile, writeFile } from "node:fs/promises";
4
+ import { join } from "node:path";
5
+ import prettier from "prettier";
6
+ import { StandardUpgrader, VsCodeFolderMissing } from "./lib.js";
7
+ const zuploSchemas = [
8
+ {
9
+ fileMatch: ["config/*.oas.json"],
10
+ url: "https://cdn.zuplo.com/schemas/openapi-v3.1-zuplo.json",
11
+ },
12
+ {
13
+ fileMatch: ["config/policies.json"],
14
+ url: "https://cdn.zuplo.com/schemas/policies.json",
15
+ },
16
+ {
17
+ fileMatch: ["config/routes.json"],
18
+ url: "https://cdn.zuplo.com/schemas/routes.json",
19
+ },
20
+ {
21
+ fileMatch: ["config/dev-portal.json"],
22
+ url: "https://cdn.zuplo.com/schemas/dev-portal.json",
23
+ },
24
+ {
25
+ fileMatch: ["docs/sidebar.json"],
26
+ url: "https://cdn.zuplo.com/schemas/sidebar.json",
27
+ },
28
+ ];
29
+ export class VsCodeSettingsJsonUpgrader extends StandardUpgrader {
30
+ async isApplicable() {
31
+ const vsCodeFolder = join(this.normalizedDir, ".vscode");
32
+ if (existsSync(vsCodeFolder)) {
33
+ return { ok: true };
34
+ }
35
+ else {
36
+ return { ok: false, error: new VsCodeFolderMissing() };
37
+ }
38
+ }
39
+ async upgrade() {
40
+ const vsCodeSettingsFile = join(this.normalizedDir, ".vscode", "settings.json");
41
+ if (!existsSync(vsCodeSettingsFile)) {
42
+ const content = `
43
+ {
44
+ "json.schemas": [
45
+ {
46
+ "fileMatch": ["config/*.oas.json"],
47
+ "url": "https://cdn.zuplo.com/schemas/openapi-v3.1-zuplo.json"
48
+ },
49
+ {
50
+ "fileMatch": ["config/policies.json"],
51
+ "url": "https://cdn.zuplo.com/schemas/policies.json"
52
+ },
53
+ {
54
+ "fileMatch": ["config/routes.json"],
55
+ "url": "https://cdn.zuplo.com/schemas/routes.json"
56
+ },
57
+ {
58
+ "fileMatch": ["config/dev-portal.json"],
59
+ "url": "https://cdn.zuplo.com/schemas/dev-portal.json"
60
+ },
61
+ {
62
+ "fileMatch": ["docs/sidebar.json"],
63
+ "url": "https://cdn.zuplo.com/schemas/sidebar.json"
64
+ }
65
+ ]
66
+ }`;
67
+ const formatted = prettier.format(content, {
68
+ parser: "json",
69
+ quoteProps: "as-needed",
70
+ });
71
+ await writeFile(vsCodeSettingsFile, formatted);
72
+ }
73
+ else {
74
+ const settingsRaw = await readFile(vsCodeSettingsFile, "utf-8");
75
+ const settingsJson = parse(settingsRaw, [], {});
76
+ for (const schema of zuploSchemas) {
77
+ const existingSchema = settingsJson["json.schemas"].find((s) => s.fileMatch[0] === schema.fileMatch[0]);
78
+ if (existingSchema) {
79
+ existingSchema.url = schema.url;
80
+ }
81
+ else {
82
+ settingsJson["json.schemas"].push(schema);
83
+ }
84
+ }
85
+ const formatted = prettier.format(JSON.stringify(settingsJson), {
86
+ parser: "json",
87
+ quoteProps: "as-needed",
88
+ });
89
+ await writeFile(vsCodeSettingsFile, formatted);
90
+ }
91
+ }
92
+ }
93
+ //# sourceMappingURL=vscode-settings-json-upgrader.js.map
@@ -7,7 +7,7 @@ import settings from "../settings.js";
7
7
  import { ZUPLO_XDG_STATE_HOME } from "../xdg/lib.js";
8
8
  export class UserIsNotLoggedIn extends Error {
9
9
  constructor() {
10
- super(`You are not logged in (or your credentials have expired). Please run \`zuplo login\` to log in.`);
10
+ super(`You are not logged in (or your credentials have expired). Please run \`zup login\` to log in.`);
11
11
  Object.setPrototypeOf(this, UserIsNotLoggedIn.prototype);
12
12
  }
13
13
  }
@@ -20,7 +20,7 @@ export async function safeMergeConfig(dir, options) {
20
20
  const contentsPostProject = applyEdits(contentsPostAccount, modifyProjectEdit);
21
21
  const formatted = prettier.format(contentsPostProject, {
22
22
  parser: "json",
23
- quoteProps: "preserve",
23
+ quoteProps: "as-needed",
24
24
  });
25
25
  await writeFile(zuploPreferredConfigFile, formatted);
26
26
  }
@@ -33,7 +33,7 @@ export async function safeMergeConfig(dir, options) {
33
33
  compatibilityDate: config.compatibilityDate,
34
34
  }), {
35
35
  parser: "json",
36
- quoteProps: "preserve",
36
+ quoteProps: "as-needed",
37
37
  });
38
38
  await writeFile(zuploPreferredConfigFile, formatted);
39
39
  }
@@ -45,7 +45,7 @@ export async function safeMergeConfig(dir, options) {
45
45
  compatibilityDate: "2023-03-14",
46
46
  }), {
47
47
  parser: "json",
48
- quoteProps: "preserve",
48
+ quoteProps: "as-needed",
49
49
  });
50
50
  await writeFile(zuploPreferredConfigFile, formatted);
51
51
  }
@@ -0,0 +1,26 @@
1
+ import { confirm } from "@inquirer/prompts";
2
+ import { printDiagnosticsToConsole, printResultToConsoleAndExitGracefully, } from "../../common/output.js";
3
+ import { PackageJsonUpgrader } from "../../common/upgraders/package-json-upgrader.js";
4
+ import { VsCodeSettingsJsonUpgrader } from "../../common/upgraders/vscode-settings-json-upgrader.js";
5
+ export async function update(argv) {
6
+ printDiagnosticsToConsole("This command will make changes to your source code. Please commit your changes to version control before continuing.");
7
+ const answer = await confirm({ message: "Continue?", default: true });
8
+ if (answer) {
9
+ const u = new PackageJsonUpgrader(argv.dir);
10
+ if ((await u.isApplicable()).ok) {
11
+ printDiagnosticsToConsole("Updating your package.json...");
12
+ await u.upgrade();
13
+ }
14
+ else {
15
+ }
16
+ const v = new VsCodeSettingsJsonUpgrader(argv.dir);
17
+ if ((await v.isApplicable()).ok) {
18
+ printDiagnosticsToConsole("Updating your .vsode settings...");
19
+ await v.upgrade();
20
+ }
21
+ else {
22
+ }
23
+ printResultToConsoleAndExitGracefully("Update completed");
24
+ }
25
+ }
26
+ //# sourceMappingURL=handler.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zuplo/cli",
3
- "version": "1.53.0",
3
+ "version": "1.54.0",
4
4
  "type": "module",
5
5
  "repository": "https://github.com/zuplo/cli",
6
6
  "author": "Zuplo, Inc.",