@zuplo/cli 6.57.17 → 6.57.19
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/common/middleware/get-environment-param.d.ts.map +1 -1
- package/dist/common/middleware/get-environment-param.js +4 -32
- package/dist/common/middleware/get-environment-param.js.map +1 -1
- package/dist/common/output.d.ts.map +1 -1
- package/dist/common/output.js +3 -0
- package/dist/common/output.js.map +1 -1
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-environment-param.d.ts","sourceRoot":"","sources":["../../../src/common/middleware/get-environment-param.ts"],"names":[],"mappings":"AAYA,wBAAsB,gBAAgB,CAAC,IAAI,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,
|
|
1
|
+
{"version":3,"file":"get-environment-param.d.ts","sourceRoot":"","sources":["../../../src/common/middleware/get-environment-param.ts"],"names":[],"mappings":"AAYA,wBAAsB,gBAAgB,CAAC,IAAI,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,iBAuJtE"}
|
|
@@ -33,42 +33,14 @@ export async function fetchEnvironment(argv) {
|
|
|
33
33
|
},
|
|
34
34
|
});
|
|
35
35
|
if (response.ok) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}).length;
|
|
40
|
-
if (numDevelopmentEnvironments <= 0) {
|
|
41
|
-
const createDevelopmenEnvironmentResponse = await fetch(`${baseUrl}`, {
|
|
42
|
-
method: "POST",
|
|
43
|
-
headers: {
|
|
44
|
-
authorization: `Bearer ${argv.authToken}`,
|
|
45
|
-
"Content-Type": "application/json",
|
|
46
|
-
},
|
|
47
|
-
body: JSON.stringify({
|
|
48
|
-
accountName: argv.account,
|
|
49
|
-
projectName: argv.project,
|
|
50
|
-
environmentType: "development",
|
|
51
|
-
}),
|
|
52
|
-
});
|
|
53
|
-
if (!createDevelopmenEnvironmentResponse.ok) {
|
|
54
|
-
logger.debug({
|
|
55
|
-
status: createDevelopmenEnvironmentResponse.status,
|
|
56
|
-
statusText: createDevelopmenEnvironmentResponse.statusText,
|
|
57
|
-
}, "Failed to create a new instance of development environment");
|
|
58
|
-
await printCriticalFailureToConsoleAndExit("Failed to create a new development environment. Please try again later.");
|
|
59
|
-
}
|
|
60
|
-
numDevelopmentEnvironments++;
|
|
61
|
-
const updatedResponse = await fetch(url, {
|
|
62
|
-
headers: {
|
|
63
|
-
authorization: `Bearer ${argv.authToken}`,
|
|
64
|
-
},
|
|
65
|
-
});
|
|
66
|
-
environmentJsonFromDeveloperAPI = (await updatedResponse.json());
|
|
36
|
+
const environmentJsonFromDeveloperAPI = (await response.json());
|
|
37
|
+
if (environmentJsonFromDeveloperAPI.data.length === 0) {
|
|
38
|
+
await printCriticalFailureToConsoleAndExit("Error: You don't have any preview or production environments for this project to link against. First, deploy this project using zuplo deploy and then link against that.");
|
|
67
39
|
}
|
|
68
40
|
const environments = environmentJsonFromDeveloperAPI.data
|
|
69
41
|
.map((env) => {
|
|
70
42
|
return {
|
|
71
|
-
[prettyPrintEnvironmentPrompt(env,
|
|
43
|
+
[prettyPrintEnvironmentPrompt(env, false)]: env.name,
|
|
72
44
|
};
|
|
73
45
|
})
|
|
74
46
|
.reduce((acc, curr) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-environment-param.js","sourceRoot":"","sources":["../../../src/common/middleware/get-environment-param.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,oCAAoC,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAChF,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,4BAA4B,EAAE,MAAM,6CAA6C,CAAC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Y,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;oBAChE,IAAI,CAAC,iBAAiB,EAAE,CAAC;wBACvB,MAAM,IAAI,KAAK,CACb,qDAAqD,CACtD,CAAC;oBACJ,CAAC;oBACD,MAAM,GAAG,iBAAiB,CAAC,IAAI,EAAE,CAAC;gBACpC,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { select } from \"@inquirer/prompts\";\nimport { simpleGit } from \"simple-git\";\nimport { Environment } from \"../api/lib.js\";\nimport { logger } from \"../logger.js\";\nimport { printCriticalFailureToConsoleAndExit, textOrJson } from \"../output.js\";\nimport settings from \"../settings.js\";\nimport { prettyPrintEnvironmentPrompt } from \"../utils/pretty-print-environment-prompt.js\";\n\n/**\n * Middleware that ensures a environment is provided in argv. If not, prompts the user.\n * Note: must be called after get account param and get project param.\n */\nexport async function fetchEnvironment(argv: { [key: string]: unknown }) {\n if (argv.environment && typeof argv.environment === \"string\") {\n return;\n }\n\n if (!argv.account || typeof argv.account !== \"string\") {\n throw new Error(\"Invalid state: account is not set.\");\n }\n if (!argv.project || typeof argv.project !== \"string\") {\n throw new Error(\"Invalid state: project is not set.\");\n }\n\n // 1. Check if the dir argument is set and if we are in a git repository\n // If we are, get the current branch and use that as the environment name.\n const branch = await getGitBranch(argv);\n\n if (branch && !argv[\"fetch-environments\"]) {\n // If the branch is set, use that as the environment name\n argv.environment = branch;\n } else {\n const baseUrl = `${settings.ZUPLO_DEVELOPER_API_ENDPOINT}/v1/environments`;\n\n const queryParams: Record<string, string> = {\n // This is safe because of the previous middleware where we set the account and project.\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n accountName: argv.account!,\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n projectName: argv.project!,\n };\n\n // Create the query string using URLSearchParams\n const url = new URL(baseUrl);\n url.search = new URLSearchParams(queryParams).toString();\n const response = await fetch(url, {\n method: \"GET\",\n headers: {\n Authorization: `Bearer ${argv.authToken}`,\n },\n });\n\n if (response.ok) {\n let environmentJsonFromDeveloperAPI = (await response.json()) as {\n data: Environment[];\n };\n\n let numDevelopmentEnvironments =\n environmentJsonFromDeveloperAPI.data.filter((env) => {\n return env.environmentType === \"development\";\n }).length;\n\n if (numDevelopmentEnvironments <= 0) {\n // Create one on-the-fly\n const createDevelopmenEnvironmentResponse = await fetch(`${baseUrl}`, {\n method: \"POST\",\n headers: {\n authorization: `Bearer ${argv.authToken}`,\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify({\n accountName: argv.account,\n projectName: argv.project,\n environmentType: \"development\",\n }),\n });\n\n if (!createDevelopmenEnvironmentResponse.ok) {\n logger.debug(\n {\n status: createDevelopmenEnvironmentResponse.status,\n statusText: createDevelopmenEnvironmentResponse.statusText,\n },\n \"Failed to create a new instance of development environment\"\n );\n await printCriticalFailureToConsoleAndExit(\n \"Failed to create a new development environment. Please try again later.\"\n );\n }\n\n numDevelopmentEnvironments++;\n\n // Re-fetch\n const updatedResponse = await fetch(url, {\n headers: {\n authorization: `Bearer ${argv.authToken}`,\n },\n });\n\n environmentJsonFromDeveloperAPI = (await updatedResponse.json()) as {\n data: Environment[];\n };\n }\n\n const environments = environmentJsonFromDeveloperAPI.data\n .map((env) => {\n return {\n [prettyPrintEnvironmentPrompt(\n env,\n numDevelopmentEnvironments == 1\n )]: env.name,\n };\n })\n .reduce((acc, curr) => {\n return { ...acc, ...curr };\n });\n\n try {\n argv.environment = await select({\n message: \"Select the environment\",\n choices: Object.entries(environments)\n .map(([key, value]) => {\n return {\n name: key,\n value: value,\n };\n })\n .sort((a, b) => a.name.localeCompare(b.name)),\n });\n } catch (error) {\n if (error.isTtyError || error.name === \"ExitPromptError\") {\n process.exit(0);\n }\n logger.trace(\"Failed to select account\", error);\n process.exit(1);\n }\n } else {\n logger.trace(\n {\n status: response.status,\n statusText: response.statusText,\n response: textOrJson(await response.text()),\n },\n \"Failed to request environments for project\"\n );\n await printCriticalFailureToConsoleAndExit(\n \"Error: Failed to request environments for the project.\"\n );\n }\n }\n}\nasync function getGitBranch(argv: { [key: string]: unknown }) {\n let branch: string | undefined;\n const dir = argv.dir;\n if (dir && typeof dir === \"string\") {\n const git = simpleGit({ baseDir: dir });\n const isGitRepo = await git.checkIsRepo();\n if (isGitRepo) {\n // Get the current branch from Git\n const status = await git.status();\n if (!status.current) {\n throw new Error(\"Invalid state: Directory is in detached head state.\");\n }\n branch = status.current.trim();\n\n // @NOTE - gitlab returns HEAD as the current branch when running git.status()\n // https://forum.gitlab.com/t/why-i-cant-get-the-branch-name/72462/6\n if (branch === \"HEAD\") {\n // Fetch remote branches to ensure the latest information\n await git.fetch([\"--all\"]);\n\n const branchCommit = await git.branch([\"-a\"]);\n const branchRef = await git.branch([\n \"-r\",\n \"--contains\",\n branchCommit.current,\n ]);\n if (branchRef && branchRef.all && branchRef.all[0]) {\n const originBranch = branchRef.all[0];\n const cleanOriginBranch = originBranch.replace(/^origin\\//, \"\");\n if (!cleanOriginBranch) {\n throw new Error(\n \"Invalid state: Directory is in detached head state.\"\n );\n }\n branch = cleanOriginBranch.trim();\n }\n }\n }\n }\n return branch;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"get-environment-param.js","sourceRoot":"","sources":["../../../src/common/middleware/get-environment-param.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,oCAAoC,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAChF,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,4BAA4B,EAAE,MAAM,6CAA6C,CAAC;AAM3F,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,IAAgC;IACrE,IAAI,IAAI,CAAC,WAAW,IAAI,OAA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AS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;oBACnD,MAAM,YAAY,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;oBACtC,MAAM,iBAAiB,GAAG,YAAY,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;oBAChE,IAAI,CAAC,iBAAiB,EAAE,CAAC;wBACvB,MAAM,IAAI,KAAK,CACb,qDAAqD,CACtD,CAAC;oBACJ,CAAC;oBACD,MAAM,GAAG,iBAAiB,CAAC,IAAI,EAAE,CAAC;gBACpC,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { select } from \"@inquirer/prompts\";\nimport { simpleGit } from \"simple-git\";\nimport { Environment } from \"../api/lib.js\";\nimport { logger } from \"../logger.js\";\nimport { printCriticalFailureToConsoleAndExit, textOrJson } from \"../output.js\";\nimport settings from \"../settings.js\";\nimport { prettyPrintEnvironmentPrompt } from \"../utils/pretty-print-environment-prompt.js\";\n\n/**\n * Middleware that ensures a environment is provided in argv. If not, prompts the user.\n * Note: must be called after get account param and get project param.\n */\nexport async function fetchEnvironment(argv: { [key: string]: unknown }) {\n if (argv.environment && typeof argv.environment === \"string\") {\n return;\n }\n\n if (!argv.account || typeof argv.account !== \"string\") {\n throw new Error(\"Invalid state: account is not set.\");\n }\n if (!argv.project || typeof argv.project !== \"string\") {\n throw new Error(\"Invalid state: project is not set.\");\n }\n\n // 1. Check if the dir argument is set and if we are in a git repository\n // If we are, get the current branch and use that as the environment name.\n const branch = await getGitBranch(argv);\n\n if (branch && !argv[\"fetch-environments\"]) {\n // If the branch is set, use that as the environment name\n argv.environment = branch;\n } else {\n const baseUrl = `${settings.ZUPLO_DEVELOPER_API_ENDPOINT}/v1/environments`;\n\n const queryParams: Record<string, string> = {\n // This is safe because of the previous middleware where we set the account and project.\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n accountName: argv.account!,\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n projectName: argv.project!,\n };\n\n // Create the query string using URLSearchParams\n const url = new URL(baseUrl);\n url.search = new URLSearchParams(queryParams).toString();\n const response = await fetch(url, {\n method: \"GET\",\n headers: {\n Authorization: `Bearer ${argv.authToken}`,\n },\n });\n\n if (response.ok) {\n const environmentJsonFromDeveloperAPI = (await response.json()) as {\n data: Environment[];\n };\n\n if (environmentJsonFromDeveloperAPI.data.length === 0) {\n await printCriticalFailureToConsoleAndExit(\n \"Error: You don't have any preview or production environments for this project to link against. First, deploy this project using zuplo deploy and then link against that.\"\n );\n }\n\n // TODO: This logic doesn't work for working copies anymore due to\n // https://github.com/zuplo/core/blob/main/apps/tenant-api/prisma/migrations/v2_20250711155424_add-working-copy-main-check/migration.sql\n // and https://github.com/zuplo/core/blob/6595268b9d2e5edfb3a20cbb086ccd363cf115f9/apps/tenant-api/src/routes/managed-dedicated/environments.ts#L96-L102\n // Leaving this logic commented out for now since we may want to bring it back.\n // let numDevelopmentEnvironments =\n // environmentJsonFromDeveloperAPI.data.filter((env) => {\n // return env.environmentType === \"development\";\n // }).length;\n\n // if (numDevelopmentEnvironments <= 0) {\n // // Create one on-the-fly\n // const createDevelopmenEnvironmentResponse = await fetch(`${baseUrl}`, {\n // method: \"POST\",\n // headers: {\n // authorization: `Bearer ${argv.authToken}`,\n // \"Content-Type\": \"application/json\",\n // },\n // body: JSON.stringify({\n // accountName: argv.account,\n // projectName: argv.project,\n // environmentType: \"development\",\n // }),\n // });\n\n // if (!createDevelopmenEnvironmentResponse.ok) {\n // console.log(await createDevelopmenEnvironmentResponse.json());\n // logger.debug(\n // {\n // status: createDevelopmenEnvironmentResponse.status,\n // statusText: createDevelopmenEnvironmentResponse.statusText,\n // },\n // \"Failed to create a new instance of development environment\"\n // );\n // await printCriticalFailureToConsoleAndExit(\n // \"Failed to create a new development environment. Please try again later.\"\n // );\n // }\n\n // numDevelopmentEnvironments++;\n\n // // Re-fetch\n // const updatedResponse = await fetch(url, {\n // headers: {\n // authorization: `Bearer ${argv.authToken}`,\n // },\n // });\n\n // environmentJsonFromDeveloperAPI = (await updatedResponse.json()) as {\n // data: Environment[];\n // };\n // }\n\n const environments = environmentJsonFromDeveloperAPI.data\n .map((env) => {\n return {\n [prettyPrintEnvironmentPrompt(\n env,\n // TODO: This is hard coded to false for now while we figure out the UX for linking working copies.\n // This is because working copy linking is broken right now.\n false\n )]: env.name,\n };\n })\n .reduce((acc, curr) => {\n return { ...acc, ...curr };\n });\n\n try {\n argv.environment = await select({\n message: \"Select the environment\",\n choices: Object.entries(environments)\n .map(([key, value]) => {\n return {\n name: key,\n value: value,\n };\n })\n .sort((a, b) => a.name.localeCompare(b.name)),\n });\n } catch (error) {\n if (error.isTtyError || error.name === \"ExitPromptError\") {\n process.exit(0);\n }\n logger.trace(\"Failed to select account\", error);\n process.exit(1);\n }\n } else {\n logger.trace(\n {\n status: response.status,\n statusText: response.statusText,\n response: textOrJson(await response.text()),\n },\n \"Failed to request environments for project\"\n );\n await printCriticalFailureToConsoleAndExit(\n \"Error: Failed to request environments for the project.\"\n );\n }\n }\n}\nasync function getGitBranch(argv: { [key: string]: unknown }) {\n let branch: string | undefined;\n const dir = argv.dir;\n if (dir && typeof dir === \"string\") {\n const git = simpleGit({ baseDir: dir });\n const isGitRepo = await git.checkIsRepo();\n if (isGitRepo) {\n // Get the current branch from Git\n const status = await git.status();\n if (!status.current) {\n throw new Error(\"Invalid state: Directory is in detached head state.\");\n }\n branch = status.current.trim();\n\n // @NOTE - gitlab returns HEAD as the current branch when running git.status()\n // https://forum.gitlab.com/t/why-i-cant-get-the-branch-name/72462/6\n if (branch === \"HEAD\") {\n // Fetch remote branches to ensure the latest information\n await git.fetch([\"--all\"]);\n\n const branchCommit = await git.branch([\"-a\"]);\n const branchRef = await git.branch([\n \"-r\",\n \"--contains\",\n branchCommit.current,\n ]);\n if (branchRef && branchRef.all && branchRef.all[0]) {\n const originBranch = branchRef.all[0];\n const cleanOriginBranch = originBranch.replace(/^origin\\//, \"\");\n if (!cleanOriginBranch) {\n throw new Error(\n \"Invalid state: Directory is in detached head state.\"\n );\n }\n branch = cleanOriginBranch.trim();\n }\n }\n }\n }\n return branch;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../src/common/output.ts"],"names":[],"mappings":"AAKA,OAAY,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAS/B,wBAAgB,yBAAyB,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,YAAY,CAAC,EAAE,GAAG,QAwB1E;AAED,wBAAgB,qBAAqB,CAAC,OAAO,CAAC,EAAE,MAAM,OAErD;AAED,wBAAgB,qBAAqB,CAAC,OAAO,CAAC,EAAE,GAAG,QAElD;AAGD,wBAAsB,oCAAoC,CACxD,OAAO,CAAC,EAAE,GAAG,EACb,OAAO,CAAC,EAAE,GAAG,
|
|
1
|
+
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../src/common/output.ts"],"names":[],"mappings":"AAKA,OAAY,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAS/B,wBAAgB,yBAAyB,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,YAAY,CAAC,EAAE,GAAG,QAwB1E;AAED,wBAAgB,qBAAqB,CAAC,OAAO,CAAC,EAAE,MAAM,OAErD;AAED,wBAAgB,qBAAqB,CAAC,OAAO,CAAC,EAAE,GAAG,QAElD;AAGD,wBAAsB,oCAAoC,CACxD,OAAO,CAAC,EAAE,GAAG,EACb,OAAO,CAAC,EAAE,GAAG,iBAad;AAID,wBAAgB,oBAAoB,CAAC,OAAO,CAAC,EAAE,GAAG,QAEjD;AAID,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,GAAG,QAE7C;AAED,wBAAsB,qCAAqC,CACzD,OAAO,CAAC,EAAE,GAAG,EACb,OAAO,CAAC,EAAE,GAAG,iBAUd;AAED,wBAAsB,oCAAoC,CAAC,KAAK,EAAE,GAAG,iBAKpE;AAaD,MAAM,CAAC,OAAO,UAAU,WAAW,SAalC;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,OAOtC;AAED,qBAAa,aAAa;IACxB,KAAK;wBACa,MAAM;wBACN,MAAM;yBACL,MAAM;MACtB;CACJ"}
|
package/dist/common/output.js
CHANGED
|
@@ -31,6 +31,9 @@ export async function printCriticalFailureToConsoleAndExit(message, spinner) {
|
|
|
31
31
|
else {
|
|
32
32
|
console.error(chalk.bold.red(message));
|
|
33
33
|
}
|
|
34
|
+
Sentry.captureMessage(message, {
|
|
35
|
+
level: "error",
|
|
36
|
+
});
|
|
34
37
|
await Sentry.close(MAX_WAIT_PENDING_TIME_MS).then(() => {
|
|
35
38
|
process.exit(1);
|
|
36
39
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"output.js","sourceRoot":"","sources":["../../src/common/output.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,MAAM,MAAM,cAAc,CAAC;AACvC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,GAAY,MAAM,KAAK,CAAC;AAC/B,OAAO,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAE1D,MAAM,MAAM,GAAG,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;AAMzC,MAAM,UAAU,yBAAyB,CAAC,OAAa,EAAE,YAAkB;IACzE,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAExC,IACE,YAAY;QACZ,OAAO,YAAY,KAAK,QAAQ;QAChC,QAAQ,IAAI,YAAY;QACxB,OAAO,YAAY,CAAC,MAAM,KAAK,QAAQ,EACvC,CAAC;QAED,OAAO,CAAC,KAAK,CACX,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,YAAY,EAAE,IAAI,EAAE,CA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OAAO,EAAE,EAAE,CAAC;QACZ,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,MAAM,OAAO,aAAa;IACxB,KAAK,GAAG,GAAG,EAAE,CAAC,CAAC;QACb,IAAI,EAAE,CAAC,OAAe,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC;QAC/C,IAAI,EAAE,CAAC,OAAe,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC;QAChD,KAAK,EAAE,CAAC,OAAe,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC;KACnD,CAAC,CAAC;CACJ","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable no-console */\n\nimport * as Sentry from \"@sentry/node\";\nimport chalk from \"chalk\";\nimport ora, { Ora } from \"ora\";\nimport { MAX_WAIT_PENDING_TIME_MS } from \"./constants.js\";\n\nconst indent = ` ${chalk.gray(\"|\")} `;\n\n// We standardize printing to the terminal with this module\n\n// According to https://unix.stackexchange.com/questions/331611/do-progress-reports-logging-information-belong-on-stderr-or-stdout\n// any diagnostic information should go to stderr, and only the actual output goes to stdout\nexport function printDiagnosticsToConsole(message?: any, maybeProblem?: any) {\n console.error(chalk.bold.blue(message));\n\n if (\n maybeProblem &&\n typeof maybeProblem === \"object\" &&\n \"detail\" in maybeProblem &&\n typeof maybeProblem.detail === \"string\"\n ) {\n // The details are better to log if we have it\n console.error(\n indent + chalk.bold.red(JSON.stringify(maybeProblem, null, 2))\n );\n } else if (\n maybeProblem &&\n typeof maybeProblem === \"object\" &&\n \"title\" in maybeProblem &&\n typeof maybeProblem.title === \"string\"\n ) {\n // If we dont have details then log the title\n console.error(\n indent + chalk.bold.red(JSON.stringify(maybeProblem.title, null, 2))\n );\n }\n}\n\nexport function printSpinnerToConsole(message?: string) {\n return ora(message).start();\n}\n\nexport function printWarningToConsole(message?: any) {\n console.error(chalk.yellow(message));\n}\n\n// This information is displayed to the user, so it should be actionable.\nexport async function printCriticalFailureToConsoleAndExit(\n message?: any,\n spinner?: Ora\n) {\n if (spinner) {\n spinner?.fail(message);\n } else {\n console.error(chalk.bold.red(message));\n }\n await Sentry.close(MAX_WAIT_PENDING_TIME_MS).then(() => {\n process.exit(1);\n });\n}\n\n// Only use this to output the actual result of a command\n// This outputs to STDOUT, which is reserved for the actual result of a command\nexport function printResultToConsole(message?: any) {\n console.log(chalk.bold.green(message));\n}\n\n// Only use this to output the actual result of a command\n// This outputs to STDOUT, which is reserved for the actual result of a command\nexport function printTableToConsole(table: any) {\n console.table(table);\n}\n\nexport async function printResultToConsoleAndExitGracefully(\n message?: any,\n spinner?: Ora\n) {\n if (spinner) {\n spinner?.succeed(message);\n } else {\n printResultToConsole(message);\n }\n await Sentry.close(MAX_WAIT_PENDING_TIME_MS).then(() => {\n process.exit(0);\n });\n}\n\nexport async function printTableToConsoleAndExitGracefully(table: any) {\n printTableToConsole(table);\n await Sentry.close(MAX_WAIT_PENDING_TIME_MS).then(() => {\n process.exit(0);\n });\n}\n\n// See https://nodejs.org/docs/latest-v18.x/api/process.html#a-note-on-process-io\n// We want to deliberately have STDOUT flush synchronously, so we can pipe the output to another command\n\ninterface WriteStreamWithHandle {\n _handle: {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n setBlocking: Function;\n };\n isTTY: boolean;\n}\n\nexport default function setBlocking() {\n // Deno and browser have no process object:\n if (typeof process === \"undefined\") return;\n [process.stdout, process.stderr].forEach((_stream) => {\n const stream = _stream as any as WriteStreamWithHandle;\n if (\n stream._handle &&\n stream.isTTY &&\n typeof stream._handle.setBlocking === \"function\"\n ) {\n stream._handle.setBlocking(true);\n }\n });\n}\n\nexport function textOrJson(text: string) {\n try {\n return JSON.parse(text);\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n } catch (_e) {\n return text;\n }\n}\n\nexport class ConsoleOutput {\n child = () => ({\n info: (message: string) => console.log(message),\n warn: (message: string) => console.warn(message),\n error: (message: string) => console.error(message),\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"output.js","sourceRoot":"","sources":["../../src/common/output.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,MAAM,MAAM,cAAc,CAAC;AACvC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,GAAY,MAAM,KAAK,CAAC;AAC/B,OAAO,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAE1D,MAAM,MAAM,GAAG,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;AAMzC,MAAM,UAAU,yBAAyB,CAAC,OAAa,EAAE,YAAkB;IACzE,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAExC,IACE,YAAY;QACZ,OAAO,YAAY,KAAK,QAAQ;QAChC,QAAQ,IAAI,YAAY;QACxB,OAAO,YAAY,CAAC,MAAM,KAAK,QAAQ,EACvC,CAAC;QAED,OAAO,CAAC,KAAK,CACX,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAC/D,CAAC;IACJ,CAAC;SAAM,IACL,YAAY;QACZ,OAAO,YAAY,KAAK,QAAQ;QAChC,OAAO,IAAI,YAAY;QACvB,OAAO,YAAY,CAAC,KAAK,KAAK,QAAQ,EACtC,CAAC;QAED,OAAO,CAAC,KAAK,CACX,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CACrE,CAAC;IACJ,CAAC;AACH,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,OAAgB;IACpD,OAAO,GAAG,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,CAAC;AAC9B,CAAC;AAED,MAAM,UAAU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AC;CACJ","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable no-console */\n\nimport * as Sentry from \"@sentry/node\";\nimport chalk from \"chalk\";\nimport ora, { Ora } from \"ora\";\nimport { MAX_WAIT_PENDING_TIME_MS } from \"./constants.js\";\n\nconst indent = ` ${chalk.gray(\"|\")} `;\n\n// We standardize printing to the terminal with this module\n\n// According to https://unix.stackexchange.com/questions/331611/do-progress-reports-logging-information-belong-on-stderr-or-stdout\n// any diagnostic information should go to stderr, and only the actual output goes to stdout\nexport function printDiagnosticsToConsole(message?: any, maybeProblem?: any) {\n console.error(chalk.bold.blue(message));\n\n if (\n maybeProblem &&\n typeof maybeProblem === \"object\" &&\n \"detail\" in maybeProblem &&\n typeof maybeProblem.detail === \"string\"\n ) {\n // The details are better to log if we have it\n console.error(\n indent + chalk.bold.red(JSON.stringify(maybeProblem, null, 2))\n );\n } else if (\n maybeProblem &&\n typeof maybeProblem === \"object\" &&\n \"title\" in maybeProblem &&\n typeof maybeProblem.title === \"string\"\n ) {\n // If we dont have details then log the title\n console.error(\n indent + chalk.bold.red(JSON.stringify(maybeProblem.title, null, 2))\n );\n }\n}\n\nexport function printSpinnerToConsole(message?: string) {\n return ora(message).start();\n}\n\nexport function printWarningToConsole(message?: any) {\n console.error(chalk.yellow(message));\n}\n\n// This information is displayed to the user, so it should be actionable.\nexport async function printCriticalFailureToConsoleAndExit(\n message?: any,\n spinner?: Ora\n) {\n if (spinner) {\n spinner?.fail(message);\n } else {\n console.error(chalk.bold.red(message));\n }\n Sentry.captureMessage(message, {\n level: \"error\",\n });\n await Sentry.close(MAX_WAIT_PENDING_TIME_MS).then(() => {\n process.exit(1);\n });\n}\n\n// Only use this to output the actual result of a command\n// This outputs to STDOUT, which is reserved for the actual result of a command\nexport function printResultToConsole(message?: any) {\n console.log(chalk.bold.green(message));\n}\n\n// Only use this to output the actual result of a command\n// This outputs to STDOUT, which is reserved for the actual result of a command\nexport function printTableToConsole(table: any) {\n console.table(table);\n}\n\nexport async function printResultToConsoleAndExitGracefully(\n message?: any,\n spinner?: Ora\n) {\n if (spinner) {\n spinner?.succeed(message);\n } else {\n printResultToConsole(message);\n }\n await Sentry.close(MAX_WAIT_PENDING_TIME_MS).then(() => {\n process.exit(0);\n });\n}\n\nexport async function printTableToConsoleAndExitGracefully(table: any) {\n printTableToConsole(table);\n await Sentry.close(MAX_WAIT_PENDING_TIME_MS).then(() => {\n process.exit(0);\n });\n}\n\n// See https://nodejs.org/docs/latest-v18.x/api/process.html#a-note-on-process-io\n// We want to deliberately have STDOUT flush synchronously, so we can pipe the output to another command\n\ninterface WriteStreamWithHandle {\n _handle: {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n setBlocking: Function;\n };\n isTTY: boolean;\n}\n\nexport default function setBlocking() {\n // Deno and browser have no process object:\n if (typeof process === \"undefined\") return;\n [process.stdout, process.stderr].forEach((_stream) => {\n const stream = _stream as any as WriteStreamWithHandle;\n if (\n stream._handle &&\n stream.isTTY &&\n typeof stream._handle.setBlocking === \"function\"\n ) {\n stream._handle.setBlocking(true);\n }\n });\n}\n\nexport function textOrJson(text: string) {\n try {\n return JSON.parse(text);\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n } catch (_e) {\n return text;\n }\n}\n\nexport class ConsoleOutput {\n child = () => ({\n info: (message: string) => console.log(message),\n warn: (message: string) => console.warn(message),\n error: (message: string) => console.error(message),\n });\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zuplo/cli",
|
|
3
|
-
"version": "6.57.
|
|
3
|
+
"version": "6.57.19",
|
|
4
4
|
"repository": "https://github.com/zuplo/zuplo",
|
|
5
5
|
"author": "Zuplo, Inc.",
|
|
6
6
|
"type": "module",
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
"@opentelemetry/api": "1.9.0",
|
|
30
30
|
"@sentry/node": "9.22.0",
|
|
31
31
|
"@swc/core": "1.10.18",
|
|
32
|
-
"@zuplo/core": "6.57.
|
|
33
|
-
"@zuplo/openapi-tools": "6.57.
|
|
34
|
-
"@zuplo/runtime": "6.57.
|
|
32
|
+
"@zuplo/core": "6.57.19",
|
|
33
|
+
"@zuplo/openapi-tools": "6.57.19",
|
|
34
|
+
"@zuplo/runtime": "6.57.19",
|
|
35
35
|
"as-table": "1.0.55",
|
|
36
36
|
"chalk": "5.4.1",
|
|
37
37
|
"chokidar": "3.5.3",
|