@storm-software/tsdown 0.15.1

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.
@@ -0,0 +1,1015 @@
1
+ import {
2
+ COLOR_KEYS,
3
+ LogLevel,
4
+ STORM_DEFAULT_DOCS,
5
+ STORM_DEFAULT_HOMEPAGE,
6
+ STORM_DEFAULT_LICENSING,
7
+ clean,
8
+ correctPaths,
9
+ findWorkspaceRoot,
10
+ formatLogMessage,
11
+ getDefaultConfig,
12
+ getLogLevel,
13
+ getLogLevelLabel,
14
+ getStopwatch,
15
+ isVerbose,
16
+ joinPaths,
17
+ writeDebug,
18
+ writeFatal,
19
+ writeSuccess,
20
+ writeSystem,
21
+ writeTrace,
22
+ writeWarning
23
+ } from "./chunk-IZXAJLBV.js";
24
+ import {
25
+ DEFAULT_BUILD_OPTIONS
26
+ } from "./chunk-UQLCBJOS.js";
27
+ import {
28
+ __name
29
+ } from "./chunk-SHUYVCID.js";
30
+
31
+ // src/build.ts
32
+ import { hfs as hfs4 } from "@humanfs/node";
33
+ import { createProjectGraphAsync as createProjectGraphAsync3, readProjectsConfigurationFromProjectGraph as readProjectsConfigurationFromProjectGraph3, writeJsonFile } from "@nx/devkit";
34
+
35
+ // ../build-tools/src/config.ts
36
+ var DEFAULT_ENVIRONMENT = "production";
37
+ var DEFAULT_TARGET = "esnext";
38
+ var DEFAULT_ORGANIZATION = "storm-software";
39
+
40
+ // ../build-tools/src/plugins/swc.ts
41
+ import { transform } from "@swc/core";
42
+
43
+ // ../build-tools/src/plugins/ts-resolve.ts
44
+ import fs from "node:fs";
45
+ import { builtinModules } from "node:module";
46
+ import path from "node:path";
47
+ import _resolve from "resolve";
48
+
49
+ // ../build-tools/src/plugins/type-definitions.ts
50
+ import { stripIndents } from "@nx/devkit";
51
+ import { relative } from "path";
52
+
53
+ // ../build-tools/src/utilities/copy-assets.ts
54
+ import { hfs as hfs2 } from "@humanfs/node";
55
+ import { createProjectGraphAsync, readProjectsConfigurationFromProjectGraph } from "@nx/devkit";
56
+ import { copyAssets as copyAssetsBase } from "@nx/js";
57
+ import { glob } from "glob";
58
+
59
+ // ../build-tools/src/utilities/read-nx-config.ts
60
+ import { hfs } from "@humanfs/node";
61
+
62
+ // ../config-tools/src/config-file/get-config-file.ts
63
+ import { loadConfig } from "c12";
64
+ import defu from "defu";
65
+ var getConfigFileByName = /* @__PURE__ */ __name(async (fileName, filePath, options = {}) => {
66
+ const workspacePath = filePath || findWorkspaceRoot(filePath);
67
+ let config = loadConfig({
68
+ cwd: workspacePath,
69
+ packageJson: true,
70
+ name: fileName,
71
+ envName: fileName?.toUpperCase(),
72
+ jitiOptions: {
73
+ debug: false,
74
+ cache: process.env.STORM_SKIP_CACHE === "true" ? false : joinPaths(process.env.STORM_CACHE_DIR || "node_modules/.cache", "storm")
75
+ },
76
+ ...options
77
+ });
78
+ if (!config || Object.keys(config).length === 0) {
79
+ config = loadConfig({
80
+ cwd: workspacePath,
81
+ packageJson: true,
82
+ name: fileName,
83
+ envName: fileName?.toUpperCase(),
84
+ jitiOptions: {
85
+ debug: false,
86
+ cache: process.env.STORM_SKIP_CACHE === "true" ? false : joinPaths(process.env.STORM_CACHE_DIR || "node_modules/.cache", "storm")
87
+ },
88
+ configFile: fileName,
89
+ ...options
90
+ });
91
+ }
92
+ return config;
93
+ }, "getConfigFileByName");
94
+ var getConfigFile = /* @__PURE__ */ __name(async (filePath, additionalFileNames = []) => {
95
+ const workspacePath = filePath ? filePath : findWorkspaceRoot(filePath);
96
+ const result = await getConfigFileByName("storm", workspacePath);
97
+ let config = result.config;
98
+ const configFile = result.configFile;
99
+ if (config && configFile && Object.keys(config).length > 0) {
100
+ writeSystem(`Found Storm configuration file "${configFile.includes(`${workspacePath}/`) ? configFile.replace(`${workspacePath}/`, "") : configFile}" at "${workspacePath}"`, {
101
+ logLevel: "all"
102
+ });
103
+ }
104
+ if (additionalFileNames && additionalFileNames.length > 0) {
105
+ const results = await Promise.all(additionalFileNames.map((fileName) => getConfigFileByName(fileName, workspacePath)));
106
+ for (const result2 of results) {
107
+ if (result2?.config && result2?.configFile && Object.keys(result2.config).length > 0) {
108
+ writeSystem(`Found alternative configuration file "${result2.configFile.includes(`${workspacePath}/`) ? result2.configFile.replace(`${workspacePath}/`, "") : result2.configFile}" at "${workspacePath}"`, {
109
+ logLevel: "all"
110
+ });
111
+ config = defu(result2.config ?? {}, config ?? {});
112
+ }
113
+ }
114
+ }
115
+ if (!config) {
116
+ return void 0;
117
+ }
118
+ config.configFile = configFile;
119
+ return config;
120
+ }, "getConfigFile");
121
+
122
+ // ../config-tools/src/create-storm-config.ts
123
+ import defu2 from "defu";
124
+
125
+ // ../config-tools/src/env/get-env.ts
126
+ var getConfigEnv = /* @__PURE__ */ __name(() => {
127
+ const prefix = "STORM_";
128
+ let config = {
129
+ extends: process.env[`${prefix}EXTENDS`] || void 0,
130
+ name: process.env[`${prefix}NAME`] || void 0,
131
+ namespace: process.env[`${prefix}NAMESPACE`] || void 0,
132
+ owner: process.env[`${prefix}OWNER`] || void 0,
133
+ bot: {
134
+ name: process.env[`${prefix}BOT_NAME`] || void 0,
135
+ email: process.env[`${prefix}BOT_EMAIL`] || void 0
136
+ },
137
+ organization: process.env[`${prefix}ORGANIZATION`] || void 0,
138
+ packageManager: process.env[`${prefix}PACKAGE_MANAGER`] || void 0,
139
+ license: process.env[`${prefix}LICENSE`] || void 0,
140
+ homepage: process.env[`${prefix}HOMEPAGE`] || void 0,
141
+ docs: process.env[`${prefix}DOCS`] || void 0,
142
+ licensing: process.env[`${prefix}LICENSING`] || void 0,
143
+ timezone: process.env[`${prefix}TIMEZONE`] || process.env.TZ || void 0,
144
+ locale: process.env[`${prefix}LOCALE`] || process.env.LOCALE || void 0,
145
+ configFile: process.env[`${prefix}CONFIG_FILE`] ? correctPaths(process.env[`${prefix}CONFIG_FILE`]) : void 0,
146
+ workspaceRoot: process.env[`${prefix}WORKSPACE_ROOT`] ? correctPaths(process.env[`${prefix}WORKSPACE_ROOT`]) : void 0,
147
+ directories: {
148
+ cache: process.env[`${prefix}CACHE_DIR`] ? correctPaths(process.env[`${prefix}CACHE_DIR`]) : void 0,
149
+ data: process.env[`${prefix}DATA_DIR`] ? correctPaths(process.env[`${prefix}DATA_DIR`]) : void 0,
150
+ config: process.env[`${prefix}CONFIG_DIR`] ? correctPaths(process.env[`${prefix}CONFIG_DIR`]) : void 0,
151
+ temp: process.env[`${prefix}TEMP_DIR`] ? correctPaths(process.env[`${prefix}TEMP_DIR`]) : void 0,
152
+ log: process.env[`${prefix}LOG_DIR`] ? correctPaths(process.env[`${prefix}LOG_DIR`]) : void 0,
153
+ build: process.env[`${prefix}BUILD_DIR`] ? correctPaths(process.env[`${prefix}BUILD_DIR`]) : void 0
154
+ },
155
+ skipCache: process.env[`${prefix}SKIP_CACHE`] !== void 0 ? Boolean(process.env[`${prefix}SKIP_CACHE`]) : void 0,
156
+ env: (process.env[`${prefix}ENV`] ?? process.env.NODE_ENV ?? process.env.ENVIRONMENT) || void 0,
157
+ // ci:
158
+ // process.env[`${prefix}CI`] !== undefined
159
+ // ? Boolean(
160
+ // process.env[`${prefix}CI`] ??
161
+ // process.env.CI ??
162
+ // process.env.CONTINUOUS_INTEGRATION
163
+ // )
164
+ // : undefined,
165
+ repository: process.env[`${prefix}REPOSITORY`] || void 0,
166
+ branch: process.env[`${prefix}BRANCH`] || void 0,
167
+ preid: process.env[`${prefix}PRE_ID`] || void 0,
168
+ externalPackagePatterns: process.env[`${prefix}EXTERNAL_PACKAGE_PATTERNS`] ? JSON.parse(process.env[`${prefix}EXTERNAL_PACKAGE_PATTERNS`]) : [],
169
+ registry: {
170
+ github: process.env[`${prefix}REGISTRY_GITHUB`] || void 0,
171
+ npm: process.env[`${prefix}REGISTRY_NPM`] || void 0,
172
+ cargo: process.env[`${prefix}REGISTRY_CARGO`] || void 0,
173
+ cyclone: process.env[`${prefix}REGISTRY_CYCLONE`] || void 0,
174
+ container: process.env[`${prefix}REGISTRY_CONTAINER`] || void 0
175
+ },
176
+ logLevel: process.env[`${prefix}LOG_LEVEL`] !== null && process.env[`${prefix}LOG_LEVEL`] !== void 0 ? process.env[`${prefix}LOG_LEVEL`] && Number.isSafeInteger(Number.parseInt(process.env[`${prefix}LOG_LEVEL`])) ? getLogLevelLabel(Number.parseInt(process.env[`${prefix}LOG_LEVEL`])) : process.env[`${prefix}LOG_LEVEL`] : void 0
177
+ };
178
+ const themeNames = Object.keys(process.env).filter((envKey) => envKey.startsWith(`${prefix}COLOR_`) && COLOR_KEYS.every((colorKey) => !envKey.startsWith(`${prefix}COLOR_LIGHT_${colorKey}`) && !envKey.startsWith(`${prefix}COLOR_DARK_${colorKey}`)));
179
+ config.colors = themeNames.length > 0 ? themeNames.reduce((ret, themeName) => {
180
+ ret[themeName] = getThemeColorConfigEnv(prefix, themeName);
181
+ return ret;
182
+ }, {}) : getThemeColorConfigEnv(prefix);
183
+ if (config.docs === STORM_DEFAULT_DOCS) {
184
+ if (config.homepage === STORM_DEFAULT_HOMEPAGE) {
185
+ config.docs = `${STORM_DEFAULT_HOMEPAGE}/projects/${config.name}/docs`;
186
+ } else {
187
+ config.docs = `${config.homepage}/docs`;
188
+ }
189
+ }
190
+ if (config.licensing === STORM_DEFAULT_LICENSING) {
191
+ if (config.homepage === STORM_DEFAULT_HOMEPAGE) {
192
+ config.licensing = `${STORM_DEFAULT_HOMEPAGE}/projects/${config.name}/licensing`;
193
+ } else {
194
+ config.licensing = `${config.homepage}/docs`;
195
+ }
196
+ }
197
+ const serializedConfig = process.env[`${prefix}CONFIG`];
198
+ if (serializedConfig) {
199
+ const parsed = JSON.parse(serializedConfig);
200
+ config = {
201
+ ...config,
202
+ ...parsed,
203
+ colors: {
204
+ ...config.colors,
205
+ ...parsed.colors
206
+ },
207
+ extensions: {
208
+ ...config.extensions,
209
+ ...parsed.extensions
210
+ }
211
+ };
212
+ }
213
+ return config;
214
+ }, "getConfigEnv");
215
+ var getThemeColorConfigEnv = /* @__PURE__ */ __name((prefix, theme) => {
216
+ const themeName = `COLOR_${theme && theme !== "base" ? `${theme}_` : ""}`.toUpperCase();
217
+ return process.env[`${prefix}${themeName}LIGHT_BRAND`] || process.env[`${prefix}${themeName}DARK_BRAND`] ? getMultiThemeColorConfigEnv(prefix + themeName) : getSingleThemeColorConfigEnv(prefix + themeName);
218
+ }, "getThemeColorConfigEnv");
219
+ var getSingleThemeColorConfigEnv = /* @__PURE__ */ __name((prefix) => {
220
+ return {
221
+ dark: process.env[`${prefix}DARK`],
222
+ light: process.env[`${prefix}LIGHT`],
223
+ brand: process.env[`${prefix}BRAND`],
224
+ alternate: process.env[`${prefix}ALTERNATE`],
225
+ accent: process.env[`${prefix}ACCENT`],
226
+ link: process.env[`${prefix}LINK`],
227
+ help: process.env[`${prefix}HELP`],
228
+ success: process.env[`${prefix}SUCCESS`],
229
+ info: process.env[`${prefix}INFO`],
230
+ warning: process.env[`${prefix}WARNING`],
231
+ danger: process.env[`${prefix}DANGER`],
232
+ fatal: process.env[`${prefix}FATAL`],
233
+ positive: process.env[`${prefix}POSITIVE`],
234
+ negative: process.env[`${prefix}NEGATIVE`]
235
+ };
236
+ }, "getSingleThemeColorConfigEnv");
237
+ var getMultiThemeColorConfigEnv = /* @__PURE__ */ __name((prefix) => {
238
+ return {
239
+ light: getBaseThemeColorConfigEnv(`${prefix}_LIGHT_`),
240
+ dark: getBaseThemeColorConfigEnv(`${prefix}_DARK_`)
241
+ };
242
+ }, "getMultiThemeColorConfigEnv");
243
+ var getBaseThemeColorConfigEnv = /* @__PURE__ */ __name((prefix) => {
244
+ return {
245
+ foreground: process.env[`${prefix}FOREGROUND`],
246
+ background: process.env[`${prefix}BACKGROUND`],
247
+ brand: process.env[`${prefix}BRAND`],
248
+ alternate: process.env[`${prefix}ALTERNATE`],
249
+ accent: process.env[`${prefix}ACCENT`],
250
+ link: process.env[`${prefix}LINK`],
251
+ help: process.env[`${prefix}HELP`],
252
+ success: process.env[`${prefix}SUCCESS`],
253
+ info: process.env[`${prefix}INFO`],
254
+ warning: process.env[`${prefix}WARNING`],
255
+ danger: process.env[`${prefix}DANGER`],
256
+ fatal: process.env[`${prefix}FATAL`],
257
+ positive: process.env[`${prefix}POSITIVE`],
258
+ negative: process.env[`${prefix}NEGATIVE`]
259
+ };
260
+ }, "getBaseThemeColorConfigEnv");
261
+
262
+ // ../config-tools/src/env/set-env.ts
263
+ var setExtensionEnv = /* @__PURE__ */ __name((extensionName, extension) => {
264
+ for (const key of Object.keys(extension ?? {})) {
265
+ if (extension[key]) {
266
+ const result = key?.replace(/([A-Z])+/g, (input) => input ? input[0]?.toUpperCase() + input.slice(1) : "").split(/(?=[A-Z])|[.\-\s_]/).map((x) => x.toLowerCase()) ?? [];
267
+ let extensionKey;
268
+ if (result.length === 0) {
269
+ return;
270
+ }
271
+ if (result.length === 1) {
272
+ extensionKey = result[0]?.toUpperCase() ?? "";
273
+ } else {
274
+ extensionKey = result.reduce((ret, part) => {
275
+ return `${ret}_${part.toLowerCase()}`;
276
+ });
277
+ }
278
+ process.env[`STORM_EXTENSION_${extensionName.toUpperCase()}_${extensionKey.toUpperCase()}`] = extension[key];
279
+ }
280
+ }
281
+ }, "setExtensionEnv");
282
+ var setConfigEnv = /* @__PURE__ */ __name((config) => {
283
+ const prefix = "STORM_";
284
+ if (config.extends) {
285
+ process.env[`${prefix}EXTENDS`] = config.extends;
286
+ }
287
+ if (config.name) {
288
+ process.env[`${prefix}NAME`] = config.name;
289
+ }
290
+ if (config.namespace) {
291
+ process.env[`${prefix}NAMESPACE`] = config.namespace;
292
+ }
293
+ if (config.owner) {
294
+ process.env[`${prefix}OWNER`] = config.owner;
295
+ }
296
+ if (config.bot) {
297
+ process.env[`${prefix}BOT_NAME`] = config.bot.name;
298
+ process.env[`${prefix}BOT_EMAIL`] = config.bot.email;
299
+ }
300
+ if (config.organization) {
301
+ process.env[`${prefix}ORGANIZATION`] = config.organization;
302
+ }
303
+ if (config.packageManager) {
304
+ process.env[`${prefix}PACKAGE_MANAGER`] = config.packageManager;
305
+ }
306
+ if (config.license) {
307
+ process.env[`${prefix}LICENSE`] = config.license;
308
+ }
309
+ if (config.homepage) {
310
+ process.env[`${prefix}HOMEPAGE`] = config.homepage;
311
+ }
312
+ if (config.docs) {
313
+ process.env[`${prefix}DOCS`] = config.docs;
314
+ }
315
+ if (config.licensing) {
316
+ process.env[`${prefix}LICENSING`] = config.licensing;
317
+ }
318
+ if (config.timezone) {
319
+ process.env[`${prefix}TIMEZONE`] = config.timezone;
320
+ process.env.TZ = config.timezone;
321
+ process.env.DEFAULT_TIMEZONE = config.timezone;
322
+ }
323
+ if (config.locale) {
324
+ process.env[`${prefix}LOCALE`] = config.locale;
325
+ process.env.LOCALE = config.locale;
326
+ process.env.DEFAULT_LOCALE = config.locale;
327
+ process.env.LANG = config.locale ? `${config.locale.replaceAll("-", "_")}.UTF-8` : "en_US.UTF-8";
328
+ }
329
+ if (config.configFile) {
330
+ process.env[`${prefix}CONFIG_FILE`] = correctPaths(config.configFile);
331
+ }
332
+ if (config.workspaceRoot) {
333
+ process.env[`${prefix}WORKSPACE_ROOT`] = correctPaths(config.workspaceRoot);
334
+ process.env.NX_WORKSPACE_ROOT = correctPaths(config.workspaceRoot);
335
+ process.env.NX_WORKSPACE_ROOT_PATH = correctPaths(config.workspaceRoot);
336
+ }
337
+ if (config.directories) {
338
+ if (!config.skipCache && config.directories.cache) {
339
+ process.env[`${prefix}CACHE_DIR`] = correctPaths(config.directories.cache);
340
+ }
341
+ if (config.directories.data) {
342
+ process.env[`${prefix}DATA_DIR`] = correctPaths(config.directories.data);
343
+ }
344
+ if (config.directories.config) {
345
+ process.env[`${prefix}CONFIG_DIR`] = correctPaths(config.directories.config);
346
+ }
347
+ if (config.directories.temp) {
348
+ process.env[`${prefix}TEMP_DIR`] = correctPaths(config.directories.temp);
349
+ }
350
+ if (config.directories.log) {
351
+ process.env[`${prefix}LOG_DIR`] = correctPaths(config.directories.log);
352
+ }
353
+ if (config.directories.build) {
354
+ process.env[`${prefix}BUILD_DIR`] = correctPaths(config.directories.build);
355
+ }
356
+ }
357
+ if (config.skipCache !== void 0) {
358
+ process.env[`${prefix}SKIP_CACHE`] = String(config.skipCache);
359
+ if (config.skipCache) {
360
+ process.env.NX_SKIP_NX_CACHE ??= String(config.skipCache);
361
+ process.env.NX_CACHE_PROJECT_GRAPH ??= String(config.skipCache);
362
+ }
363
+ }
364
+ if (config.env) {
365
+ process.env[`${prefix}ENV`] = config.env;
366
+ process.env.NODE_ENV = config.env;
367
+ process.env.ENVIRONMENT = config.env;
368
+ }
369
+ if (config.colors?.base?.light || config.colors?.base?.dark) {
370
+ for (const key of Object.keys(config.colors)) {
371
+ setThemeColorConfigEnv(`${prefix}COLOR_${key}_`, config.colors[key]);
372
+ }
373
+ } else {
374
+ setThemeColorConfigEnv(`${prefix}COLOR_`, config.colors);
375
+ }
376
+ if (config.repository) {
377
+ process.env[`${prefix}REPOSITORY`] = config.repository;
378
+ }
379
+ if (config.branch) {
380
+ process.env[`${prefix}BRANCH`] = config.branch;
381
+ }
382
+ if (config.preid) {
383
+ process.env[`${prefix}PRE_ID`] = String(config.preid);
384
+ }
385
+ if (config.externalPackagePatterns) {
386
+ process.env[`${prefix}EXTERNAL_PACKAGE_PATTERNS`] = JSON.stringify(config.externalPackagePatterns);
387
+ }
388
+ if (config.registry) {
389
+ if (config.registry.github) {
390
+ process.env[`${prefix}REGISTRY_GITHUB`] = String(config.registry.github);
391
+ }
392
+ if (config.registry.npm) {
393
+ process.env[`${prefix}REGISTRY_NPM`] = String(config.registry.npm);
394
+ }
395
+ if (config.registry.cargo) {
396
+ process.env[`${prefix}REGISTRY_CARGO`] = String(config.registry.cargo);
397
+ }
398
+ if (config.registry.cyclone) {
399
+ process.env[`${prefix}REGISTRY_CYCLONE`] = String(config.registry.cyclone);
400
+ }
401
+ if (config.registry.container) {
402
+ process.env[`${prefix}REGISTRY_CONTAINER`] = String(config.registry.cyclone);
403
+ }
404
+ }
405
+ if (config.logLevel) {
406
+ process.env[`${prefix}LOG_LEVEL`] = String(config.logLevel);
407
+ process.env.LOG_LEVEL = String(config.logLevel);
408
+ process.env.NX_VERBOSE_LOGGING = String(getLogLevel(config.logLevel) >= LogLevel.DEBUG ? true : false);
409
+ process.env.RUST_BACKTRACE = getLogLevel(config.logLevel) >= LogLevel.DEBUG ? "full" : "none";
410
+ }
411
+ process.env[`${prefix}CONFIG`] = JSON.stringify(config);
412
+ for (const key of Object.keys(config.extensions ?? {})) {
413
+ config.extensions[key] && Object.keys(config.extensions[key]) && setExtensionEnv(key, config.extensions[key]);
414
+ }
415
+ }, "setConfigEnv");
416
+ var setThemeColorConfigEnv = /* @__PURE__ */ __name((prefix, config) => {
417
+ return config?.light?.brand || config?.dark?.brand ? setMultiThemeColorConfigEnv(prefix, config) : setSingleThemeColorConfigEnv(prefix, config);
418
+ }, "setThemeColorConfigEnv");
419
+ var setSingleThemeColorConfigEnv = /* @__PURE__ */ __name((prefix, config) => {
420
+ if (config.dark) {
421
+ process.env[`${prefix}DARK`] = config.dark;
422
+ }
423
+ if (config.light) {
424
+ process.env[`${prefix}LIGHT`] = config.light;
425
+ }
426
+ if (config.brand) {
427
+ process.env[`${prefix}BRAND`] = config.brand;
428
+ }
429
+ if (config.alternate) {
430
+ process.env[`${prefix}ALTERNATE`] = config.alternate;
431
+ }
432
+ if (config.accent) {
433
+ process.env[`${prefix}ACCENT`] = config.accent;
434
+ }
435
+ if (config.link) {
436
+ process.env[`${prefix}LINK`] = config.link;
437
+ }
438
+ if (config.help) {
439
+ process.env[`${prefix}HELP`] = config.help;
440
+ }
441
+ if (config.success) {
442
+ process.env[`${prefix}SUCCESS`] = config.success;
443
+ }
444
+ if (config.info) {
445
+ process.env[`${prefix}INFO`] = config.info;
446
+ }
447
+ if (config.warning) {
448
+ process.env[`${prefix}WARNING`] = config.warning;
449
+ }
450
+ if (config.danger) {
451
+ process.env[`${prefix}DANGER`] = config.danger;
452
+ }
453
+ if (config.fatal) {
454
+ process.env[`${prefix}FATAL`] = config.fatal;
455
+ }
456
+ if (config.positive) {
457
+ process.env[`${prefix}POSITIVE`] = config.positive;
458
+ }
459
+ if (config.negative) {
460
+ process.env[`${prefix}NEGATIVE`] = config.negative;
461
+ }
462
+ }, "setSingleThemeColorConfigEnv");
463
+ var setMultiThemeColorConfigEnv = /* @__PURE__ */ __name((prefix, config) => {
464
+ return {
465
+ light: setBaseThemeColorConfigEnv(`${prefix}LIGHT_`, config.light),
466
+ dark: setBaseThemeColorConfigEnv(`${prefix}DARK_`, config.dark)
467
+ };
468
+ }, "setMultiThemeColorConfigEnv");
469
+ var setBaseThemeColorConfigEnv = /* @__PURE__ */ __name((prefix, config) => {
470
+ if (config.foreground) {
471
+ process.env[`${prefix}FOREGROUND`] = config.foreground;
472
+ }
473
+ if (config.background) {
474
+ process.env[`${prefix}BACKGROUND`] = config.background;
475
+ }
476
+ if (config.brand) {
477
+ process.env[`${prefix}BRAND`] = config.brand;
478
+ }
479
+ if (config.alternate) {
480
+ process.env[`${prefix}ALTERNATE`] = config.alternate;
481
+ }
482
+ if (config.accent) {
483
+ process.env[`${prefix}ACCENT`] = config.accent;
484
+ }
485
+ if (config.link) {
486
+ process.env[`${prefix}LINK`] = config.link;
487
+ }
488
+ if (config.help) {
489
+ process.env[`${prefix}HELP`] = config.help;
490
+ }
491
+ if (config.success) {
492
+ process.env[`${prefix}SUCCESS`] = config.success;
493
+ }
494
+ if (config.info) {
495
+ process.env[`${prefix}INFO`] = config.info;
496
+ }
497
+ if (config.warning) {
498
+ process.env[`${prefix}WARNING`] = config.warning;
499
+ }
500
+ if (config.danger) {
501
+ process.env[`${prefix}DANGER`] = config.danger;
502
+ }
503
+ if (config.fatal) {
504
+ process.env[`${prefix}FATAL`] = config.fatal;
505
+ }
506
+ if (config.positive) {
507
+ process.env[`${prefix}POSITIVE`] = config.positive;
508
+ }
509
+ if (config.negative) {
510
+ process.env[`${prefix}NEGATIVE`] = config.negative;
511
+ }
512
+ }, "setBaseThemeColorConfigEnv");
513
+
514
+ // ../config-tools/src/create-storm-config.ts
515
+ var _static_cache = void 0;
516
+ var loadStormConfig = /* @__PURE__ */ __name(async (workspaceRoot) => {
517
+ let config = {};
518
+ if (_static_cache?.data && _static_cache?.timestamp && _static_cache.timestamp >= Date.now() + 3e4) {
519
+ writeTrace(`Configuration cache hit - ${_static_cache.timestamp}`, _static_cache.data);
520
+ return _static_cache.data;
521
+ }
522
+ let _workspaceRoot = workspaceRoot;
523
+ if (!_workspaceRoot) {
524
+ _workspaceRoot = findWorkspaceRoot();
525
+ }
526
+ const configFile = await getConfigFile(_workspaceRoot);
527
+ if (!configFile) {
528
+ writeWarning("No Storm config file found in the current workspace. Please ensure this is the expected behavior - you can add a `storm.json` file to the root of your workspace if it is not.\n", {
529
+ logLevel: "all"
530
+ });
531
+ }
532
+ config = defu2(getConfigEnv(), configFile, getDefaultConfig(_workspaceRoot));
533
+ setConfigEnv(config);
534
+ writeTrace(`\u2699\uFE0F Using Storm configuration:
535
+ ${formatLogMessage(config)}`, config);
536
+ return config;
537
+ }, "loadStormConfig");
538
+
539
+ // ../build-tools/src/utilities/read-nx-config.ts
540
+ var readNxConfig = /* @__PURE__ */ __name(async (workspaceRoot) => {
541
+ let rootDir = workspaceRoot;
542
+ if (!rootDir) {
543
+ const config = await loadStormConfig();
544
+ rootDir = config.workspaceRoot;
545
+ }
546
+ const nxJsonPath = joinPaths(rootDir, "nx.json");
547
+ if (!await hfs.isFile(nxJsonPath)) {
548
+ throw new Error("Cannot find project.json configuration");
549
+ }
550
+ return hfs.json(nxJsonPath);
551
+ }, "readNxConfig");
552
+
553
+ // ../build-tools/src/utilities/copy-assets.ts
554
+ var copyAssets = /* @__PURE__ */ __name(async (config, assets, outputPath, projectRoot, projectName, sourceRoot, generatePackageJson2 = true, includeSrc = false, banner, footer) => {
555
+ const pendingAssets = Array.from(assets ?? []);
556
+ if (!pendingAssets?.some((asset) => asset?.glob === "*.md")) {
557
+ pendingAssets.push({
558
+ input: projectRoot,
559
+ glob: "*.md",
560
+ output: "/"
561
+ });
562
+ }
563
+ if (generatePackageJson2 === false) {
564
+ pendingAssets.push({
565
+ input: sourceRoot,
566
+ glob: "package.json",
567
+ output: "."
568
+ });
569
+ }
570
+ if (!pendingAssets?.some((asset) => asset?.glob === "LICENSE")) {
571
+ pendingAssets.push({
572
+ input: "",
573
+ glob: "LICENSE",
574
+ output: "."
575
+ });
576
+ }
577
+ if (includeSrc === true) {
578
+ pendingAssets.push({
579
+ input: sourceRoot,
580
+ glob: "**/{*.ts,*.tsx,*.js,*.jsx}",
581
+ output: "src/"
582
+ });
583
+ }
584
+ const nxJson = readNxConfig(config.workspaceRoot);
585
+ const projectGraph = await createProjectGraphAsync({
586
+ exitOnError: true
587
+ });
588
+ const projectsConfigurations = readProjectsConfigurationFromProjectGraph(projectGraph);
589
+ if (!projectsConfigurations?.projects?.[projectName]) {
590
+ throw new Error("The Build process failed because the project does not have a valid configuration in the project.json file. Check if the file exists in the root of the project.");
591
+ }
592
+ const buildTarget = projectsConfigurations.projects[projectName]?.targets?.build;
593
+ if (!buildTarget) {
594
+ throw new Error(`The Build process failed because the project does not have a valid build target in the project.json file. Check if the file exists in the root of the project at ${joinPaths(projectRoot, "project.json")}`);
595
+ }
596
+ const result = await copyAssetsBase({
597
+ assets,
598
+ watch: false,
599
+ outputPath
600
+ }, {
601
+ root: config.workspaceRoot,
602
+ targetName: "build",
603
+ target: buildTarget,
604
+ projectName,
605
+ projectGraph,
606
+ projectsConfigurations,
607
+ nxJsonConfiguration: nxJson,
608
+ cwd: config.workspaceRoot,
609
+ isVerbose: isVerbose(config.logLevel)
610
+ });
611
+ if (!result.success) {
612
+ throw new Error("The Build process failed trying to copy assets");
613
+ }
614
+ if (includeSrc === true) {
615
+ writeDebug(`\u{1F4DD} Adding banner and writing source files: ${joinPaths(outputPath, "src")}`, config);
616
+ const files = await glob([
617
+ joinPaths(config.workspaceRoot, outputPath, "src/**/*.ts"),
618
+ joinPaths(config.workspaceRoot, outputPath, "src/**/*.tsx"),
619
+ joinPaths(config.workspaceRoot, outputPath, "src/**/*.js"),
620
+ joinPaths(config.workspaceRoot, outputPath, "src/**/*.jsx")
621
+ ]);
622
+ await Promise.allSettled(files.map(async (file) => hfs2.write(file, `${banner && typeof banner === "string" ? banner.startsWith("//") ? banner : `// ${banner}` : ""}
623
+
624
+ ${await hfs2.text(file)}
625
+
626
+ ${footer && typeof footer === "string" ? footer.startsWith("//") ? footer : `// ${footer}` : ""}`)));
627
+ }
628
+ }, "copyAssets");
629
+
630
+ // ../build-tools/src/utilities/generate-package-json.ts
631
+ import { hfs as hfs3 } from "@humanfs/node";
632
+ import { calculateProjectBuildableDependencies } from "@nx/js/src/utils/buildable-libs-utils";
633
+ import { Glob } from "glob";
634
+ import { createProjectGraphAsync as createProjectGraphAsync2, readProjectsConfigurationFromProjectGraph as readProjectsConfigurationFromProjectGraph2 } from "nx/src/project-graph/project-graph";
635
+ var addPackageDependencies = /* @__PURE__ */ __name(async (workspaceRoot, projectRoot, projectName, packageJson) => {
636
+ const projectGraph = await createProjectGraphAsync2({
637
+ exitOnError: true
638
+ });
639
+ const projectConfigurations = readProjectsConfigurationFromProjectGraph2(projectGraph);
640
+ if (!projectConfigurations?.projects?.[projectName]) {
641
+ throw new Error("The Build process failed because the project does not have a valid configuration in the project.json file. Check if the file exists in the root of the project.");
642
+ }
643
+ const projectJsonPath = joinPaths(workspaceRoot, projectRoot, "project.json");
644
+ if (!await hfs3.isFile(projectJsonPath)) {
645
+ throw new Error("Cannot find project.json configuration");
646
+ }
647
+ if (!projectConfigurations?.projects?.[projectName]) {
648
+ throw new Error("The Build process failed because the project does not have a valid configuration in the project.json file. Check if the file exists in the root of the project.");
649
+ }
650
+ const projectDependencies = calculateProjectBuildableDependencies(void 0, projectGraph, workspaceRoot, projectName, process.env.NX_TASK_TARGET_TARGET || "build", process.env.NX_TASK_TARGET_CONFIGURATION || "production", true);
651
+ const localPackages = [];
652
+ for (const project of projectDependencies.dependencies.filter((dep) => dep.node.type === "lib" && dep.node.data.root !== projectRoot && dep.node.data.root !== workspaceRoot)) {
653
+ const projectNode = project.node;
654
+ if (projectNode.data.root) {
655
+ const projectPackageJsonPath = joinPaths(workspaceRoot, projectNode.data.root, "package.json");
656
+ if (await hfs3.isFile(projectPackageJsonPath)) {
657
+ const projectPackageJson = await hfs3.json(projectPackageJsonPath);
658
+ if (projectPackageJson.private !== false) {
659
+ localPackages.push(projectPackageJson);
660
+ }
661
+ }
662
+ }
663
+ }
664
+ if (localPackages.length > 0) {
665
+ writeTrace(`\u{1F4E6} Adding local packages to package.json: ${localPackages.map((p) => p.name).join(", ")}`);
666
+ packageJson.peerDependencies = localPackages.reduce((ret, localPackage) => {
667
+ if (!ret[localPackage.name]) {
668
+ ret[localPackage.name] = `>=${localPackage.version || "0.0.1"}`;
669
+ }
670
+ return ret;
671
+ }, packageJson.peerDependencies ?? {});
672
+ packageJson.peerDependenciesMeta = localPackages.reduce((ret, localPackage) => {
673
+ if (!ret[localPackage.name]) {
674
+ ret[localPackage.name] = {
675
+ optional: false
676
+ };
677
+ }
678
+ return ret;
679
+ }, packageJson.peerDependenciesMeta ?? {});
680
+ packageJson.devDependencies = localPackages.reduce((ret, localPackage) => {
681
+ if (!ret[localPackage.name]) {
682
+ ret[localPackage.name] = localPackage.version || "0.0.1";
683
+ }
684
+ return ret;
685
+ }, packageJson.peerDependencies ?? {});
686
+ } else {
687
+ writeTrace("\u{1F4E6} No local packages dependencies to add to package.json");
688
+ }
689
+ return packageJson;
690
+ }, "addPackageDependencies");
691
+ var addWorkspacePackageJsonFields = /* @__PURE__ */ __name(async (config, projectRoot, sourceRoot, projectName, includeSrc = false, packageJson) => {
692
+ const workspaceRoot = config.workspaceRoot ? config.workspaceRoot : findWorkspaceRoot();
693
+ const workspacePackageJson = await hfs3.json(joinPaths(workspaceRoot, "package.json"));
694
+ packageJson.type ??= "module";
695
+ packageJson.sideEffects ??= false;
696
+ if (includeSrc === true) {
697
+ let distSrc = sourceRoot.replace(projectRoot, "");
698
+ if (distSrc.startsWith("/")) {
699
+ distSrc = distSrc.substring(1);
700
+ }
701
+ packageJson.source ??= `${joinPaths(distSrc, "index.ts").replaceAll("\\", "/")}`;
702
+ }
703
+ packageJson.files ??= [
704
+ "dist/**/*"
705
+ ];
706
+ if (includeSrc === true && !packageJson.files.includes("src")) {
707
+ packageJson.files.push("src/**/*");
708
+ }
709
+ packageJson.publishConfig ??= {
710
+ access: "public"
711
+ };
712
+ packageJson.description ??= workspacePackageJson.description;
713
+ packageJson.homepage ??= workspacePackageJson.homepage;
714
+ packageJson.bugs ??= workspacePackageJson.bugs;
715
+ packageJson.license ??= workspacePackageJson.license;
716
+ packageJson.keywords ??= workspacePackageJson.keywords;
717
+ packageJson.funding ??= workspacePackageJson.funding;
718
+ packageJson.author ??= workspacePackageJson.author;
719
+ packageJson.maintainers ??= workspacePackageJson.maintainers;
720
+ if (!packageJson.maintainers && packageJson.author) {
721
+ packageJson.maintainers = [
722
+ packageJson.author
723
+ ];
724
+ }
725
+ packageJson.contributors ??= workspacePackageJson.contributors;
726
+ if (!packageJson.contributors && packageJson.author) {
727
+ packageJson.contributors = [
728
+ packageJson.author
729
+ ];
730
+ }
731
+ packageJson.repository ??= workspacePackageJson.repository;
732
+ packageJson.repository.directory ??= projectRoot ? projectRoot : joinPaths("packages", projectName);
733
+ return packageJson;
734
+ }, "addWorkspacePackageJsonFields");
735
+ var addPackageJsonExport = /* @__PURE__ */ __name((file, type = "module", sourceRoot) => {
736
+ let entry = file.replaceAll("\\", "/");
737
+ if (sourceRoot) {
738
+ entry = entry.replace(sourceRoot, "");
739
+ }
740
+ return {
741
+ "import": {
742
+ "types": `./dist/${entry}.d.${type === "module" ? "ts" : "mts"}`,
743
+ "default": `./dist/${entry}.${type === "module" ? "js" : "mjs"}`
744
+ },
745
+ "require": {
746
+ "types": `./dist/${entry}.d.${type === "commonjs" ? "ts" : "cts"}`,
747
+ "default": `./dist/${entry}.${type === "commonjs" ? "js" : "cjs"}`
748
+ },
749
+ "default": {
750
+ "types": `./dist/${entry}.d.ts`,
751
+ "default": `./dist/${entry}.js`
752
+ }
753
+ };
754
+ }, "addPackageJsonExport");
755
+
756
+ // ../build-tools/src/utilities/get-entry-points.ts
757
+ import { glob as glob2 } from "glob";
758
+ var getEntryPoints = /* @__PURE__ */ __name(async (config, projectRoot, sourceRoot, entry, emitOnAll = false) => {
759
+ const workspaceRoot = config.workspaceRoot ? config.workspaceRoot : findWorkspaceRoot();
760
+ const entryPoints = [];
761
+ if (entry) {
762
+ if (Array.isArray(entry)) {
763
+ entryPoints.push(...entry);
764
+ } else if (typeof entry === "string") {
765
+ entryPoints.push(entry);
766
+ } else {
767
+ entryPoints.push(...Object.values(entry));
768
+ }
769
+ }
770
+ if (emitOnAll) {
771
+ entryPoints.push(joinPaths(workspaceRoot, sourceRoot || projectRoot, "**/*.{ts,tsx}"));
772
+ }
773
+ const results = [];
774
+ for (const entryPoint in entryPoints) {
775
+ if (entryPoint.includes("*")) {
776
+ const files = await glob2(entryPoint, {
777
+ withFileTypes: true
778
+ });
779
+ results.push(...files.reduce((ret, filePath) => {
780
+ const result = correctPaths(joinPaths(filePath.path, filePath.name).replaceAll(correctPaths(workspaceRoot), "").replaceAll(correctPaths(projectRoot), ""));
781
+ if (result) {
782
+ writeDebug(`Trying to add entry point ${result} at "${joinPaths(filePath.path, filePath.name)}"`, config);
783
+ if (!results.includes(result)) {
784
+ results.push(result);
785
+ }
786
+ }
787
+ return ret;
788
+ }, []));
789
+ } else {
790
+ results.push(entryPoint);
791
+ }
792
+ }
793
+ return results;
794
+ }, "getEntryPoints");
795
+
796
+ // ../build-tools/src/utilities/get-env.ts
797
+ var getEnv = /* @__PURE__ */ __name((builder, options) => {
798
+ return {
799
+ STORM_BUILD: builder,
800
+ STORM_ORG: options.orgName || DEFAULT_ORGANIZATION,
801
+ STORM_NAME: options.name,
802
+ STORM_ENV: options.envName || DEFAULT_ENVIRONMENT,
803
+ STORM_PLATFORM: options.platform,
804
+ STORM_FORMAT: JSON.stringify(options.format),
805
+ STORM_TARGET: JSON.stringify(options.target),
806
+ ...options.env
807
+ };
808
+ }, "getEnv");
809
+
810
+ // ../build-tools/src/utilities/task-graph.ts
811
+ import { createTaskGraph, mapTargetDefaultsToDependencies } from "nx/src/tasks-runner/create-task-graph";
812
+
813
+ // src/build.ts
814
+ import defu3 from "defu";
815
+ import { findWorkspaceRoot as findWorkspaceRoot2 } from "nx/src/utils/find-workspace-root";
816
+ import { build as tsdown } from "tsdown";
817
+ var resolveOptions = /* @__PURE__ */ __name(async (userOptions) => {
818
+ const projectRoot = userOptions.projectRoot;
819
+ const workspaceRoot = findWorkspaceRoot2(projectRoot);
820
+ if (!workspaceRoot) {
821
+ throw new Error("Cannot find Nx workspace root");
822
+ }
823
+ const config = await loadStormConfig(workspaceRoot.dir);
824
+ writeDebug(" \u2699\uFE0F Resolving build options", config);
825
+ const stopwatch = getStopwatch("Build options resolution");
826
+ const projectGraph = await createProjectGraphAsync3({
827
+ exitOnError: true
828
+ });
829
+ const projectJsonPath = joinPaths(workspaceRoot.dir, projectRoot, "project.json");
830
+ if (!await hfs4.isFile(projectJsonPath)) {
831
+ throw new Error("Cannot find project.json configuration");
832
+ }
833
+ const projectJson = await hfs4.json(projectJsonPath);
834
+ const projectName = projectJson.name;
835
+ const projectConfigurations = readProjectsConfigurationFromProjectGraph3(projectGraph);
836
+ if (!projectConfigurations?.projects?.[projectName]) {
837
+ throw new Error("The Build process failed because the project does not have a valid configuration in the project.json file. Check if the file exists in the root of the project.");
838
+ }
839
+ const options = defu3(userOptions, DEFAULT_BUILD_OPTIONS);
840
+ options.name ??= `${projectName}-${options.format}`;
841
+ options.target ??= DEFAULT_TARGET;
842
+ const packageJsonPath = joinPaths(workspaceRoot.dir, options.projectRoot, "package.json");
843
+ if (!await hfs4.isFile(packageJsonPath)) {
844
+ throw new Error("Cannot find package.json configuration");
845
+ }
846
+ const env = getEnv("tsdown", options);
847
+ const result = {
848
+ ...options,
849
+ config,
850
+ ...userOptions,
851
+ tsconfig: joinPaths(projectRoot, userOptions.tsconfig ? userOptions.tsconfig.replace(projectRoot, "") : "tsconfig.json"),
852
+ format: options.format || "cjs",
853
+ entryPoints: await getEntryPoints(config, projectRoot, projectJson.sourceRoot, userOptions.entry || [
854
+ "./src/index.ts"
855
+ ], userOptions.emitOnAll),
856
+ outdir: userOptions.outputPath || joinPaths("dist", projectRoot),
857
+ plugins: [],
858
+ name: userOptions.name || projectName,
859
+ projectConfigurations,
860
+ projectName,
861
+ projectGraph,
862
+ sourceRoot: userOptions.sourceRoot || projectJson.sourceRoot || joinPaths(projectRoot, "src"),
863
+ minify: userOptions.minify || !userOptions.debug,
864
+ verbose: userOptions.verbose || isVerbose() || userOptions.debug === true,
865
+ includeSrc: userOptions.includeSrc === true,
866
+ metafile: userOptions.metafile !== false,
867
+ generatePackageJson: userOptions.generatePackageJson !== false,
868
+ clean: userOptions.clean !== false,
869
+ emitOnAll: userOptions.emitOnAll === true,
870
+ dts: userOptions.emitTypes === true ? {
871
+ transformer: "oxc"
872
+ } : userOptions.emitTypes,
873
+ bundleDts: userOptions.emitTypes,
874
+ assets: userOptions.assets ?? [],
875
+ shims: userOptions.injectShims !== true,
876
+ bundle: userOptions.bundle !== false,
877
+ watch: userOptions.watch === true,
878
+ define: {
879
+ STORM_FORMAT: JSON.stringify(options.format || "cjs"),
880
+ ...options.format === "cjs" && options.injectShims ? {
881
+ "import.meta.url": "importMetaUrl"
882
+ } : {},
883
+ ...options.define,
884
+ ...Object.keys(env || {}).reduce((res, key) => {
885
+ const value = JSON.stringify(env[key]);
886
+ return {
887
+ ...res,
888
+ [`process.env.${key}`]: value,
889
+ [`import.meta.env.${key}`]: value
890
+ };
891
+ }, {})
892
+ }
893
+ };
894
+ stopwatch();
895
+ return result;
896
+ }, "resolveOptions");
897
+ async function generatePackageJson(options) {
898
+ if (options.generatePackageJson !== false && await hfs4.isFile(joinPaths(options.projectRoot, "package.json"))) {
899
+ writeDebug(" \u270D\uFE0F Writing package.json file", options.config);
900
+ const stopwatch = getStopwatch("Write package.json file");
901
+ const packageJsonPath = joinPaths(options.projectRoot, "project.json");
902
+ if (!await hfs4.isFile(packageJsonPath)) {
903
+ throw new Error("Cannot find package.json configuration");
904
+ }
905
+ let packageJson = await hfs4.json(joinPaths(options.config.workspaceRoot, options.projectRoot, "package.json"));
906
+ if (!packageJson) {
907
+ throw new Error("Cannot find package.json configuration file");
908
+ }
909
+ packageJson = await addPackageDependencies(options.config.workspaceRoot, options.projectRoot, options.projectName, packageJson);
910
+ packageJson = await addWorkspacePackageJsonFields(options.config, options.projectRoot, options.sourceRoot, options.projectName, false, packageJson);
911
+ packageJson.exports ??= {};
912
+ packageJson.exports["./package.json"] ??= "./package.json";
913
+ packageJson.exports["."] ??= addPackageJsonExport("index", packageJson.type, options.sourceRoot);
914
+ let entryPoints = [
915
+ {
916
+ in: "./src/index.ts",
917
+ out: "./src/index.ts"
918
+ }
919
+ ];
920
+ if (options.entryPoints) {
921
+ if (Array.isArray(options.entryPoints)) {
922
+ entryPoints = options.entryPoints.map((entryPoint) => typeof entryPoint === "string" ? {
923
+ in: entryPoint,
924
+ out: entryPoint
925
+ } : entryPoint);
926
+ }
927
+ for (const entryPoint of entryPoints) {
928
+ const split = entryPoint.out.split(".");
929
+ split.pop();
930
+ const entry = split.join(".").replaceAll("\\", "/");
931
+ packageJson.exports[`./${entry}`] ??= addPackageJsonExport(entry, packageJson.type, options.sourceRoot);
932
+ }
933
+ }
934
+ packageJson.main = packageJson.type === "commonjs" ? "./dist/index.js" : "./dist/index.cjs";
935
+ packageJson.module = packageJson.type === "module" ? "./dist/index.js" : "./dist/index.mjs";
936
+ packageJson.types = "./dist/index.d.ts";
937
+ packageJson.exports = Object.keys(packageJson.exports).reduce((ret, key) => {
938
+ if (key.endsWith("/index") && !ret[key.replace("/index", "")]) {
939
+ ret[key.replace("/index", "")] = packageJson.exports[key];
940
+ }
941
+ return ret;
942
+ }, packageJson.exports);
943
+ await writeJsonFile(joinPaths(options.outdir, "package.json"), packageJson);
944
+ stopwatch();
945
+ }
946
+ return options;
947
+ }
948
+ __name(generatePackageJson, "generatePackageJson");
949
+ async function executeTSDown(options) {
950
+ writeDebug(` \u{1F680} Running ${options.name} build`, options.config);
951
+ const stopwatch = getStopwatch(`${options.name} build`);
952
+ await tsdown({
953
+ ...options,
954
+ entry: options.entryPoints,
955
+ outDir: options.outdir,
956
+ config: false
957
+ });
958
+ stopwatch();
959
+ return options;
960
+ }
961
+ __name(executeTSDown, "executeTSDown");
962
+ async function copyBuildAssets(options) {
963
+ writeDebug(` \u{1F4CB} Copying asset files to output directory: ${options.outdir}`, options.config);
964
+ const stopwatch = getStopwatch(`${options.name} asset copy`);
965
+ await copyAssets(options.config, options.assets ?? [], options.outdir, options.projectRoot, options.projectName, options.sourceRoot, true, false);
966
+ stopwatch();
967
+ return options;
968
+ }
969
+ __name(copyBuildAssets, "copyBuildAssets");
970
+ async function reportResults(options) {
971
+ writeSuccess(` \u{1F4E6} The ${options.name} build completed successfully`, options.config);
972
+ }
973
+ __name(reportResults, "reportResults");
974
+ async function cleanOutputPath(options) {
975
+ if (options.clean !== false && options.outdir) {
976
+ await clean(options.name, options.outdir, options.config);
977
+ }
978
+ return options;
979
+ }
980
+ __name(cleanOutputPath, "cleanOutputPath");
981
+ async function build(options) {
982
+ writeDebug(` \u26A1 Executing Storm TSDown pipeline`);
983
+ const stopwatch = getStopwatch("TSDown pipeline");
984
+ try {
985
+ const opts = Array.isArray(options) ? options : [
986
+ options
987
+ ];
988
+ if (opts.length === 0) {
989
+ throw new Error("No build options were provided");
990
+ }
991
+ const resolved = await Promise.all(opts.map(async (opt) => await resolveOptions(opt)));
992
+ if (resolved.length > 0) {
993
+ await cleanOutputPath(resolved[0]);
994
+ await generatePackageJson(resolved[0]);
995
+ await Promise.all(resolved.map(async (opt) => {
996
+ await executeTSDown(opt);
997
+ await copyBuildAssets(opt);
998
+ await reportResults(opt);
999
+ }));
1000
+ } else {
1001
+ writeWarning(" \u{1F6A7} No options were passed to TSBuild. Please check the parameters passed to the `build` function.");
1002
+ }
1003
+ writeSuccess(" \u{1F3C1} TSDown pipeline build completed successfully");
1004
+ } catch (error) {
1005
+ writeFatal(" \u274C Fatal errors occurred during the build that could not be recovered from. The build process has been terminated.");
1006
+ throw error;
1007
+ } finally {
1008
+ stopwatch();
1009
+ }
1010
+ }
1011
+ __name(build, "build");
1012
+
1013
+ export {
1014
+ build
1015
+ };