@supernovaio/cli 2.0.15 → 2.0.16
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/commands/template-upload-docker.d.ts.map +1 -1
- package/dist/commands/template-upload-docker.js +29 -9
- package/dist/commands/template-upload-docker.js.map +1 -1
- package/dist/types/base-command.d.ts.map +1 -1
- package/dist/types/base-command.js +5 -3
- package/dist/types/base-command.js.map +1 -1
- package/dist/types/sentry-command.d.ts.map +1 -1
- package/dist/types/sentry-command.js +6 -3
- package/dist/types/sentry-command.js.map +1 -1
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"template-upload-docker.d.ts","sourceRoot":"","sources":["../../src/commands/template-upload-docker.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,KAAK,CAAA;AAGhC,OAAO,EAAe,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAQ9D,QAAA,MAAM,oBAAoB,gDAAe,CAAA;AAEzC,KAAK,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAA;AAuBhE,MAAM,CAAC,OAAO,OAAO,oBAAqB,SAAQ,aAAa,CAAC,oBAAoB,CAAC;IACnF,OAAgB,IAAI,KAAK;IACzB,OAAgB,WAAW,SAAiD;IAC5E,OAAgB,QAAQ,WAAgE;IACxF,OAAgB,MAAM,EAAE,OAAO,CAAO;IACtC,OAAgB,KAAK;;;;MAapB;IAED,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED,IAAI,YAAY,IAAI,OAAO,CAAC,oBAAoB,CAAC,CAEhD;IAGY,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"template-upload-docker.d.ts","sourceRoot":"","sources":["../../src/commands/template-upload-docker.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,KAAK,CAAA;AAGhC,OAAO,EAAe,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAQ9D,QAAA,MAAM,oBAAoB,gDAAe,CAAA;AAEzC,KAAK,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAA;AAuBhE,MAAM,CAAC,OAAO,OAAO,oBAAqB,SAAQ,aAAa,CAAC,oBAAoB,CAAC;IACnF,OAAgB,IAAI,KAAK;IACzB,OAAgB,WAAW,SAAiD;IAC5E,OAAgB,QAAQ,WAAgE;IACxF,OAAgB,MAAM,EAAE,OAAO,CAAO;IACtC,OAAgB,KAAK;;;;MAapB;IAED,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED,IAAI,YAAY,IAAI,OAAO,CAAC,oBAAoB,CAAC,CAEhD;IAGY,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;YAqDnB,oBAAoB;IAMlC,OAAO,CAAC,cAAc;YAIR,cAAc;YAId,kBAAkB;YAclB,gBAAgB;YAchB,eAAe;YAQf,mBAAmB;CA0BlC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.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 globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="74258b89-1bcd-5ade-b708-d120c59a1edb")}catch(e){}}();
|
|
3
3
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
4
4
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
5
5
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -40,7 +40,7 @@ RUN apt-get update && apt-get install -y curl && apt-get clean && rm -rf /var/li
|
|
|
40
40
|
WORKDIR /home/user
|
|
41
41
|
|
|
42
42
|
COPY . .
|
|
43
|
-
RUN npm i
|
|
43
|
+
RUN npm i && rm .npmrc
|
|
44
44
|
RUN node docker-scripts/extract-private-packages.js
|
|
45
45
|
`;
|
|
46
46
|
export default class TemplateUploadDocker extends SentryCommand {
|
|
@@ -81,6 +81,17 @@ export default class TemplateUploadDocker extends SentryCommand {
|
|
|
81
81
|
else
|
|
82
82
|
throw error;
|
|
83
83
|
}
|
|
84
|
+
if (pkg.supernova?.privateDependencies) {
|
|
85
|
+
this.log(`Following packages will be linked as private dependencies: ${pkg.supernova.privateDependencies}`);
|
|
86
|
+
if (!(await fileExists(path.join(process.cwd(), ".npmrc")))) {
|
|
87
|
+
this.error(`CLI needs private NPM registry access to be able to bundle private dependencies.\n` +
|
|
88
|
+
`Please provide .npmrc file in the root directory and include neccessary access tokens.`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
this.warn(`package.json doesn't contain 'supernova.privateDependencies' declaration.`);
|
|
93
|
+
this.warn(`Dependencies coming from private registries will fail`);
|
|
94
|
+
}
|
|
84
95
|
const buildData = await apiClient.sandboxes.builds.start({
|
|
85
96
|
workspaceId: flags.workspaceId,
|
|
86
97
|
designSystemId: flags.designSystemId,
|
|
@@ -128,19 +139,15 @@ export default class TemplateUploadDocker extends SentryCommand {
|
|
|
128
139
|
});
|
|
129
140
|
process.child.stdin.write(dockerfile);
|
|
130
141
|
process.child.stdin.end();
|
|
131
|
-
|
|
142
|
+
await process;
|
|
132
143
|
action.stop("done");
|
|
133
|
-
console.log(result.stdout);
|
|
134
|
-
console.log(result.stderr);
|
|
135
144
|
}
|
|
136
145
|
async pushDockerImage(buildDir, imageUrl) {
|
|
137
146
|
action.start("⬆️ Uploading docker image to Supernova");
|
|
138
|
-
|
|
147
|
+
await exec(`docker push ${imageUrl}`, {
|
|
139
148
|
cwd: buildDir,
|
|
140
149
|
});
|
|
141
150
|
action.stop("done");
|
|
142
|
-
console.log(result.stdout);
|
|
143
|
-
console.log(result.stderr);
|
|
144
151
|
}
|
|
145
152
|
async remoteTemplateBuild(client, buildId) {
|
|
146
153
|
action.start("📦 Creating template with the image");
|
|
@@ -179,10 +186,23 @@ async function readPackageJson() {
|
|
|
179
186
|
throw new Error(`Error parsing package.json: 'version' must be defined`);
|
|
180
187
|
if (typeof pkg.dependencies !== "object" || pkg.dependencies === null)
|
|
181
188
|
throw new Error(`Error parsing package.json: 'dependencies' must be defined`);
|
|
189
|
+
if (pkg.supernova?.privateDependencies) {
|
|
190
|
+
const privateDependencies = pkg.supernova?.privateDependencies;
|
|
191
|
+
if (!Array.isArray(privateDependencies))
|
|
192
|
+
throw new TypeError(`supernova.privateDependencies must be an array`);
|
|
193
|
+
for (const [i, d] of privateDependencies.entries()) {
|
|
194
|
+
if (typeof d !== "string") {
|
|
195
|
+
throw new TypeError(`supernova.privateDependencies[${i}] must be a string`);
|
|
196
|
+
}
|
|
197
|
+
if (!pkg.dependencies[d]) {
|
|
198
|
+
throw new Error(`Private dependency ${d} is not listed in 'dependencies'`);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
182
202
|
return pkg;
|
|
183
203
|
}
|
|
184
204
|
function imageUrl(build) {
|
|
185
205
|
return `${build.dockerRegistryDomain}${build.build.dockerImagePath}`;
|
|
186
206
|
}
|
|
187
207
|
//# sourceMappingURL=template-upload-docker.js.map
|
|
188
|
-
//# debugId=
|
|
208
|
+
//# debugId=74258b89-1bcd-5ade-b708-d120c59a1edb
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"template-upload-docker.js","sources":["../../src/commands/template-upload-docker.ts"],"sourceRoot":"","sourcesContent":["import { Flags } from \"@oclif/core\"\nimport { action } from \"@oclif/core/ux\"\nimport { SentryTraced } from \"@sentry/nestjs\"\nimport { exec as execCallback } from \"node:child_process\"\nimport * as fs from \"node:fs/promises\"\nimport path from \"node:path\"\nimport { promisify } from \"node:util\"\nimport { z, ZodType } from \"zod\"\nimport fsx from \"fs-extra\"\n\nimport { commonFlags, SentryCommand } from \"../types/index.js\"\n\nimport { DTOSandboxTemplateBuildCreateResponse, SupernovaApiClient } from \"@supernova-studio/client\"\nimport { sleep } from \"../utils/common.js\"\nimport { tmpdir } from \"node:os\"\n\nconst exec = promisify(execCallback)\n\nconst TemplateUploadConfig = z.object({})\n\ntype TemplateUploadConfig = z.infer<typeof TemplateUploadConfig>\n\nasync function fileExists(p: string) {\n try {\n await fs.access(p)\n return true\n } catch {\n return false\n }\n}\n\nconst dockerfile = `\nFROM node:22-slim\n\nRUN apt-get update && apt-get install -y curl && apt-get clean && rm -rf /var/lib/apt/lists/*\n\nWORKDIR /home/user\n\nCOPY . .\nRUN npm i\nRUN node docker-scripts/extract-private-packages.js\n`\n\nexport default class TemplateUploadDocker extends SentryCommand<TemplateUploadConfig> {\n static override args = {}\n static override description = \"Upload custom prototype app sandbox template\"\n static override examples = [\"<%= config.bin %> <%= command.id %> TemplateUploadDocker \"]\n static override hidden: boolean = true\n static override flags = {\n ...commonFlags,\n from: Flags.string({\n char: \"f\",\n description: \"Directory to upload template from, defaults to the current directory\",\n required: false,\n }),\n workspaceId: Flags.string({ char: \"w\", description: \"Workspace ID to upload the template to\", required: true }),\n designSystemId: Flags.string({\n char: \"d\",\n description: \"Design system ID to upload the template to\",\n required: true,\n }),\n }\n\n get commandId(): string {\n return TemplateUploadDocker.id\n }\n\n get configSchema(): ZodType<TemplateUploadConfig> {\n return TemplateUploadConfig\n }\n\n @SentryTraced()\n public async run(): Promise<void> {\n const apiClient = await this.apiClient()\n const { flags } = await this.parse()\n\n // Read package json\n let pkg\n try {\n pkg = await readPackageJson()\n } catch (error) {\n if (error instanceof Error) this.error(`Failed to read or parse package.json: ${error.message}`)\n else throw error\n }\n\n //\n // From here\n //\n\n // Request build\n const buildData = await apiClient.sandboxes.builds.start({\n workspaceId: flags.workspaceId,\n designSystemId: flags.designSystemId,\n name: pkg.name,\n version: pkg.version,\n })\n\n // Build image\n const url = imageUrl(buildData)\n\n await this.validateDockerDaemon()\n const buildDir = await this.createBuildDir()\n\n try {\n await this.prepareBuildFolder(buildDir)\n await this.buildDockerImage(buildDir, url)\n await this.pushDockerImage(buildDir, url)\n await this.remoteTemplateBuild(apiClient, buildData.build.id)\n\n this.log(`✅ Template has been successfully uploaded`)\n } finally {\n await this.deleteBuildDir(buildDir)\n }\n }\n\n private async validateDockerDaemon() {\n await exec(\"docker info\").catch(() => {\n this.error(`Docker is not available, please start docker daemon and try again`)\n })\n }\n\n private createBuildDir(): Promise<string> {\n return fs.mkdtemp(path.join(tmpdir(), \"supernova-template-bundle-\"))\n }\n\n private async deleteBuildDir(buildDir: string) {\n await fs.rm(buildDir, { recursive: true, force: true })\n }\n\n private async prepareBuildFolder(buildDir: string) {\n // Move working directory to temp folder from where it will be built\n await fsx.copy(process.cwd(), buildDir, {\n filter(src) {\n return !src.includes(\"node_modules/\") && !src.includes(\".git/\") && !src.includes(\".out/\")\n },\n })\n\n // Inject Supernova scripts\n const cliSrcPath = path.resolve(path.dirname(new URL(import.meta.url).pathname), \"..\")\n\n await fsx.copy(path.join(cliSrcPath, \"docker-scripts\"), path.join(buildDir, \"docker-scripts\"))\n }\n\n private async buildDockerImage(buildDir: string, imageUrl: string) {\n action.start(\"🔨 Building docker image\")\n\n const process = exec(`docker build --progress=plain -t ${imageUrl} --pull --platform linux/amd64 -f - .`, {\n cwd: buildDir,\n })\n process.child.stdin!.write(dockerfile)\n process.child.stdin!.end()\n\n const result = await process\n\n action.stop(\"done\")\n\n console.log(result.stdout)\n console.log(result.stderr)\n }\n\n private async pushDockerImage(buildDir: string, imageUrl: string) {\n action.start(\"⬆️ Uploading docker image to Supernova\")\n const result = await exec(`docker push ${imageUrl}`, {\n cwd: buildDir,\n })\n action.stop(\"done\")\n\n console.log(result.stdout)\n console.log(result.stderr)\n }\n\n private async remoteTemplateBuild(client: SupernovaApiClient, buildId: string) {\n // Poll every 2 seconds for roughly 5 minutes\n action.start(\"📦 Creating template with the image\")\n\n // Trigger remote build phase\n await client.sandboxes.builds.finalize(buildId)\n\n // Await remote build\n const pollIntervalMs = 2000\n const timeoutMs = 5 * 60 * 1000\n\n const startTime = Date.now()\n\n let build\n do {\n await sleep(pollIntervalMs)\n build = (await client.sandboxes.builds.get(buildId)).build\n } while (build.state === \"Building\" && Date.now() - startTime < timeoutMs)\n\n // Verify build state\n if (build.state !== \"Success\") {\n this.error(`Template creation failed`)\n }\n\n action.stop(\"done\")\n }\n}\n\ntype PackageJson = { name: string; version: string; dependencies: Record<string, string> }\n\nasync function readPackageJson(): Promise<PackageJson> {\n const pkgPath = path.join(process.cwd(), \"package.json\")\n\n if (!(await fileExists(pkgPath))) throw new Error(`package.json file was not found in the current directory`)\n\n const raw = await fs.readFile(pkgPath, \"utf8\")\n const pkg = JSON.parse(raw)\n\n if (typeof pkg !== \"object\" || pkg === null) throw new Error(`Error parsing package.json: not a json`)\n\n if (typeof pkg.name !== \"string\") throw new Error(`Error parsing package.json: 'name' must be defined`)\n if (typeof pkg.version !== \"string\") throw new Error(`Error parsing package.json: 'version' must be defined`)\n if (typeof pkg.dependencies !== \"object\" || pkg.dependencies === null)\n throw new Error(`Error parsing package.json: 'dependencies' must be defined`)\n\n return pkg\n}\n\nfunction imageUrl(build: DTOSandboxTemplateBuildCreateResponse) {\n return `${build.dockerRegistryDomain}${build.build.dockerImagePath}`\n}\n"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,IAAI,IAAI,YAAY,EAAE,MAAM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M,CAAC,CAAA;IAC9C,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAE3B,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAA;IAEtG,IAAI,OAAO,GAAG,CAAC,IAAI,KAAK,QAAQ;QAAE,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAA;IACvG,IAAI,OAAO,GAAG,CAAC,OAAO,KAAK,QAAQ;QAAE,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAA;IAC7G,IAAI,OAAO,GAAG,CAAC,YAAY,KAAK,QAAQ,IAAI,GAAG,CAAC,YAAY,KAAK,IAAI;QACnE,MAAM,IAAI,KAAK,CAAC,4DAA4D,CAAC,CAAA;IAE/E,OAAO,GAAG,CAAA;AACZ,CAAC;AAED,SAAS,QAAQ,CAAC,KAA4C;IAC5D,OAAO,GAAG,KAAK,CAAC,oBAAoB,GAAG,KAAK,CAAC,KAAK,CAAC,eAAe,EAAE,CAAA;AACtE,CAAC","debug_id":"6eb6eb61-932b-5a32-84c1-8a9f053cd157"}
|
|
1
|
+
{"version":3,"file":"template-upload-docker.js","sources":["../../src/commands/template-upload-docker.ts"],"sourceRoot":"","sourcesContent":["import { Flags } from \"@oclif/core\"\nimport { action } from \"@oclif/core/ux\"\nimport { SentryTraced } from \"@sentry/nestjs\"\nimport { exec as execCallback } from \"node:child_process\"\nimport * as fs from \"node:fs/promises\"\nimport path from \"node:path\"\nimport { promisify } from \"node:util\"\nimport { z, ZodType } from \"zod\"\nimport fsx from \"fs-extra\"\n\nimport { commonFlags, SentryCommand } from \"../types/index.js\"\n\nimport { DTOSandboxTemplateBuildCreateResponse, SupernovaApiClient } from \"@supernova-studio/client\"\nimport { sleep } from \"../utils/common.js\"\nimport { tmpdir } from \"node:os\"\n\nconst exec = promisify(execCallback)\n\nconst TemplateUploadConfig = z.object({})\n\ntype TemplateUploadConfig = z.infer<typeof TemplateUploadConfig>\n\nasync function fileExists(p: string) {\n try {\n await fs.access(p)\n return true\n } catch {\n return false\n }\n}\n\nconst dockerfile = `\nFROM node:22-slim\n\nRUN apt-get update && apt-get install -y curl && apt-get clean && rm -rf /var/lib/apt/lists/*\n\nWORKDIR /home/user\n\nCOPY . .\nRUN npm i && rm .npmrc\nRUN node docker-scripts/extract-private-packages.js\n`\n\nexport default class TemplateUploadDocker extends SentryCommand<TemplateUploadConfig> {\n static override args = {}\n static override description = \"Upload custom prototype app sandbox template\"\n static override examples = [\"<%= config.bin %> <%= command.id %> TemplateUploadDocker \"]\n static override hidden: boolean = true\n static override flags = {\n ...commonFlags,\n from: Flags.string({\n char: \"f\",\n description: \"Directory to upload template from, defaults to the current directory\",\n required: false,\n }),\n workspaceId: Flags.string({ char: \"w\", description: \"Workspace ID to upload the template to\", required: true }),\n designSystemId: Flags.string({\n char: \"d\",\n description: \"Design system ID to upload the template to\",\n required: true,\n }),\n }\n\n get commandId(): string {\n return TemplateUploadDocker.id\n }\n\n get configSchema(): ZodType<TemplateUploadConfig> {\n return TemplateUploadConfig\n }\n\n @SentryTraced()\n public async run(): Promise<void> {\n const apiClient = await this.apiClient()\n const { flags } = await this.parse()\n\n // Read package json\n let pkg\n try {\n pkg = await readPackageJson()\n } catch (error) {\n if (error instanceof Error) this.error(`Failed to read or parse package.json: ${error.message}`)\n else throw error\n }\n\n if (pkg.supernova?.privateDependencies) {\n this.log(`Following packages will be linked as private dependencies: ${pkg.supernova.privateDependencies}`)\n\n if (!(await fileExists(path.join(process.cwd(), \".npmrc\")))) {\n this.error(\n `CLI needs private NPM registry access to be able to bundle private dependencies.\\n` +\n `Please provide .npmrc file in the root directory and include neccessary access tokens.`,\n )\n }\n } else {\n this.warn(`package.json doesn't contain 'supernova.privateDependencies' declaration.`)\n this.warn(`Dependencies coming from private registries will fail`)\n }\n\n // Request build\n const buildData = await apiClient.sandboxes.builds.start({\n workspaceId: flags.workspaceId,\n designSystemId: flags.designSystemId,\n name: pkg.name,\n version: pkg.version,\n })\n\n // Build image\n const url = imageUrl(buildData)\n\n await this.validateDockerDaemon()\n const buildDir = await this.createBuildDir()\n\n try {\n await this.prepareBuildFolder(buildDir)\n await this.buildDockerImage(buildDir, url)\n await this.pushDockerImage(buildDir, url)\n await this.remoteTemplateBuild(apiClient, buildData.build.id)\n\n this.log(`✅ Template has been successfully uploaded`)\n } finally {\n await this.deleteBuildDir(buildDir)\n }\n }\n\n private async validateDockerDaemon() {\n await exec(\"docker info\").catch(() => {\n this.error(`Docker is not available, please start docker daemon and try again`)\n })\n }\n\n private createBuildDir(): Promise<string> {\n return fs.mkdtemp(path.join(tmpdir(), \"supernova-template-bundle-\"))\n }\n\n private async deleteBuildDir(buildDir: string) {\n await fs.rm(buildDir, { recursive: true, force: true })\n }\n\n private async prepareBuildFolder(buildDir: string) {\n // Move working directory to temp folder from where it will be built\n await fsx.copy(process.cwd(), buildDir, {\n filter(src) {\n return !src.includes(\"node_modules/\") && !src.includes(\".git/\") && !src.includes(\".out/\")\n },\n })\n\n // Inject Supernova scripts\n const cliSrcPath = path.resolve(path.dirname(new URL(import.meta.url).pathname), \"..\")\n\n await fsx.copy(path.join(cliSrcPath, \"docker-scripts\"), path.join(buildDir, \"docker-scripts\"))\n }\n\n private async buildDockerImage(buildDir: string, imageUrl: string) {\n action.start(\"🔨 Building docker image\")\n\n const process = exec(`docker build --progress=plain -t ${imageUrl} --pull --platform linux/amd64 -f - .`, {\n cwd: buildDir,\n })\n process.child.stdin!.write(dockerfile)\n process.child.stdin!.end()\n\n await process\n\n action.stop(\"done\")\n }\n\n private async pushDockerImage(buildDir: string, imageUrl: string) {\n action.start(\"⬆️ Uploading docker image to Supernova\")\n await exec(`docker push ${imageUrl}`, {\n cwd: buildDir,\n })\n action.stop(\"done\")\n }\n\n private async remoteTemplateBuild(client: SupernovaApiClient, buildId: string) {\n // Poll every 2 seconds for roughly 5 minutes\n action.start(\"📦 Creating template with the image\")\n\n // Trigger remote build phase\n await client.sandboxes.builds.finalize(buildId)\n\n // Await remote build\n const pollIntervalMs = 2000\n const timeoutMs = 5 * 60 * 1000\n\n const startTime = Date.now()\n\n let build\n do {\n await sleep(pollIntervalMs)\n build = (await client.sandboxes.builds.get(buildId)).build\n } while (build.state === \"Building\" && Date.now() - startTime < timeoutMs)\n\n // Verify build state\n if (build.state !== \"Success\") {\n this.error(`Template creation failed`)\n }\n\n action.stop(\"done\")\n }\n}\n\ntype PackageJson = {\n name: string\n version: string\n dependencies: Record<string, string>\n supernova:\n | {\n privateDependencies: string[] | undefined\n }\n | undefined\n}\n\nasync function readPackageJson(): Promise<PackageJson> {\n const pkgPath = path.join(process.cwd(), \"package.json\")\n\n if (!(await fileExists(pkgPath))) throw new Error(`package.json file was not found in the current directory`)\n\n const raw = await fs.readFile(pkgPath, \"utf8\")\n const pkg = JSON.parse(raw)\n\n if (typeof pkg !== \"object\" || pkg === null) throw new Error(`Error parsing package.json: not a json`)\n\n if (typeof pkg.name !== \"string\") throw new Error(`Error parsing package.json: 'name' must be defined`)\n if (typeof pkg.version !== \"string\") throw new Error(`Error parsing package.json: 'version' must be defined`)\n if (typeof pkg.dependencies !== \"object\" || pkg.dependencies === null)\n throw new Error(`Error parsing package.json: 'dependencies' must be defined`)\n\n if (pkg.supernova?.privateDependencies) {\n const privateDependencies = pkg.supernova?.privateDependencies\n if (!Array.isArray(privateDependencies)) throw new TypeError(`supernova.privateDependencies must be an array`)\n\n for (const [i, d] of privateDependencies.entries()) {\n if (typeof d !== \"string\") {\n throw new TypeError(`supernova.privateDependencies[${i}] must be a string`)\n }\n\n if (!pkg.dependencies[d]) {\n throw new Error(`Private dependency ${d} is not listed in 'dependencies'`)\n }\n }\n }\n\n return pkg\n}\n\nfunction imageUrl(build: DTOSandboxTemplateBuildCreateResponse) {\n return `${build.dockerRegistryDomain}${build.build.dockerImagePath}`\n}\n"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAA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E,EAAE,CAAC;YACnD,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE,CAAC;gBAC1B,MAAM,IAAI,SAAS,CAAC,iCAAiC,CAAC,oBAAoB,CAAC,CAAA;YAC7E,CAAC;YAED,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC;gBACzB,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,kCAAkC,CAAC,CAAA;YAC5E,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,GAAG,CAAA;AACZ,CAAC;AAED,SAAS,QAAQ,CAAC,KAA4C;IAC5D,OAAO,GAAG,KAAK,CAAC,oBAAoB,GAAG,KAAK,CAAC,KAAK,CAAC,eAAe,EAAE,CAAA;AACtE,CAAC","debug_id":"74258b89-1bcd-5ade-b708-d120c59a1edb"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-command.d.ts","sourceRoot":"","sources":["../../src/types/base-command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAErC,OAAO,EAAmB,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAE9E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAGvB,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAA;AACnE,OAAO,EAAgB,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAK1D,8BAAsB,WAAW,CAAC,CAAC,SAAS,MAAM,CAAE,SAAQ,OAAO;IACjE,SAAS,CAAC,GAAG,EAAE,SAAS,CAAiB;IACzC,SAAS,CAAC,aAAa,yBAAuC;IAC9D,OAAO,CAAC,UAAU,CAAgC;IAElD,QAAQ,KAAK,SAAS,IAAI,MAAM,CAAA;IAChC,QAAQ,KAAK,YAAY,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;cAEzB,SAAS;cAWT,IAAI;
|
|
1
|
+
{"version":3,"file":"base-command.d.ts","sourceRoot":"","sources":["../../src/types/base-command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAErC,OAAO,EAAmB,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAE9E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAGvB,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAA;AACnE,OAAO,EAAgB,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAK1D,8BAAsB,WAAW,CAAC,CAAC,SAAS,MAAM,CAAE,SAAQ,OAAO;IACjE,SAAS,CAAC,GAAG,EAAE,SAAS,CAAiB;IACzC,SAAS,CAAC,aAAa,yBAAuC;IAC9D,OAAO,CAAC,UAAU,CAAgC;IAElD,QAAQ,KAAK,SAAS,IAAI,MAAM,CAAA;IAChC,QAAQ,KAAK,YAAY,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;cAEzB,SAAS;cAWT,IAAI;cAQJ,aAAa,CAAC,cAAc,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;cAY1E,oBAAoB,IAAI,OAAO,CAAC,MAAM,CAAC;cAwCvC,YAAY,CAAC,cAAc,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;cAqBzE,cAAc,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;YAyBvD,MAAM;CAYrB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.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 globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="3c88dddb-c4e4-5734-93dd-f6bf5c033b83")}catch(e){}}();
|
|
3
3
|
import { Command } from "@oclif/core";
|
|
4
4
|
import * as Sentry from "@sentry/node";
|
|
5
5
|
import inquirer from "inquirer";
|
|
@@ -21,7 +21,9 @@ export class BaseCommand extends Command {
|
|
|
21
21
|
}
|
|
22
22
|
async init() {
|
|
23
23
|
await super.init();
|
|
24
|
-
|
|
24
|
+
if (this.env !== "production") {
|
|
25
|
+
this.log(`Using ${this.env} environment`);
|
|
26
|
+
}
|
|
25
27
|
}
|
|
26
28
|
async promptBrandId(designSystemId, versionId) {
|
|
27
29
|
const client = await this.apiClient();
|
|
@@ -105,4 +107,4 @@ export class BaseCommand extends Command {
|
|
|
105
107
|
}
|
|
106
108
|
}
|
|
107
109
|
//# sourceMappingURL=base-command.js.map
|
|
108
|
-
//# debugId=
|
|
110
|
+
//# debugId=3c88dddb-c4e4-5734-93dd-f6bf5c033b83
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-command.js","sources":["../../src/types/base-command.ts"],"sourceRoot":"","sourcesContent":["import { Command } from \"@oclif/core\"\nimport * as Sentry from \"@sentry/node\"\nimport { DTODesignSystem, SupernovaApiClient } from \"@supernova-studio/client\"\nimport inquirer from \"inquirer\"\nimport { z } from \"zod\"\n\nimport { getApiClient } from \"../utils/api-client.js\"\nimport { SupernovaConfigService } from \"../utils/config.service.js\"\nimport { getTargetEnv, TargetEnv } from \"./environment.js\"\n\nconst hasAccess = (role?: DTODesignSystem[\"role\"]) =>\n role && [\"Admin\", \"Contributor\", \"Creator\", \"Owner\"].includes(role)\n\nexport abstract class BaseCommand<T extends object> extends Command {\n protected env: TargetEnv = getTargetEnv()\n protected configService = SupernovaConfigService.getInstance()\n private _apiClient: SupernovaApiClient | undefined\n\n abstract get commandId(): string\n abstract get configSchema(): z.ZodType<T>\n\n protected async apiClient() {\n if (this._apiClient) return this._apiClient\n\n const apiClient = await getApiClient(this.env)\n\n const { user: me } = await apiClient.users.getMe()\n Sentry.setUser({ id: me.id })\n\n return apiClient\n }\n\n protected async init() {\n await super.init()\n this.log(`Using ${this.env} environment`)\n }\n\n protected async promptBrandId(designSystemId: string, versionId?: string): Promise<string> {\n const client = await this.apiClient()\n const brandsEndpoint = client.designSystems.versions.brands\n\n const { brands } = await brandsEndpoint.list(designSystemId, versionId ?? \"head\")\n\n const options = brands.map(b => ({ name: b.meta.name, value: b.persistentId }))\n if (options.length === 1) return options[0].value\n\n return this.prompt(\"Select a brand:\", options)\n }\n\n protected async promptDesignSystemId(): Promise<string> {\n const { designSystems: client } = await this.apiClient()\n const { designSystems, workspaces } = await client.listUserDesignSystems()\n const workspaceById = new Map(workspaces.map(ws => [ws.id, ws]))\n const dsNameCount = designSystems.reduce((acc, { meta: { name }, role }) => {\n if (hasAccess(role)) acc.set(name, (acc.get(name) ?? 0) + 1)\n\n return acc\n }, new Map<string, number>())\n\n if (designSystems.length === 0) {\n this.error(\"You don't have any design system.\")\n }\n\n const dsIds = designSystems\n .sort(({ meta: { name: a } }, { meta: { name: b } }) => a.localeCompare(b))\n .map(({ id, meta: { name }, role, workspaceId }) => ({\n id,\n name: (dsNameCount.get(name) ?? 0) > 1 ? `${name} (${workspaceById.get(workspaceId)?.profile?.name})` : name,\n role,\n }))\n .filter(({ role }) => hasAccess(role))\n\n if (dsIds.length === 0) {\n this.error(\"You don't have access to any design system.\")\n }\n\n if (dsIds.length === 1) {\n return dsIds[0].id\n }\n\n return this.prompt(\n \"Select a design system:\",\n dsIds.map(({ id, name }) => ({\n name,\n value: id,\n })),\n )\n }\n\n protected async getVersionId(designSystemId: string, versionId?: string): Promise<string> {\n if (versionId) return versionId\n const { versions } = (await this.apiClient()).designSystems\n const verIds = (await versions.list(designSystemId)).designSystemVersions.map(({ id, meta: { name } }) => ({\n id,\n name,\n }))\n\n if (verIds.length === 1) {\n return verIds[0].id\n }\n\n return this.prompt(\n \"Select a version:\",\n verIds.map(wrk => ({\n name: wrk.name,\n value: wrk.id,\n })),\n )\n }\n\n protected async getWorkspaceId(workspaceId?: string): Promise<string> {\n if (workspaceId) return workspaceId\n const { workspaces } = await this.apiClient()\n const wrks = (await workspaces.list()).membership.map(\n ({\n workspace: {\n id,\n profile: { name },\n },\n }) => ({ id, name }),\n )\n\n if (wrks.length === 1) {\n return wrks[0].id\n }\n\n return this.prompt(\n \"Select a workspace:\",\n wrks.map(wrk => ({\n name: wrk.name,\n value: wrk.id,\n })),\n )\n }\n\n private async prompt(message: string, choices: { name: string; value: string }[]) {\n const choice = await inquirer.prompt([\n {\n choices: [...choices, { name: \"Exit\", value: \"exit\" }],\n message,\n name: \"selected\",\n type: \"list\",\n },\n ])\n\n return choice.selected as string\n }\n}\n"],"names":[],"mappings":";;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AACrC,OAAO,KAAK,MAAM,MAAM,cAAc,CAAA;AAEtC,OAAO,QAAQ,MAAM,UAAU,CAAA;AAG/B,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AACrD,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAA;AACnE,OAAO,EAAE,YAAY,EAAa,MAAM,kBAAkB,CAAA;AAE1D,MAAM,SAAS,GAAG,CAAC,IAA8B,EAAE,EAAE,CACnD,IAAI,IAAI,CAAC,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;AAErE,MAAM,OAAgB,WAA8B,SAAQ,OAAO;IACvD,GAAG,GAAc,YAAY,EAAE,CAAA;IAC/B,aAAa,GAAG,sBAAsB,CAAC,WAAW,EAAE,CAAA;IACtD,UAAU,CAAgC;IAKxC,KAAK,CAAC,SAAS;QACvB,IAAI,IAAI,CAAC,UAAU;YAAE,OAAO,IAAI,CAAC,UAAU,CAAA;QAE3C,MAAM,SAAS,GAAG,MAAM,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QAE9C,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,MAAM,SAAS,CAAC,KAAK,CAAC,KAAK,EAAE,CAAA;QAClD,MAAM,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAA;QAE7B,OAAO,SAAS,CAAA;IAClB,CAAC;IAES,KAAK,CAAC,IAAI;QAClB,MAAM,KAAK,CAAC,IAAI,EAAE,CAAA;
|
|
1
|
+
{"version":3,"file":"base-command.js","sources":["../../src/types/base-command.ts"],"sourceRoot":"","sourcesContent":["import { Command } from \"@oclif/core\"\nimport * as Sentry from \"@sentry/node\"\nimport { DTODesignSystem, SupernovaApiClient } from \"@supernova-studio/client\"\nimport inquirer from \"inquirer\"\nimport { z } from \"zod\"\n\nimport { getApiClient } from \"../utils/api-client.js\"\nimport { SupernovaConfigService } from \"../utils/config.service.js\"\nimport { getTargetEnv, TargetEnv } from \"./environment.js\"\n\nconst hasAccess = (role?: DTODesignSystem[\"role\"]) =>\n role && [\"Admin\", \"Contributor\", \"Creator\", \"Owner\"].includes(role)\n\nexport abstract class BaseCommand<T extends object> extends Command {\n protected env: TargetEnv = getTargetEnv()\n protected configService = SupernovaConfigService.getInstance()\n private _apiClient: SupernovaApiClient | undefined\n\n abstract get commandId(): string\n abstract get configSchema(): z.ZodType<T>\n\n protected async apiClient() {\n if (this._apiClient) return this._apiClient\n\n const apiClient = await getApiClient(this.env)\n\n const { user: me } = await apiClient.users.getMe()\n Sentry.setUser({ id: me.id })\n\n return apiClient\n }\n\n protected async init() {\n await super.init()\n\n if (this.env !== \"production\") {\n this.log(`Using ${this.env} environment`)\n }\n }\n\n protected async promptBrandId(designSystemId: string, versionId?: string): Promise<string> {\n const client = await this.apiClient()\n const brandsEndpoint = client.designSystems.versions.brands\n\n const { brands } = await brandsEndpoint.list(designSystemId, versionId ?? \"head\")\n\n const options = brands.map(b => ({ name: b.meta.name, value: b.persistentId }))\n if (options.length === 1) return options[0].value\n\n return this.prompt(\"Select a brand:\", options)\n }\n\n protected async promptDesignSystemId(): Promise<string> {\n const { designSystems: client } = await this.apiClient()\n const { designSystems, workspaces } = await client.listUserDesignSystems()\n const workspaceById = new Map(workspaces.map(ws => [ws.id, ws]))\n const dsNameCount = designSystems.reduce((acc, { meta: { name }, role }) => {\n if (hasAccess(role)) acc.set(name, (acc.get(name) ?? 0) + 1)\n\n return acc\n }, new Map<string, number>())\n\n if (designSystems.length === 0) {\n this.error(\"You don't have any design system.\")\n }\n\n const dsIds = designSystems\n .sort(({ meta: { name: a } }, { meta: { name: b } }) => a.localeCompare(b))\n .map(({ id, meta: { name }, role, workspaceId }) => ({\n id,\n name: (dsNameCount.get(name) ?? 0) > 1 ? `${name} (${workspaceById.get(workspaceId)?.profile?.name})` : name,\n role,\n }))\n .filter(({ role }) => hasAccess(role))\n\n if (dsIds.length === 0) {\n this.error(\"You don't have access to any design system.\")\n }\n\n if (dsIds.length === 1) {\n return dsIds[0].id\n }\n\n return this.prompt(\n \"Select a design system:\",\n dsIds.map(({ id, name }) => ({\n name,\n value: id,\n })),\n )\n }\n\n protected async getVersionId(designSystemId: string, versionId?: string): Promise<string> {\n if (versionId) return versionId\n const { versions } = (await this.apiClient()).designSystems\n const verIds = (await versions.list(designSystemId)).designSystemVersions.map(({ id, meta: { name } }) => ({\n id,\n name,\n }))\n\n if (verIds.length === 1) {\n return verIds[0].id\n }\n\n return this.prompt(\n \"Select a version:\",\n verIds.map(wrk => ({\n name: wrk.name,\n value: wrk.id,\n })),\n )\n }\n\n protected async getWorkspaceId(workspaceId?: string): Promise<string> {\n if (workspaceId) return workspaceId\n const { workspaces } = await this.apiClient()\n const wrks = (await workspaces.list()).membership.map(\n ({\n workspace: {\n id,\n profile: { name },\n },\n }) => ({ id, name }),\n )\n\n if (wrks.length === 1) {\n return wrks[0].id\n }\n\n return this.prompt(\n \"Select a workspace:\",\n wrks.map(wrk => ({\n name: wrk.name,\n value: wrk.id,\n })),\n )\n }\n\n private async prompt(message: string, choices: { name: string; value: string }[]) {\n const choice = await inquirer.prompt([\n {\n choices: [...choices, { name: \"Exit\", value: \"exit\" }],\n message,\n name: \"selected\",\n type: \"list\",\n },\n ])\n\n return choice.selected as string\n }\n}\n"],"names":[],"mappings":";;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AACrC,OAAO,KAAK,MAAM,MAAM,cAAc,CAAA;AAEtC,OAAO,QAAQ,MAAM,UAAU,CAAA;AAG/B,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AACrD,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAA;AACnE,OAAO,EAAE,YAAY,EAAa,MAAM,kBAAkB,CAAA;AAE1D,MAAM,SAAS,GAAG,CAAC,IAA8B,EAAE,EAAE,CACnD,IAAI,IAAI,CAAC,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;AAErE,MAAM,OAAgB,WAA8B,SAAQ,OAAO;IACvD,GAAG,GAAc,YAAY,EAAE,CAAA;IAC/B,aAAa,GAAG,sBAAsB,CAAC,WAAW,EAAE,CAAA;IACtD,UAAU,CAAgC;IAKxC,KAAK,CAAC,SAAS;QACvB,IAAI,IAAI,CAAC,UAAU;YAAE,OAAO,IAAI,CAAC,UAAU,CAAA;QAE3C,MAAM,SAAS,GAAG,MAAM,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QAE9C,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,MAAM,SAAS,CAAC,KAAK,CAAC,KAAK,EAAE,CAAA;QAClD,MAAM,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAA;QAE7B,OAAO,SAAS,CAAA;IAClB,CAAC;IAES,KAAK,CAAC,IAAI;QAClB,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,EAAE,UAAU,EAAE,GAAG,MAAM,IAAI,CAAC,SAAS,EAAE,CAAA;QAC7C,MAAM,IAAI,GAAG,CAAC,MAAM,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC,UAAU,CAAC,GAAG,CACnD,CAAC,EACC,SAAS,EAAE,EACT,EAAE,EACF,OAAO,EAAE,EAAE,IAAI,EAAE,GAClB,GACF,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CACrB,CAAA;QAED,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACtB,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;QACnB,CAAC;QAED,OAAO,IAAI,CAAC,MAAM,CAChB,qBAAqB,EACrB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YACf,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,KAAK,EAAE,GAAG,CAAC,EAAE;SACd,CAAC,CAAC,CACJ,CAAA;IACH,CAAC;IAEO,KAAK,CAAC,MAAM,CAAC,OAAe,EAAE,OAA0C;QAC9E,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,MAAM,CAAC;YACnC;gBACE,OAAO,EAAE,CAAC,GAAG,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;gBACtD,OAAO;gBACP,IAAI,EAAE,UAAU;gBAChB,IAAI,EAAE,MAAM;aACb;SACF,CAAC,CAAA;QAEF,OAAO,MAAM,CAAC,QAAkB,CAAA;IAClC,CAAC;CACF","debug_id":"3c88dddb-c4e4-5734-93dd-f6bf5c033b83"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sentry-command.d.ts","sourceRoot":"","sources":["../../src/types/sentry-command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAC3C,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AAG1E,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAA;AAI5E,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"sentry-command.d.ts","sourceRoot":"","sources":["../../src/types/sentry-command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAC3C,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AAG1E,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAA;AAI5E,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAI/C,8BAAsB,aAAa,CAAC,CAAC,SAAS,MAAM,CAAE,SAAQ,WAAW,CAAC,CAAC,CAAC;IAC1E,SAAS,aAAa,IAAI,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM;IAI9C,KAAK,CAAC,KAAK,EAAE,YAAY,GAAG;QAAE,KAAK,CAAC,EAAE;YAAE,IAAI,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE;IA0BxD,OAAO;IAEA,KAAK,CAAC,CAAC,SAAS,UAAU,EAAE,CAAC,SAAS,UAAU,EAAE,CAAC,SAAS,SAAS,EAChF,OAAO,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EACxB,IAAI,CAAC,EAAE,MAAM,EAAE,GACd,OAAO,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;CAgClC"}
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.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 globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="5fd0eafb-6347-5ea5-9e64-049c2e4820a4")}catch(e){}}();
|
|
3
3
|
import * as Sentry from "@sentry/node";
|
|
4
4
|
import { isAxiosError } from "axios";
|
|
5
5
|
import { BaseCommand } from "./base-command.js";
|
|
6
6
|
import { NotAuthorizedError } from "./not-authorized.error.js";
|
|
7
|
+
import { CLIError } from "@oclif/core/errors";
|
|
7
8
|
export class SentryCommand extends BaseCommand {
|
|
8
9
|
constructor(argv, config) {
|
|
9
10
|
super(argv, config);
|
|
10
11
|
}
|
|
11
12
|
async catch(error) {
|
|
12
|
-
|
|
13
|
+
if (!(error instanceof CLIError)) {
|
|
14
|
+
this.logToStderr(error.message);
|
|
15
|
+
}
|
|
13
16
|
if (error.oclif)
|
|
14
17
|
throw error;
|
|
15
18
|
if (error instanceof NotAuthorizedError)
|
|
@@ -60,4 +63,4 @@ export class SentryCommand extends BaseCommand {
|
|
|
60
63
|
}
|
|
61
64
|
}
|
|
62
65
|
//# sourceMappingURL=sentry-command.js.map
|
|
63
|
-
//# debugId=
|
|
66
|
+
//# debugId=5fd0eafb-6347-5ea5-9e64-049c2e4820a4
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sentry-command.js","sources":["../../src/types/sentry-command.ts"],"sourceRoot":"","sourcesContent":["import { Config } from \"@oclif/core/config\"\nimport { CommandError, Input, ParserOutput } from \"@oclif/core/interfaces\"\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-expect-error\nimport { ArgOutput, FlagOutput } from \"@oclif/core/lib/interfaces/parser.js\"\nimport * as Sentry from \"@sentry/node\"\nimport { isAxiosError } from \"axios\"\n\nimport { BaseCommand } from \"./base-command.js\"\nimport { NotAuthorizedError } from \"./not-authorized.error.js\"\n\nexport abstract class SentryCommand<T extends object> extends BaseCommand<T> {\n protected constructor(argv: string[], config: Config) {\n super(argv, config)\n }\n\n async catch(error: CommandError & { oclif?: { exit: number } }) {\n this.logToStderr(error.message)\n if (error.oclif) throw error\n if (error instanceof NotAuthorizedError) throw error\n\n if (isAxiosError(error)) {\n const captureMetadata = {\n code: error.code,\n message: error.message,\n response: {\n status: error.response?.status,\n data: error.response?.data,\n },\n }\n\n Sentry.captureMessage(`Axios error metadata: ${JSON.stringify(captureMetadata)}`)\n }\n\n Sentry.captureException(error)\n this.logToStderr(`Something went wrong. Please try again later.`)\n }\n\n async finally() {}\n\n public async parse<F extends FlagOutput, B extends FlagOutput, A extends ArgOutput>(\n options?: Input<F, B, A>,\n argv?: string[],\n ): Promise<ParserOutput<F, B, A>> {\n Sentry.addBreadcrumb({\n category: \"command\",\n data: {\n commandName: this.id,\n },\n level: \"debug\",\n message: \"Starting command parse\",\n })\n\n const parsed = await super.parse(options, argv)\n const span = Sentry.getActiveSpan()\n if (span) {\n span.setAttributes({\n args: Object.keys(parsed.args),\n designSystemId: parsed.flags.designSystemId,\n flags: Object.keys(parsed.flags),\n workspaceId: parsed.flags.workspaceId,\n })\n }\n\n Sentry.addBreadcrumb({\n category: \"command\",\n data: {\n result: \"success\",\n },\n level: \"debug\",\n message: \"Command parse completed\",\n })\n\n return parsed\n }\n}\n"],"names":[],"mappings":";;AAKA,OAAO,KAAK,MAAM,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AAEpC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;
|
|
1
|
+
{"version":3,"file":"sentry-command.js","sources":["../../src/types/sentry-command.ts"],"sourceRoot":"","sourcesContent":["import { Config } from \"@oclif/core/config\"\nimport { CommandError, Input, ParserOutput } from \"@oclif/core/interfaces\"\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-expect-error\nimport { ArgOutput, FlagOutput } from \"@oclif/core/lib/interfaces/parser.js\"\nimport * as Sentry from \"@sentry/node\"\nimport { isAxiosError } from \"axios\"\n\nimport { BaseCommand } from \"./base-command.js\"\nimport { NotAuthorizedError } from \"./not-authorized.error.js\"\nimport { CLIError } from \"@oclif/core/errors\"\n\nexport abstract class SentryCommand<T extends object> extends BaseCommand<T> {\n protected constructor(argv: string[], config: Config) {\n super(argv, config)\n }\n\n async catch(error: CommandError & { oclif?: { exit: number } }) {\n if (!(error instanceof CLIError)) {\n // Invocations of `this.error(...)` from command classes will already be logged, no need to repeat\n this.logToStderr(error.message)\n }\n\n if (error.oclif) throw error\n if (error instanceof NotAuthorizedError) throw error\n\n if (isAxiosError(error)) {\n const captureMetadata = {\n code: error.code,\n message: error.message,\n response: {\n status: error.response?.status,\n data: error.response?.data,\n },\n }\n\n Sentry.captureMessage(`Axios error metadata: ${JSON.stringify(captureMetadata)}`)\n }\n\n Sentry.captureException(error)\n this.logToStderr(`Something went wrong. Please try again later.`)\n }\n\n async finally() {}\n\n public async parse<F extends FlagOutput, B extends FlagOutput, A extends ArgOutput>(\n options?: Input<F, B, A>,\n argv?: string[],\n ): Promise<ParserOutput<F, B, A>> {\n Sentry.addBreadcrumb({\n category: \"command\",\n data: {\n commandName: this.id,\n },\n level: \"debug\",\n message: \"Starting command parse\",\n })\n\n const parsed = await super.parse(options, argv)\n const span = Sentry.getActiveSpan()\n if (span) {\n span.setAttributes({\n args: Object.keys(parsed.args),\n designSystemId: parsed.flags.designSystemId,\n flags: Object.keys(parsed.flags),\n workspaceId: parsed.flags.workspaceId,\n })\n }\n\n Sentry.addBreadcrumb({\n category: \"command\",\n data: {\n result: \"success\",\n },\n level: \"debug\",\n message: \"Command parse completed\",\n })\n\n return parsed\n }\n}\n"],"names":[],"mappings":";;AAKA,OAAO,KAAK,MAAM,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,YAAY,EAAE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