@reliverse/dler 1.2.0 → 1.2.1
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 +43 -20
- package/bin/cli/args/init/cmd/index.js +66 -0
- package/bin/cli/args/{spells/mod.js → spell/spell-mod.js} +1 -1
- package/bin/cli/args/split/split-impl.js +117 -0
- package/bin/cli/args/split/split-mod.js +22 -113
- package/bin/cli/args/tools/tools-impl.js +1 -1
- package/bin/init.js +4 -4
- package/bin/libs/cfg/cfg-default.js +1 -1
- package/bin/libs/sdk/sdk-impl/build/build-regular.js +2 -2
- package/bin/libs/sdk/sdk-impl/{spells/spells-executors.js → spell/spell-executors.js} +1 -1
- package/bin/libs/sdk/sdk-impl/{spells/spells-main.js → spell/spell-mod.js} +3 -3
- package/bin/libs/sdk/sdk-impl/utils/tools/tools-impl.js +1 -1
- package/bin/libs/sdk/sdk-impl/utils/utils-build.js +1 -1
- package/bin/libs/sdk/sdk-impl/utils/utils-jsr-json.js +1 -1
- package/bin/libs/sdk/sdk-impl/utils/utils-pkg-json-libs.js +6 -6
- package/bin/libs/sdk/sdk-impl/utils/utils-pkg-json-reg.js +8 -8
- package/package.json +9 -9
- package/bin/cli/args/split/split-main.js +0 -26
- package/bin/libs/cfg/cfg-main.js +0 -1
- /package/bin/cli/args/agg/{main.js → agg-mod.js} +0 -0
- /package/bin/cli/args/conv/{main.js → conv-mod.js} +0 -0
- /package/bin/cli/args/deps/{mod.js → deps-mod.js} +0 -0
- /package/bin/cli/args/init/{main.txt → init-mod.txt} +0 -0
- /package/bin/cli/args/init/libs/reinit/{reinit-main.js → reinit-mod.js} +0 -0
- /package/bin/cli/args/init/libs/reinit/reint-impl/{mod.txt → reinit-mod.txt} +0 -0
- /package/bin/cli/args/inject/{cli-mod.js → inject-mod.js} +0 -0
- /package/bin/cli/args/inject/{main.txt → inject-mod.txt} +0 -0
- /package/bin/cli/args/merger/{main.txt → merger-mod.txt} +0 -0
- /package/bin/cli/args/mono/{main.js → mono-mod.js} +0 -0
- /package/bin/libs/sdk/sdk-impl/{spells/spells-filesystem.js → spell/spell-filesystem.js} +0 -0
- /package/bin/libs/sdk/sdk-impl/{spells/spells-parser.js → spell/spell-parser.js} +0 -0
- /package/bin/libs/sdk/sdk-impl/{spells/spells-types.js → spell/spell-types.js} +0 -0
- /package/bin/libs/sdk/{sdk-main.js → sdk-mod.js} +0 -0
- /package/bin/{main.js → mod.js} +0 -0
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# dler (prev. relidler) • reliverse bundler
|
|
2
2
|
|
|
3
|
-
[💖 github sponsors](https://github.com/sponsors/blefnk) — [💬 discord](https://discord.gg/pb8ukbwpsj) — [✨ repo](https://github.com/reliverse/dler
|
|
3
|
+
[💖 github sponsors](https://github.com/sponsors/blefnk) — [💬 discord](https://discord.gg/pb8ukbwpsj) — [✨ repo](https://github.com/reliverse/dler) — [📦 npm](https://npmjs.com/@reliverse/dler) — [📚 docs](https://docs.reliverse.org/reliverse/dler)
|
|
4
4
|
|
|
5
5
|
> @reliverse/dler (`/ˈdiː.lər/`, dealer) is a flexible, unified, and fully automated bundler for typescript and javascript projects, as well as an npm and jsr publishing tool.
|
|
6
6
|
|
|
@@ -51,20 +51,26 @@ ensure git, node.js, and bun/pnpm/yarn/npm are installed. then:
|
|
|
51
51
|
git clone https://github.com/reliverse/dler.git
|
|
52
52
|
cd dler
|
|
53
53
|
bun i
|
|
54
|
-
bun dev # bun src/
|
|
54
|
+
bun dev # bun src/mod.ts --dev
|
|
55
55
|
```
|
|
56
56
|
|
|
57
57
|
### installation
|
|
58
58
|
|
|
59
|
-
1. **install
|
|
59
|
+
1. **install**:
|
|
60
|
+
|
|
61
|
+
**install as dev dep (recommended)**:
|
|
60
62
|
|
|
61
63
|
```sh
|
|
62
|
-
bun
|
|
64
|
+
bun add -D @reliverse/dler
|
|
65
|
+
# or update as needed:
|
|
66
|
+
bun update --latest
|
|
63
67
|
```
|
|
64
68
|
|
|
65
|
-
**or
|
|
69
|
+
**or install globally**:
|
|
66
70
|
|
|
67
71
|
```sh
|
|
72
|
+
bun i -g @reliverse/dler
|
|
73
|
+
# or update as needed:
|
|
68
74
|
bun -g update --latest
|
|
69
75
|
```
|
|
70
76
|
|
|
@@ -83,20 +89,37 @@ bun dev # bun src/main.ts --dev
|
|
|
83
89
|
bun add -d @reliverse/dler-cfg
|
|
84
90
|
```
|
|
85
91
|
|
|
86
|
-
c. **
|
|
92
|
+
c. **add `".config/**/*.ts"` to `include` in `tsconfig.json`**:
|
|
93
|
+
|
|
94
|
+
```json
|
|
95
|
+
"include": [".config/**/*.ts", ...]
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
d. **package.json**:
|
|
99
|
+
|
|
100
|
+
```json
|
|
101
|
+
"scripts": {
|
|
102
|
+
"build": "dler build", // this is optional
|
|
103
|
+
"pub": "dler pub" // this does build+publish
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
e. **initialize config**:
|
|
87
108
|
|
|
88
109
|
```sh
|
|
89
|
-
|
|
110
|
+
bun [build|pub] # if installed as dev dep
|
|
111
|
+
dler [build|pub] # if installed globally
|
|
90
112
|
```
|
|
91
113
|
|
|
92
114
|
- the `.config/dler.ts` file is automatically created on first run.
|
|
93
115
|
- **it's recommended to customize this file according to your needs.**
|
|
94
|
-
- you can check an example config here: [.config/dler.ts](https://github.com/reliverse/dler
|
|
116
|
+
- you can check an example config here: [.config/dler.ts](https://github.com/reliverse/dler/blob/main/.config/dler.ts)
|
|
95
117
|
|
|
96
118
|
3. **run and enjoy**:
|
|
97
119
|
|
|
98
120
|
```sh
|
|
99
|
-
|
|
121
|
+
bun [build|pub] # if installed as dev dep
|
|
122
|
+
dler [build|pub] # if installed globally
|
|
100
123
|
```
|
|
101
124
|
|
|
102
125
|
absolutely! here’s your improved section, now listing all available spell types:
|
|
@@ -149,17 +172,17 @@ more params coming soon...
|
|
|
149
172
|
|
|
150
173
|
from dler’s cli:
|
|
151
174
|
|
|
152
|
-
- `dler
|
|
153
|
-
- `dler
|
|
154
|
-
- `dler
|
|
175
|
+
- `dler spell --trigger rename-file,... --files tsconfig.json,...`
|
|
176
|
+
- `dler spell --trigger all`
|
|
177
|
+
- `dler spell`
|
|
155
178
|
|
|
156
179
|
from your own code:
|
|
157
180
|
|
|
158
181
|
```ts
|
|
159
|
-
await dler.
|
|
160
|
-
// await dler.
|
|
161
|
-
//
|
|
162
|
-
//
|
|
182
|
+
await dler.spell({ spells: ["rename-file"], files: [] });
|
|
183
|
+
// await dler.spell({}) // means all spells and all files
|
|
184
|
+
// spell: ["all"] // means all spells
|
|
185
|
+
// spell: [] // means all spells
|
|
163
186
|
// files: [] // means all files
|
|
164
187
|
```
|
|
165
188
|
|
|
@@ -221,7 +244,7 @@ deep imports like `dep/some/file` or `@org/dep/some/thing` are always resolved t
|
|
|
221
244
|
builds and publishes specific subdirectories of your main project as standalone packages.
|
|
222
245
|
|
|
223
246
|
**usage example**:
|
|
224
|
-
using `@reliverse/dler-cfg` to package [src/libs/cfg](https://github.com/reliverse/dler
|
|
247
|
+
using `@reliverse/dler-cfg` to package [src/libs/cfg](https://github.com/reliverse/dler/tree/main/src/libs/cfg):
|
|
225
248
|
|
|
226
249
|
```ts
|
|
227
250
|
// .config/dler.ts
|
|
@@ -233,7 +256,7 @@ libslist: {
|
|
|
233
256
|
libdeclarations: true,
|
|
234
257
|
libdescription: "@reliverse/dler defineconfig",
|
|
235
258
|
libdirname: "cfg",
|
|
236
|
-
libmainfile: "cfg/cfg-
|
|
259
|
+
libmainfile: "cfg/cfg-mod.ts",
|
|
237
260
|
libpkgkeepdeps: false,
|
|
238
261
|
libtranspileminify: true,
|
|
239
262
|
},
|
|
@@ -268,12 +291,12 @@ dler tools --tool <tool> --input <dir> --out <file> [options]
|
|
|
268
291
|
|
|
269
292
|
**usage example**: if you're exploring the example [playground](#playground), you can try the following:
|
|
270
293
|
|
|
271
|
-
1. open [src/libs/sdk/sdk-
|
|
294
|
+
1. open [src/libs/sdk/sdk-mod.ts](https://github.com/reliverse/dler/blob/main/src/libs/sdk/sdk-mod.ts) in your ide.
|
|
272
295
|
2. press `ctrl+a`, then `backspace`. run the command below and watch the magic happen:
|
|
273
296
|
|
|
274
297
|
```bash
|
|
275
298
|
bun tools:agg # shortcut for:
|
|
276
|
-
bun src/
|
|
299
|
+
bun src/mod.ts tools --dev --tool agg --input src/libs/sdk/sdk-impl --out src/libs/sdk/sdk-mod.ts --recursive --named --strip src/libs/sdk
|
|
277
300
|
```
|
|
278
301
|
|
|
279
302
|
## api (for advanced users)
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { relinka } from "@reliverse/relinka";
|
|
2
|
+
import { defineCommand } from "@reliverse/rempts";
|
|
3
|
+
import fs from "fs-extra";
|
|
4
|
+
import path from "pathe";
|
|
5
|
+
export default defineCommand({
|
|
6
|
+
meta: {
|
|
7
|
+
name: "init",
|
|
8
|
+
version: "1.0.0",
|
|
9
|
+
description: "Scaffold new CLI commands quickly."
|
|
10
|
+
},
|
|
11
|
+
args: {
|
|
12
|
+
cmd: {
|
|
13
|
+
type: "array",
|
|
14
|
+
required: true,
|
|
15
|
+
description: "Names of commands to initialize"
|
|
16
|
+
},
|
|
17
|
+
force: {
|
|
18
|
+
type: "boolean",
|
|
19
|
+
default: false,
|
|
20
|
+
description: "Overwrite existing commands"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
async run({ args }) {
|
|
24
|
+
const root = path.resolve("src/cli/args");
|
|
25
|
+
for (const cmdName of args.cmd) {
|
|
26
|
+
const dirPath = path.join(root, cmdName);
|
|
27
|
+
const filePath = path.join(dirPath, "index.ts");
|
|
28
|
+
if (await fs.pathExists(filePath) && !args.force) {
|
|
29
|
+
relinka(
|
|
30
|
+
"warn",
|
|
31
|
+
`\u274C Command "${cmdName}" already exists. Use --force to overwrite.`
|
|
32
|
+
);
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
|
36
|
+
const content = generateCommandTemplate(cmdName);
|
|
37
|
+
fs.writeFileSync(filePath, content, "utf-8");
|
|
38
|
+
relinka("info", `\u2705 Created new command: ${filePath}`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
function generateCommandTemplate(cmdName) {
|
|
43
|
+
return `import { relinka } from "@reliverse/relinka";
|
|
44
|
+
|
|
45
|
+
import { defineCommand } from "@reliverse/rempts";
|
|
46
|
+
|
|
47
|
+
export default defineCommand({
|
|
48
|
+
meta: {
|
|
49
|
+
name: "${cmdName}",
|
|
50
|
+
version: "1.0.0",
|
|
51
|
+
description: "Describe what ${cmdName} command does.",
|
|
52
|
+
},
|
|
53
|
+
args: {
|
|
54
|
+
exampleArg: {
|
|
55
|
+
type: "string",
|
|
56
|
+
default: "defaultValue",
|
|
57
|
+
description: "An example argument",
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
async run({ args }) {
|
|
61
|
+
relinka("info", "Command '${cmdName}' executed.");
|
|
62
|
+
relinka("info", "Received args:", args);
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
`;
|
|
66
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Command } from "commander";
|
|
2
|
-
import { spells } from "../../../libs/sdk/sdk-impl/
|
|
2
|
+
import { spells } from "../../../libs/sdk/sdk-impl/spell/spell-mod.js";
|
|
3
3
|
export const createCli = () => {
|
|
4
4
|
const program = new Command();
|
|
5
5
|
program.name("dler-spells").description("Execute magic spells in your codebase").version("1.0.0");
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import fs from "fs-extra";
|
|
2
|
+
import path from "pathe";
|
|
3
|
+
import ts from "typescript";
|
|
4
|
+
export function parseCommandLineArgs() {
|
|
5
|
+
const args = process.argv.slice(2);
|
|
6
|
+
let directory = ".";
|
|
7
|
+
let fileLineThreshold = 300;
|
|
8
|
+
let funcLineThreshold = 50;
|
|
9
|
+
for (let i = 0; i < args.length; i++) {
|
|
10
|
+
const arg = args[i];
|
|
11
|
+
if (arg === "--dir" && args[i + 1]) {
|
|
12
|
+
directory = args[i + 1] ?? ".";
|
|
13
|
+
i++;
|
|
14
|
+
} else if (arg === "--file-threshold" && args[i + 1]) {
|
|
15
|
+
fileLineThreshold = Number(args[i + 1]);
|
|
16
|
+
i++;
|
|
17
|
+
} else if (arg === "--func-threshold" && args[i + 1]) {
|
|
18
|
+
funcLineThreshold = Number(args[i + 1]);
|
|
19
|
+
i++;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return { directory, fileLineThreshold, funcLineThreshold };
|
|
23
|
+
}
|
|
24
|
+
export function getAllSourceFiles(dir) {
|
|
25
|
+
const results = [];
|
|
26
|
+
function searchDirectory(directory) {
|
|
27
|
+
const files = fs.readdirSync(directory);
|
|
28
|
+
for (const file of files) {
|
|
29
|
+
const fullPath = path.join(directory, file);
|
|
30
|
+
if (fs.statSync(fullPath).isDirectory()) {
|
|
31
|
+
searchDirectory(fullPath);
|
|
32
|
+
} else if (/\.(ts|js)$/.test(file)) {
|
|
33
|
+
results.push(fullPath);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
searchDirectory(dir);
|
|
38
|
+
return results;
|
|
39
|
+
}
|
|
40
|
+
export function splitLargeFileByLines(filePath, threshold) {
|
|
41
|
+
const originalContent = fs.readFileSync(filePath, "utf8");
|
|
42
|
+
const lines = originalContent.split("\n");
|
|
43
|
+
if (lines.length <= threshold) {
|
|
44
|
+
return [filePath];
|
|
45
|
+
}
|
|
46
|
+
console.log(`File "${filePath}" exceeds ${threshold} lines. Splitting...`);
|
|
47
|
+
const baseName = path.basename(filePath, path.extname(filePath));
|
|
48
|
+
const ext = path.extname(filePath);
|
|
49
|
+
const dirName = path.dirname(filePath);
|
|
50
|
+
const newFilePaths = [];
|
|
51
|
+
let chunkIndex = 0;
|
|
52
|
+
let i = 0;
|
|
53
|
+
while (i < lines.length) {
|
|
54
|
+
chunkIndex++;
|
|
55
|
+
const chunkLines = lines.slice(i, i + threshold);
|
|
56
|
+
const newFileName = `${baseName}.part${chunkIndex}${ext}`;
|
|
57
|
+
const newFileFullPath = path.join(dirName, newFileName);
|
|
58
|
+
fs.writeFileSync(newFileFullPath, chunkLines.join("\n"), "utf8");
|
|
59
|
+
newFilePaths.push(newFileFullPath);
|
|
60
|
+
i += threshold;
|
|
61
|
+
}
|
|
62
|
+
return newFilePaths;
|
|
63
|
+
}
|
|
64
|
+
export function splitLargeFunctions(filePath, funcLineThreshold) {
|
|
65
|
+
const sourceCode = fs.readFileSync(filePath, "utf8");
|
|
66
|
+
const sourceFile = ts.createSourceFile(
|
|
67
|
+
filePath,
|
|
68
|
+
sourceCode,
|
|
69
|
+
ts.ScriptTarget.ESNext,
|
|
70
|
+
true
|
|
71
|
+
);
|
|
72
|
+
let newSource = sourceCode;
|
|
73
|
+
const getLineOfPosition = (pos) => {
|
|
74
|
+
return sourceFile.getLineAndCharacterOfPosition(pos).line;
|
|
75
|
+
};
|
|
76
|
+
const largeFunctions = [];
|
|
77
|
+
function visit(node) {
|
|
78
|
+
if (ts.isFunctionDeclaration(node) && node.body) {
|
|
79
|
+
const startLine = getLineOfPosition(node.body.pos);
|
|
80
|
+
const endLine = getLineOfPosition(node.body.end);
|
|
81
|
+
const lineCount = endLine - startLine;
|
|
82
|
+
if (lineCount > funcLineThreshold) {
|
|
83
|
+
const name = node.name?.text || "<anonymous>";
|
|
84
|
+
largeFunctions.push({
|
|
85
|
+
name,
|
|
86
|
+
startPos: node.body.pos,
|
|
87
|
+
endPos: node.body.end,
|
|
88
|
+
lineCount
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
ts.forEachChild(node, visit);
|
|
93
|
+
}
|
|
94
|
+
visit(sourceFile);
|
|
95
|
+
if (largeFunctions.length === 0) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
console.log(
|
|
99
|
+
`File "${filePath}" has ${largeFunctions.length} function(s) above ${funcLineThreshold} lines. Attempting to split...`
|
|
100
|
+
);
|
|
101
|
+
largeFunctions.sort((a, b) => b.startPos - a.startPos).forEach((fn) => {
|
|
102
|
+
const bodyText = sourceCode.slice(fn.startPos, fn.endPos);
|
|
103
|
+
const midIndex = Math.floor(bodyText.length / 2);
|
|
104
|
+
const helperFunctionName = `${fn.name}HelperAutoGen`;
|
|
105
|
+
const replacementText = `{
|
|
106
|
+
// Original function was split automatically
|
|
107
|
+
${bodyText.slice(0, midIndex)}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function ${helperFunctionName}() {
|
|
111
|
+
// auto-generated second half
|
|
112
|
+
${bodyText.slice(midIndex)}
|
|
113
|
+
`;
|
|
114
|
+
newSource = newSource.slice(0, fn.startPos) + replacementText + newSource.slice(fn.endPos);
|
|
115
|
+
});
|
|
116
|
+
fs.writeFileSync(filePath, newSource, "utf8");
|
|
117
|
+
}
|
|
@@ -1,117 +1,26 @@
|
|
|
1
1
|
import fs from "fs-extra";
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
2
|
+
import {
|
|
3
|
+
getAllSourceFiles,
|
|
4
|
+
parseCommandLineArgs,
|
|
5
|
+
splitLargeFileByLines,
|
|
6
|
+
splitLargeFunctions
|
|
7
|
+
} from "./split-impl.js";
|
|
8
|
+
async function main() {
|
|
9
|
+
const { directory, fileLineThreshold, funcLineThreshold } = parseCommandLineArgs();
|
|
10
|
+
const allFiles = getAllSourceFiles(directory);
|
|
11
|
+
for (const filePath of allFiles) {
|
|
12
|
+
const lineCount = fs.readFileSync(filePath, "utf8").split("\n").length;
|
|
13
|
+
if (lineCount > fileLineThreshold) {
|
|
14
|
+
const newSplits = splitLargeFileByLines(filePath, fileLineThreshold);
|
|
15
|
+
newSplits.forEach((splitFilePath) => {
|
|
16
|
+
splitLargeFunctions(splitFilePath, funcLineThreshold);
|
|
17
|
+
});
|
|
18
|
+
} else {
|
|
19
|
+
splitLargeFunctions(filePath, funcLineThreshold);
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
-
return { directory, fileLineThreshold, funcLineThreshold };
|
|
23
|
-
}
|
|
24
|
-
export function getAllSourceFiles(dir) {
|
|
25
|
-
const results = [];
|
|
26
|
-
function searchDirectory(directory) {
|
|
27
|
-
const files = fs.readdirSync(directory);
|
|
28
|
-
for (const file of files) {
|
|
29
|
-
const fullPath = path.join(directory, file);
|
|
30
|
-
if (fs.statSync(fullPath).isDirectory()) {
|
|
31
|
-
searchDirectory(fullPath);
|
|
32
|
-
} else if (/\.(ts|js)$/.test(file)) {
|
|
33
|
-
results.push(fullPath);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
searchDirectory(dir);
|
|
38
|
-
return results;
|
|
39
|
-
}
|
|
40
|
-
export function splitLargeFileByLines(filePath, threshold) {
|
|
41
|
-
const originalContent = fs.readFileSync(filePath, "utf8");
|
|
42
|
-
const lines = originalContent.split("\n");
|
|
43
|
-
if (lines.length <= threshold) {
|
|
44
|
-
return [filePath];
|
|
45
|
-
}
|
|
46
|
-
console.log(`File "${filePath}" exceeds ${threshold} lines. Splitting...`);
|
|
47
|
-
const baseName = path.basename(filePath, path.extname(filePath));
|
|
48
|
-
const ext = path.extname(filePath);
|
|
49
|
-
const dirName = path.dirname(filePath);
|
|
50
|
-
const newFilePaths = [];
|
|
51
|
-
let chunkIndex = 0;
|
|
52
|
-
let i = 0;
|
|
53
|
-
while (i < lines.length) {
|
|
54
|
-
chunkIndex++;
|
|
55
|
-
const chunkLines = lines.slice(i, i + threshold);
|
|
56
|
-
const newFileName = `${baseName}.part${chunkIndex}${ext}`;
|
|
57
|
-
const newFileFullPath = path.join(dirName, newFileName);
|
|
58
|
-
fs.writeFileSync(newFileFullPath, chunkLines.join("\n"), "utf8");
|
|
59
|
-
newFilePaths.push(newFileFullPath);
|
|
60
|
-
i += threshold;
|
|
61
|
-
}
|
|
62
|
-
return newFilePaths;
|
|
63
|
-
}
|
|
64
|
-
export function splitLargeFunctions(filePath, funcLineThreshold) {
|
|
65
|
-
const sourceCode = fs.readFileSync(filePath, "utf8");
|
|
66
|
-
const sourceFile = ts.createSourceFile(
|
|
67
|
-
filePath,
|
|
68
|
-
sourceCode,
|
|
69
|
-
ts.ScriptTarget.ESNext,
|
|
70
|
-
true
|
|
71
|
-
);
|
|
72
|
-
let newSource = sourceCode;
|
|
73
|
-
const getLineOfPosition = (pos) => {
|
|
74
|
-
return sourceFile.getLineAndCharacterOfPosition(pos).line;
|
|
75
|
-
};
|
|
76
|
-
const largeFunctions = [];
|
|
77
|
-
function visit(node) {
|
|
78
|
-
if (ts.isFunctionDeclaration(node) && node.body) {
|
|
79
|
-
const startLine = getLineOfPosition(node.body.pos);
|
|
80
|
-
const endLine = getLineOfPosition(node.body.end);
|
|
81
|
-
const lineCount = endLine - startLine;
|
|
82
|
-
if (lineCount > funcLineThreshold) {
|
|
83
|
-
const name = node.name?.text || "<anonymous>";
|
|
84
|
-
largeFunctions.push({
|
|
85
|
-
name,
|
|
86
|
-
startPos: node.body.pos,
|
|
87
|
-
endPos: node.body.end,
|
|
88
|
-
lineCount
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
ts.forEachChild(node, visit);
|
|
93
|
-
}
|
|
94
|
-
visit(sourceFile);
|
|
95
|
-
if (largeFunctions.length === 0) {
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
console.log(
|
|
99
|
-
`File "${filePath}" has ${largeFunctions.length} function(s) above ${funcLineThreshold} lines. Attempting to split...`
|
|
100
|
-
);
|
|
101
|
-
largeFunctions.sort((a, b) => b.startPos - a.startPos).forEach((fn) => {
|
|
102
|
-
const bodyText = sourceCode.slice(fn.startPos, fn.endPos);
|
|
103
|
-
const midIndex = Math.floor(bodyText.length / 2);
|
|
104
|
-
const helperFunctionName = `${fn.name}HelperAutoGen`;
|
|
105
|
-
const replacementText = `{
|
|
106
|
-
// Original function was split automatically
|
|
107
|
-
${bodyText.slice(0, midIndex)}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
function ${helperFunctionName}() {
|
|
111
|
-
// auto-generated second half
|
|
112
|
-
${bodyText.slice(midIndex)}
|
|
113
|
-
`;
|
|
114
|
-
newSource = newSource.slice(0, fn.startPos) + replacementText + newSource.slice(fn.endPos);
|
|
115
|
-
});
|
|
116
|
-
fs.writeFileSync(filePath, newSource, "utf8");
|
|
117
22
|
}
|
|
23
|
+
main().catch((err) => {
|
|
24
|
+
console.error(err);
|
|
25
|
+
process.exit(1);
|
|
26
|
+
});
|
|
@@ -285,7 +285,7 @@ export function printUsage(isDev) {
|
|
|
285
285
|
if (isDev) {
|
|
286
286
|
relinka(
|
|
287
287
|
"info",
|
|
288
|
-
"bun dev:tools agg --input src/libs/sdk/sdk-impl --out src/libs/sdk/sdk-
|
|
288
|
+
"bun dev:tools agg --input src/libs/sdk/sdk-impl --out src/libs/sdk/sdk-mod.ts --recursive --named --strip src/libs/sdk"
|
|
289
289
|
);
|
|
290
290
|
} else {
|
|
291
291
|
relinka(
|
package/bin/init.js
CHANGED
|
@@ -30,7 +30,7 @@ export async function initDlerConfig(isDev) {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
function generateConfig(isDev) {
|
|
33
|
-
const importDefineConfigStatement = isDev ? `import { defineConfig } from "
|
|
33
|
+
const importDefineConfigStatement = isDev ? `import { defineConfig } from "./libs/cfg/cfg-mod.js";` : `import { defineConfig } from "@reliverse/dler-cfg";`;
|
|
34
34
|
const verboseValue = getValue(isDev, true, DEFAULT_CONFIG.commonVerbose);
|
|
35
35
|
const isCLIValue = getValue(isDev, true, DEFAULT_CONFIG.coreIsCLI);
|
|
36
36
|
const registryValue = getValue(
|
|
@@ -58,7 +58,7 @@ function generateConfig(isDev) {
|
|
|
58
58
|
libDeclarations: true,
|
|
59
59
|
libDescription: "@reliverse/dler defineConfig",
|
|
60
60
|
libDirName: "cfg",
|
|
61
|
-
libMainFile: "cfg/cfg-
|
|
61
|
+
libMainFile: "cfg/cfg-mod.ts",
|
|
62
62
|
libPkgKeepDeps: false,
|
|
63
63
|
libTranspileMinify: true,
|
|
64
64
|
},
|
|
@@ -66,7 +66,7 @@ function generateConfig(isDev) {
|
|
|
66
66
|
libDeclarations: true,
|
|
67
67
|
libDescription: "@reliverse/dler without cli",
|
|
68
68
|
libDirName: "sdk",
|
|
69
|
-
libMainFile: "sdk/sdk-
|
|
69
|
+
libMainFile: "sdk/sdk-mod.ts",
|
|
70
70
|
libPkgKeepDeps: true,
|
|
71
71
|
libTranspileMinify: true,
|
|
72
72
|
},
|
|
@@ -75,7 +75,7 @@ function generateConfig(isDev) {
|
|
|
75
75
|
// libDeclarations: true,
|
|
76
76
|
// libDescription: "@acme/cli defineConfig",
|
|
77
77
|
// libDirName: "libName",
|
|
78
|
-
// libMainFile: "libName/libName-
|
|
78
|
+
// libMainFile: "libName/libName-mod.ts",
|
|
79
79
|
// libPkgKeepDeps: true,
|
|
80
80
|
// libTranspileMinify: true,
|
|
81
81
|
// },
|
|
@@ -81,7 +81,7 @@ export async function regular_buildJsrDist(isDev, isJsr, coreIsCLI, coreEntrySrc
|
|
|
81
81
|
const filesCount = await outDirBinFilesCount(outDirBin);
|
|
82
82
|
relinka(
|
|
83
83
|
"success",
|
|
84
|
-
`[${distJsrDirNameResolved}] Successfully created regular distribution: "dist-jsr" (${outDirBin}/
|
|
84
|
+
`[${distJsrDirNameResolved}] Successfully created regular distribution: "dist-jsr" (${outDirBin}/mod.ts) with (${filesCount} files (${prettyBytes(
|
|
85
85
|
dirSize
|
|
86
86
|
)}))`
|
|
87
87
|
);
|
|
@@ -129,7 +129,7 @@ export async function regular_buildNpmDist(isDev, coreEntrySrcDir, distNpmDirNam
|
|
|
129
129
|
);
|
|
130
130
|
relinka(
|
|
131
131
|
"success",
|
|
132
|
-
`[${distNpmDirNameResolved}] Successfully created regular distribution: "dist-npm" (${outDirBin}/
|
|
132
|
+
`[${distNpmDirNameResolved}] Successfully created regular distribution: "dist-npm" (${outDirBin}/mod.js) with (${filesCount} files (${prettyBytes(
|
|
133
133
|
dirSize
|
|
134
134
|
)}))`
|
|
135
135
|
);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as executors from "./
|
|
2
|
-
import * as fs from "./
|
|
3
|
-
import { extractSpellsFromFile } from "./
|
|
1
|
+
import * as executors from "./spell-executors.js";
|
|
2
|
+
import * as fs from "./spell-filesystem.js";
|
|
3
|
+
import { extractSpellsFromFile } from "./spell-parser.js";
|
|
4
4
|
export const executeSpell = async (spell, filePath, content) => {
|
|
5
5
|
if (spell.params.hooked) {
|
|
6
6
|
return {
|
|
@@ -10,7 +10,7 @@ export function printUsage(isDev) {
|
|
|
10
10
|
if (isDev) {
|
|
11
11
|
relinka(
|
|
12
12
|
"info",
|
|
13
|
-
"bun dev:tools agg --input src/libs/sdk/sdk-impl --out src/libs/sdk/sdk-
|
|
13
|
+
"bun dev:tools agg --input src/libs/sdk/sdk-impl --out src/libs/sdk/sdk-mod.ts --recursive --named --strip src/libs/sdk"
|
|
14
14
|
);
|
|
15
15
|
} else {
|
|
16
16
|
relinka(
|
|
@@ -51,7 +51,7 @@ export async function renameEntryFile(isJsr, outDirBin, originalEntryFileBasenam
|
|
|
51
51
|
if (isJsr) {
|
|
52
52
|
if (originalEntryFileBasename.endsWith(".ts")) {
|
|
53
53
|
sourceEntryBasename = originalEntryFileBasename;
|
|
54
|
-
targetEntryBasename = "
|
|
54
|
+
targetEntryBasename = "mod.ts";
|
|
55
55
|
} else {
|
|
56
56
|
sourceEntryBasename = `${originalBasenameNoExt}.${outputExt}`;
|
|
57
57
|
targetEntryBasename = `main.${outputExt}`;
|
|
@@ -189,7 +189,7 @@ async function library_writeJsrPackageJSON(libName, outDirBin, outDirRoot, origi
|
|
|
189
189
|
libDeclarations: false,
|
|
190
190
|
libDescription: "",
|
|
191
191
|
libDirName: libName,
|
|
192
|
-
libMainFile: "src/libs/libName/libName-
|
|
192
|
+
libMainFile: "src/libs/libName/libName-mod.ts",
|
|
193
193
|
libPkgKeepDeps: false,
|
|
194
194
|
libTranspileMinify: true
|
|
195
195
|
},
|
|
@@ -205,7 +205,7 @@ async function library_writeJsrPackageJSON(libName, outDirBin, outDirRoot, origi
|
|
|
205
205
|
rmDepsPatterns
|
|
206
206
|
),
|
|
207
207
|
exports: {
|
|
208
|
-
".": "./bin/
|
|
208
|
+
".": "./bin/mod.ts"
|
|
209
209
|
}
|
|
210
210
|
});
|
|
211
211
|
await fs.writeJSON(path.join(outDirRoot, "package.json"), jsrPkg, {
|
|
@@ -229,7 +229,7 @@ async function library_writeNpmLibPackageJSON(libName, outDirBin, outDirRoot, or
|
|
|
229
229
|
libDeclarations: true,
|
|
230
230
|
libDescription: "",
|
|
231
231
|
libDirName: libName,
|
|
232
|
-
libMainFile: "src/libs/libName/libName-
|
|
232
|
+
libMainFile: "src/libs/libName/libName-mod.ts",
|
|
233
233
|
libPkgKeepDeps: true,
|
|
234
234
|
libTranspileMinify: true
|
|
235
235
|
},
|
|
@@ -245,11 +245,11 @@ async function library_writeNpmLibPackageJSON(libName, outDirBin, outDirRoot, or
|
|
|
245
245
|
rmDepsPatterns
|
|
246
246
|
),
|
|
247
247
|
exports: {
|
|
248
|
-
".": `./bin/
|
|
248
|
+
".": `./bin/mod.${unifiedBundlerOutExt}`
|
|
249
249
|
},
|
|
250
250
|
files: ["bin", "package.json", "README.md", "LICENSE"],
|
|
251
|
-
main: `./bin/
|
|
252
|
-
module: `./bin/
|
|
251
|
+
main: `./bin/mod.${unifiedBundlerOutExt}`,
|
|
252
|
+
module: `./bin/mod.${unifiedBundlerOutExt}`,
|
|
253
253
|
publishConfig: { access: "public" }
|
|
254
254
|
});
|
|
255
255
|
await fs.writeJSON(path.join(outDirRoot, "package.json"), npmPkg, {
|
|
@@ -22,11 +22,11 @@ export async function regular_createPackageJSON(outDirRoot, isJsr, coreIsCLI, un
|
|
|
22
22
|
const outDirBin = path.join(outDirRoot, "bin");
|
|
23
23
|
const outExt = unifiedBundlerOutExt || "js";
|
|
24
24
|
if (isJsr) {
|
|
25
|
-
const binEntry = coreIsCLI ? { [cliCommandName]: "bin/
|
|
25
|
+
const binEntry = coreIsCLI ? { [cliCommandName]: "bin/mod.ts" } : void 0;
|
|
26
26
|
if (coreIsCLI) {
|
|
27
27
|
relinka(
|
|
28
28
|
"verbose",
|
|
29
|
-
`Adding CLI bin entry for JSR: { "${cliCommandName}": "bin/
|
|
29
|
+
`Adding CLI bin entry for JSR: { "${cliCommandName}": "bin/mod.ts" }`
|
|
30
30
|
);
|
|
31
31
|
}
|
|
32
32
|
const jsrPkg = definePackageJSON({
|
|
@@ -47,7 +47,7 @@ export async function regular_createPackageJSON(outDirRoot, isJsr, coreIsCLI, un
|
|
|
47
47
|
rmDepsPatterns
|
|
48
48
|
),
|
|
49
49
|
exports: {
|
|
50
|
-
".": "./bin/
|
|
50
|
+
".": "./bin/mod.ts"
|
|
51
51
|
}
|
|
52
52
|
});
|
|
53
53
|
await fs.writeJSON(path.join(outDirRoot, "package.json"), jsrPkg, {
|
|
@@ -60,11 +60,11 @@ export async function regular_createPackageJSON(outDirRoot, isJsr, coreIsCLI, un
|
|
|
60
60
|
);
|
|
61
61
|
}
|
|
62
62
|
} else {
|
|
63
|
-
const binEntry = coreIsCLI ? { [cliCommandName]: `bin/
|
|
63
|
+
const binEntry = coreIsCLI ? { [cliCommandName]: `bin/mod.${outExt}` } : void 0;
|
|
64
64
|
if (coreIsCLI) {
|
|
65
65
|
relinka(
|
|
66
66
|
"verbose",
|
|
67
|
-
`Adding CLI bin entry for NPM: { "${cliCommandName}": "bin/
|
|
67
|
+
`Adding CLI bin entry for NPM: { "${cliCommandName}": "bin/mod.${outExt}" }`
|
|
68
68
|
);
|
|
69
69
|
}
|
|
70
70
|
const npmPkg = definePackageJSON({
|
|
@@ -85,11 +85,11 @@ export async function regular_createPackageJSON(outDirRoot, isJsr, coreIsCLI, un
|
|
|
85
85
|
rmDepsPatterns
|
|
86
86
|
),
|
|
87
87
|
exports: {
|
|
88
|
-
".": `./bin/
|
|
88
|
+
".": `./bin/mod.${outExt}`
|
|
89
89
|
},
|
|
90
90
|
files: ["bin", "package.json", "README.md", "LICENSE"],
|
|
91
|
-
main: `./bin/
|
|
92
|
-
module: `./bin/
|
|
91
|
+
main: `./bin/mod.${outExt}`,
|
|
92
|
+
module: `./bin/mod.${outExt}`,
|
|
93
93
|
publishConfig: { access: "public" }
|
|
94
94
|
});
|
|
95
95
|
await fs.writeJSON(path.join(outDirRoot, "package.json"), npmPkg, {
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
10
10
|
"@rollup/plugin-replace": "^6.0.2",
|
|
11
11
|
"@rollup/pluginutils": "^5.1.4",
|
|
12
|
-
"bun": "^1.2.
|
|
12
|
+
"bun": "^1.2.13",
|
|
13
13
|
"chalk": "^5.4.1",
|
|
14
14
|
"commander": "^13.1.0",
|
|
15
15
|
"defu": "^6.1.4",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"rollup": "^4.40.2",
|
|
33
33
|
"rollup-plugin-dts": "^6.2.1",
|
|
34
34
|
"scule": "^1.3.0",
|
|
35
|
-
"semver": "^7.7.
|
|
35
|
+
"semver": "^7.7.2",
|
|
36
36
|
"tinyglobby": "^0.2.13",
|
|
37
37
|
"untyped": "^2.0.0"
|
|
38
38
|
},
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"license": "MIT",
|
|
42
42
|
"name": "@reliverse/dler",
|
|
43
43
|
"type": "module",
|
|
44
|
-
"version": "1.2.
|
|
44
|
+
"version": "1.2.1",
|
|
45
45
|
"keywords": [
|
|
46
46
|
"reliverse",
|
|
47
47
|
"cli",
|
|
@@ -58,14 +58,14 @@
|
|
|
58
58
|
"url": "git+https://github.com/reliverse/dler.git"
|
|
59
59
|
},
|
|
60
60
|
"bin": {
|
|
61
|
-
"dler": "bin/
|
|
61
|
+
"dler": "bin/mod.js"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
64
|
"@biomejs/biome": "^1.9.4",
|
|
65
65
|
"@eslint/js": "^9.26.0",
|
|
66
66
|
"@stylistic/eslint-plugin": "^4.2.0",
|
|
67
67
|
"@total-typescript/ts-reset": "^0.6.1",
|
|
68
|
-
"@types/bun": "^1.2.
|
|
68
|
+
"@types/bun": "^1.2.13",
|
|
69
69
|
"@types/fs-extra": "^11.0.4",
|
|
70
70
|
"@types/node": "^22.15.17",
|
|
71
71
|
"@types/semver": "^7.7.0",
|
|
@@ -74,10 +74,10 @@
|
|
|
74
74
|
"eslint-plugin-perfectionist": "^4.12.3",
|
|
75
75
|
"knip": "^5.55.1",
|
|
76
76
|
"typescript": "^5.8.3",
|
|
77
|
-
"typescript-eslint": "^8.32.
|
|
77
|
+
"typescript-eslint": "^8.32.1"
|
|
78
78
|
},
|
|
79
79
|
"exports": {
|
|
80
|
-
".": "./bin/
|
|
80
|
+
".": "./bin/mod.js"
|
|
81
81
|
},
|
|
82
82
|
"files": [
|
|
83
83
|
"bin",
|
|
@@ -85,8 +85,8 @@
|
|
|
85
85
|
"README.md",
|
|
86
86
|
"LICENSE"
|
|
87
87
|
],
|
|
88
|
-
"main": "./bin/
|
|
89
|
-
"module": "./bin/
|
|
88
|
+
"main": "./bin/mod.js",
|
|
89
|
+
"module": "./bin/mod.js",
|
|
90
90
|
"publishConfig": {
|
|
91
91
|
"access": "public"
|
|
92
92
|
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import fs from "fs-extra";
|
|
2
|
-
import {
|
|
3
|
-
getAllSourceFiles,
|
|
4
|
-
parseCommandLineArgs,
|
|
5
|
-
splitLargeFileByLines,
|
|
6
|
-
splitLargeFunctions
|
|
7
|
-
} from "./split-mod.js";
|
|
8
|
-
async function main() {
|
|
9
|
-
const { directory, fileLineThreshold, funcLineThreshold } = parseCommandLineArgs();
|
|
10
|
-
const allFiles = getAllSourceFiles(directory);
|
|
11
|
-
for (const filePath of allFiles) {
|
|
12
|
-
const lineCount = fs.readFileSync(filePath, "utf8").split("\n").length;
|
|
13
|
-
if (lineCount > fileLineThreshold) {
|
|
14
|
-
const newSplits = splitLargeFileByLines(filePath, fileLineThreshold);
|
|
15
|
-
newSplits.forEach((splitFilePath) => {
|
|
16
|
-
splitLargeFunctions(splitFilePath, funcLineThreshold);
|
|
17
|
-
});
|
|
18
|
-
} else {
|
|
19
|
-
splitLargeFunctions(filePath, funcLineThreshold);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
main().catch((err) => {
|
|
24
|
-
console.error(err);
|
|
25
|
-
process.exit(1);
|
|
26
|
-
});
|
package/bin/libs/cfg/cfg-main.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { defineConfig } from "./cfg-mod.js";
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/bin/{main.js → mod.js}
RENAMED
|
File without changes
|