@reliverse/dler 1.2.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 +312 -0
- package/bin/cli/args/agg/main.js +0 -0
- package/bin/cli/args/conv/README.md +3 -0
- package/bin/cli/args/conv/main.js +0 -0
- package/bin/cli/args/deps/analyzer.js +42 -0
- package/bin/cli/args/deps/filesystem.js +42 -0
- package/bin/cli/args/deps/formatter.js +65 -0
- package/bin/cli/args/deps/mod.js +48 -0
- package/bin/cli/args/deps/parser.js +59 -0
- package/bin/cli/args/deps/types.js +0 -0
- package/bin/cli/args/init/README.md +121 -0
- package/bin/cli/args/init/libs/reinit/reinit-main.js +5 -0
- package/bin/cli/args/init/libs/reinit/reint-impl/const.js +26 -0
- package/bin/cli/args/init/libs/reinit/reint-impl/mod.txt +395 -0
- package/bin/cli/args/init/libs/reinit/reint-impl/templates/t-gitignore.js +9 -0
- package/bin/cli/args/init/libs/reinit/reint-impl/templates/t-license.js +22 -0
- package/bin/cli/args/init/libs/reinit/reint-impl/templates/t-readme.js +59 -0
- package/bin/cli/args/init/libs/reinit/reint-impl/types.js +0 -0
- package/bin/cli/args/init/libs/reinit/reint-impl/utils.js +3 -0
- package/bin/cli/args/init/main.txt +121 -0
- package/bin/cli/args/init/types.js +1 -0
- package/bin/cli/args/inject/README.md +148 -0
- package/bin/cli/args/inject/arg-ts-expect-error.txt +49 -0
- package/bin/cli/args/inject/cli-mod.js +32 -0
- package/bin/cli/args/inject/main.txt +28 -0
- package/bin/cli/args/inject/reinject.config.js +4 -0
- package/bin/cli/args/inject/ts-expect-error.txt +277 -0
- package/bin/cli/args/merger/README.md +125 -0
- package/bin/cli/args/merger/main.txt +306 -0
- package/bin/cli/args/mono/main.js +0 -0
- package/bin/cli/args/spells/mod.js +44 -0
- package/bin/cli/args/split/README.md +13 -0
- package/bin/cli/args/split/split-main.js +26 -0
- package/bin/cli/args/split/split-mod.js +117 -0
- package/bin/cli/args/tools/index.js +81 -0
- package/bin/cli/args/tools/tools-impl.js +296 -0
- package/bin/cli.js +111 -0
- package/bin/init.js +157 -0
- package/bin/libs/cfg/cfg-default.js +50 -0
- package/bin/libs/cfg/cfg-main.js +1 -0
- package/bin/libs/cfg/cfg-mod.js +4 -0
- package/bin/libs/cfg/cfg-types.js +1 -0
- package/bin/libs/sdk/sdk-impl/build/build-library.js +865 -0
- package/bin/libs/sdk/sdk-impl/build/build-regular.js +373 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/auto.js +110 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/build.js +322 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/copy/copy.js +62 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/copy/types.js +0 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/mkdist/mkdist.js +57 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/mkdist/types.js +0 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/build.js +104 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/config.js +124 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/plugins/cjs.js +48 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/plugins/esbuild.js +91 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/plugins/json.js +17 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/plugins/raw.js +20 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/plugins/shebang.js +42 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/stub.js +137 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/types.js +0 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/utils.js +41 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/watch.js +33 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/types.js +6 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/untyped/index.js +125 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/untyped/types.js +0 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/utils.js +158 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/validate.js +68 -0
- package/bin/libs/sdk/sdk-impl/library-flow.js +169 -0
- package/bin/libs/sdk/sdk-impl/pub/pub-library.js +132 -0
- package/bin/libs/sdk/sdk-impl/pub/pub-regular.js +69 -0
- package/bin/libs/sdk/sdk-impl/regular-flow.js +219 -0
- package/bin/libs/sdk/sdk-impl/spells/spells-executors.js +307 -0
- package/bin/libs/sdk/sdk-impl/spells/spells-filesystem.js +72 -0
- package/bin/libs/sdk/sdk-impl/spells/spells-main.js +87 -0
- package/bin/libs/sdk/sdk-impl/spells/spells-parser.js +60 -0
- package/bin/libs/sdk/sdk-impl/spells/spells-types.js +0 -0
- package/bin/libs/sdk/sdk-impl/utils/tools/tools-agg.js +149 -0
- package/bin/libs/sdk/sdk-impl/utils/tools/tools-impl.js +21 -0
- package/bin/libs/sdk/sdk-impl/utils/utils-build.js +102 -0
- package/bin/libs/sdk/sdk-impl/utils/utils-bump.js +238 -0
- package/bin/libs/sdk/sdk-impl/utils/utils-clean.js +35 -0
- package/bin/libs/sdk/sdk-impl/utils/utils-consts.js +17 -0
- package/bin/libs/sdk/sdk-impl/utils/utils-cwd.js +36 -0
- package/bin/libs/sdk/sdk-impl/utils/utils-deps.js +73 -0
- package/bin/libs/sdk/sdk-impl/utils/utils-determine.js +25 -0
- package/bin/libs/sdk/sdk-impl/utils/utils-error.js +17 -0
- package/bin/libs/sdk/sdk-impl/utils/utils-fs.js +202 -0
- package/bin/libs/sdk/sdk-impl/utils/utils-info.js +42 -0
- package/bin/libs/sdk/sdk-impl/utils/utils-jsr-json.js +51 -0
- package/bin/libs/sdk/sdk-impl/utils/utils-paths.js +658 -0
- package/bin/libs/sdk/sdk-impl/utils/utils-perf.js +22 -0
- package/bin/libs/sdk/sdk-impl/utils/utils-pkg-json-libs.js +259 -0
- package/bin/libs/sdk/sdk-impl/utils/utils-pkg-json-reg.js +207 -0
- package/bin/libs/sdk/sdk-impl/utils/utils-tsconfig.js +44 -0
- package/bin/libs/sdk/sdk-main.js +114 -0
- package/bin/libs/sdk/sdk-types.js +1 -0
- package/bin/load.js +27 -0
- package/bin/main.js +46 -0
- package/bin/tools.txt +92 -0
- package/bin/types.js +0 -0
- package/package.json +93 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { relinka } from "@reliverse/relinka";
|
|
2
|
+
import { defineCommand } from "@reliverse/rempts";
|
|
3
|
+
import path from "pathe";
|
|
4
|
+
import { printUsage, useAggregator } from "./tools-impl.js";
|
|
5
|
+
const TOOLS = ["agg"];
|
|
6
|
+
export default defineCommand({
|
|
7
|
+
meta: {
|
|
8
|
+
name: "tools",
|
|
9
|
+
version: "1.2.0",
|
|
10
|
+
description: `Runs selected dler tool. Available tools: ${TOOLS.join(", ")}`
|
|
11
|
+
},
|
|
12
|
+
args: {
|
|
13
|
+
dev: {
|
|
14
|
+
description: "Run in development mode",
|
|
15
|
+
type: "boolean"
|
|
16
|
+
},
|
|
17
|
+
import: {
|
|
18
|
+
description: "If true, produce import lines instead of export lines",
|
|
19
|
+
type: "boolean"
|
|
20
|
+
},
|
|
21
|
+
input: {
|
|
22
|
+
description: "Directory containing .ts/.js files",
|
|
23
|
+
type: "string"
|
|
24
|
+
},
|
|
25
|
+
named: {
|
|
26
|
+
description: "Parse each file for named exports (function/class/const/let)",
|
|
27
|
+
type: "boolean"
|
|
28
|
+
},
|
|
29
|
+
out: {
|
|
30
|
+
description: "Output aggregator file path",
|
|
31
|
+
type: "string"
|
|
32
|
+
},
|
|
33
|
+
recursive: {
|
|
34
|
+
description: "Recursively scan subdirectories (default false)",
|
|
35
|
+
type: "boolean"
|
|
36
|
+
},
|
|
37
|
+
strip: {
|
|
38
|
+
description: "Remove this path prefix from final imports/exports",
|
|
39
|
+
type: "string"
|
|
40
|
+
},
|
|
41
|
+
tool: {
|
|
42
|
+
description: "Tool to run",
|
|
43
|
+
type: "string"
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
async run({ args }) {
|
|
47
|
+
const isDev = args.dev;
|
|
48
|
+
if (!args.tool) {
|
|
49
|
+
relinka("error", "Missing required param: --tool <toolName>");
|
|
50
|
+
printUsage(isDev);
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
if (!TOOLS.includes(args.tool)) {
|
|
54
|
+
relinka("error", `Error: Invalid tool: ${args.tool}`);
|
|
55
|
+
relinka("info", `Available tools: ${TOOLS.join(", ")}`);
|
|
56
|
+
printUsage(isDev);
|
|
57
|
+
process.exit(1);
|
|
58
|
+
}
|
|
59
|
+
if (args.tool === "agg") {
|
|
60
|
+
if (!args.input) {
|
|
61
|
+
relinka("error", "Missing required param: --input <directory>");
|
|
62
|
+
printUsage(isDev);
|
|
63
|
+
process.exit(1);
|
|
64
|
+
}
|
|
65
|
+
if (!args.out) {
|
|
66
|
+
relinka("error", "Missing required param: --out <fileName>");
|
|
67
|
+
printUsage(isDev);
|
|
68
|
+
process.exit(1);
|
|
69
|
+
}
|
|
70
|
+
await useAggregator({
|
|
71
|
+
inputDir: path.resolve(args.input),
|
|
72
|
+
isRecursive: !!args.recursive,
|
|
73
|
+
outFile: path.resolve(args.out),
|
|
74
|
+
stripPrefix: args.strip ? path.resolve(args.strip) : "",
|
|
75
|
+
useImport: !!args.import,
|
|
76
|
+
useNamed: !!args.named
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
process.exit(0);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import { relinka } from "@reliverse/relinka";
|
|
2
|
+
import fs from "fs-extra";
|
|
3
|
+
import MagicString from "magic-string";
|
|
4
|
+
import path from "pathe";
|
|
5
|
+
const AGGREGATOR_START = "// AUTO-GENERATED AGGREGATOR START";
|
|
6
|
+
const AGGREGATOR_END = "// AUTO-GENERATED AGGREGATOR END";
|
|
7
|
+
export async function useAggregator({
|
|
8
|
+
inputDir,
|
|
9
|
+
isRecursive,
|
|
10
|
+
outFile,
|
|
11
|
+
stripPrefix,
|
|
12
|
+
useImport,
|
|
13
|
+
useNamed,
|
|
14
|
+
ignoreDirs = ["node_modules", ".git"],
|
|
15
|
+
sortLines = false,
|
|
16
|
+
headerComment = "",
|
|
17
|
+
verbose = false,
|
|
18
|
+
includeInternal = false,
|
|
19
|
+
internalMarker = "#",
|
|
20
|
+
overrideFile = false
|
|
21
|
+
}) {
|
|
22
|
+
try {
|
|
23
|
+
const st = await fs.stat(inputDir).catch(() => null);
|
|
24
|
+
if (!st?.isDirectory()) {
|
|
25
|
+
relinka("error", `Error: --input is not a valid directory: ${inputDir}`);
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
28
|
+
const exts = [".ts", ".js"];
|
|
29
|
+
if (verbose)
|
|
30
|
+
relinka(
|
|
31
|
+
"info",
|
|
32
|
+
`Scanning directory ${inputDir} for files with extensions: ${exts.join(
|
|
33
|
+
", "
|
|
34
|
+
)}`
|
|
35
|
+
);
|
|
36
|
+
const filePaths = await collectFiles(
|
|
37
|
+
inputDir,
|
|
38
|
+
exts,
|
|
39
|
+
isRecursive,
|
|
40
|
+
ignoreDirs,
|
|
41
|
+
verbose,
|
|
42
|
+
includeInternal,
|
|
43
|
+
internalMarker
|
|
44
|
+
);
|
|
45
|
+
if (!filePaths.length) {
|
|
46
|
+
relinka("warn", `No matching .ts/.js files found in ${inputDir}`);
|
|
47
|
+
}
|
|
48
|
+
const usedIdentifiers = /* @__PURE__ */ new Set();
|
|
49
|
+
const aggregatorLinesArrays = await Promise.all(
|
|
50
|
+
filePaths.map(
|
|
51
|
+
(fp) => generateAggregatorLines(
|
|
52
|
+
fp,
|
|
53
|
+
inputDir,
|
|
54
|
+
stripPrefix,
|
|
55
|
+
useImport,
|
|
56
|
+
useNamed,
|
|
57
|
+
usedIdentifiers
|
|
58
|
+
)
|
|
59
|
+
)
|
|
60
|
+
);
|
|
61
|
+
const allLines = aggregatorLinesArrays.flat();
|
|
62
|
+
if (sortLines) {
|
|
63
|
+
allLines.sort();
|
|
64
|
+
if (verbose) relinka("info", "Sorted aggregator lines alphabetically.");
|
|
65
|
+
}
|
|
66
|
+
if (outFile.startsWith(inputDir)) {
|
|
67
|
+
relinka(
|
|
68
|
+
"warn",
|
|
69
|
+
`Warning: The output file is inside (or overlaps with) the input directory.
|
|
70
|
+
Might re-import (or re-export) itself.
|
|
71
|
+
input: ${inputDir}
|
|
72
|
+
out: ${outFile}
|
|
73
|
+
`
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
const aggregatorContent = allLines.join("\n");
|
|
77
|
+
const aggregatorBlock = `${headerComment ? `${headerComment}
|
|
78
|
+
` : ""}${AGGREGATOR_START}
|
|
79
|
+
${aggregatorContent}
|
|
80
|
+
${AGGREGATOR_END}
|
|
81
|
+
`;
|
|
82
|
+
let finalText;
|
|
83
|
+
if (overrideFile) {
|
|
84
|
+
finalText = aggregatorBlock;
|
|
85
|
+
if (verbose) {
|
|
86
|
+
relinka("info", "Override mode: rewriting entire file.");
|
|
87
|
+
}
|
|
88
|
+
} else {
|
|
89
|
+
let existingContent = "";
|
|
90
|
+
try {
|
|
91
|
+
existingContent = await fs.readFile(outFile, "utf8");
|
|
92
|
+
} catch {
|
|
93
|
+
if (verbose)
|
|
94
|
+
relinka("info", "Aggregator file does not exist. Creating new one.");
|
|
95
|
+
}
|
|
96
|
+
if (existingContent?.includes(AGGREGATOR_START) && existingContent.includes(AGGREGATOR_END)) {
|
|
97
|
+
if (verbose) {
|
|
98
|
+
relinka(
|
|
99
|
+
"info",
|
|
100
|
+
"Existing aggregator block found. Updating auto-generated section."
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
const s = new MagicString(existingContent);
|
|
104
|
+
const startIdx = existingContent.indexOf(AGGREGATOR_START);
|
|
105
|
+
const endIdx = existingContent.indexOf(AGGREGATOR_END) + AGGREGATOR_END.length;
|
|
106
|
+
s.update(startIdx, endIdx, aggregatorBlock.trim());
|
|
107
|
+
finalText = s.toString();
|
|
108
|
+
} else {
|
|
109
|
+
if (existingContent) {
|
|
110
|
+
if (verbose)
|
|
111
|
+
relinka(
|
|
112
|
+
"info",
|
|
113
|
+
"No aggregator block found. Appending auto-generated section."
|
|
114
|
+
);
|
|
115
|
+
finalText = `${existingContent.trim()}
|
|
116
|
+
|
|
117
|
+
${aggregatorBlock}`;
|
|
118
|
+
} else {
|
|
119
|
+
finalText = aggregatorBlock;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
await fs.ensureFile(outFile);
|
|
124
|
+
await fs.writeFile(outFile, finalText, "utf8");
|
|
125
|
+
relinka(
|
|
126
|
+
"success",
|
|
127
|
+
`Aggregator done: processed ${allLines.length} lines in:
|
|
128
|
+
${outFile}`
|
|
129
|
+
);
|
|
130
|
+
} catch (error) {
|
|
131
|
+
relinka("error", `Aggregator failed: ${error}`);
|
|
132
|
+
process.exit(1);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function buildPathRelative(filePath, inputDir, stripPrefix) {
|
|
136
|
+
let resolved = path.resolve(filePath);
|
|
137
|
+
const resolvedStrip = stripPrefix ? path.resolve(stripPrefix) : "";
|
|
138
|
+
if (resolvedStrip && resolved.startsWith(resolvedStrip)) {
|
|
139
|
+
resolved = resolved.slice(resolvedStrip.length);
|
|
140
|
+
} else {
|
|
141
|
+
resolved = path.relative(path.resolve(inputDir), resolved);
|
|
142
|
+
}
|
|
143
|
+
while (resolved.startsWith(path.sep)) {
|
|
144
|
+
resolved = resolved.slice(1);
|
|
145
|
+
}
|
|
146
|
+
resolved = resolved.replace(/\\/g, "/");
|
|
147
|
+
if (resolved.toLowerCase().endsWith(".ts")) {
|
|
148
|
+
resolved = `${resolved.slice(0, -3)}.js`;
|
|
149
|
+
}
|
|
150
|
+
if (!resolved.startsWith("./") && !resolved.startsWith("../")) {
|
|
151
|
+
resolved = `./${resolved}`;
|
|
152
|
+
}
|
|
153
|
+
return resolved;
|
|
154
|
+
}
|
|
155
|
+
async function collectFiles(dir, exts, recursive, ignoreDirs, verbose, includeInternal, internalMarker) {
|
|
156
|
+
const found = [];
|
|
157
|
+
const entries = await fs.readdir(dir, { withFileTypes: true });
|
|
158
|
+
for (const entry of entries) {
|
|
159
|
+
const fullPath = path.join(dir, entry.name);
|
|
160
|
+
if (entry.isDirectory()) {
|
|
161
|
+
if (ignoreDirs.includes(entry.name)) {
|
|
162
|
+
if (verbose) {
|
|
163
|
+
relinka("info", `Skipping ignored directory: ${fullPath}`);
|
|
164
|
+
}
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
if (recursive) {
|
|
168
|
+
const sub = await collectFiles(
|
|
169
|
+
fullPath,
|
|
170
|
+
exts,
|
|
171
|
+
recursive,
|
|
172
|
+
ignoreDirs,
|
|
173
|
+
verbose,
|
|
174
|
+
includeInternal,
|
|
175
|
+
internalMarker
|
|
176
|
+
);
|
|
177
|
+
found.push(...sub);
|
|
178
|
+
}
|
|
179
|
+
} else if (entry.isFile()) {
|
|
180
|
+
if (!includeInternal && path.basename(fullPath).startsWith(internalMarker)) {
|
|
181
|
+
if (verbose) {
|
|
182
|
+
relinka("info", `Skipping internal file: ${fullPath}`);
|
|
183
|
+
}
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
if (exts.some((ext) => entry.name.toLowerCase().endsWith(ext))) {
|
|
187
|
+
if (verbose) {
|
|
188
|
+
relinka("info", `Found file: ${fullPath}`);
|
|
189
|
+
}
|
|
190
|
+
found.push(fullPath);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return found;
|
|
195
|
+
}
|
|
196
|
+
async function generateAggregatorLines(filePath, inputDir, stripPrefix, useImport, useNamed, usedIdentifiers) {
|
|
197
|
+
const importPath = buildPathRelative(filePath, inputDir, stripPrefix);
|
|
198
|
+
if (!useNamed) {
|
|
199
|
+
if (useImport) {
|
|
200
|
+
let ident = guessStarImportIdentifier(filePath);
|
|
201
|
+
if (usedIdentifiers) {
|
|
202
|
+
let uniqueIdent = ident;
|
|
203
|
+
let counter = 1;
|
|
204
|
+
while (usedIdentifiers.has(uniqueIdent)) {
|
|
205
|
+
uniqueIdent = `${ident}_${counter}`;
|
|
206
|
+
counter++;
|
|
207
|
+
}
|
|
208
|
+
usedIdentifiers.add(uniqueIdent);
|
|
209
|
+
ident = uniqueIdent;
|
|
210
|
+
}
|
|
211
|
+
return [`import * as ${ident} from "${importPath}";`];
|
|
212
|
+
}
|
|
213
|
+
return [`export * from "${importPath}";`];
|
|
214
|
+
}
|
|
215
|
+
const { typeNames, valueNames } = await getNamedExports(filePath);
|
|
216
|
+
if (!typeNames.length && !valueNames.length) {
|
|
217
|
+
return [];
|
|
218
|
+
}
|
|
219
|
+
if (useImport) {
|
|
220
|
+
const lines2 = [];
|
|
221
|
+
if (typeNames.length > 0) {
|
|
222
|
+
lines2.push(
|
|
223
|
+
`import type { ${typeNames.join(", ")} } from "${importPath}";`
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
if (valueNames.length > 0) {
|
|
227
|
+
lines2.push(`import { ${valueNames.join(", ")} } from "${importPath}";`);
|
|
228
|
+
}
|
|
229
|
+
return lines2;
|
|
230
|
+
}
|
|
231
|
+
const lines = [];
|
|
232
|
+
if (typeNames.length > 0) {
|
|
233
|
+
lines.push(`export type { ${typeNames.join(", ")} } from "${importPath}";`);
|
|
234
|
+
}
|
|
235
|
+
if (valueNames.length > 0) {
|
|
236
|
+
lines.push(`export { ${valueNames.join(", ")} } from "${importPath}";`);
|
|
237
|
+
}
|
|
238
|
+
return lines;
|
|
239
|
+
}
|
|
240
|
+
async function getNamedExports(filePath) {
|
|
241
|
+
try {
|
|
242
|
+
const code = await fs.readFile(filePath, "utf-8");
|
|
243
|
+
const pattern = /^export\s+(?:async\s+)?(function|const|class|let|type|interface)\s+([A-Za-z0-9_$]+)/gm;
|
|
244
|
+
const typeNamesSet = /* @__PURE__ */ new Set();
|
|
245
|
+
const valueNamesSet = /* @__PURE__ */ new Set();
|
|
246
|
+
let match;
|
|
247
|
+
while (true) {
|
|
248
|
+
match = pattern.exec(code);
|
|
249
|
+
if (match === null) break;
|
|
250
|
+
const keyword = match[1];
|
|
251
|
+
const name = match[2];
|
|
252
|
+
if (keyword && name) {
|
|
253
|
+
if (keyword === "type" || keyword === "interface") {
|
|
254
|
+
typeNamesSet.add(name);
|
|
255
|
+
} else {
|
|
256
|
+
valueNamesSet.add(name);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return {
|
|
261
|
+
typeNames: Array.from(typeNamesSet),
|
|
262
|
+
valueNames: Array.from(valueNamesSet)
|
|
263
|
+
};
|
|
264
|
+
} catch (error) {
|
|
265
|
+
relinka("error", `Error reading file ${filePath}: ${error}`);
|
|
266
|
+
return { typeNames: [], valueNames: [] };
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
function guessStarImportIdentifier(filePath) {
|
|
270
|
+
const base = path.basename(filePath, path.extname(filePath));
|
|
271
|
+
let identifier = base.replace(/[^a-zA-Z0-9_$]/g, "_");
|
|
272
|
+
if (/^\d/.test(identifier)) {
|
|
273
|
+
identifier = `_${identifier}`;
|
|
274
|
+
}
|
|
275
|
+
return identifier || "file";
|
|
276
|
+
}
|
|
277
|
+
export function printUsage(isDev) {
|
|
278
|
+
relinka("info", "====================");
|
|
279
|
+
relinka("info", "TOOLS USAGE EXAMPLES");
|
|
280
|
+
relinka("info", "====================");
|
|
281
|
+
relinka(
|
|
282
|
+
"info",
|
|
283
|
+
`${isDev ? "bun dev:agg" : "dler tools"} --tool agg --input <dir> --out <file> [options]`
|
|
284
|
+
);
|
|
285
|
+
if (isDev) {
|
|
286
|
+
relinka(
|
|
287
|
+
"info",
|
|
288
|
+
"bun dev:tools agg --input src/libs/sdk/sdk-impl --out src/libs/sdk/sdk-main.ts --recursive --named --strip src/libs/sdk"
|
|
289
|
+
);
|
|
290
|
+
} else {
|
|
291
|
+
relinka(
|
|
292
|
+
"info",
|
|
293
|
+
"dler tools --tool agg --input src/libs --out aggregator.ts --recursive --named"
|
|
294
|
+
);
|
|
295
|
+
}
|
|
296
|
+
}
|
package/bin/cli.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { relinka } from "@reliverse/relinka";
|
|
2
|
+
import fs from "fs-extra";
|
|
3
|
+
import path from "pathe";
|
|
4
|
+
import { processLibraryFlow } from "./libs/sdk/sdk-impl/library-flow.js";
|
|
5
|
+
import { processRegularFlow } from "./libs/sdk/sdk-impl/regular-flow.js";
|
|
6
|
+
import { bumpHandler } from "./libs/sdk/sdk-impl/utils/utils-bump.js";
|
|
7
|
+
import { removeDistFolders } from "./libs/sdk/sdk-impl/utils/utils-clean.js";
|
|
8
|
+
import { PROJECT_ROOT } from "./libs/sdk/sdk-impl/utils/utils-consts.js";
|
|
9
|
+
import { handleDlerError } from "./libs/sdk/sdk-impl/utils/utils-error.js";
|
|
10
|
+
import { finalizeBuild } from "./libs/sdk/sdk-impl/utils/utils-info.js";
|
|
11
|
+
import { createPerfTimer } from "./libs/sdk/sdk-impl/utils/utils-perf.js";
|
|
12
|
+
import { loadConfig } from "./load.js";
|
|
13
|
+
export async function dler(isDev) {
|
|
14
|
+
const timer = createPerfTimer();
|
|
15
|
+
try {
|
|
16
|
+
const config = await loadConfig();
|
|
17
|
+
if (isDev) {
|
|
18
|
+
config.commonPubPause = true;
|
|
19
|
+
config.bumpDisable = true;
|
|
20
|
+
relinka(
|
|
21
|
+
"info",
|
|
22
|
+
"Development mode: Publishing paused and version bumping disabled."
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
if (config.logsFreshFile) {
|
|
26
|
+
await fs.remove(path.join(PROJECT_ROOT, config.logsFileName));
|
|
27
|
+
}
|
|
28
|
+
await removeDistFolders(
|
|
29
|
+
config.distNpmDirName,
|
|
30
|
+
config.distJsrDirName,
|
|
31
|
+
config.libsDirDist,
|
|
32
|
+
config.libsList
|
|
33
|
+
);
|
|
34
|
+
if (!config.bumpDisable) {
|
|
35
|
+
await bumpHandler(
|
|
36
|
+
config.bumpMode,
|
|
37
|
+
config.bumpDisable,
|
|
38
|
+
config.commonPubPause,
|
|
39
|
+
config.bumpFilter
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
await processRegularFlow(
|
|
43
|
+
timer,
|
|
44
|
+
isDev,
|
|
45
|
+
config.coreIsCLI,
|
|
46
|
+
config.libsActMode,
|
|
47
|
+
config.commonPubRegistry,
|
|
48
|
+
config.coreEntrySrcDir,
|
|
49
|
+
config.distNpmDirName,
|
|
50
|
+
config.distNpmBuilder,
|
|
51
|
+
config.coreEntryFile,
|
|
52
|
+
config.distJsrDryRun,
|
|
53
|
+
config.distJsrFailOnWarn,
|
|
54
|
+
config.commonPubPause,
|
|
55
|
+
config.distJsrDirName,
|
|
56
|
+
config.distJsrBuilder,
|
|
57
|
+
config.transpileTarget,
|
|
58
|
+
config.transpileFormat,
|
|
59
|
+
config.transpileSplitting,
|
|
60
|
+
config.transpileMinify,
|
|
61
|
+
config.transpileSourcemap,
|
|
62
|
+
config.transpilePublicPath,
|
|
63
|
+
config.distJsrAllowDirty,
|
|
64
|
+
config.distJsrSlowTypes,
|
|
65
|
+
config.distNpmOutFilesExt,
|
|
66
|
+
config.rmDepsMode,
|
|
67
|
+
config.transpileStub,
|
|
68
|
+
config.transpileWatch,
|
|
69
|
+
config.distJsrGenTsconfig,
|
|
70
|
+
config.coreDeclarations
|
|
71
|
+
);
|
|
72
|
+
await processLibraryFlow(
|
|
73
|
+
timer,
|
|
74
|
+
isDev,
|
|
75
|
+
config.libsActMode,
|
|
76
|
+
config.libsList,
|
|
77
|
+
config.distJsrDryRun,
|
|
78
|
+
config.distJsrFailOnWarn,
|
|
79
|
+
config.libsDirDist,
|
|
80
|
+
config.libsDirSrc,
|
|
81
|
+
config.commonPubPause,
|
|
82
|
+
config.commonPubRegistry,
|
|
83
|
+
config.distNpmOutFilesExt,
|
|
84
|
+
config.distNpmBuilder,
|
|
85
|
+
config.coreEntrySrcDir,
|
|
86
|
+
config.rmDepsMode,
|
|
87
|
+
config.rmDepsPatterns,
|
|
88
|
+
config.transpileEsbuild,
|
|
89
|
+
config.transpileTarget,
|
|
90
|
+
config.transpileFormat,
|
|
91
|
+
config.transpileSplitting,
|
|
92
|
+
config.transpileSourcemap,
|
|
93
|
+
config.transpilePublicPath,
|
|
94
|
+
config.distJsrBuilder,
|
|
95
|
+
config.transpileStub,
|
|
96
|
+
config.transpileWatch,
|
|
97
|
+
config.distJsrOutFilesExt
|
|
98
|
+
);
|
|
99
|
+
await finalizeBuild(
|
|
100
|
+
timer,
|
|
101
|
+
config.commonPubPause,
|
|
102
|
+
config.libsList,
|
|
103
|
+
config.distNpmDirName,
|
|
104
|
+
config.distJsrDirName,
|
|
105
|
+
config.libsDirDist,
|
|
106
|
+
isDev
|
|
107
|
+
);
|
|
108
|
+
} catch (error) {
|
|
109
|
+
handleDlerError(error, timer);
|
|
110
|
+
}
|
|
111
|
+
}
|
package/bin/init.js
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { relinka } from "@reliverse/relinka";
|
|
2
|
+
import fs from "fs-extra";
|
|
3
|
+
import path from "pathe";
|
|
4
|
+
import { DEFAULT_CONFIG } from "./libs/cfg/cfg-default.js";
|
|
5
|
+
const CONFIG_FILENAME = ".config/dler.ts";
|
|
6
|
+
export async function initDlerConfig(isDev) {
|
|
7
|
+
const configPath = path.resolve(process.cwd(), CONFIG_FILENAME);
|
|
8
|
+
const configExists = await fs.pathExists(configPath);
|
|
9
|
+
if (configExists) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
try {
|
|
13
|
+
const configContent = generateConfig(isDev);
|
|
14
|
+
await fs.outputFile(configPath, configContent, "utf-8");
|
|
15
|
+
relinka("success", `Config was created at ${configPath}`);
|
|
16
|
+
relinka("info", "Edit this file to customize build and publish settings");
|
|
17
|
+
if (!isDev) {
|
|
18
|
+
relinka("info", "Please note: commonPubPause is set to true by default");
|
|
19
|
+
relinka("info", "When you're ready, run `dler` to build and publish");
|
|
20
|
+
} else {
|
|
21
|
+
relinka("info", "When you're ready, run `bun pub` to build and publish");
|
|
22
|
+
}
|
|
23
|
+
process.exit(0);
|
|
24
|
+
} catch (error) {
|
|
25
|
+
relinka(
|
|
26
|
+
"error",
|
|
27
|
+
`Error creating configuration file: ${error instanceof Error ? error.message : String(error)}`
|
|
28
|
+
);
|
|
29
|
+
process.exit(1);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function generateConfig(isDev) {
|
|
33
|
+
const importDefineConfigStatement = isDev ? `import { defineConfig } from "../src/libs/cfg/cfg-main.js";` : `import { defineConfig } from "@reliverse/dler-cfg";`;
|
|
34
|
+
const verboseValue = getValue(isDev, true, DEFAULT_CONFIG.commonVerbose);
|
|
35
|
+
const isCLIValue = getValue(isDev, true, DEFAULT_CONFIG.coreIsCLI);
|
|
36
|
+
const registryValue = getValue(
|
|
37
|
+
isDev,
|
|
38
|
+
"npm-jsr",
|
|
39
|
+
DEFAULT_CONFIG.commonPubRegistry
|
|
40
|
+
);
|
|
41
|
+
const pausePublishValue = getValue(
|
|
42
|
+
isDev,
|
|
43
|
+
false,
|
|
44
|
+
DEFAULT_CONFIG.commonPubPause
|
|
45
|
+
);
|
|
46
|
+
const coreDeclarationsValue = getValue(
|
|
47
|
+
isDev,
|
|
48
|
+
false,
|
|
49
|
+
DEFAULT_CONFIG.coreDeclarations
|
|
50
|
+
);
|
|
51
|
+
const libsActModeValue = getValue(
|
|
52
|
+
isDev,
|
|
53
|
+
"main-and-libs",
|
|
54
|
+
DEFAULT_CONFIG.libsActMode
|
|
55
|
+
);
|
|
56
|
+
const libsObject = isDev ? `{
|
|
57
|
+
"@reliverse/dler-cfg": {
|
|
58
|
+
libDeclarations: true,
|
|
59
|
+
libDescription: "@reliverse/dler defineConfig",
|
|
60
|
+
libDirName: "cfg",
|
|
61
|
+
libMainFile: "cfg/cfg-main.ts",
|
|
62
|
+
libPkgKeepDeps: false,
|
|
63
|
+
libTranspileMinify: true,
|
|
64
|
+
},
|
|
65
|
+
"@reliverse/dler-sdk": {
|
|
66
|
+
libDeclarations: true,
|
|
67
|
+
libDescription: "@reliverse/dler without cli",
|
|
68
|
+
libDirName: "sdk",
|
|
69
|
+
libMainFile: "sdk/sdk-main.ts",
|
|
70
|
+
libPkgKeepDeps: true,
|
|
71
|
+
libTranspileMinify: true,
|
|
72
|
+
},
|
|
73
|
+
}` : `{
|
|
74
|
+
// "@acme/cli-libName": {
|
|
75
|
+
// libDeclarations: true,
|
|
76
|
+
// libDescription: "@acme/cli defineConfig",
|
|
77
|
+
// libDirName: "libName",
|
|
78
|
+
// libMainFile: "libName/libName-main.ts",
|
|
79
|
+
// libPkgKeepDeps: true,
|
|
80
|
+
// libTranspileMinify: true,
|
|
81
|
+
// },
|
|
82
|
+
}`;
|
|
83
|
+
const configTemplate = `${importDefineConfigStatement}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Reliverse Bundler Configuration
|
|
87
|
+
* Hover over a field to see more details
|
|
88
|
+
* @see https://github.com/reliverse/dler
|
|
89
|
+
*/
|
|
90
|
+
export default defineConfig({
|
|
91
|
+
// Bump configuration
|
|
92
|
+
bumpDisable: ${DEFAULT_CONFIG.bumpDisable},
|
|
93
|
+
bumpFilter: ${JSON.stringify(DEFAULT_CONFIG.bumpFilter)},
|
|
94
|
+
bumpMode: "${DEFAULT_CONFIG.bumpMode}",
|
|
95
|
+
|
|
96
|
+
// Common configuration
|
|
97
|
+
commonPubPause: ${pausePublishValue},
|
|
98
|
+
commonPubRegistry: "${registryValue}",
|
|
99
|
+
commonVerbose: ${verboseValue},
|
|
100
|
+
|
|
101
|
+
// Core configuration
|
|
102
|
+
coreDeclarations: ${coreDeclarationsValue},
|
|
103
|
+
coreEntryFile: "${DEFAULT_CONFIG.coreEntryFile}",
|
|
104
|
+
coreEntrySrcDir: "${DEFAULT_CONFIG.coreEntrySrcDir}",
|
|
105
|
+
coreIsCLI: ${isCLIValue},
|
|
106
|
+
|
|
107
|
+
// JSR-only config
|
|
108
|
+
distJsrAllowDirty: ${DEFAULT_CONFIG.distJsrAllowDirty},
|
|
109
|
+
distJsrBuilder: "${DEFAULT_CONFIG.distJsrBuilder}",
|
|
110
|
+
distJsrCopyRootFiles: ${JSON.stringify(DEFAULT_CONFIG.distJsrCopyRootFiles)},
|
|
111
|
+
distJsrDirName: "${DEFAULT_CONFIG.distJsrDirName}",
|
|
112
|
+
distJsrDryRun: ${DEFAULT_CONFIG.distJsrDryRun},
|
|
113
|
+
distJsrFailOnWarn: ${DEFAULT_CONFIG.distJsrFailOnWarn},
|
|
114
|
+
distJsrGenTsconfig: ${DEFAULT_CONFIG.distJsrGenTsconfig},
|
|
115
|
+
distJsrOutFilesExt: "${DEFAULT_CONFIG.distJsrOutFilesExt}",
|
|
116
|
+
distJsrSlowTypes: ${DEFAULT_CONFIG.distJsrSlowTypes},
|
|
117
|
+
|
|
118
|
+
// NPM-only config
|
|
119
|
+
distNpmBuilder: "${DEFAULT_CONFIG.distNpmBuilder}",
|
|
120
|
+
distNpmCopyRootFiles: ${JSON.stringify(DEFAULT_CONFIG.distNpmCopyRootFiles)},
|
|
121
|
+
distNpmDirName: "${DEFAULT_CONFIG.distNpmDirName}",
|
|
122
|
+
distNpmOutFilesExt: "${DEFAULT_CONFIG.distNpmOutFilesExt}",
|
|
123
|
+
|
|
124
|
+
// Libraries Dler Plugin
|
|
125
|
+
// Publish specific dirs as separate packages
|
|
126
|
+
// This feature is experimental at the moment
|
|
127
|
+
// Please commit your changes before using it
|
|
128
|
+
libsActMode: "${libsActModeValue}",
|
|
129
|
+
libsDirDist: "${DEFAULT_CONFIG.libsDirDist}",
|
|
130
|
+
libsDirSrc: "${DEFAULT_CONFIG.libsDirSrc}",
|
|
131
|
+
libsList: ${libsObject},
|
|
132
|
+
|
|
133
|
+
// Logger setup
|
|
134
|
+
logsFileName: "${DEFAULT_CONFIG.logsFileName}",
|
|
135
|
+
logsFreshFile: ${DEFAULT_CONFIG.logsFreshFile},
|
|
136
|
+
|
|
137
|
+
// Dependency filtering
|
|
138
|
+
rmDepsMode: "${DEFAULT_CONFIG.rmDepsMode}",
|
|
139
|
+
rmDepsPatterns: ${JSON.stringify(DEFAULT_CONFIG.rmDepsPatterns)},
|
|
140
|
+
|
|
141
|
+
// Build setup
|
|
142
|
+
transpileEsbuild: "${DEFAULT_CONFIG.transpileEsbuild}",
|
|
143
|
+
transpileFormat: "${DEFAULT_CONFIG.transpileFormat}",
|
|
144
|
+
transpileMinify: ${DEFAULT_CONFIG.transpileMinify},
|
|
145
|
+
transpilePublicPath: "${DEFAULT_CONFIG.transpilePublicPath}",
|
|
146
|
+
transpileSourcemap: "${DEFAULT_CONFIG.transpileSourcemap}",
|
|
147
|
+
transpileSplitting: ${DEFAULT_CONFIG.transpileSplitting},
|
|
148
|
+
transpileStub: ${DEFAULT_CONFIG.transpileStub},
|
|
149
|
+
transpileTarget: "${DEFAULT_CONFIG.transpileTarget}",
|
|
150
|
+
transpileWatch: ${DEFAULT_CONFIG.transpileWatch},
|
|
151
|
+
});
|
|
152
|
+
`;
|
|
153
|
+
return configTemplate;
|
|
154
|
+
}
|
|
155
|
+
function getValue(isDev, devValue, prodValue) {
|
|
156
|
+
return isDev ? devValue : prodValue;
|
|
157
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export const DEFAULT_CONFIG = {
|
|
2
|
+
bumpDisable: false,
|
|
3
|
+
bumpFilter: ["package.json", ".config/rse.ts"],
|
|
4
|
+
bumpMode: "autoPatch",
|
|
5
|
+
commonPubPause: true,
|
|
6
|
+
commonPubRegistry: "npm",
|
|
7
|
+
commonVerbose: false,
|
|
8
|
+
coreDeclarations: true,
|
|
9
|
+
coreEntryFile: "main.ts",
|
|
10
|
+
coreEntrySrcDir: "src",
|
|
11
|
+
coreIsCLI: false,
|
|
12
|
+
distJsrAllowDirty: true,
|
|
13
|
+
distJsrBuilder: "jsr",
|
|
14
|
+
distJsrCopyRootFiles: ["README.md", "LICENSE"],
|
|
15
|
+
distJsrDirName: "dist-jsr",
|
|
16
|
+
distJsrDryRun: false,
|
|
17
|
+
distJsrFailOnWarn: false,
|
|
18
|
+
distJsrGenTsconfig: false,
|
|
19
|
+
distJsrOutFilesExt: "ts",
|
|
20
|
+
distJsrSlowTypes: true,
|
|
21
|
+
distNpmBuilder: "mkdist",
|
|
22
|
+
distNpmCopyRootFiles: ["README.md", "LICENSE"],
|
|
23
|
+
distNpmDirName: "dist-npm",
|
|
24
|
+
distNpmOutFilesExt: "js",
|
|
25
|
+
libsActMode: "main-project-only",
|
|
26
|
+
libsDirDist: "dist-libs",
|
|
27
|
+
libsDirSrc: "src/libs",
|
|
28
|
+
libsList: {},
|
|
29
|
+
logsFileName: "logs/relinka.log",
|
|
30
|
+
logsFreshFile: true,
|
|
31
|
+
rmDepsMode: "patterns-and-devdeps",
|
|
32
|
+
rmDepsPatterns: [
|
|
33
|
+
"@types",
|
|
34
|
+
"biome",
|
|
35
|
+
"eslint",
|
|
36
|
+
"knip",
|
|
37
|
+
"prettier",
|
|
38
|
+
"typescript",
|
|
39
|
+
"@reliverse/config"
|
|
40
|
+
],
|
|
41
|
+
transpileEsbuild: "es2023",
|
|
42
|
+
transpileFormat: "esm",
|
|
43
|
+
transpileMinify: true,
|
|
44
|
+
transpilePublicPath: "/",
|
|
45
|
+
transpileSourcemap: "none",
|
|
46
|
+
transpileSplitting: false,
|
|
47
|
+
transpileStub: false,
|
|
48
|
+
transpileTarget: "node",
|
|
49
|
+
transpileWatch: false
|
|
50
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { defineConfig } from "./cfg-mod.js";
|