pluribuild 0.1.0
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/LICENSE +21 -0
- package/README.md +11 -0
- package/dist/index.cjs +77 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.mjs +51 -0
- package/dist/run.mjs +315 -0
- package/index.ts +5 -0
- package/package.json +35 -0
- package/src/BuildOptions.ts +8 -0
- package/src/EntryPoint.ts +4 -0
- package/src/build.ts +41 -0
- package/src/getDefaultEntryPoints.ts +22 -0
- package/src/run.ts +20 -0
- package/src/toEntryPoint.ts +18 -0
- package/tsconfig.json +17 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Alexander Tkačenko
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# pluribuild
|
|
2
|
+
|
|
3
|
+
Build multiple entry points into multiple output files with a single command.
|
|
4
|
+
|
|
5
|
+
Run `npx pluribuild` to build:
|
|
6
|
+
- `entries/<name>/src/index.ts(x)` into `dist/<name>/index.js`;
|
|
7
|
+
- `entries/<name>/x.ts(x)` into `dist/<name>/x.js` (`index` as `x` is fine, too).
|
|
8
|
+
|
|
9
|
+
Run `npx pluribuild <dir>` to point to a parent directory other than `entries`.
|
|
10
|
+
|
|
11
|
+
Add `--dev` to the command to enable rebuilds on code changes. Add `--minify=off` to turn off minification.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
+
get: ((k) => from[k]).bind(null, key),
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
20
|
+
value: mod,
|
|
21
|
+
enumerable: true
|
|
22
|
+
}) : target, mod));
|
|
23
|
+
|
|
24
|
+
let esbuild = require("esbuild");
|
|
25
|
+
esbuild = __toESM(esbuild);
|
|
26
|
+
let node_fs = require("node:fs");
|
|
27
|
+
let node_path = require("node:path");
|
|
28
|
+
|
|
29
|
+
function toEntryPoint(toName) {
|
|
30
|
+
return (path) => {
|
|
31
|
+
let name = toName(path);
|
|
32
|
+
if (!name) throw new Error(`Invalid entry point name: "${path}"`);
|
|
33
|
+
name = name.replace(/\.\w+$/, "");
|
|
34
|
+
return [name, {
|
|
35
|
+
in: path,
|
|
36
|
+
out: name
|
|
37
|
+
}];
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function getDefaultEntryPoints(dir = "entries") {
|
|
42
|
+
let entryPoints = new Map([...(0, node_fs.globSync)(`${dir}/[!_]*/src/index.{ts,tsx}`).map(toEntryPoint((path) => {
|
|
43
|
+
let p = path.split(node_path.sep);
|
|
44
|
+
return `${p.at(-3)}/${p.at(-1)}`;
|
|
45
|
+
})), ...(0, node_fs.globSync)(`${dir}/[!_]*/[!_]*.{ts,tsx}`).map(toEntryPoint((path) => path.split(node_path.sep).slice(-2).join("/")))]);
|
|
46
|
+
return Array.from(entryPoints.values());
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async function build({ entryPoints, dev, dir, ...options } = {}) {
|
|
50
|
+
let e = entryPoints ?? getDefaultEntryPoints(dir);
|
|
51
|
+
if (Object.keys(e).length === 0) {
|
|
52
|
+
console.warn("No entry points");
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
let buildOptions = {
|
|
56
|
+
entryPoints: e,
|
|
57
|
+
outdir: "dist",
|
|
58
|
+
bundle: true,
|
|
59
|
+
splitting: true,
|
|
60
|
+
format: "esm",
|
|
61
|
+
jsx: "automatic",
|
|
62
|
+
loader: {
|
|
63
|
+
".png": "dataurl",
|
|
64
|
+
".svg": "dataurl",
|
|
65
|
+
".html": "text",
|
|
66
|
+
".txt": "text"
|
|
67
|
+
},
|
|
68
|
+
minify: true,
|
|
69
|
+
...options
|
|
70
|
+
};
|
|
71
|
+
if (dev) await (await esbuild.default.context(buildOptions)).watch();
|
|
72
|
+
await esbuild.default.build(buildOptions);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
exports.build = build;
|
|
76
|
+
exports.getDefaultEntryPoints = getDefaultEntryPoints;
|
|
77
|
+
exports.toEntryPoint = toEntryPoint;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { BuildOptions as BuildOptions$1 } from "esbuild";
|
|
2
|
+
|
|
3
|
+
type BuildOptions = BuildOptions$1 & {
|
|
4
|
+
/** Directory containing entry points. */dir?: string; /** Development mode. Enables rebuilds on code changes. */
|
|
5
|
+
dev?: boolean;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
declare function build({
|
|
9
|
+
entryPoints,
|
|
10
|
+
dev,
|
|
11
|
+
dir,
|
|
12
|
+
...options
|
|
13
|
+
}?: BuildOptions): Promise<void>;
|
|
14
|
+
|
|
15
|
+
type EntryPoint = {
|
|
16
|
+
in: string;
|
|
17
|
+
out: string;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
declare function getDefaultEntryPoints(dir?: string): EntryPoint[];
|
|
21
|
+
|
|
22
|
+
declare function toEntryPoint(toName: (path: string) => string | undefined): (path: string) => [string, EntryPoint];
|
|
23
|
+
|
|
24
|
+
export { BuildOptions, EntryPoint, build, getDefaultEntryPoints, toEntryPoint };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import esbuild from "esbuild";
|
|
2
|
+
import { globSync } from "node:fs";
|
|
3
|
+
import { sep } from "node:path";
|
|
4
|
+
|
|
5
|
+
function toEntryPoint(toName) {
|
|
6
|
+
return (path) => {
|
|
7
|
+
let name = toName(path);
|
|
8
|
+
if (!name) throw new Error(`Invalid entry point name: "${path}"`);
|
|
9
|
+
name = name.replace(/\.\w+$/, "");
|
|
10
|
+
return [name, {
|
|
11
|
+
in: path,
|
|
12
|
+
out: name
|
|
13
|
+
}];
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function getDefaultEntryPoints(dir = "entries") {
|
|
18
|
+
let entryPoints = new Map([...globSync(`${dir}/[!_]*/src/index.{ts,tsx}`).map(toEntryPoint((path) => {
|
|
19
|
+
let p = path.split(sep);
|
|
20
|
+
return `${p.at(-3)}/${p.at(-1)}`;
|
|
21
|
+
})), ...globSync(`${dir}/[!_]*/[!_]*.{ts,tsx}`).map(toEntryPoint((path) => path.split(sep).slice(-2).join("/")))]);
|
|
22
|
+
return Array.from(entryPoints.values());
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async function build({ entryPoints, dev, dir, ...options } = {}) {
|
|
26
|
+
let e = entryPoints ?? getDefaultEntryPoints(dir);
|
|
27
|
+
if (Object.keys(e).length === 0) {
|
|
28
|
+
console.warn("No entry points");
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
let buildOptions = {
|
|
32
|
+
entryPoints: e,
|
|
33
|
+
outdir: "dist",
|
|
34
|
+
bundle: true,
|
|
35
|
+
splitting: true,
|
|
36
|
+
format: "esm",
|
|
37
|
+
jsx: "automatic",
|
|
38
|
+
loader: {
|
|
39
|
+
".png": "dataurl",
|
|
40
|
+
".svg": "dataurl",
|
|
41
|
+
".html": "text",
|
|
42
|
+
".txt": "text"
|
|
43
|
+
},
|
|
44
|
+
minify: true,
|
|
45
|
+
...options
|
|
46
|
+
};
|
|
47
|
+
if (dev) await (await esbuild.context(buildOptions)).watch();
|
|
48
|
+
await esbuild.build(buildOptions);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export { build, getDefaultEntryPoints, toEntryPoint };
|
package/dist/run.mjs
ADDED
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
9
|
+
try {
|
|
10
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
11
|
+
} catch (e) {
|
|
12
|
+
throw mod = 0, e;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
var __copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
+
for (let key of __getOwnPropNames(from))
|
|
18
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
19
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
24
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
25
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
26
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
27
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
28
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
29
|
+
mod
|
|
30
|
+
));
|
|
31
|
+
|
|
32
|
+
// node_modules/args-json/dist/index.cjs
|
|
33
|
+
var require_dist = __commonJS({
|
|
34
|
+
"node_modules/args-json/dist/index.cjs"(exports) {
|
|
35
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
36
|
+
function getDefaultInput() {
|
|
37
|
+
return typeof process === "undefined" ? [] : process.argv;
|
|
38
|
+
}
|
|
39
|
+
var offValues = /* @__PURE__ */ new Set([
|
|
40
|
+
"0",
|
|
41
|
+
"false",
|
|
42
|
+
"null",
|
|
43
|
+
"undefined",
|
|
44
|
+
"off"
|
|
45
|
+
]);
|
|
46
|
+
function isOff(x) {
|
|
47
|
+
return offValues.has(String(x));
|
|
48
|
+
}
|
|
49
|
+
function isExplicitlyOff(x) {
|
|
50
|
+
return isOff(x) && String(x) !== "undefined";
|
|
51
|
+
}
|
|
52
|
+
function isKey2(x) {
|
|
53
|
+
return x.startsWith("-") && x.length === 2 && x !== "--" || x.startsWith("--") && x.length > 2;
|
|
54
|
+
}
|
|
55
|
+
var onValues = /* @__PURE__ */ new Set([
|
|
56
|
+
"1",
|
|
57
|
+
"true",
|
|
58
|
+
"on"
|
|
59
|
+
]);
|
|
60
|
+
function isOn(x) {
|
|
61
|
+
return onValues.has(String(x));
|
|
62
|
+
}
|
|
63
|
+
function normalizeInput(input) {
|
|
64
|
+
let source = input ?? getDefaultInput();
|
|
65
|
+
let result = [];
|
|
66
|
+
for (let s of source) {
|
|
67
|
+
if (s.startsWith("-") && s.includes("=")) {
|
|
68
|
+
let key = s.slice(0, s.indexOf("="));
|
|
69
|
+
if (isKey2(key)) {
|
|
70
|
+
result.push(key, s.slice(key.length + 1));
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
result.push(s);
|
|
75
|
+
}
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
78
|
+
var Args2 = class {
|
|
79
|
+
_input;
|
|
80
|
+
constructor(input) {
|
|
81
|
+
this._input = normalizeInput(input);
|
|
82
|
+
}
|
|
83
|
+
hasKey(x) {
|
|
84
|
+
return isKey2(x) && this._input.includes(x);
|
|
85
|
+
}
|
|
86
|
+
isOn(key) {
|
|
87
|
+
let args3 = this._input;
|
|
88
|
+
let k = args3.indexOf(key);
|
|
89
|
+
return k !== -1 && (k === args3.length - 1 || isKey2(args3[k + 1]) || isOn(args3[k + 1]));
|
|
90
|
+
}
|
|
91
|
+
isOff(key) {
|
|
92
|
+
let args3 = this._input;
|
|
93
|
+
let k = args3.indexOf(key);
|
|
94
|
+
return k === -1 || isOff(args3[k + 1]);
|
|
95
|
+
}
|
|
96
|
+
isExplicitlyOff(key) {
|
|
97
|
+
let args3 = this._input;
|
|
98
|
+
let k = args3.indexOf(key);
|
|
99
|
+
return k !== -1 && isExplicitlyOff(args3[k + 1]);
|
|
100
|
+
}
|
|
101
|
+
getValue(key, fallback) {
|
|
102
|
+
let args3 = this._input;
|
|
103
|
+
let keys = Array.isArray(key) ? key : [key];
|
|
104
|
+
for (let k of keys) {
|
|
105
|
+
let i = args3.indexOf(k);
|
|
106
|
+
if (i !== -1 && args3[i + 1] && !isKey2(args3[i + 1])) return args3[i + 1];
|
|
107
|
+
}
|
|
108
|
+
return fallback;
|
|
109
|
+
}
|
|
110
|
+
getValues(key, fallback) {
|
|
111
|
+
let args3 = this._input;
|
|
112
|
+
let keys = Array.isArray(key) ? key : [key];
|
|
113
|
+
let values = [];
|
|
114
|
+
for (let k of keys) {
|
|
115
|
+
let i = args3.indexOf(k);
|
|
116
|
+
while (i !== -1 && args3[i + 1] && !isKey2(args3[i + 1])) values.push(args3[++i]);
|
|
117
|
+
}
|
|
118
|
+
return values.length === 0 ? fallback : values;
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
var args2 = new Args2();
|
|
122
|
+
function getValue(key, fallback) {
|
|
123
|
+
if (fallback === void 0) return args2.getValue(key);
|
|
124
|
+
return args2.getValue(key, fallback);
|
|
125
|
+
}
|
|
126
|
+
function getValues(key, fallback) {
|
|
127
|
+
if (fallback === void 0) return args2.getValues(key);
|
|
128
|
+
return args2.getValues(key, fallback);
|
|
129
|
+
}
|
|
130
|
+
function hasKey(x) {
|
|
131
|
+
return args2.hasKey(x);
|
|
132
|
+
}
|
|
133
|
+
function split(x) {
|
|
134
|
+
let words = [], word = "";
|
|
135
|
+
let hasOpenSingleQuote = false;
|
|
136
|
+
let hasOpenDoubleQuote = false;
|
|
137
|
+
for (let i = 0; i < x.length; i++) {
|
|
138
|
+
let c = x[i];
|
|
139
|
+
if (/^\s/.test(c) && !hasOpenSingleQuote && !hasOpenDoubleQuote) {
|
|
140
|
+
if (word) words.push(word);
|
|
141
|
+
word = "";
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
if (c === "'" && x[i - 1] !== "\\") hasOpenSingleQuote = !hasOpenSingleQuote;
|
|
145
|
+
if (c === '"' && x[i - 1] !== "\\") hasOpenDoubleQuote = !hasOpenDoubleQuote;
|
|
146
|
+
word += c;
|
|
147
|
+
}
|
|
148
|
+
if (word) words.push(word);
|
|
149
|
+
return words;
|
|
150
|
+
}
|
|
151
|
+
function toCamelCase(x) {
|
|
152
|
+
let s = x.replace(/^[-_.\s~+]|[-_.\s~+]$/g, "");
|
|
153
|
+
if (!/[-_.\s~+]/.test(s)) return s.slice(0, 1).toLowerCase() + s.slice(1);
|
|
154
|
+
return s.toLowerCase().replace(/[-_.\s~+](\S)/g, (_, match) => match.toUpperCase());
|
|
155
|
+
}
|
|
156
|
+
function toKey(x) {
|
|
157
|
+
if (x === void 0 || !isKey2(x)) return;
|
|
158
|
+
if (x.startsWith("-") && x.length === 2) return toCamelCase(x.slice(1));
|
|
159
|
+
if (x.startsWith("--") && x.length > 2) return toCamelCase(x.slice(2));
|
|
160
|
+
}
|
|
161
|
+
function parseArgs(input, map) {
|
|
162
|
+
let normalizedInput;
|
|
163
|
+
let normalizedMap;
|
|
164
|
+
if (input === void 0) normalizedInput = getDefaultInput();
|
|
165
|
+
else if (typeof input === "string") normalizedInput = split(input);
|
|
166
|
+
else if (Array.isArray(input)) normalizedInput = input.map((x) => String(x));
|
|
167
|
+
else if (input !== null && typeof input === "object") {
|
|
168
|
+
normalizedInput = getDefaultInput();
|
|
169
|
+
normalizedMap = input;
|
|
170
|
+
} else normalizedInput = [];
|
|
171
|
+
normalizedInput = normalizedInput.flatMap((item) => {
|
|
172
|
+
let normalizedItem = item.trim();
|
|
173
|
+
let k = normalizedItem.indexOf("=");
|
|
174
|
+
if (k === -1) return normalizedItem;
|
|
175
|
+
let key2 = normalizedItem.slice(0, k);
|
|
176
|
+
let value = normalizedItem.slice(k + 1);
|
|
177
|
+
if (!isKey2(key2)) return normalizedItem;
|
|
178
|
+
return [key2, value];
|
|
179
|
+
});
|
|
180
|
+
if (map) normalizedMap = map;
|
|
181
|
+
let key = "";
|
|
182
|
+
let parsedArgs = {};
|
|
183
|
+
for (let rawValue of normalizedInput) {
|
|
184
|
+
rawValue = rawValue.trim();
|
|
185
|
+
if (rawValue.startsWith('"') && rawValue.endsWith('"')) rawValue = rawValue.slice(1, -1);
|
|
186
|
+
else if (rawValue.startsWith("'") && rawValue.endsWith("'")) rawValue = rawValue.slice(1, -1);
|
|
187
|
+
let parsedKey = toKey(rawValue);
|
|
188
|
+
if (parsedKey !== void 0) {
|
|
189
|
+
let nextKey = normalizedMap?.[parsedKey] ?? parsedKey;
|
|
190
|
+
if (key && nextKey !== key && parsedArgs[key] === void 0) parsedArgs[key] = true;
|
|
191
|
+
key = nextKey;
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
let parsedValue;
|
|
195
|
+
if (rawValue) try {
|
|
196
|
+
parsedValue = JSON.parse(rawValue);
|
|
197
|
+
} catch {
|
|
198
|
+
parsedValue = rawValue;
|
|
199
|
+
}
|
|
200
|
+
else parsedValue = true;
|
|
201
|
+
let prevValue = parsedArgs[key];
|
|
202
|
+
let value;
|
|
203
|
+
if (prevValue === void 0) value = key === "" ? [parsedValue] : parsedValue;
|
|
204
|
+
else if (Array.isArray(prevValue)) value = [...prevValue, parsedValue];
|
|
205
|
+
else value = [prevValue, parsedValue];
|
|
206
|
+
parsedArgs[key] = value;
|
|
207
|
+
}
|
|
208
|
+
if (key && parsedArgs[key] === void 0) parsedArgs[key] = true;
|
|
209
|
+
return parsedArgs;
|
|
210
|
+
}
|
|
211
|
+
exports.Args = Args2;
|
|
212
|
+
exports.args = args2;
|
|
213
|
+
exports.getValue = getValue;
|
|
214
|
+
exports.getValues = getValues;
|
|
215
|
+
exports.hasKey = hasKey;
|
|
216
|
+
exports.isExplicitlyOff = isExplicitlyOff;
|
|
217
|
+
exports.isKey = isKey2;
|
|
218
|
+
exports.isOff = isOff;
|
|
219
|
+
exports.isOn = isOn;
|
|
220
|
+
exports.parseArgs = parseArgs;
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
// src/run.ts
|
|
225
|
+
var import_args_json = __toESM(require_dist(), 1);
|
|
226
|
+
|
|
227
|
+
// src/build.ts
|
|
228
|
+
import esbuild from "esbuild";
|
|
229
|
+
|
|
230
|
+
// src/getDefaultEntryPoints.ts
|
|
231
|
+
import { globSync } from "node:fs";
|
|
232
|
+
import { sep } from "node:path";
|
|
233
|
+
|
|
234
|
+
// src/toEntryPoint.ts
|
|
235
|
+
function toEntryPoint(toName) {
|
|
236
|
+
return (path) => {
|
|
237
|
+
let name = toName(path);
|
|
238
|
+
if (!name) throw new Error(`Invalid entry point name: "${path}"`);
|
|
239
|
+
name = name.replace(/\.\w+$/, "");
|
|
240
|
+
return [
|
|
241
|
+
name,
|
|
242
|
+
{
|
|
243
|
+
in: path,
|
|
244
|
+
out: name
|
|
245
|
+
}
|
|
246
|
+
];
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// src/getDefaultEntryPoints.ts
|
|
251
|
+
function getDefaultEntryPoints(dir = "entries") {
|
|
252
|
+
let entryPoints = new Map([
|
|
253
|
+
// entries/x/src/index.ts -> dist/x/index.js
|
|
254
|
+
...globSync(`${dir}/[!_]*/src/index.{ts,tsx}`).map(
|
|
255
|
+
toEntryPoint((path) => {
|
|
256
|
+
let p = path.split(sep);
|
|
257
|
+
return `${p.at(-3)}/${p.at(-1)}`;
|
|
258
|
+
})
|
|
259
|
+
),
|
|
260
|
+
// entries/x/index.ts -> dist/x/index.js (overrides entries/x/src/index.ts, if present)
|
|
261
|
+
// entries/x/y.ts -> dist/x/y.js
|
|
262
|
+
...globSync(`${dir}/[!_]*/[!_]*.{ts,tsx}`).map(
|
|
263
|
+
toEntryPoint((path) => path.split(sep).slice(-2).join("/"))
|
|
264
|
+
)
|
|
265
|
+
]);
|
|
266
|
+
return Array.from(entryPoints.values());
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// src/build.ts
|
|
270
|
+
async function build({
|
|
271
|
+
entryPoints,
|
|
272
|
+
dev,
|
|
273
|
+
dir,
|
|
274
|
+
...options2
|
|
275
|
+
} = {}) {
|
|
276
|
+
let e = entryPoints ?? getDefaultEntryPoints(dir);
|
|
277
|
+
if (Object.keys(e).length === 0) {
|
|
278
|
+
console.warn("No entry points");
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
let buildOptions = {
|
|
282
|
+
entryPoints: e,
|
|
283
|
+
outdir: "dist",
|
|
284
|
+
bundle: true,
|
|
285
|
+
splitting: true,
|
|
286
|
+
format: "esm",
|
|
287
|
+
jsx: "automatic",
|
|
288
|
+
loader: {
|
|
289
|
+
".png": "dataurl",
|
|
290
|
+
".svg": "dataurl",
|
|
291
|
+
".html": "text",
|
|
292
|
+
".txt": "text"
|
|
293
|
+
},
|
|
294
|
+
minify: true,
|
|
295
|
+
...options2
|
|
296
|
+
};
|
|
297
|
+
if (dev) {
|
|
298
|
+
let ctx = await esbuild.context(buildOptions);
|
|
299
|
+
await ctx.watch();
|
|
300
|
+
}
|
|
301
|
+
await esbuild.build(buildOptions);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// src/run.ts
|
|
305
|
+
var args = new import_args_json.Args();
|
|
306
|
+
var options = {
|
|
307
|
+
dev: args.hasKey("--dev"),
|
|
308
|
+
minify: !args.isExplicitlyOff("--minify")
|
|
309
|
+
};
|
|
310
|
+
var rawArgs = process.argv.slice(2);
|
|
311
|
+
if (rawArgs.length !== 0 && !(0, import_args_json.isKey)(rawArgs[0])) options.dir = rawArgs[0];
|
|
312
|
+
for (let [k, v] of Object.entries(options)) {
|
|
313
|
+
if (v === void 0) delete options[k];
|
|
314
|
+
}
|
|
315
|
+
build(options);
|
package/index.ts
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "pluribuild",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Build multiple entry points into multiple output files with a single command",
|
|
5
|
+
"main": "./dist/index.cjs",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"compile-bin": "esbuild src/run.ts --bundle --outfile=dist/run.mjs --platform=node --format=esm --external:esbuild",
|
|
11
|
+
"preversion": "npx npm-run-all shape compile-bin",
|
|
12
|
+
"shape": "npx codeshape",
|
|
13
|
+
"typecheck": "npx codeshape typecheck"
|
|
14
|
+
},
|
|
15
|
+
"bin": {
|
|
16
|
+
"pluribuild": "./dist/run.mjs"
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/axtk/pluribuild.git"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"build",
|
|
24
|
+
"entry points"
|
|
25
|
+
],
|
|
26
|
+
"author": "axtk",
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"args-json": "^1.4.3",
|
|
30
|
+
"esbuild": "^0.28.2"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/node": "^22.20.2"
|
|
34
|
+
}
|
|
35
|
+
}
|
package/src/build.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import esbuild, { type BuildOptions as EsbuildOptions } from "esbuild";
|
|
2
|
+
import type { BuildOptions } from "./BuildOptions.ts";
|
|
3
|
+
import { getDefaultEntryPoints } from "./getDefaultEntryPoints.ts";
|
|
4
|
+
|
|
5
|
+
export async function build({
|
|
6
|
+
entryPoints,
|
|
7
|
+
dev,
|
|
8
|
+
dir,
|
|
9
|
+
...options
|
|
10
|
+
}: BuildOptions = {}) {
|
|
11
|
+
let e = entryPoints ?? getDefaultEntryPoints(dir);
|
|
12
|
+
|
|
13
|
+
if (Object.keys(e).length === 0) {
|
|
14
|
+
console.warn("No entry points");
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
let buildOptions: EsbuildOptions = {
|
|
19
|
+
entryPoints: e,
|
|
20
|
+
outdir: "dist",
|
|
21
|
+
bundle: true,
|
|
22
|
+
splitting: true,
|
|
23
|
+
format: "esm",
|
|
24
|
+
jsx: "automatic",
|
|
25
|
+
loader: {
|
|
26
|
+
".png": "dataurl",
|
|
27
|
+
".svg": "dataurl",
|
|
28
|
+
".html": "text",
|
|
29
|
+
".txt": "text",
|
|
30
|
+
},
|
|
31
|
+
minify: true,
|
|
32
|
+
...options,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
if (dev) {
|
|
36
|
+
let ctx = await esbuild.context(buildOptions);
|
|
37
|
+
await ctx.watch();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
await esbuild.build(buildOptions);
|
|
41
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { globSync } from "node:fs";
|
|
2
|
+
import { sep } from "node:path";
|
|
3
|
+
import { toEntryPoint } from "./toEntryPoint.ts";
|
|
4
|
+
|
|
5
|
+
export function getDefaultEntryPoints(dir = "entries") {
|
|
6
|
+
let entryPoints = new Map([
|
|
7
|
+
// entries/x/src/index.ts -> dist/x/index.js
|
|
8
|
+
...globSync(`${dir}/[!_]*/src/index.{ts,tsx}`).map(
|
|
9
|
+
toEntryPoint((path) => {
|
|
10
|
+
let p = path.split(sep);
|
|
11
|
+
return `${p.at(-3)}/${p.at(-1)}`;
|
|
12
|
+
}),
|
|
13
|
+
),
|
|
14
|
+
// entries/x/index.ts -> dist/x/index.js (overrides entries/x/src/index.ts, if present)
|
|
15
|
+
// entries/x/y.ts -> dist/x/y.js
|
|
16
|
+
...globSync(`${dir}/[!_]*/[!_]*.{ts,tsx}`).map(
|
|
17
|
+
toEntryPoint((path) => path.split(sep).slice(-2).join("/")),
|
|
18
|
+
),
|
|
19
|
+
]);
|
|
20
|
+
|
|
21
|
+
return Array.from(entryPoints.values());
|
|
22
|
+
}
|
package/src/run.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Args, isKey } from "args-json";
|
|
3
|
+
import type { BuildOptions } from "./BuildOptions.ts";
|
|
4
|
+
import { build } from "./build.ts";
|
|
5
|
+
|
|
6
|
+
let args = new Args();
|
|
7
|
+
|
|
8
|
+
let options: BuildOptions = {
|
|
9
|
+
dev: args.hasKey("--dev"),
|
|
10
|
+
minify: !args.isExplicitlyOff("--minify"),
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
let rawArgs = process.argv.slice(2);
|
|
14
|
+
if (rawArgs.length !== 0 && !isKey(rawArgs[0])) options.dir = rawArgs[0];
|
|
15
|
+
|
|
16
|
+
for (let [k, v] of Object.entries(options)) {
|
|
17
|
+
if (v === undefined) delete options[k as keyof BuildOptions];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
build(options);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { EntryPoint } from "./EntryPoint.ts";
|
|
2
|
+
|
|
3
|
+
export function toEntryPoint(toName: (path: string) => string | undefined) {
|
|
4
|
+
return (path: string): [string, EntryPoint] => {
|
|
5
|
+
let name = toName(path);
|
|
6
|
+
|
|
7
|
+
if (!name) throw new Error(`Invalid entry point name: "${path}"`);
|
|
8
|
+
name = name.replace(/\.\w+$/, "");
|
|
9
|
+
|
|
10
|
+
return [
|
|
11
|
+
name,
|
|
12
|
+
{
|
|
13
|
+
in: path,
|
|
14
|
+
out: name,
|
|
15
|
+
},
|
|
16
|
+
];
|
|
17
|
+
};
|
|
18
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"include": ["./index.ts", "src"],
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"declaration": true,
|
|
5
|
+
"emitDeclarationOnly": true,
|
|
6
|
+
"lib": ["ESNext", "DOM", "DOM.Iterable"],
|
|
7
|
+
"types": ["node"],
|
|
8
|
+
"target": "esnext",
|
|
9
|
+
"outDir": "dist",
|
|
10
|
+
"module": "nodenext",
|
|
11
|
+
"moduleResolution": "nodenext",
|
|
12
|
+
"allowImportingTsExtensions": true,
|
|
13
|
+
"strict": true,
|
|
14
|
+
"noUnusedLocals": true,
|
|
15
|
+
"noUnusedParameters": true
|
|
16
|
+
}
|
|
17
|
+
}
|