1515
1616 -------------------------------------------------------------------*/
1717
18+ import type { AssetGlob } from "@storm-software/build-tools" ;
1819import { build as esbuild } from "@storm-software/esbuild" ;
1920import stormStack from "@storm-stack/build-plugin/esbuild" ;
21+ import { EntryPointsOption } from "../types" ;
22+
23+ /**
24+ * The options for building a NodeJs application
25+ */
26+ export interface NodeAppBuildOptions {
27+ /**
28+ * The entry point(s) of the project
29+ *
30+ * @defaultValue ["src/index.ts"]
31+ */
32+ entryPoints ?: EntryPointsOption ;
33+
34+ /**
35+ * Should the build be run in development mode
36+ *
37+ * @remarks
38+ * When set to `true`, the build will not be minified and will include sourcemaps
39+ *
40+ * @defaultValue false
41+ */
42+ debug ?: boolean ;
43+
44+ /**
45+ * A list of files to include in the build package
46+ *
47+ * @defaultValue []
48+ */
49+ assets ?: ( AssetGlob | string ) [ ] ;
50+
51+ /**
52+ * The output path of the build
53+ *
54+ * @remarks
55+ * The path is relative to the distribution/build directory. In most cases, you should not need to change this.
56+ *
57+ * @defaultValue "dist"
58+ */
59+ outputPath ?: string ;
60+ }
2061
2162/**
2263 * Build a NodeJs application
@@ -26,27 +67,24 @@ import stormStack from "@storm-stack/build-plugin/esbuild";
2667 */
2768export const build = async (
2869 projectRoot : string ,
29- entry :
30- | string
31- | string [ ]
32- | Record < string , string >
33- | {
34- in : string ;
35- out : string ;
36- } [ ] = [ "src/index.ts" ]
70+ options : NodeAppBuildOptions = { }
3771) => {
38- const entryPoints = typeof entry === "string" ? [ entry ] : entry ;
72+ const entryPoints = ! options . entryPoints
73+ ? [ "src/index.ts" ]
74+ : typeof options . entryPoints === "string"
75+ ? [ options . entryPoints ]
76+ : options . entryPoints ;
3977
4078 await esbuild ( [
4179 {
4280 entryPoints,
4381 projectRoot,
44- outdir : "dist" ,
82+ outdir : options . outputPath || "dist" ,
4583 platform : "node" ,
4684 format : "cjs" ,
4785 bundle : true ,
48- minify : true ,
49- sourcemap : true ,
86+ minify : ! options . debug ,
87+ sourcemap : options . debug ,
5088 plugins : [
5189 stormStack ( {
5290 cache : true
@@ -56,12 +94,12 @@ export const build = async (
5694 {
5795 entryPoints,
5896 projectRoot,
59- outdir : "dist" ,
97+ outdir : options . outputPath || "dist" ,
6098 platform : "node" ,
6199 format : "esm" ,
62100 bundle : true ,
63- minify : true ,
64- sourcemap : true ,
101+ minify : ! options . debug ,
102+ sourcemap : options . debug ,
65103 plugins : [
66104 stormStack ( {
67105 cache : true
0 commit comments