@supernovaio/cli 2.0.14 → 2.0.15
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 +3 -0
- package/dist/commands/template-upload-docker.d.ts.map +1 -1
- package/dist/commands/template-upload-docker.js +40 -11
- package/dist/commands/template-upload-docker.js.map +1 -1
- package/dist/docker-scripts/extract-private-packages.js +74 -0
- package/oclif.manifest.json +1 -1
- package/package.json +4 -2
|
@@ -16,6 +16,9 @@ export default class TemplateUploadDocker extends SentryCommand<TemplateUploadCo
|
|
|
16
16
|
get configSchema(): ZodType<TemplateUploadConfig>;
|
|
17
17
|
run(): Promise<void>;
|
|
18
18
|
private validateDockerDaemon;
|
|
19
|
+
private createBuildDir;
|
|
20
|
+
private deleteBuildDir;
|
|
21
|
+
private prepareBuildFolder;
|
|
19
22
|
private buildDockerImage;
|
|
20
23
|
private pushDockerImage;
|
|
21
24
|
private remoteTemplateBuild;
|
|
@@ -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;
|
|
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;YA2CnB,oBAAoB;IAMlC,OAAO,CAAC,cAAc;YAIR,cAAc;YAId,kBAAkB;YAclB,gBAAgB;YAiBhB,eAAe;YAWf,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]="6eb6eb61-932b-5a32-84c1-8a9f053cd157")}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);
|
|
@@ -17,8 +17,10 @@ import * as fs from "node:fs/promises";
|
|
|
17
17
|
import path from "node:path";
|
|
18
18
|
import { promisify } from "node:util";
|
|
19
19
|
import { z } from "zod";
|
|
20
|
+
import fsx from "fs-extra";
|
|
20
21
|
import { commonFlags, SentryCommand } from "../types/index.js";
|
|
21
22
|
import { sleep } from "../utils/common.js";
|
|
23
|
+
import { tmpdir } from "node:os";
|
|
22
24
|
const exec = promisify(execCallback);
|
|
23
25
|
const TemplateUploadConfig = z.object({});
|
|
24
26
|
async function fileExists(p) {
|
|
@@ -38,7 +40,8 @@ RUN apt-get update && apt-get install -y curl && apt-get clean && rm -rf /var/li
|
|
|
38
40
|
WORKDIR /home/user
|
|
39
41
|
|
|
40
42
|
COPY . .
|
|
41
|
-
RUN
|
|
43
|
+
RUN npm i
|
|
44
|
+
RUN node docker-scripts/extract-private-packages.js
|
|
42
45
|
`;
|
|
43
46
|
export default class TemplateUploadDocker extends SentryCommand {
|
|
44
47
|
static args = {};
|
|
@@ -86,19 +89,43 @@ export default class TemplateUploadDocker extends SentryCommand {
|
|
|
86
89
|
});
|
|
87
90
|
const url = imageUrl(buildData);
|
|
88
91
|
await this.validateDockerDaemon();
|
|
89
|
-
await this.
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
92
|
+
const buildDir = await this.createBuildDir();
|
|
93
|
+
try {
|
|
94
|
+
await this.prepareBuildFolder(buildDir);
|
|
95
|
+
await this.buildDockerImage(buildDir, url);
|
|
96
|
+
await this.pushDockerImage(buildDir, url);
|
|
97
|
+
await this.remoteTemplateBuild(apiClient, buildData.build.id);
|
|
98
|
+
this.log(`✅ Template has been successfully uploaded`);
|
|
99
|
+
}
|
|
100
|
+
finally {
|
|
101
|
+
await this.deleteBuildDir(buildDir);
|
|
102
|
+
}
|
|
93
103
|
}
|
|
94
104
|
async validateDockerDaemon() {
|
|
95
105
|
await exec("docker info").catch(() => {
|
|
96
106
|
this.error(`Docker is not available, please start docker daemon and try again`);
|
|
97
107
|
});
|
|
98
108
|
}
|
|
99
|
-
|
|
109
|
+
createBuildDir() {
|
|
110
|
+
return fs.mkdtemp(path.join(tmpdir(), "supernova-template-bundle-"));
|
|
111
|
+
}
|
|
112
|
+
async deleteBuildDir(buildDir) {
|
|
113
|
+
await fs.rm(buildDir, { recursive: true, force: true });
|
|
114
|
+
}
|
|
115
|
+
async prepareBuildFolder(buildDir) {
|
|
116
|
+
await fsx.copy(process.cwd(), buildDir, {
|
|
117
|
+
filter(src) {
|
|
118
|
+
return !src.includes("node_modules/") && !src.includes(".git/") && !src.includes(".out/");
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
const cliSrcPath = path.resolve(path.dirname(new URL(import.meta.url).pathname), "..");
|
|
122
|
+
await fsx.copy(path.join(cliSrcPath, "docker-scripts"), path.join(buildDir, "docker-scripts"));
|
|
123
|
+
}
|
|
124
|
+
async buildDockerImage(buildDir, imageUrl) {
|
|
100
125
|
action.start("🔨 Building docker image");
|
|
101
|
-
const process = exec(`docker build --progress=plain -t ${imageUrl} --pull --platform linux/amd64 -f -
|
|
126
|
+
const process = exec(`docker build --progress=plain -t ${imageUrl} --pull --platform linux/amd64 -f - .`, {
|
|
127
|
+
cwd: buildDir,
|
|
128
|
+
});
|
|
102
129
|
process.child.stdin.write(dockerfile);
|
|
103
130
|
process.child.stdin.end();
|
|
104
131
|
const result = await process;
|
|
@@ -106,9 +133,11 @@ export default class TemplateUploadDocker extends SentryCommand {
|
|
|
106
133
|
console.log(result.stdout);
|
|
107
134
|
console.log(result.stderr);
|
|
108
135
|
}
|
|
109
|
-
async pushDockerImage(imageUrl) {
|
|
136
|
+
async pushDockerImage(buildDir, imageUrl) {
|
|
110
137
|
action.start("⬆️ Uploading docker image to Supernova");
|
|
111
|
-
const result = await exec(`docker push ${imageUrl}
|
|
138
|
+
const result = await exec(`docker push ${imageUrl}`, {
|
|
139
|
+
cwd: buildDir,
|
|
140
|
+
});
|
|
112
141
|
action.stop("done");
|
|
113
142
|
console.log(result.stdout);
|
|
114
143
|
console.log(result.stderr);
|
|
@@ -156,4 +185,4 @@ function imageUrl(build) {
|
|
|
156
185
|
return `${build.dockerRegistryDomain}${build.build.dockerImagePath}`;
|
|
157
186
|
}
|
|
158
187
|
//# sourceMappingURL=template-upload-docker.js.map
|
|
159
|
-
//# debugId=
|
|
188
|
+
//# debugId=6eb6eb61-932b-5a32-84c1-8a9f053cd157
|
|
@@ -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\"\n\nimport { commonFlags, SentryCommand } from \"../types/index.js\"\n\nimport { DTOSandboxTemplateBuildCreateResponse, SupernovaApiClient } from \"@supernova-studio/client\"\nimport { sleep } from \"../utils/common.js\"\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 rm -rf node_modules && npm i && npm install -g pm2\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 await this.buildDockerImage(url)\n await this.pushDockerImage(url)\n await this.remoteTemplateBuild(apiClient, buildData.build.id)\n\n this.log(`✅ Template has been successfully uploaded`)\n\n // // Create a new build\n\n // try {\n // await buildAndUpload(apiClient, buildData)\n // } catch (e) {\n // // TODO Artem: mark build as failed\n // // TODO Artem: mark\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 async buildDockerImage(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 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(imageUrl: string) {\n action.start(\"⬆️ Uploading docker image to Supernova\")\n const result = await exec(`docker push ${imageUrl}`)\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,oBAAoB,CAAA;AACzD,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACtC,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AACrC,OAAO,EAAE,CAAC,EAAW,MAAM,KAAK,CAAA;AAEhC,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAG9D,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAE1C,MAAM,IAAI,GAAG,SAAS,CAAC,YAAY,CAAC,CAAA;AAEpC,MA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AG,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":"af9409d8-4d1b-519b-a0d8-58e14ea316e3"}
|
|
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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
6
|
+
|
|
7
|
+
;(() => {
|
|
8
|
+
const packageJsonPath = path.join(process.cwd(), "package.json")
|
|
9
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath).toString())
|
|
10
|
+
|
|
11
|
+
const privateDependencies = packageJson.supernova?.privateDependencies
|
|
12
|
+
if (!privateDependencies) return
|
|
13
|
+
if (!Array.isArray(privateDependencies)) {
|
|
14
|
+
throw new TypeError(
|
|
15
|
+
`supernova.privateDependencies must be an array, example: "privateDependencies": ["@example/package"]`,
|
|
16
|
+
)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (privateDependencies.length === 0) return
|
|
20
|
+
|
|
21
|
+
// Validate all private dependencies
|
|
22
|
+
for (const [i, d] of privateDependencies.entries()) {
|
|
23
|
+
if (typeof d !== "string") {
|
|
24
|
+
throw new TypeError(`Invalid value at supernova.privateDependencies[${i}]: '${d}'`)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (!packageJson.dependencies[d]) {
|
|
28
|
+
throw new Error(`Private dependency ${d} must be present in package.json dependencies`)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (!fs.existsSync(getDependencySourceFullPath(d))) {
|
|
32
|
+
throw new Error(`Private dependency ${d} must be present in node_modules`)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
for (const dependency of privateDependencies) {
|
|
37
|
+
// Move the dependency
|
|
38
|
+
const src = getDependencySourceFullPath(dependency)
|
|
39
|
+
const target = getDependencyTargetFullPath(dependency)
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
// Make sure the target directory exists
|
|
43
|
+
fs.mkdirSync(target, { recursive: true })
|
|
44
|
+
|
|
45
|
+
// Copy folder to private-deps
|
|
46
|
+
execSync(`cp -R ${src}/ ${path.dirname(target)}`)
|
|
47
|
+
|
|
48
|
+
// Remove from source
|
|
49
|
+
fs.rmSync(src, { recursive: true })
|
|
50
|
+
} catch (error) {
|
|
51
|
+
console.error(`Couldn't move dependency ${dependency} from ${src} to ${target}`)
|
|
52
|
+
throw error
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Switch dependency from version to file directive
|
|
56
|
+
packageJson.dependencies[dependency] = `file:${getDependencyTargetRelativePath(dependency)}`
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
fs.writeFileSync(packageJsonPath, Buffer.from(JSON.stringify(packageJson, null, 2) + "\n"))
|
|
60
|
+
})()
|
|
61
|
+
|
|
62
|
+
function getDependencySourceFullPath(name) {
|
|
63
|
+
return path.join(process.cwd(), "node_modules", name)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function getDependencyTargetFullPath(name) {
|
|
67
|
+
return path.join(process.cwd(), PRIVATE_DEPS_DIR_NAME, name)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function getDependencyTargetRelativePath(name) {
|
|
71
|
+
return path.join(".", PRIVATE_DEPS_DIR_NAME, name)
|
|
72
|
+
}
|
|
73
|
+
!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]="c8431c5b-b015-5d9d-bdef-9202f73e7f49")}catch(e){}}();
|
|
74
|
+
//# debugId=c8431c5b-b015-5d9d-bdef-9202f73e7f49
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@supernovaio/cli",
|
|
3
3
|
"description": "Supernova.io Command Line Interface",
|
|
4
|
-
"version": "2.0.
|
|
4
|
+
"version": "2.0.15",
|
|
5
5
|
"author": "Supernova.io",
|
|
6
6
|
"bin": {
|
|
7
7
|
"supernova": "./bin/run"
|
|
@@ -21,11 +21,13 @@
|
|
|
21
21
|
"@supernova-studio/pulsar-language": "^2.6.12",
|
|
22
22
|
"@supernovaio/code-analyzer": "^1.0.1-alpha.2",
|
|
23
23
|
"@supernovaio/sdk": "2.0.36",
|
|
24
|
+
"@types/fs-extra": "^11.0.4",
|
|
24
25
|
"adm-zip": "^0.5.16",
|
|
25
26
|
"axios": "^1.8.4",
|
|
26
27
|
"cli-progress": "^3.12.0",
|
|
27
28
|
"colors": "^1.4.0",
|
|
28
29
|
"dotenv": "^16.4.7",
|
|
30
|
+
"fs-extra": "^11.3.2",
|
|
29
31
|
"inquirer": "^12.5.2",
|
|
30
32
|
"ip-cidr": "^4.0.2",
|
|
31
33
|
"jwt-decode": "^4.0.0",
|
|
@@ -130,7 +132,7 @@
|
|
|
130
132
|
},
|
|
131
133
|
"repository": "https://github.com/Supernova-Studio/cli",
|
|
132
134
|
"scripts": {
|
|
133
|
-
"build": "npx shx rm -rf dist && tsc -b",
|
|
135
|
+
"build": "npx shx rm -rf dist && tsc -b && cp -R ./src/docker-scripts ./dist",
|
|
134
136
|
"check-types": "tsc --noEmit",
|
|
135
137
|
"lint": "eslint",
|
|
136
138
|
"lint:ci": "eslint . --quiet",
|