@supernovaio/cli-next 2.3.4-alpha0 → 2.3.6
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/components-import.js +1 -4
- package/dist/commands/components-import.js.map +1 -1
- package/dist/commands/describe-design-system.js +1 -4
- package/dist/commands/describe-design-system.js.map +1 -1
- package/dist/commands/describe-workspaces.js +1 -4
- package/dist/commands/describe-workspaces.js.map +1 -1
- package/dist/commands/login.js +1 -4
- package/dist/commands/login.js.map +1 -1
- package/dist/commands/logout.js +1 -4
- package/dist/commands/logout.js.map +1 -1
- package/dist/commands/publish-documentation.js +1 -4
- package/dist/commands/publish-documentation.js.map +1 -1
- package/dist/commands/storybook-import.d.ts.map +1 -1
- package/dist/commands/storybook-import.js +9 -9
- package/dist/commands/storybook-import.js.map +1 -1
- package/dist/commands/sync-tokens.js +1 -4
- package/dist/commands/sync-tokens.js.map +1 -1
- package/dist/commands/whoami.js +1 -4
- package/dist/commands/whoami.js.map +1 -1
- package/dist/hooks/postrun/save-config.js +1 -4
- package/dist/hooks/postrun/save-config.js.map +1 -1
- package/dist/hooks/prerun/load-config.js +1 -4
- package/dist/hooks/prerun/load-config.js.map +1 -1
- package/dist/hooks/prerun/sentry.js +1 -4
- package/dist/hooks/prerun/sentry.js.map +1 -1
- package/dist/index.js +1 -4
- package/dist/index.js.map +1 -1
- package/dist/services/auth.service.js +1 -4
- package/dist/services/auth.service.js.map +1 -1
- package/dist/services/index.js +1 -4
- package/dist/services/index.js.map +1 -1
- package/dist/services/user.service.js +1 -4
- package/dist/services/user.service.js.map +1 -1
- package/dist/services/vault.service.js +1 -4
- package/dist/services/vault.service.js.map +1 -1
- package/dist/types/base-command.d.ts +1 -0
- package/dist/types/base-command.d.ts.map +1 -1
- package/dist/types/base-command.js +5 -4
- package/dist/types/base-command.js.map +1 -1
- package/dist/types/config.js +1 -4
- package/dist/types/config.js.map +1 -1
- package/dist/types/environment.js +1 -4
- package/dist/types/environment.js.map +1 -1
- package/dist/types/flags.js +1 -4
- package/dist/types/flags.js.map +1 -1
- package/dist/types/index.js +1 -4
- package/dist/types/index.js.map +1 -1
- package/dist/types/login.js +1 -4
- package/dist/types/login.js.map +1 -1
- package/dist/types/not-authorized.error.js +1 -4
- package/dist/types/not-authorized.error.js.map +1 -1
- package/dist/types/sentry-command.js +1 -4
- package/dist/types/sentry-command.js.map +1 -1
- package/dist/types/types.d.ts +0 -14
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/types.js +1 -4
- package/dist/types/types.js.map +1 -1
- package/dist/utils/api-client.js +1 -4
- package/dist/utils/api-client.js.map +1 -1
- package/dist/utils/common.js +1 -4
- package/dist/utils/common.js.map +1 -1
- package/dist/utils/config.service.js +2 -5
- package/dist/utils/config.service.js.map +1 -1
- package/dist/utils/figma-tokens-data-loader.js +1 -4
- package/dist/utils/figma-tokens-data-loader.js.map +1 -1
- package/dist/utils/index.js +1 -4
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/run-exporter/exporter-utils.d.ts +1 -13
- package/dist/utils/run-exporter/exporter-utils.d.ts.map +1 -1
- package/dist/utils/run-exporter/exporter-utils.js +2 -19
- package/dist/utils/run-exporter/exporter-utils.js.map +1 -1
- package/dist/utils/sdk.js +1 -4
- package/dist/utils/sdk.js.map +1 -1
- package/oclif.manifest.json +2 -89
- package/package.json +4 -4
- package/dist/commands/run-local-exporter.d.ts +0 -44
- package/dist/commands/run-local-exporter.d.ts.map +0 -1
- package/dist/commands/run-local-exporter.js +0 -226
- package/dist/commands/run-local-exporter.js.map +0 -1
|
@@ -1,226 +0,0 @@
|
|
|
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]="9d01d59c-5dbf-5f3b-bae6-ace3ba63ece1")}catch(e){}}();
|
|
3
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
4
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
5
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
6
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
7
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
8
|
-
};
|
|
9
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
10
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
11
|
-
};
|
|
12
|
-
import { Flags } from "@oclif/core";
|
|
13
|
-
import { SentryTraced } from "@sentry/nestjs";
|
|
14
|
-
import * as pulsarCoreTypes from "@supernova-studio/pulsar-core";
|
|
15
|
-
import axios from "axios";
|
|
16
|
-
import * as fs from "node:fs";
|
|
17
|
-
import { createRequire } from "node:module";
|
|
18
|
-
import path from "node:path";
|
|
19
|
-
import "colors";
|
|
20
|
-
import { z } from "zod";
|
|
21
|
-
import { SentryCommand } from "../types/index.js";
|
|
22
|
-
import { exportConfiguration } from "../utils/run-exporter/exporter-utils.js";
|
|
23
|
-
import { getWritableVersion } from "../utils/sdk.js";
|
|
24
|
-
const require = createRequire(import.meta.url);
|
|
25
|
-
const pulsarCoreProvider = require("@supernova-studio/pulsar-core");
|
|
26
|
-
const pulsarLanguageProvider = require("@supernova-studio/pulsar-language");
|
|
27
|
-
export class RunLocalExporter extends SentryCommand {
|
|
28
|
-
static aliases;
|
|
29
|
-
static description = "Run local exporter package";
|
|
30
|
-
static examples = [
|
|
31
|
-
`$ @supernovaio/cli run-local-exporter \
|
|
32
|
-
--apiKey="[API_KEY]" \
|
|
33
|
-
--designSystemId="[DESIGN_SYSTEM_ID]" \
|
|
34
|
-
--themeId="[THEME_ID]" \
|
|
35
|
-
--brandId="[BRAND_ID]" \
|
|
36
|
-
--exporterDir="[./path/to/exporter/dir]" \
|
|
37
|
-
--outputDir="[./path/to/output/dir]" \
|
|
38
|
-
--allowOverridingOutput
|
|
39
|
-
`,
|
|
40
|
-
];
|
|
41
|
-
static flags = {
|
|
42
|
-
allowOverridingOutput: Flags.boolean({
|
|
43
|
-
default: false,
|
|
44
|
-
description: "When enabled, CLI will override output in the output directory if same files where present. When disabled, encountering the same file with throw an error.",
|
|
45
|
-
required: false,
|
|
46
|
-
}),
|
|
47
|
-
apiKey: Flags.string({ description: "API key to use for accessing Supernova instance", required: true }),
|
|
48
|
-
brandId: Flags.string({
|
|
49
|
-
description: "Brand to export. Will only be used when exporter has usesBrands: true, but then it is required to be provided",
|
|
50
|
-
required: false,
|
|
51
|
-
}),
|
|
52
|
-
designSystemId: Flags.string({ description: "Design System to export from", required: true }),
|
|
53
|
-
exporterDir: Flags.string({ description: "Path to exporter package", required: true }),
|
|
54
|
-
outputDir: Flags.string({
|
|
55
|
-
description: "Path to output folder. Must be empty, unless `forceClearOutputDir` is set",
|
|
56
|
-
required: true,
|
|
57
|
-
}),
|
|
58
|
-
proxyUrl: Flags.string({
|
|
59
|
-
description: "When set, CLI will use provided proxy URL for all requests",
|
|
60
|
-
hidden: true,
|
|
61
|
-
required: false,
|
|
62
|
-
}),
|
|
63
|
-
themeId: Flags.string({
|
|
64
|
-
description: "Theme to export. Will only be used when exporter has usesThemes: true, and is optional",
|
|
65
|
-
required: false,
|
|
66
|
-
}),
|
|
67
|
-
};
|
|
68
|
-
get commandId() {
|
|
69
|
-
return RunLocalExporter.id;
|
|
70
|
-
}
|
|
71
|
-
get configSchema() {
|
|
72
|
-
return z.object({});
|
|
73
|
-
}
|
|
74
|
-
async executeExporter(flags, versionId) {
|
|
75
|
-
const logger = new pulsarLanguageProvider.PLLogger();
|
|
76
|
-
const pulsarEngine = new pulsarCoreProvider.PCPulsar(pulsarCoreTypes.PCPulsarExporterMode.full, logger);
|
|
77
|
-
try {
|
|
78
|
-
await pulsarEngine.initiateWithLocalFolderURL(flags.exporterDir, pulsarCoreTypes.PCExporterEnvironment.ci);
|
|
79
|
-
const config = exportConfiguration({
|
|
80
|
-
apiKey: flags.apiKey,
|
|
81
|
-
brandId: flags.brandId,
|
|
82
|
-
dsId: flags.designSystemId,
|
|
83
|
-
environment: this.env,
|
|
84
|
-
exportPath: flags.exporterDir,
|
|
85
|
-
logger,
|
|
86
|
-
proxyUrl: flags.proxyUrl,
|
|
87
|
-
themeId: flags.themeId,
|
|
88
|
-
versionId,
|
|
89
|
-
});
|
|
90
|
-
const result = await pulsarEngine.executeExporter(config, false);
|
|
91
|
-
return {
|
|
92
|
-
logger,
|
|
93
|
-
result,
|
|
94
|
-
success: true,
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
catch (error) {
|
|
98
|
-
return {
|
|
99
|
-
logger,
|
|
100
|
-
result: error,
|
|
101
|
-
success: false,
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
async run() {
|
|
106
|
-
const { flags } = await this.parse(RunLocalExporter);
|
|
107
|
-
const { version } = await getWritableVersion(flags);
|
|
108
|
-
const result = await this.executeExporter(flags, version.id);
|
|
109
|
-
if (flags.log) {
|
|
110
|
-
this.logRun(result.logger);
|
|
111
|
-
}
|
|
112
|
-
if (result.success) {
|
|
113
|
-
await this.writeToBuildPath(result.result, flags);
|
|
114
|
-
this.log("Export finished successfully".green);
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
this.error(`Export failed: ${result.result.message}`.red, {
|
|
118
|
-
code: "ERR_EXPORT_FAILED",
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
async downloadFileToMemory(fileUrl) {
|
|
123
|
-
const response = await axios({
|
|
124
|
-
method: "get",
|
|
125
|
-
responseType: "arraybuffer",
|
|
126
|
-
url: fileUrl,
|
|
127
|
-
});
|
|
128
|
-
return Buffer.from(response.data);
|
|
129
|
-
}
|
|
130
|
-
ensureDirectoryExists(filePath, forceLastFragmentIsDirectory = false) {
|
|
131
|
-
if (forceLastFragmentIsDirectory && !filePath.endsWith("/")) {
|
|
132
|
-
filePath += "/";
|
|
133
|
-
}
|
|
134
|
-
if (fs.existsSync(filePath)) {
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
fs.mkdirSync(filePath, { recursive: true });
|
|
138
|
-
}
|
|
139
|
-
logRun(logger) {
|
|
140
|
-
for (const log of logger.logs) {
|
|
141
|
-
let message = log.message.trim();
|
|
142
|
-
if (message.startsWith('"')) {
|
|
143
|
-
message = message.slice(1);
|
|
144
|
-
}
|
|
145
|
-
if (message.endsWith('"')) {
|
|
146
|
-
message = message.slice(0, Math.max(0, message.length - 1));
|
|
147
|
-
}
|
|
148
|
-
console.log(`[user]`.gray + message.white);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
async writeToBuildPath(result, flags) {
|
|
152
|
-
if (!fs.existsSync(flags.outputDir)) {
|
|
153
|
-
this.ensureDirectoryExists(flags.outputDir);
|
|
154
|
-
}
|
|
155
|
-
if (!flags.allowOverridingOutput) {
|
|
156
|
-
for (const file of result.emittedFiles) {
|
|
157
|
-
const destination = path.join(flags.outputDir, file.path);
|
|
158
|
-
if (fs.existsSync(destination)) {
|
|
159
|
-
throw new Error(`Exporter produced file for destination ${destination} but that file already exists. Enable --allowOverridingOutput option to allow overriding`);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
const filesToWrite = [];
|
|
164
|
-
const processFile = async (file) => {
|
|
165
|
-
const filePath = path.join(flags.outputDir, ...file.path.split("/"));
|
|
166
|
-
const fileDirectory = path.dirname(filePath);
|
|
167
|
-
this.ensureDirectoryExists(fileDirectory);
|
|
168
|
-
switch (file.type) {
|
|
169
|
-
case "copy_file": {
|
|
170
|
-
const fileContent = fs.readFileSync(file.content);
|
|
171
|
-
filesToWrite.push({ content: fileContent, filePath });
|
|
172
|
-
break;
|
|
173
|
-
}
|
|
174
|
-
case "copy_file_remote": {
|
|
175
|
-
const fileContent = await this.downloadFileToMemory(file.content);
|
|
176
|
-
filesToWrite.push({ content: fileContent, filePath });
|
|
177
|
-
break;
|
|
178
|
-
}
|
|
179
|
-
case "string": {
|
|
180
|
-
filesToWrite.push({ content: file.content, filePath });
|
|
181
|
-
break;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
};
|
|
185
|
-
const chunkSize = 4;
|
|
186
|
-
for (let i = 0; i < result.emittedFiles.length; i += chunkSize) {
|
|
187
|
-
const chunk = result.emittedFiles.slice(i, i + chunkSize);
|
|
188
|
-
await Promise.all(chunk.map(file => processFile(file)));
|
|
189
|
-
}
|
|
190
|
-
for (const { content, filePath } of filesToWrite) {
|
|
191
|
-
fs.writeFileSync(filePath, content);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
__decorate([
|
|
196
|
-
SentryTraced(),
|
|
197
|
-
__metadata("design:type", Function),
|
|
198
|
-
__metadata("design:paramtypes", [Object, String]),
|
|
199
|
-
__metadata("design:returntype", Promise)
|
|
200
|
-
], RunLocalExporter.prototype, "executeExporter", null);
|
|
201
|
-
__decorate([
|
|
202
|
-
SentryTraced(),
|
|
203
|
-
__metadata("design:type", Function),
|
|
204
|
-
__metadata("design:paramtypes", []),
|
|
205
|
-
__metadata("design:returntype", Promise)
|
|
206
|
-
], RunLocalExporter.prototype, "run", null);
|
|
207
|
-
__decorate([
|
|
208
|
-
SentryTraced(),
|
|
209
|
-
__metadata("design:type", Function),
|
|
210
|
-
__metadata("design:paramtypes", [String]),
|
|
211
|
-
__metadata("design:returntype", Promise)
|
|
212
|
-
], RunLocalExporter.prototype, "downloadFileToMemory", null);
|
|
213
|
-
__decorate([
|
|
214
|
-
SentryTraced(),
|
|
215
|
-
__metadata("design:type", Function),
|
|
216
|
-
__metadata("design:paramtypes", [String, Boolean]),
|
|
217
|
-
__metadata("design:returntype", void 0)
|
|
218
|
-
], RunLocalExporter.prototype, "ensureDirectoryExists", null);
|
|
219
|
-
__decorate([
|
|
220
|
-
SentryTraced(),
|
|
221
|
-
__metadata("design:type", Function),
|
|
222
|
-
__metadata("design:paramtypes", [Object, Object]),
|
|
223
|
-
__metadata("design:returntype", Promise)
|
|
224
|
-
], RunLocalExporter.prototype, "writeToBuildPath", null);
|
|
225
|
-
//# sourceMappingURL=run-local-exporter.js.map
|
|
226
|
-
//# debugId=9d01d59c-5dbf-5f3b-bae6-ace3ba63ece1
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"run-local-exporter.js","sources":["../../src/commands/run-local-exporter.ts"],"sourceRoot":"","sourcesContent":["//\n// run-exporter.ts\n// Supernova CLI\n//\n// Created by Jiri Trecak.\n// Copyright © Supernova.io. All rights reserved.\n//\n\n// --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---\n// MARK: - Imports\n\nimport { Flags } from \"@oclif/core\"\nimport { SentryTraced } from \"@sentry/nestjs\"\nimport * as pulsarCoreTypes from \"@supernova-studio/pulsar-core\"\n// eslint-disable-next-line n/no-extraneous-import\nimport * as pulsarLanguageTypes from \"@supernova-studio/pulsar-language\"\nimport axios from \"axios\"\nimport * as fs from \"node:fs\"\nimport { createRequire } from \"node:module\"\nimport path from \"node:path\"\n// eslint-disable-next-line no-restricted-imports\nimport \"colors\"\nimport { z } from \"zod\"\n\nimport { SentryCommand } from \"../types/index.js\"\nimport { exportConfiguration } from \"../utils/run-exporter/exporter-utils.js\"\nimport { getWritableVersion } from \"../utils/sdk.js\"\n\nconst require = createRequire(import.meta.url)\nconst pulsarCoreProvider = require(\"@supernova-studio/pulsar-core\") as typeof pulsarCoreTypes\nconst pulsarLanguageProvider = require(\"@supernova-studio/pulsar-language\") as typeof pulsarLanguageTypes\n\n// --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---\n// MARK: - Definition\n\ninterface RunLocalExporterFlags {\n allowOverridingOutput: boolean\n apiKey: string\n brandId?: string\n designSystemId: string\n exporterDir: string\n outputDir: string\n proxyUrl?: string\n themeId?: string\n}\n\n// --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---\n// MARK: - Configuration\n\n// --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---\n// MARK: - Tool implementation\n\n/** Command that describes the structure of provided design system */\nexport class RunLocalExporter extends SentryCommand<object> {\n // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---\n // MARK: - Command configuration\n\n // How this command can be run\n static aliases: [\"run-local-exporter\"]\n // Command help description\n static description = \"Run local exporter package\"\n // Examples how to use the command\n static examples = [\n `$ @supernovaio/cli run-local-exporter \\\n --apiKey=\"[API_KEY]\" \\\n --designSystemId=\"[DESIGN_SYSTEM_ID]\" \\\n --themeId=\"[THEME_ID]\" \\\n --brandId=\"[BRAND_ID]\" \\\n --exporterDir=\"[./path/to/exporter/dir]\" \\\n --outputDir=\"[./path/to/output/dir]\" \\\n --allowOverridingOutput\n `,\n ]\n // Static flags to enable / disable features\n static flags = {\n allowOverridingOutput: Flags.boolean({\n default: false,\n description:\n \"When enabled, CLI will override output in the output directory if same files where present. When disabled, encountering the same file with throw an error.\",\n required: false,\n }),\n apiKey: Flags.string({ description: \"API key to use for accessing Supernova instance\", required: true }),\n brandId: Flags.string({\n description:\n \"Brand to export. Will only be used when exporter has usesBrands: true, but then it is required to be provided\",\n required: false,\n }),\n designSystemId: Flags.string({ description: \"Design System to export from\", required: true }),\n exporterDir: Flags.string({ description: \"Path to exporter package\", required: true }),\n outputDir: Flags.string({\n description: \"Path to output folder. Must be empty, unless `forceClearOutputDir` is set\",\n required: true,\n }),\n proxyUrl: Flags.string({\n description: \"When set, CLI will use provided proxy URL for all requests\",\n hidden: true,\n required: false,\n }),\n themeId: Flags.string({\n description: \"Theme to export. Will only be used when exporter has usesThemes: true, and is optional\",\n required: false,\n }),\n }\n\n get commandId(): string {\n return RunLocalExporter.id\n }\n\n get configSchema() {\n return z.object({})\n }\n\n // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---\n // MARK: - Command runtime\n\n @SentryTraced()\n async executeExporter(\n flags: RunLocalExporterFlags,\n versionId: string,\n ): Promise<{\n logger: pulsarLanguageTypes.PLLogger\n result: Error | pulsarCoreTypes.PCEngineExporterProcessingResult\n success: boolean\n }> {\n // Log engine\n const logger = new pulsarLanguageProvider.PLLogger()\n\n // Initialize pulsar engine and export\n const pulsarEngine = new pulsarCoreProvider.PCPulsar(pulsarCoreTypes.PCPulsarExporterMode.full, logger)\n try {\n // Load pulsar with local URL\n await pulsarEngine.initiateWithLocalFolderURL(flags.exporterDir, pulsarCoreTypes.PCExporterEnvironment.ci)\n\n // Prepare configuration\n const config = exportConfiguration({\n apiKey: flags.apiKey,\n brandId: flags.brandId,\n dsId: flags.designSystemId,\n environment: this.env,\n exportPath: flags.exporterDir,\n logger,\n proxyUrl: flags.proxyUrl,\n themeId: flags.themeId,\n versionId,\n })\n\n // Set logo overrides\n const result = await pulsarEngine.executeExporter(config, false)\n return {\n logger,\n result,\n success: true,\n }\n } catch (error) {\n // Return error\n return {\n logger,\n result: error as Error,\n success: false,\n }\n }\n }\n\n @SentryTraced()\n async run(): Promise<void> {\n const { flags } = await this.parse(RunLocalExporter)\n\n // Execute exporter\n // Get workspace -> design system –> version\n const { version } = await getWritableVersion(flags)\n const result = await this.executeExporter(flags, version.id)\n\n // Log user logs from the execution\n // Note this is currently not used because console.log is directly routed to the stdout and we have no control over it. Pulsar must be updated before this is doable\n if (flags.log) {\n this.logRun(result.logger)\n }\n\n if (result.success) {\n // Write result to output\n await this.writeToBuildPath(result.result as pulsarCoreTypes.PCEngineExporterProcessingResult, flags)\n this.log(\"Export finished successfully\".green)\n } else {\n // Catch write error\n this.error(`Export failed: ${(result.result as Error).message}`.red, {\n code: \"ERR_EXPORT_FAILED\",\n })\n }\n }\n\n /** Download file into memory using Axios */\n @SentryTraced()\n private async downloadFileToMemory(fileUrl: string): Promise<Buffer> {\n const response = await axios({\n method: \"get\",\n responseType: \"arraybuffer\",\n url: fileUrl,\n })\n\n return Buffer.from(response.data)\n }\n\n /** Ensure directory exists - if it doesn't create it, recursively */\n @SentryTraced()\n private ensureDirectoryExists(filePath: string, forceLastFragmentIsDirectory: boolean = false) {\n // If the last fragment of path is forced, even paths without / are treated as dirs\n if (forceLastFragmentIsDirectory && !filePath.endsWith(\"/\")) {\n filePath += \"/\"\n }\n\n // Only make directory if it doesn't exist\n if (fs.existsSync(filePath)) {\n return\n }\n\n fs.mkdirSync(filePath, { recursive: true })\n }\n\n /** Log run to output */\n private logRun(logger: pulsarLanguageTypes.PLLogger) {\n for (const log of logger.logs) {\n let message = log.message.trim()\n if (message.startsWith('\"')) {\n message = message.slice(1)\n }\n\n if (message.endsWith('\"')) {\n message = message.slice(0, Math.max(0, message.length - 1))\n }\n\n console.log(`[user]`.gray + message.white)\n }\n }\n\n @SentryTraced()\n private async writeToBuildPath(\n result: pulsarCoreTypes.PCEngineExporterProcessingResult,\n flags: RunLocalExporterFlags,\n ) {\n // Create build directory if it doesn't exist, otherwise keep as it is. It should never be deleted!\n if (!fs.existsSync(flags.outputDir)) {\n this.ensureDirectoryExists(flags.outputDir)\n }\n\n // If overriding is disabled, test every possible file and if it exists, throw an error\n if (!flags.allowOverridingOutput) {\n for (const file of result.emittedFiles) {\n const destination = path.join(flags.outputDir, file.path)\n if (fs.existsSync(destination)) {\n throw new Error(\n `Exporter produced file for destination ${destination} but that file already exists. Enable --allowOverridingOutput option to allow overriding`,\n )\n }\n }\n }\n\n // Temporary structure to hold file contents\n const filesToWrite: { content: Buffer | string; filePath: string }[] = []\n\n // Function to process a single file\n const processFile = async (file: pulsarCoreTypes.PCEngineFileDescriptor) => {\n const filePath = path.join(flags.outputDir, ...file.path.split(\"/\"))\n const fileDirectory = path.dirname(filePath)\n this.ensureDirectoryExists(fileDirectory)\n\n switch (file.type) {\n case \"copy_file\": {\n const fileContent = fs.readFileSync(file.content)\n filesToWrite.push({ content: fileContent, filePath })\n\n break\n }\n\n case \"copy_file_remote\": {\n const fileContent = await this.downloadFileToMemory(file.content)\n filesToWrite.push({ content: fileContent, filePath })\n\n break\n }\n\n case \"string\": {\n filesToWrite.push({ content: file.content, filePath })\n\n break\n }\n // No default\n }\n }\n\n // Process all files in chunks to speed up the process\n const chunkSize = 4\n for (let i = 0; i < result.emittedFiles.length; i += chunkSize) {\n const chunk = result.emittedFiles.slice(i, i + chunkSize)\n await Promise.all(chunk.map(file => processFile(file)))\n }\n\n // Write all files from the temporary structure to the filesystem as a final step - this is to avoid partial writes\n for (const { content, filePath } of filesToWrite) {\n fs.writeFileSync(filePath, content)\n }\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;AAWA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,KAAK,eAAe,MAAM,+BAA+B,CAAA;AAGhE,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,KAAK,EAAE,MAAM,SAAS,CAAA;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,IAAI,MAAM,WAAW,CAAA;AAE5B,OAAO,QAAQ,CAAA;AACf,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAA;AAC7E,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAEpD,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAC9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