@zuplo/cli 1.42.0 → 1.44.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/dist/cli.js CHANGED
@@ -24,6 +24,7 @@ if (gte(process.versions.node, MIN_NODE_VERSION)) {
24
24
  .command(variable)
25
25
  .demandCommand()
26
26
  .strictCommands()
27
+ .version()
27
28
  .help().argv;
28
29
  }
29
30
  else {
@@ -1,5 +1,7 @@
1
1
  import { configure } from "../common/middleware/user-configuration.js";
2
2
  import setBlocking from "../common/output.js";
3
+ import { YargsChecker } from "../common/validators/lib.js";
4
+ import { ProjectIsSetValidator } from "../common/validators/project-name-validator.js";
3
5
  import { deleteZup } from "../delete/handler.js";
4
6
  export default {
5
7
  desc: "Deletes the zup at the URL",
@@ -25,7 +27,10 @@ export default {
25
27
  })
26
28
  .boolean("wait")
27
29
  .demandOption(["api-key", "url"])
28
- .middleware([setBlocking, configure]);
30
+ .middleware([setBlocking, configure])
31
+ .check(async (argv) => {
32
+ return await new YargsChecker(new ProjectIsSetValidator()).check(argv);
33
+ });
29
34
  },
30
35
  handler: async (argv) => {
31
36
  await deleteZup(argv);
@@ -12,6 +12,11 @@ export default {
12
12
  type: "string",
13
13
  describe: "The API Key from Zuplo",
14
14
  envVar: "API_KEY",
15
+ })
16
+ .option("project", {
17
+ type: "string",
18
+ hidden: true,
19
+ describe: "The project name",
15
20
  })
16
21
  .option("dir", {
17
22
  type: "string",
@@ -27,10 +32,10 @@ export default {
27
32
  })
28
33
  .demandOption(["api-key"])
29
34
  .boolean("verify-remote")
35
+ .middleware([setBlocking, configure])
30
36
  .check(async (argv) => {
31
- return await new YargsChecker(validDeployDirectoryValidator).check(argv.dir);
32
- })
33
- .middleware([setBlocking, configure]);
37
+ return await new YargsChecker(validDeployDirectoryValidator).check(argv);
38
+ });
34
39
  },
35
40
  handler: async (argv) => {
36
41
  await deploy(argv);
package/dist/cmds/list.js CHANGED
@@ -1,5 +1,7 @@
1
1
  import { configure } from "../common/middleware/user-configuration.js";
2
2
  import setBlocking from "../common/output.js";
3
+ import { YargsChecker } from "../common/validators/lib.js";
4
+ import { ProjectIsSetValidator } from "../common/validators/project-name-validator.js";
3
5
  import { list } from "../list/handler.js";
4
6
  export default {
5
7
  desc: "Lists all deployed zups",
@@ -16,7 +18,10 @@ export default {
16
18
  describe: "The project name",
17
19
  })
18
20
  .demandOption(["api-key"])
19
- .middleware([setBlocking, configure]);
21
+ .middleware([setBlocking, configure])
22
+ .check(async (argv) => {
23
+ return await new YargsChecker(new ProjectIsSetValidator()).check(argv);
24
+ });
20
25
  },
21
26
  handler: async (argv) => {
22
27
  await list(argv);
package/dist/cmds/test.js CHANGED
@@ -23,7 +23,7 @@ export default {
23
23
  hidden: true,
24
24
  })
25
25
  .check(async (argv) => {
26
- return await new YargsChecker(validTestDirectoryValidator).check(argv.dir);
26
+ return await new YargsChecker(validTestDirectoryValidator).check(argv);
27
27
  })
28
28
  .middleware([setBlocking]);
29
29
  },
@@ -1,5 +1,7 @@
1
1
  import { configure } from "../../common/middleware/user-configuration.js";
2
2
  import setBlocking from "../../common/output.js";
3
+ import { YargsChecker } from "../../common/validators/lib.js";
4
+ import { ProjectIsSetValidator } from "../../common/validators/project-name-validator.js";
3
5
  import { create } from "../../variable/create/handler.js";
4
6
  export default {
5
7
  desc: "Creates a new variable for a branch",
@@ -32,7 +34,10 @@ export default {
32
34
  describe: "The project name",
33
35
  })
34
36
  .demandOption(["api-key", "name", "value", "is-secret", "branch"])
35
- .middleware([setBlocking, configure]);
37
+ .middleware([setBlocking, configure])
38
+ .check(async (argv) => {
39
+ return await new YargsChecker(new ProjectIsSetValidator()).check(argv);
40
+ });
36
41
  },
37
42
  handler: async (argv) => {
38
43
  create(argv);
@@ -1,5 +1,7 @@
1
1
  import { configure } from "../../common/middleware/user-configuration.js";
2
2
  import setBlocking from "../../common/output.js";
3
+ import { YargsChecker } from "../../common/validators/lib.js";
4
+ import { ProjectIsSetValidator } from "../../common/validators/project-name-validator.js";
3
5
  import { update } from "../../variable/update/handler.js";
4
6
  export default {
5
7
  desc: "Updates an existing variable for a branch",
@@ -23,7 +25,10 @@ export default {
23
25
  describe: "The project name",
24
26
  })
25
27
  .demandOption(["api-key", "name", "value", "branch"])
26
- .middleware([setBlocking, configure]);
28
+ .middleware([setBlocking, configure])
29
+ .check(async (argv) => {
30
+ return await new YargsChecker(new ProjectIsSetValidator()).check(argv);
31
+ });
27
32
  },
28
33
  handler: async (argv) => {
29
34
  update(argv);
@@ -4,6 +4,7 @@ import { join } from "node:path";
4
4
  import { simpleGit } from "simple-git";
5
5
  import { TEST_IN_FOLDER } from "../constants.js";
6
6
  import { CompositeValidator } from "./lib.js";
7
+ import { ProjectIsSetValidator } from "./project-name-validator.js";
7
8
  export class NotAGitRepoError extends Error {
8
9
  constructor() {
9
10
  super("Invalid directory: The current directory is not a Git repository.");
@@ -41,7 +42,8 @@ export class MissingGitRemote extends Error {
41
42
  }
42
43
  }
43
44
  export class GitVersionControlValidator {
44
- async validate(dir) {
45
+ async validate(option) {
46
+ const { dir } = option;
45
47
  try {
46
48
  await simpleGit({ baseDir: dir }).status();
47
49
  return { ok: true };
@@ -55,7 +57,8 @@ export class GitVersionControlValidator {
55
57
  }
56
58
  }
57
59
  export class GitCommitValidator {
58
- async validate(dir) {
60
+ async validate(option) {
61
+ const { dir } = option;
59
62
  try {
60
63
  const git = simpleGit({ baseDir: dir });
61
64
  const commits = await git.log({ maxCount: 1 });
@@ -76,7 +79,8 @@ export class GitCommitValidator {
76
79
  }
77
80
  }
78
81
  export class GitBranchValidator {
79
- async validate(dir) {
82
+ async validate(option) {
83
+ const { dir } = option;
80
84
  const git = simpleGit({ baseDir: dir });
81
85
  const branch = await git.branch();
82
86
  if (!branch.current) {
@@ -89,7 +93,8 @@ export class GitBranchValidator {
89
93
  }
90
94
  }
91
95
  export class GitRemoteValidator {
92
- async validate(dir) {
96
+ async validate(option) {
97
+ const { dir } = option;
93
98
  const git = simpleGit({ baseDir: dir });
94
99
  const remotes = await git.getRemotes(true);
95
100
  const origin = remotes.find((r) => r.name === "origin");
@@ -103,12 +108,13 @@ export class GitRemoteValidator {
103
108
  }
104
109
  }
105
110
  export class ZuploProjectValidator {
106
- async validate(dir) {
111
+ async validate(options) {
112
+ const { dir } = options;
107
113
  try {
108
114
  if (existsSync(`${dir}/config/routes.json`)) {
109
115
  return { ok: true };
110
116
  }
111
- else {
117
+ else if (existsSync(`${dir}/config`)) {
112
118
  const files = readdirSync(join(dir, "config"));
113
119
  const existingOASFiles = files.filter((file) => file.endsWith(".oas.json")).length >= 1;
114
120
  if (existingOASFiles === true) {
@@ -129,7 +135,8 @@ export class ZuploProjectValidator {
129
135
  }
130
136
  }
131
137
  export class ZuploProjectHasTestsValidator {
132
- async validate(dir) {
138
+ async validate(option) {
139
+ const { dir } = option;
133
140
  try {
134
141
  if (fg.sync(`${dir}/${TEST_IN_FOLDER}/**/*.test.ts`).length >= 1) {
135
142
  return { ok: true };
@@ -149,6 +156,6 @@ export class ZuploProjectHasTestsValidator {
149
156
  }
150
157
  }
151
158
  }
152
- export const validDeployDirectoryValidator = new CompositeValidator(new ZuploProjectValidator(), new GitVersionControlValidator(), new GitCommitValidator(), new GitBranchValidator(), new GitRemoteValidator());
159
+ export const validDeployDirectoryValidator = new CompositeValidator(new ZuploProjectValidator(), new GitVersionControlValidator(), new GitCommitValidator(), new GitBranchValidator(), new GitRemoteValidator(), new ProjectIsSetValidator());
153
160
  export const validTestDirectoryValidator = new CompositeValidator(new ZuploProjectValidator(), new ZuploProjectHasTestsValidator());
154
161
  //# sourceMappingURL=file-system-validator.js.map
@@ -0,0 +1,30 @@
1
+ export class ProjectIsNotSet extends Error {
2
+ constructor() {
3
+ super(`Missing project name. This command requires a project to be specified. Either specify it using --project or set it in zuplo.jsonc.
4
+
5
+ zuplo.jsonc should look like this:
6
+
7
+ {
8
+ "version": 1,
9
+ "project": "<name-of-your-project>",
10
+ "compatibilityDate": "2023-03-14"
11
+ }
12
+
13
+ `);
14
+ Object.setPrototypeOf(this, ProjectIsNotSet.prototype);
15
+ }
16
+ }
17
+ export class ProjectIsSetValidator {
18
+ async validate(argv) {
19
+ if (!argv.project) {
20
+ return {
21
+ ok: false,
22
+ error: new ProjectIsNotSet(),
23
+ };
24
+ }
25
+ else {
26
+ return { ok: true };
27
+ }
28
+ }
29
+ }
30
+ //# sourceMappingURL=project-name-validator.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zuplo/cli",
3
- "version": "1.42.0",
3
+ "version": "1.44.0",
4
4
  "type": "module",
5
5
  "repository": "https://github.com/zuplo/cli",
6
6
  "author": "Zuplo, Inc.",