@zuplo/cli 1.94.0 → 1.96.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.
@@ -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]="2b8e3bc1-2016-5443-a600-5394af1e0854")}catch(e){}}();
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]="18229bd2-cc3c-521a-93e5-30a1d8f03044")}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";
@@ -27,11 +27,7 @@ export default {
27
27
  describe: "The OpenAPI file to import",
28
28
  conflicts: ["source-url"],
29
29
  })
30
- .option("source-url", {
31
- type: "string",
32
- describe: "The URL of the OpenAPI file to import",
33
- conflicts: ["source"],
34
- })
30
+ .demandOption(["source"])
35
31
  .middleware([setBlocking])
36
32
  .check(async (argv) => {
37
33
  return await new YargsChecker(new ZuploProjectValidator()).check(argv);
@@ -43,4 +39,4 @@ export default {
43
39
  },
44
40
  };
45
41
  //# sourceMappingURL=import-openapi.js.map
46
- //# debugId=2b8e3bc1-2016-5443-a600-5394af1e0854
42
+ //# debugId=18229bd2-cc3c-521a-93e5-30a1d8f03044
@@ -1,13 +1,11 @@
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]="03b26528-a437-52aa-bbe9-e5b6db2de295")}catch(e){}}();
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]="f08b6c48-3b56-54ec-b0b8-3e814ec8612f")}catch(e){}}();
3
3
  import { confirm } from "@inquirer/prompts";
4
- import { randomUUID } from "node:crypto";
5
- import { createWriteStream, existsSync, mkdirSync, writeFileSync, } from "node:fs";
6
- import { readFile } from "node:fs/promises";
4
+ import jsYaml from "js-yaml";
5
+ import { existsSync, writeFileSync } from "node:fs";
6
+ import { mkdir, readFile, writeFile } from "node:fs/promises";
7
7
  import { tmpdir } from "node:os";
8
8
  import { basename, dirname, extname, join, relative } from "node:path";
9
- import { Readable } from "node:stream";
10
- import { finished } from "node:stream/promises";
11
9
  import prettier from "prettier";
12
10
  import { logger } from "../../common/logger.js";
13
11
  import { printCriticalFailureToConsoleAndExit, printDiagnosticsToConsole, printResultToConsoleAndExitGracefully, } from "../../common/output.js";
@@ -24,105 +22,109 @@ const BASE_TEMPLATE = `
24
22
 
25
23
  `;
26
24
  export async function importOpenApi(argv) {
27
- if (!argv.source && !argv["source-url"]) {
28
- await printCriticalFailureToConsoleAndExit(`Missing required argument: either source or source-url must be provided.`);
25
+ let normalizedFilePath;
26
+ let handleAsUrl = true;
27
+ try {
28
+ const _url = new URL(argv.source);
29
29
  }
30
- else {
31
- let normalizedFilePath;
32
- if (argv.source) {
33
- const filePath = argv.source;
34
- normalizedFilePath = join(relative(process.cwd(), filePath));
35
- if (!existsSync(normalizedFilePath)) {
36
- await printCriticalFailureToConsoleAndExit(`The file ${normalizedFilePath} to import does not exist.`);
37
- }
38
- }
39
- else {
40
- const url = argv["source-url"];
41
- let parsedUrl;
30
+ catch (err) {
31
+ handleAsUrl = false;
32
+ }
33
+ if (handleAsUrl) {
34
+ const parsedUrl = new URL(argv.source);
35
+ const tempDir = tmpdir();
36
+ const guessedFileName = basename(parsedUrl.pathname).replace(/\.[^/.]+$/, "") ||
37
+ `imported-${Buffer.from(argv.source).toString("base64")}`;
38
+ normalizedFilePath = join(tempDir, guessedFileName);
39
+ await mkdir(dirname(normalizedFilePath), { recursive: true });
40
+ try {
41
+ const response = await fetch(parsedUrl);
42
+ const text = await response.text();
42
43
  try {
43
- parsedUrl = new URL(url);
44
- const tempDir = tmpdir();
45
- normalizedFilePath = join(tempDir, randomUUID(), basename(parsedUrl.pathname));
46
- mkdirSync(dirname(normalizedFilePath), { recursive: true });
44
+ const _json = JSON.parse(text);
45
+ normalizedFilePath = normalizedFilePath + ".json";
46
+ await writeFile(normalizedFilePath, text, { flag: "w+" });
47
47
  }
48
48
  catch (err) {
49
- logger.error(err);
50
- await printCriticalFailureToConsoleAndExit(`The url ${url} is not valid and could not be parsed.`);
51
- throw err;
52
- }
53
- try {
54
- const response = await fetch(url);
55
- if (!response.ok) {
56
- throw new Error(`HTTP error! Status: ${response.status}`);
49
+ try {
50
+ const _yaml = jsYaml.load(text);
51
+ normalizedFilePath = normalizedFilePath + ".yaml";
52
+ await writeFile(normalizedFilePath, text, { flag: "w+" });
53
+ }
54
+ catch (err) {
55
+ await printCriticalFailureToConsoleAndExit(`Failed to parse the remote OpenAPI file as either JSON or YAML.`);
57
56
  }
58
- const fileStream = createWriteStream(normalizedFilePath, {
59
- flags: "wx",
60
- });
61
- await finished(Readable.fromWeb(response.body).pipe(fileStream));
62
- }
63
- catch (err) {
64
- logger.error(err);
65
- await printCriticalFailureToConsoleAndExit(`Failed to download the remote OpenAPI file.`);
66
57
  }
67
58
  }
68
- const rawOpenApiSpec = await readFile(normalizedFilePath);
69
- const extName = extname(normalizedFilePath);
70
- const basePath = basename(normalizedFilePath, extName);
71
- const fileContent = rawOpenApiSpec.toString();
72
- const parsedOpenApiSpec = await parseOpenApiFile(extName, fileContent);
73
- const destinationFilePath = join(process.cwd(), "config", `${basePath.replace("oas", "")}.oas.json`);
74
- let originalDocument;
75
- if (!existsSync(destinationFilePath)) {
76
- originalDocument = (await parseOpenApiFile(".json", BASE_TEMPLATE));
59
+ catch (err) {
60
+ logger.error(err);
61
+ await printCriticalFailureToConsoleAndExit(`Failed to download the remote OpenAPI file.`);
77
62
  }
78
- else {
79
- const existingOpenApiSpec = await readFile(destinationFilePath);
80
- const existingFileContent = existingOpenApiSpec.toString();
81
- originalDocument = (await parseOpenApiFile(extName, existingFileContent));
63
+ }
64
+ else {
65
+ const filePath = argv.source;
66
+ normalizedFilePath = join(relative(process.cwd(), filePath));
67
+ if (!existsSync(normalizedFilePath)) {
68
+ await printCriticalFailureToConsoleAndExit(`The file ${normalizedFilePath} to import does not exist.`);
82
69
  }
83
- const { created, merged, retained } = generateMergeChangeset(originalDocument, parsedOpenApiSpec);
84
- printDiagnosticsToConsole("This import will...");
70
+ }
71
+ const rawOpenApiSpec = await readFile(normalizedFilePath);
72
+ const extName = extname(normalizedFilePath);
73
+ const basePath = basename(normalizedFilePath, extName);
74
+ const fileContent = rawOpenApiSpec.toString();
75
+ const parsedOpenApiSpec = await parseOpenApiFile(extName, fileContent);
76
+ const destinationFilePath = join(process.cwd(), "config", `${basePath.replace("oas", "")}.oas.json`);
77
+ let originalDocument;
78
+ if (!existsSync(destinationFilePath)) {
79
+ originalDocument = (await parseOpenApiFile(".json", BASE_TEMPLATE));
80
+ }
81
+ else {
82
+ const existingOpenApiSpec = await readFile(destinationFilePath);
83
+ const existingFileContent = existingOpenApiSpec.toString();
84
+ originalDocument = (await parseOpenApiFile(extName, existingFileContent));
85
+ }
86
+ const { created, merged, retained } = generateMergeChangeset(originalDocument, parsedOpenApiSpec);
87
+ printDiagnosticsToConsole("This import will...");
88
+ printDiagnosticsToConsole("");
89
+ if (created.size > 0) {
90
+ printDiagnosticsToConsole(`Create ${created.size} new ${created.size > 1 ? "operations" : "operation"}`);
85
91
  printDiagnosticsToConsole("");
86
- if (created.size > 0) {
87
- printDiagnosticsToConsole(`Create ${created.size} new ${created.size > 1 ? "operations" : "operation"}`);
88
- printDiagnosticsToConsole("");
89
- created.forEach((operation) => {
90
- printDiagnosticsToConsole(operation);
91
- });
92
- printDiagnosticsToConsole("");
93
- }
94
- if (merged.size > 0) {
95
- printDiagnosticsToConsole(`Merge ${merged.size} new ${merged.size > 1 ? "operations" : "operation"}`);
96
- printDiagnosticsToConsole("");
97
- merged.forEach((operation) => {
98
- printDiagnosticsToConsole(operation);
99
- });
100
- printDiagnosticsToConsole("");
101
- }
102
- if (retained.size > 0) {
103
- printDiagnosticsToConsole(`Retain ${retained.size} new ${retained.size > 1 ? "operations" : "operation"}`);
104
- printDiagnosticsToConsole("");
105
- retained.forEach((operation) => {
106
- printDiagnosticsToConsole(operation);
107
- });
108
- printDiagnosticsToConsole("");
109
- }
110
- if (argv.prompt) {
111
- printDiagnosticsToConsole("");
112
- const answer = await confirm({ message: "Proceed?", default: true });
113
- if (!answer) {
114
- await printResultToConsoleAndExitGracefully("Import cancelled.");
115
- }
116
- }
117
- addOperationIdsAsNecessary(parsedOpenApiSpec);
118
- const formattedOpenApi = prettier.format(JSON.stringify(parsedOpenApiSpec), {
119
- parser: "json-stringify",
92
+ created.forEach((operation) => {
93
+ printDiagnosticsToConsole(operation);
120
94
  });
121
- writeFileSync(destinationFilePath, formattedOpenApi, {
122
- flag: "w",
95
+ printDiagnosticsToConsole("");
96
+ }
97
+ if (merged.size > 0) {
98
+ printDiagnosticsToConsole(`Merge ${merged.size} new ${merged.size > 1 ? "operations" : "operation"}`);
99
+ printDiagnosticsToConsole("");
100
+ merged.forEach((operation) => {
101
+ printDiagnosticsToConsole(operation);
123
102
  });
124
- await printResultToConsoleAndExitGracefully(`Import successful. File written to ${destinationFilePath}`);
103
+ printDiagnosticsToConsole("");
104
+ }
105
+ if (retained.size > 0) {
106
+ printDiagnosticsToConsole(`Retain ${retained.size} new ${retained.size > 1 ? "operations" : "operation"}`);
107
+ printDiagnosticsToConsole("");
108
+ retained.forEach((operation) => {
109
+ printDiagnosticsToConsole(operation);
110
+ });
111
+ printDiagnosticsToConsole("");
112
+ }
113
+ if (argv.prompt) {
114
+ printDiagnosticsToConsole("");
115
+ const answer = await confirm({ message: "Proceed?", default: true });
116
+ if (!answer) {
117
+ await printResultToConsoleAndExitGracefully("Import cancelled.");
118
+ }
125
119
  }
120
+ addOperationIdsAsNecessary(parsedOpenApiSpec);
121
+ const formattedOpenApi = prettier.format(JSON.stringify(parsedOpenApiSpec), {
122
+ parser: "json-stringify",
123
+ });
124
+ writeFileSync(destinationFilePath, formattedOpenApi, {
125
+ flag: "w",
126
+ });
127
+ await printResultToConsoleAndExitGracefully(`Import successful. File written to ${destinationFilePath}`);
126
128
  }
127
129
  //# sourceMappingURL=handler.js.map
128
- //# debugId=03b26528-a437-52aa-bbe9-e5b6db2de295
130
+ //# debugId=f08b6c48-3b56-54ec-b0b8-3e814ec8612f
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zuplo/cli",
3
- "version": "1.94.0",
3
+ "version": "1.96.0",
4
4
  "type": "module",
5
5
  "repository": "https://github.com/zuplo/cli",
6
6
  "description": "The command-line interface for Zuplo",
@@ -61,9 +61,9 @@
61
61
  "@inquirer/prompts": "^3.0.4",
62
62
  "@sentry/node": "7.69.0",
63
63
  "@swc/core": "1.3.78",
64
- "@zuplo/core": "5.1569.0",
64
+ "@zuplo/core": "5.1570.0",
65
65
  "@zuplo/pino-pretty-configurations": "^1.5.0",
66
- "@zuplo/runtime": "5.1569.0 ",
66
+ "@zuplo/runtime": "5.1570.0 ",
67
67
  "chalk": "^5.1.2",
68
68
  "chokidar": "^3.5.3",
69
69
  "deno-bin": "1.37.1",