@adddog/build-configs 0.0.1 → 0.0.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/README.md +1 -1
- package/dist/cli/index.mjs +130 -122
- 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 -3
- 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/dist/tsup.config.d.mts +1 -1
- package/dist/tsup.config.d.ts +1 -1
- package/dist/tsup.config.mjs +2 -4
- package/dist/tsup.config.mjs.map +1 -1
- package/package.json +24 -14
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,22 @@
|
|
|
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
|
-
import 'tsup';
|
|
17
17
|
import 'unbuild';
|
|
18
18
|
|
|
19
|
-
const version = "0.0.
|
|
19
|
+
const version = "0.0.6";
|
|
20
20
|
|
|
21
21
|
const logger = consola.create({
|
|
22
22
|
formatOptions: {
|
|
@@ -99,7 +99,7 @@ async function detectBundler(cwd = process.cwd()) {
|
|
|
99
99
|
interopDefault: true
|
|
100
100
|
});
|
|
101
101
|
const config = await jiti.import(configPath);
|
|
102
|
-
if (
|
|
102
|
+
if ("entries" in config || "rollup" in config || Array.isArray(config) && config[0] && "entries" in config[0]) {
|
|
103
103
|
return "unbuild";
|
|
104
104
|
}
|
|
105
105
|
} catch {
|
|
@@ -220,7 +220,8 @@ async function updatePackageJson(updates, cwd = process.cwd()) {
|
|
|
220
220
|
const pkgPath = join(cwd, "package.json");
|
|
221
221
|
const pkg = await getPackageJson(cwd) ?? {};
|
|
222
222
|
const updated = defu(updates, pkg);
|
|
223
|
-
await writeFile(pkgPath, JSON.stringify(updated, null, 2)
|
|
223
|
+
await writeFile(pkgPath, `${JSON.stringify(updated, null, 2)}
|
|
224
|
+
`);
|
|
224
225
|
}
|
|
225
226
|
|
|
226
227
|
async function buildCommand(entries, options) {
|
|
@@ -304,6 +305,112 @@ async function buildCommand(entries, options) {
|
|
|
304
305
|
}
|
|
305
306
|
}
|
|
306
307
|
|
|
308
|
+
async function infoCommand(options) {
|
|
309
|
+
try {
|
|
310
|
+
logger.start("Gathering project information...\n");
|
|
311
|
+
const pkg = await getPackageJson();
|
|
312
|
+
const projectName = pkg?.name ?? "unknown";
|
|
313
|
+
const projectVersion = pkg?.version ?? "0.0.0";
|
|
314
|
+
const configPath = await discoverConfigFile(
|
|
315
|
+
process.cwd(),
|
|
316
|
+
options.config
|
|
317
|
+
);
|
|
318
|
+
let bundler = "none";
|
|
319
|
+
let config = {};
|
|
320
|
+
if (configPath) {
|
|
321
|
+
const loaded = await loadConfig({
|
|
322
|
+
...options.config && { configPath: options.config },
|
|
323
|
+
bundler: "auto"
|
|
324
|
+
});
|
|
325
|
+
bundler = loaded.bundler;
|
|
326
|
+
config = loaded.config;
|
|
327
|
+
}
|
|
328
|
+
logBox("Project Information", [
|
|
329
|
+
`Name: ${colors.primary(projectName)}`,
|
|
330
|
+
`Version: ${colors.primary(projectVersion)}`,
|
|
331
|
+
`Config: ${configPath ? colors.file(configPath) : colors.dim("not found")}`,
|
|
332
|
+
`Bundler: ${bundler !== "none" ? colors.bundler(bundler) : colors.dim("not configured")}`
|
|
333
|
+
]);
|
|
334
|
+
if (bundler !== "none") {
|
|
335
|
+
console.log(`
|
|
336
|
+
${colors.bold("Build Configuration:")}`);
|
|
337
|
+
if (bundler === "tsup") {
|
|
338
|
+
const tsupConfig = config;
|
|
339
|
+
console.log(`${colors.dim("\u251C\u2500")} Entry: ${JSON.stringify(tsupConfig.entry ?? ["src/index.ts"])}`);
|
|
340
|
+
console.log(`${colors.dim("\u251C\u2500")} Format: ${JSON.stringify(tsupConfig.format ?? ["esm", "cjs"])}`);
|
|
341
|
+
console.log(
|
|
342
|
+
`${colors.dim("\u251C\u2500")} Target: ${tsupConfig.target ?? "node18"}`
|
|
343
|
+
);
|
|
344
|
+
console.log(
|
|
345
|
+
`${colors.dim("\u251C\u2500")} Platform: ${tsupConfig.platform ?? "node"}`
|
|
346
|
+
);
|
|
347
|
+
console.log(
|
|
348
|
+
`${colors.dim("\u251C\u2500")} DTS: ${tsupConfig.dts !== false ? colors.success("\u2713") : colors.dim("\u2717")}`
|
|
349
|
+
);
|
|
350
|
+
console.log(
|
|
351
|
+
`${colors.dim("\u251C\u2500")} Sourcemap: ${tsupConfig.sourcemap !== false ? colors.success("\u2713") : colors.dim("\u2717")}`
|
|
352
|
+
);
|
|
353
|
+
console.log(
|
|
354
|
+
`${colors.dim("\u251C\u2500")} Minify: ${tsupConfig.minify ? colors.success("\u2713") : colors.dim("\u2717")}`
|
|
355
|
+
);
|
|
356
|
+
console.log(
|
|
357
|
+
`${colors.dim("\u2514\u2500")} Clean: ${tsupConfig.clean !== false ? colors.success("\u2713") : colors.dim("\u2717")}`
|
|
358
|
+
);
|
|
359
|
+
} else {
|
|
360
|
+
const unbuildConfig = config;
|
|
361
|
+
console.log(
|
|
362
|
+
`${colors.dim("\u251C\u2500")} Entries: ${JSON.stringify(unbuildConfig.entries ?? ["src/index"])}`
|
|
363
|
+
);
|
|
364
|
+
console.log(
|
|
365
|
+
`${colors.dim("\u251C\u2500")} Out Dir: ${unbuildConfig.outDir ?? "dist"}`
|
|
366
|
+
);
|
|
367
|
+
console.log(
|
|
368
|
+
`${colors.dim("\u251C\u2500")} Declaration: ${unbuildConfig.declaration !== false ? colors.success("\u2713") : colors.dim("\u2717")}`
|
|
369
|
+
);
|
|
370
|
+
console.log(
|
|
371
|
+
`${colors.dim("\u251C\u2500")} Emit CJS: ${unbuildConfig.rollup?.emitCJS ? colors.success("\u2713") : colors.dim("\u2717")}`
|
|
372
|
+
);
|
|
373
|
+
console.log(
|
|
374
|
+
`${colors.dim("\u251C\u2500")} Sourcemap: ${unbuildConfig.sourcemap ? colors.success("\u2713") : colors.dim("\u2717")}`
|
|
375
|
+
);
|
|
376
|
+
console.log(
|
|
377
|
+
`${colors.dim("\u251C\u2500")} Parallel: ${unbuildConfig.parallel !== false ? colors.success("\u2713") : colors.dim("\u2717")}`
|
|
378
|
+
);
|
|
379
|
+
console.log(
|
|
380
|
+
`${colors.dim("\u2514\u2500")} Clean: ${unbuildConfig.clean !== false ? colors.success("\u2713") : colors.dim("\u2717")}`
|
|
381
|
+
);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
if (pkg?.exports) {
|
|
385
|
+
console.log(`
|
|
386
|
+
${colors.bold("Package Exports:")}`);
|
|
387
|
+
console.log(JSON.stringify(pkg.exports, null, 2));
|
|
388
|
+
}
|
|
389
|
+
if (pkg?.scripts) {
|
|
390
|
+
const buildScripts = Object.entries(pkg.scripts).filter(
|
|
391
|
+
([key]) => key.includes("build") || key.includes("watch")
|
|
392
|
+
);
|
|
393
|
+
if (buildScripts.length > 0) {
|
|
394
|
+
console.log(`
|
|
395
|
+
${colors.bold("Build Scripts:")}`);
|
|
396
|
+
buildScripts.forEach(([name, script]) => {
|
|
397
|
+
console.log(` ${colors.command(name.padEnd(20))} ${colors.dim(script)}`);
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
if (bundler === "none") {
|
|
402
|
+
console.log(`
|
|
403
|
+
${colors.warning("\u26A0 No build configuration found")}`);
|
|
404
|
+
console.log(
|
|
405
|
+
colors.info("\nRun ") + colors.command("rad-build init") + colors.info(" to set up your project")
|
|
406
|
+
);
|
|
407
|
+
}
|
|
408
|
+
} catch (error) {
|
|
409
|
+
logger.error("Failed to gather information", error);
|
|
410
|
+
process.exit(1);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|
|
307
414
|
function generateTsupConfig(options = {}) {
|
|
308
415
|
const config = {
|
|
309
416
|
entry: options.entry ?? ["src/index.ts"],
|
|
@@ -337,9 +444,9 @@ function generatePackageJsonScripts(bundler) {
|
|
|
337
444
|
const buildCommand = bundler === "tsup" ? "tsup" : "unbuild";
|
|
338
445
|
const watchCommand = bundler === "tsup" ? "tsup --watch" : "unbuild --watch";
|
|
339
446
|
return {
|
|
340
|
-
build: buildCommand,
|
|
447
|
+
"build": buildCommand,
|
|
341
448
|
"build:watch": watchCommand,
|
|
342
|
-
prepublishOnly: "pnpm build"
|
|
449
|
+
"prepublishOnly": "pnpm build"
|
|
343
450
|
};
|
|
344
451
|
}
|
|
345
452
|
function generatePackageJsonExports(_bundler, formats) {
|
|
@@ -470,8 +577,9 @@ async function initCommand(options) {
|
|
|
470
577
|
p.cancel("Operation cancelled");
|
|
471
578
|
process.exit(0);
|
|
472
579
|
}
|
|
580
|
+
const formatsArray = formats;
|
|
473
581
|
finalConfig = {
|
|
474
|
-
format:
|
|
582
|
+
format: formatsArray,
|
|
475
583
|
sourcemap: features.includes("sourcemaps"),
|
|
476
584
|
minify: features.includes("minify")
|
|
477
585
|
};
|
|
@@ -495,14 +603,16 @@ async function initCommand(options) {
|
|
|
495
603
|
const pkg = await getPackageJson();
|
|
496
604
|
if (pkg) {
|
|
497
605
|
const scripts = generatePackageJsonScripts(bundler);
|
|
498
|
-
const
|
|
606
|
+
const formatArray = Array.isArray(finalConfig.format) ? finalConfig.format : finalConfig.format ? [finalConfig.format] : ["esm", "cjs"];
|
|
607
|
+
const exports$1 = generatePackageJsonExports(
|
|
499
608
|
bundler,
|
|
500
|
-
|
|
609
|
+
formatArray
|
|
501
610
|
);
|
|
611
|
+
const pkgScripts = typeof pkg.scripts === "object" && pkg.scripts !== null ? pkg.scripts : {};
|
|
502
612
|
await updatePackageJson({
|
|
503
|
-
scripts: { ...
|
|
504
|
-
exports,
|
|
505
|
-
main:
|
|
613
|
+
scripts: { ...pkgScripts, ...scripts },
|
|
614
|
+
exports: exports$1,
|
|
615
|
+
main: formatArray.includes("cjs") || finalConfig.rollup?.emitCJS ? "./dist/index.cjs" : void 0,
|
|
506
616
|
module: "./dist/index.mjs",
|
|
507
617
|
types: "./dist/index.d.ts",
|
|
508
618
|
files: ["dist"]
|
|
@@ -682,8 +792,8 @@ async function validateCommand(options) {
|
|
|
682
792
|
logError("\u2717 Configuration validation failed");
|
|
683
793
|
if (result.error) {
|
|
684
794
|
logger.error("\nValidation errors:");
|
|
685
|
-
result.error.
|
|
686
|
-
logger.error(` ${colors.error("\u2022")} ${err.path.join(".")}: ${err.message}`);
|
|
795
|
+
result.error.issues.forEach((err) => {
|
|
796
|
+
logger.error(` ${colors.error("\u2022")} ${String(err.path.join("."))}: ${err.message}`);
|
|
687
797
|
});
|
|
688
798
|
}
|
|
689
799
|
process.exit(1);
|
|
@@ -694,108 +804,6 @@ async function validateCommand(options) {
|
|
|
694
804
|
}
|
|
695
805
|
}
|
|
696
806
|
|
|
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
807
|
async function watchCommand(options) {
|
|
800
808
|
logger.info("Starting watch mode...");
|
|
801
809
|
await buildCommand([], {
|