@adddog/build-configs 0.0.1 → 0.0.5
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/README.md +1 -1
- package/dist/cli/index.mjs +128 -119
- package/dist/cli/index.mjs.map +1 -1
- package/dist/index.d.mts +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.mjs +1 -2
- package/dist/index.mjs.map +1 -1
- package/dist/presets/index.d.mts +0 -5
- package/dist/presets/index.d.ts +0 -5
- package/dist/presets/index.mjs +188 -186
- package/dist/presets/index.mjs.map +1 -1
- package/package.json +19 -10
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Reusable build configurations and CLI for [tsup](https://tsup.egoist.dev/) and [unbuild](https://github.com/unjs/unbuild) with sensible defaults, presets, and interactive setup.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+

|
|
6
6
|
|
|
7
7
|
- 🚀 **CLI Tool** - Interactive project initialization and build commands
|
|
8
8
|
- 📦 **Preset System** - Pre-configured setups for common use cases
|
package/dist/cli/index.mjs
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import process from 'node:process';
|
|
2
3
|
import { cac } from 'cac';
|
|
3
|
-
import { consola } from 'consola';
|
|
4
|
-
import pc from 'picocolors';
|
|
5
|
-
import { execa } from 'execa';
|
|
6
4
|
import { existsSync, writeFileSync } from 'node:fs';
|
|
7
5
|
import { join, resolve } from 'node:path';
|
|
6
|
+
import { execa } from 'execa';
|
|
7
|
+
import { makeTsupConfig } from '../tsup.config.mjs';
|
|
8
|
+
import { makeUnbuildConfig } from '../unbuild.config.mjs';
|
|
8
9
|
import { readFile, writeFile } from 'node:fs/promises';
|
|
9
|
-
import { createJiti } from 'jiti';
|
|
10
10
|
import { defu } from 'defu';
|
|
11
|
+
import { createJiti } from 'jiti';
|
|
11
12
|
import { getPreset, listPresets } from '../presets/index.mjs';
|
|
12
|
-
import {
|
|
13
|
-
import
|
|
13
|
+
import { consola } from 'consola';
|
|
14
|
+
import pc from 'picocolors';
|
|
14
15
|
import * as p from '@clack/prompts';
|
|
15
16
|
import { z } from 'zod';
|
|
16
17
|
import 'tsup';
|
|
17
18
|
import 'unbuild';
|
|
18
19
|
|
|
19
|
-
const version = "0.0.
|
|
20
|
+
const version = "0.0.5";
|
|
20
21
|
|
|
21
22
|
const logger = consola.create({
|
|
22
23
|
formatOptions: {
|
|
@@ -99,7 +100,7 @@ async function detectBundler(cwd = process.cwd()) {
|
|
|
99
100
|
interopDefault: true
|
|
100
101
|
});
|
|
101
102
|
const config = await jiti.import(configPath);
|
|
102
|
-
if (
|
|
103
|
+
if ("entries" in config || "rollup" in config || Array.isArray(config) && config[0] && "entries" in config[0]) {
|
|
103
104
|
return "unbuild";
|
|
104
105
|
}
|
|
105
106
|
} catch {
|
|
@@ -220,7 +221,8 @@ async function updatePackageJson(updates, cwd = process.cwd()) {
|
|
|
220
221
|
const pkgPath = join(cwd, "package.json");
|
|
221
222
|
const pkg = await getPackageJson(cwd) ?? {};
|
|
222
223
|
const updated = defu(updates, pkg);
|
|
223
|
-
await writeFile(pkgPath, JSON.stringify(updated, null, 2)
|
|
224
|
+
await writeFile(pkgPath, `${JSON.stringify(updated, null, 2)}
|
|
225
|
+
`);
|
|
224
226
|
}
|
|
225
227
|
|
|
226
228
|
async function buildCommand(entries, options) {
|
|
@@ -304,6 +306,112 @@ async function buildCommand(entries, options) {
|
|
|
304
306
|
}
|
|
305
307
|
}
|
|
306
308
|
|
|
309
|
+
async function infoCommand(options) {
|
|
310
|
+
try {
|
|
311
|
+
logger.start("Gathering project information...\n");
|
|
312
|
+
const pkg = await getPackageJson();
|
|
313
|
+
const projectName = pkg?.name ?? "unknown";
|
|
314
|
+
const projectVersion = pkg?.version ?? "0.0.0";
|
|
315
|
+
const configPath = await discoverConfigFile(
|
|
316
|
+
process.cwd(),
|
|
317
|
+
options.config
|
|
318
|
+
);
|
|
319
|
+
let bundler = "none";
|
|
320
|
+
let config = {};
|
|
321
|
+
if (configPath) {
|
|
322
|
+
const loaded = await loadConfig({
|
|
323
|
+
...options.config && { configPath: options.config },
|
|
324
|
+
bundler: "auto"
|
|
325
|
+
});
|
|
326
|
+
bundler = loaded.bundler;
|
|
327
|
+
config = loaded.config;
|
|
328
|
+
}
|
|
329
|
+
logBox("Project Information", [
|
|
330
|
+
`Name: ${colors.primary(projectName)}`,
|
|
331
|
+
`Version: ${colors.primary(projectVersion)}`,
|
|
332
|
+
`Config: ${configPath ? colors.file(configPath) : colors.dim("not found")}`,
|
|
333
|
+
`Bundler: ${bundler !== "none" ? colors.bundler(bundler) : colors.dim("not configured")}`
|
|
334
|
+
]);
|
|
335
|
+
if (bundler !== "none") {
|
|
336
|
+
console.log(`
|
|
337
|
+
${colors.bold("Build Configuration:")}`);
|
|
338
|
+
if (bundler === "tsup") {
|
|
339
|
+
const tsupConfig = config;
|
|
340
|
+
console.log(`${colors.dim("\u251C\u2500")} Entry: ${JSON.stringify(tsupConfig.entry ?? ["src/index.ts"])}`);
|
|
341
|
+
console.log(`${colors.dim("\u251C\u2500")} Format: ${JSON.stringify(tsupConfig.format ?? ["esm", "cjs"])}`);
|
|
342
|
+
console.log(
|
|
343
|
+
`${colors.dim("\u251C\u2500")} Target: ${tsupConfig.target ?? "node18"}`
|
|
344
|
+
);
|
|
345
|
+
console.log(
|
|
346
|
+
`${colors.dim("\u251C\u2500")} Platform: ${tsupConfig.platform ?? "node"}`
|
|
347
|
+
);
|
|
348
|
+
console.log(
|
|
349
|
+
`${colors.dim("\u251C\u2500")} DTS: ${tsupConfig.dts !== false ? colors.success("\u2713") : colors.dim("\u2717")}`
|
|
350
|
+
);
|
|
351
|
+
console.log(
|
|
352
|
+
`${colors.dim("\u251C\u2500")} Sourcemap: ${tsupConfig.sourcemap !== false ? colors.success("\u2713") : colors.dim("\u2717")}`
|
|
353
|
+
);
|
|
354
|
+
console.log(
|
|
355
|
+
`${colors.dim("\u251C\u2500")} Minify: ${tsupConfig.minify ? colors.success("\u2713") : colors.dim("\u2717")}`
|
|
356
|
+
);
|
|
357
|
+
console.log(
|
|
358
|
+
`${colors.dim("\u2514\u2500")} Clean: ${tsupConfig.clean !== false ? colors.success("\u2713") : colors.dim("\u2717")}`
|
|
359
|
+
);
|
|
360
|
+
} else {
|
|
361
|
+
const unbuildConfig = config;
|
|
362
|
+
console.log(
|
|
363
|
+
`${colors.dim("\u251C\u2500")} Entries: ${JSON.stringify(unbuildConfig.entries ?? ["src/index"])}`
|
|
364
|
+
);
|
|
365
|
+
console.log(
|
|
366
|
+
`${colors.dim("\u251C\u2500")} Out Dir: ${unbuildConfig.outDir ?? "dist"}`
|
|
367
|
+
);
|
|
368
|
+
console.log(
|
|
369
|
+
`${colors.dim("\u251C\u2500")} Declaration: ${unbuildConfig.declaration !== false ? colors.success("\u2713") : colors.dim("\u2717")}`
|
|
370
|
+
);
|
|
371
|
+
console.log(
|
|
372
|
+
`${colors.dim("\u251C\u2500")} Emit CJS: ${unbuildConfig.rollup?.emitCJS ? colors.success("\u2713") : colors.dim("\u2717")}`
|
|
373
|
+
);
|
|
374
|
+
console.log(
|
|
375
|
+
`${colors.dim("\u251C\u2500")} Sourcemap: ${unbuildConfig.sourcemap ? colors.success("\u2713") : colors.dim("\u2717")}`
|
|
376
|
+
);
|
|
377
|
+
console.log(
|
|
378
|
+
`${colors.dim("\u251C\u2500")} Parallel: ${unbuildConfig.parallel !== false ? colors.success("\u2713") : colors.dim("\u2717")}`
|
|
379
|
+
);
|
|
380
|
+
console.log(
|
|
381
|
+
`${colors.dim("\u2514\u2500")} Clean: ${unbuildConfig.clean !== false ? colors.success("\u2713") : colors.dim("\u2717")}`
|
|
382
|
+
);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
if (pkg?.exports) {
|
|
386
|
+
console.log(`
|
|
387
|
+
${colors.bold("Package Exports:")}`);
|
|
388
|
+
console.log(JSON.stringify(pkg.exports, null, 2));
|
|
389
|
+
}
|
|
390
|
+
if (pkg?.scripts) {
|
|
391
|
+
const buildScripts = Object.entries(pkg.scripts).filter(
|
|
392
|
+
([key]) => key.includes("build") || key.includes("watch")
|
|
393
|
+
);
|
|
394
|
+
if (buildScripts.length > 0) {
|
|
395
|
+
console.log(`
|
|
396
|
+
${colors.bold("Build Scripts:")}`);
|
|
397
|
+
buildScripts.forEach(([name, script]) => {
|
|
398
|
+
console.log(` ${colors.command(name.padEnd(20))} ${colors.dim(script)}`);
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
if (bundler === "none") {
|
|
403
|
+
console.log(`
|
|
404
|
+
${colors.warning("\u26A0 No build configuration found")}`);
|
|
405
|
+
console.log(
|
|
406
|
+
colors.info("\nRun ") + colors.command("rad-build init") + colors.info(" to set up your project")
|
|
407
|
+
);
|
|
408
|
+
}
|
|
409
|
+
} catch (error) {
|
|
410
|
+
logger.error("Failed to gather information", error);
|
|
411
|
+
process.exit(1);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
307
415
|
function generateTsupConfig(options = {}) {
|
|
308
416
|
const config = {
|
|
309
417
|
entry: options.entry ?? ["src/index.ts"],
|
|
@@ -337,9 +445,9 @@ function generatePackageJsonScripts(bundler) {
|
|
|
337
445
|
const buildCommand = bundler === "tsup" ? "tsup" : "unbuild";
|
|
338
446
|
const watchCommand = bundler === "tsup" ? "tsup --watch" : "unbuild --watch";
|
|
339
447
|
return {
|
|
340
|
-
build: buildCommand,
|
|
448
|
+
"build": buildCommand,
|
|
341
449
|
"build:watch": watchCommand,
|
|
342
|
-
prepublishOnly: "pnpm build"
|
|
450
|
+
"prepublishOnly": "pnpm build"
|
|
343
451
|
};
|
|
344
452
|
}
|
|
345
453
|
function generatePackageJsonExports(_bundler, formats) {
|
|
@@ -470,8 +578,9 @@ async function initCommand(options) {
|
|
|
470
578
|
p.cancel("Operation cancelled");
|
|
471
579
|
process.exit(0);
|
|
472
580
|
}
|
|
581
|
+
const formatsArray = formats;
|
|
473
582
|
finalConfig = {
|
|
474
|
-
format:
|
|
583
|
+
format: formatsArray,
|
|
475
584
|
sourcemap: features.includes("sourcemaps"),
|
|
476
585
|
minify: features.includes("minify")
|
|
477
586
|
};
|
|
@@ -495,14 +604,16 @@ async function initCommand(options) {
|
|
|
495
604
|
const pkg = await getPackageJson();
|
|
496
605
|
if (pkg) {
|
|
497
606
|
const scripts = generatePackageJsonScripts(bundler);
|
|
607
|
+
const formatArray = Array.isArray(finalConfig.format) ? finalConfig.format : finalConfig.format ? [finalConfig.format] : ["esm", "cjs"];
|
|
498
608
|
const exports = generatePackageJsonExports(
|
|
499
609
|
bundler,
|
|
500
|
-
|
|
610
|
+
formatArray
|
|
501
611
|
);
|
|
612
|
+
const pkgScripts = typeof pkg.scripts === "object" && pkg.scripts !== null ? pkg.scripts : {};
|
|
502
613
|
await updatePackageJson({
|
|
503
|
-
scripts: { ...
|
|
614
|
+
scripts: { ...pkgScripts, ...scripts },
|
|
504
615
|
exports,
|
|
505
|
-
main:
|
|
616
|
+
main: formatArray.includes("cjs") || finalConfig.rollup?.emitCJS ? "./dist/index.cjs" : void 0,
|
|
506
617
|
module: "./dist/index.mjs",
|
|
507
618
|
types: "./dist/index.d.ts",
|
|
508
619
|
files: ["dist"]
|
|
@@ -682,8 +793,8 @@ async function validateCommand(options) {
|
|
|
682
793
|
logError("\u2717 Configuration validation failed");
|
|
683
794
|
if (result.error) {
|
|
684
795
|
logger.error("\nValidation errors:");
|
|
685
|
-
result.error.
|
|
686
|
-
logger.error(` ${colors.error("\u2022")} ${err.path.join(".")}: ${err.message}`);
|
|
796
|
+
result.error.issues.forEach((err) => {
|
|
797
|
+
logger.error(` ${colors.error("\u2022")} ${String(err.path.join("."))}: ${err.message}`);
|
|
687
798
|
});
|
|
688
799
|
}
|
|
689
800
|
process.exit(1);
|
|
@@ -694,108 +805,6 @@ async function validateCommand(options) {
|
|
|
694
805
|
}
|
|
695
806
|
}
|
|
696
807
|
|
|
697
|
-
async function infoCommand(options) {
|
|
698
|
-
try {
|
|
699
|
-
logger.start("Gathering project information...\n");
|
|
700
|
-
const pkg = await getPackageJson();
|
|
701
|
-
const projectName = pkg?.name ?? "unknown";
|
|
702
|
-
const projectVersion = pkg?.version ?? "0.0.0";
|
|
703
|
-
const configPath = await discoverConfigFile(
|
|
704
|
-
process.cwd(),
|
|
705
|
-
options.config
|
|
706
|
-
);
|
|
707
|
-
let bundler = "none";
|
|
708
|
-
let config = {};
|
|
709
|
-
if (configPath) {
|
|
710
|
-
const loaded = await loadConfig({
|
|
711
|
-
...options.config && { configPath: options.config },
|
|
712
|
-
bundler: "auto"
|
|
713
|
-
});
|
|
714
|
-
bundler = loaded.bundler;
|
|
715
|
-
config = loaded.config;
|
|
716
|
-
}
|
|
717
|
-
logBox("Project Information", [
|
|
718
|
-
`Name: ${colors.primary(projectName)}`,
|
|
719
|
-
`Version: ${colors.primary(projectVersion)}`,
|
|
720
|
-
`Config: ${configPath ? colors.file(configPath) : colors.dim("not found")}`,
|
|
721
|
-
`Bundler: ${bundler !== "none" ? colors.bundler(bundler) : colors.dim("not configured")}`
|
|
722
|
-
]);
|
|
723
|
-
if (bundler !== "none") {
|
|
724
|
-
console.log("\n" + colors.bold("Build Configuration:"));
|
|
725
|
-
if (bundler === "tsup") {
|
|
726
|
-
const tsupConfig = config;
|
|
727
|
-
console.log(colors.dim("\u251C\u2500") + " Entry: " + JSON.stringify(tsupConfig.entry ?? ["src/index.ts"]));
|
|
728
|
-
console.log(colors.dim("\u251C\u2500") + " Format: " + JSON.stringify(tsupConfig.format ?? ["esm", "cjs"]));
|
|
729
|
-
console.log(
|
|
730
|
-
colors.dim("\u251C\u2500") + " Target: " + (tsupConfig.target ?? "node18")
|
|
731
|
-
);
|
|
732
|
-
console.log(
|
|
733
|
-
colors.dim("\u251C\u2500") + " Platform: " + (tsupConfig.platform ?? "node")
|
|
734
|
-
);
|
|
735
|
-
console.log(
|
|
736
|
-
colors.dim("\u251C\u2500") + " DTS: " + (tsupConfig.dts !== false ? colors.success("\u2713") : colors.dim("\u2717"))
|
|
737
|
-
);
|
|
738
|
-
console.log(
|
|
739
|
-
colors.dim("\u251C\u2500") + " Sourcemap: " + (tsupConfig.sourcemap !== false ? colors.success("\u2713") : colors.dim("\u2717"))
|
|
740
|
-
);
|
|
741
|
-
console.log(
|
|
742
|
-
colors.dim("\u251C\u2500") + " Minify: " + (tsupConfig.minify ? colors.success("\u2713") : colors.dim("\u2717"))
|
|
743
|
-
);
|
|
744
|
-
console.log(
|
|
745
|
-
colors.dim("\u2514\u2500") + " Clean: " + (tsupConfig.clean !== false ? colors.success("\u2713") : colors.dim("\u2717"))
|
|
746
|
-
);
|
|
747
|
-
} else {
|
|
748
|
-
const unbuildConfig = config;
|
|
749
|
-
console.log(
|
|
750
|
-
colors.dim("\u251C\u2500") + " Entries: " + JSON.stringify(unbuildConfig.entries ?? ["src/index"])
|
|
751
|
-
);
|
|
752
|
-
console.log(
|
|
753
|
-
colors.dim("\u251C\u2500") + " Out Dir: " + (unbuildConfig.outDir ?? "dist")
|
|
754
|
-
);
|
|
755
|
-
console.log(
|
|
756
|
-
colors.dim("\u251C\u2500") + " Declaration: " + (unbuildConfig.declaration !== false ? colors.success("\u2713") : colors.dim("\u2717"))
|
|
757
|
-
);
|
|
758
|
-
console.log(
|
|
759
|
-
colors.dim("\u251C\u2500") + " Emit CJS: " + (unbuildConfig.rollup?.emitCJS ? colors.success("\u2713") : colors.dim("\u2717"))
|
|
760
|
-
);
|
|
761
|
-
console.log(
|
|
762
|
-
colors.dim("\u251C\u2500") + " Sourcemap: " + (unbuildConfig.sourcemap ? colors.success("\u2713") : colors.dim("\u2717"))
|
|
763
|
-
);
|
|
764
|
-
console.log(
|
|
765
|
-
colors.dim("\u251C\u2500") + " Parallel: " + (unbuildConfig.parallel !== false ? colors.success("\u2713") : colors.dim("\u2717"))
|
|
766
|
-
);
|
|
767
|
-
console.log(
|
|
768
|
-
colors.dim("\u2514\u2500") + " Clean: " + (unbuildConfig.clean !== false ? colors.success("\u2713") : colors.dim("\u2717"))
|
|
769
|
-
);
|
|
770
|
-
}
|
|
771
|
-
}
|
|
772
|
-
if (pkg?.exports) {
|
|
773
|
-
console.log("\n" + colors.bold("Package Exports:"));
|
|
774
|
-
console.log(JSON.stringify(pkg.exports, null, 2));
|
|
775
|
-
}
|
|
776
|
-
if (pkg?.scripts) {
|
|
777
|
-
const buildScripts = Object.entries(pkg.scripts).filter(
|
|
778
|
-
([key]) => key.includes("build") || key.includes("watch")
|
|
779
|
-
);
|
|
780
|
-
if (buildScripts.length > 0) {
|
|
781
|
-
console.log("\n" + colors.bold("Build Scripts:"));
|
|
782
|
-
buildScripts.forEach(([name, script]) => {
|
|
783
|
-
console.log(` ${colors.command(name.padEnd(20))} ${colors.dim(script)}`);
|
|
784
|
-
});
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
if (bundler === "none") {
|
|
788
|
-
console.log("\n" + colors.warning("\u26A0 No build configuration found"));
|
|
789
|
-
console.log(
|
|
790
|
-
colors.info("\nRun ") + colors.command("rad-build init") + colors.info(" to set up your project")
|
|
791
|
-
);
|
|
792
|
-
}
|
|
793
|
-
} catch (error) {
|
|
794
|
-
logger.error("Failed to gather information", error);
|
|
795
|
-
process.exit(1);
|
|
796
|
-
}
|
|
797
|
-
}
|
|
798
|
-
|
|
799
808
|
async function watchCommand(options) {
|
|
800
809
|
logger.info("Starting watch mode...");
|
|
801
810
|
await buildCommand([], {
|