@reliverse/dler 1.7.16 → 1.7.18
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 +134 -206
- package/bin/app/agg/run.js +2 -8
- package/bin/app/build/cmd.js +4 -4
- package/bin/app/build/impl.d.ts +2 -6
- package/bin/app/build/impl.js +2 -46
- package/bin/app/conv/cmd.d.ts +8 -33
- package/bin/app/conv/cmd.js +185 -163
- package/bin/app/copy/cmd.js +1 -1
- package/bin/app/init/init-impl.js +3 -3
- package/bin/app/init/init-types.d.ts +8 -8
- package/bin/app/merge/cmd.d.ts +10 -24
- package/bin/app/merge/cmd.js +47 -464
- package/bin/app/migrate/codemods/anything-bun.js +1 -1
- package/bin/app/migrate/codemods/fs-relifso.d.ts +2 -2
- package/bin/app/migrate/codemods/fs-relifso.js +1 -1
- package/bin/app/migrate/codemods/nodenext-bundler.d.ts +2 -2
- package/bin/app/migrate/codemods/nodenext-bundler.js +1 -1
- package/bin/app/migrate/codemods/path-pathkit.d.ts +2 -2
- package/bin/app/migrate/codemods/path-pathkit.js +1 -1
- package/bin/app/migrate/codemods/readdir-glob.d.ts +2 -2
- package/bin/app/migrate/codemods/readdir-glob.js +1 -1
- package/bin/app/mkdist/cmd.js +4 -2
- package/bin/app/pack/cmd.d.ts +44 -0
- package/bin/app/pack/cmd.js +313 -0
- package/bin/app/pub/cmd.js +4 -4
- package/bin/app/pub/impl.d.ts +7 -0
- package/bin/app/pub/impl.js +97 -0
- package/bin/app/rename/cmd.js +1 -1
- package/bin/app/spell/cmd.d.ts +14 -5
- package/bin/app/spell/cmd.js +33 -33
- package/bin/app/spell/old.js +0 -0
- package/bin/app/{mock → unpack}/cmd.d.ts +10 -14
- package/bin/app/unpack/cmd.js +200 -0
- package/bin/cli.js +2 -2
- package/bin/libs/cfg/cfg-mod.d.ts +69 -0
- package/bin/libs/cfg/cfg-mod.js +61 -0
- package/bin/libs/cfg/rse/rse-impl/rse-biome.d.ts +2 -0
- package/bin/libs/cfg/rse/rse-impl/rse-biome.js +34 -0
- package/bin/libs/cfg/rse/rse-impl/rse-consts.d.ts +35 -0
- package/bin/libs/cfg/rse/rse-impl/rse-consts.js +37 -0
- package/bin/libs/cfg/rse/rse-impl/rse-content.d.ts +14 -0
- package/bin/libs/cfg/rse/rse-impl/rse-content.js +15 -0
- package/bin/libs/cfg/rse/rse-impl/rse-core.d.ts +14 -0
- package/bin/libs/cfg/rse/rse-impl/rse-core.js +63 -0
- package/bin/libs/cfg/rse/rse-impl/rse-create.d.ts +36 -0
- package/bin/libs/cfg/rse/rse-impl/rse-create.js +254 -0
- package/bin/libs/cfg/rse/rse-impl/rse-def-utils.d.ts +6 -0
- package/bin/libs/cfg/rse/rse-impl/rse-def-utils.js +225 -0
- package/bin/libs/cfg/rse/rse-impl/rse-default.d.ts +3 -0
- package/bin/libs/cfg/rse/rse-impl/rse-default.js +155 -0
- package/bin/libs/cfg/rse/rse-impl/rse-define.d.ts +125 -0
- package/bin/libs/cfg/rse/rse-impl/rse-define.js +4 -0
- package/bin/libs/cfg/rse/rse-impl/rse-detect.d.ts +23 -0
- package/bin/libs/cfg/rse/rse-impl/rse-detect.js +347 -0
- package/bin/libs/cfg/rse/rse-impl/rse-gen-cfg.d.ts +3 -0
- package/bin/libs/cfg/rse/rse-impl/rse-gen-cfg.js +186 -0
- package/bin/libs/cfg/rse/rse-impl/rse-inject.d.ts +1 -0
- package/bin/libs/cfg/rse/rse-impl/rse-inject.js +57 -0
- package/bin/libs/cfg/rse/rse-impl/rse-migrate.d.ts +5 -0
- package/bin/libs/cfg/rse/rse-impl/rse-migrate.js +56 -0
- package/bin/libs/cfg/rse/rse-impl/rse-path.d.ts +11 -0
- package/bin/libs/cfg/rse/rse-impl/rse-path.js +33 -0
- package/bin/libs/cfg/rse/rse-impl/rse-prompts.d.ts +5 -0
- package/bin/libs/cfg/rse/rse-impl/rse-prompts.js +12 -0
- package/bin/libs/cfg/rse/rse-impl/rse-read.d.ts +11 -0
- package/bin/libs/cfg/rse/rse-impl/rse-read.js +84 -0
- package/bin/libs/cfg/rse/rse-impl/rse-repair.d.ts +16 -0
- package/bin/libs/cfg/rse/rse-impl/rse-repair.js +137 -0
- package/bin/libs/cfg/rse/rse-impl/rse-schema.d.ts +130 -0
- package/bin/libs/cfg/rse/rse-impl/rse-schema.js +444 -0
- package/bin/libs/cfg/rse/rse-impl/rse-types.d.ts +75 -0
- package/bin/libs/cfg/rse/rse-impl/rse-types.js +0 -0
- package/bin/libs/cfg/rse/rse-impl/rse-unstable.d.ts +11 -0
- package/bin/libs/cfg/rse/rse-impl/rse-unstable.js +41 -0
- package/bin/libs/cfg/rse/rse-impl/rse-update.d.ts +10 -0
- package/bin/libs/cfg/rse/rse-impl/rse-update.js +152 -0
- package/bin/libs/cfg/rse/rse-impl/rse-utils.d.ts +17 -0
- package/bin/libs/cfg/rse/rse-impl/rse-utils.js +86 -0
- package/bin/libs/cfg/rse/rse-mod.d.ts +20 -0
- package/bin/libs/cfg/rse/rse-mod.js +20 -0
- package/bin/libs/cfg/types.d.ts +533 -0
- package/bin/libs/cfg/types.js +0 -0
- package/bin/libs/sdk/sdk-impl/build/build-library.d.ts +5 -5
- package/bin/libs/sdk/sdk-impl/build/build-library.js +1 -174
- package/bin/libs/sdk/sdk-impl/build/build-regular.d.ts +2 -1
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/build.js +287 -240
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/mkdist/mkdist-impl/loaders/vue.d.ts +4 -4
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/mkdist/mkdist-impl/make.d.ts +8 -5
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/mkdist/mkdist-impl/make.js +199 -119
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/mkdist/mkdist-impl/utils/spinner.d.ts +99 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/mkdist/mkdist-impl/utils/spinner.js +206 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/mkdist/mkdist-mod.js +92 -46
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/plugins/raw.d.ts +2 -2
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/utils.d.ts +2 -2
- package/bin/libs/sdk/sdk-impl/config/default.d.ts +6 -0
- package/bin/libs/sdk/sdk-impl/{cfg → config}/default.js +8 -18
- package/bin/libs/sdk/sdk-impl/{cfg → config}/info.js +1 -1
- package/bin/libs/sdk/sdk-impl/{cfg → config}/init.js +53 -43
- package/bin/libs/sdk/sdk-impl/{cfg → config}/load.d.ts +2 -2
- package/bin/libs/sdk/sdk-impl/{cfg → config}/load.js +6 -6
- package/bin/libs/sdk/sdk-impl/config/types.d.ts +533 -0
- package/bin/libs/sdk/sdk-impl/config/types.js +0 -0
- package/bin/libs/sdk/sdk-impl/library-flow.d.ts +2 -1
- package/bin/libs/sdk/sdk-impl/regular-flow.d.ts +2 -1
- package/bin/libs/sdk/sdk-impl/rules/reliverse/dler-config-health/dler-config-health.js +2 -2
- package/bin/libs/sdk/sdk-impl/rules/reliverse/missing-deps/deps-types.d.ts +6 -6
- package/bin/libs/sdk/sdk-impl/rules/reliverse/missing-deps/filesystem.js +1 -1
- package/bin/libs/sdk/sdk-impl/rules/reliverse/no-index-files/no-index-files.js +1 -1
- package/bin/libs/sdk/sdk-impl/rules/reliverse/self-include/self-include.js +2 -2
- package/bin/libs/sdk/sdk-impl/spell/applyMagicSpells.d.ts +38 -0
- package/bin/libs/sdk/sdk-impl/spell/applyMagicSpells.js +474 -0
- package/bin/libs/sdk/sdk-impl/spell/spells.d.ts +31 -0
- package/bin/libs/sdk/sdk-impl/spell/spells.js +85 -0
- package/bin/libs/sdk/sdk-impl/utils/binary.js +1 -1
- package/bin/libs/sdk/sdk-impl/utils/comments.d.ts +6 -0
- package/bin/libs/sdk/sdk-impl/utils/comments.js +41 -0
- package/bin/libs/sdk/sdk-impl/utils/finalize.d.ts +2 -1
- package/bin/libs/sdk/sdk-impl/utils/finalize.js +1 -0
- package/bin/libs/sdk/sdk-impl/utils/pack-unpack/pu-constants.d.ts +6 -0
- package/bin/libs/sdk/sdk-impl/utils/pack-unpack/pu-constants.js +7 -0
- package/bin/libs/sdk/sdk-impl/utils/pack-unpack/pu-file-utils.d.ts +5 -0
- package/bin/libs/sdk/sdk-impl/utils/pack-unpack/pu-file-utils.js +40 -0
- package/bin/libs/sdk/sdk-impl/utils/pack-unpack/pu-types.d.ts +24 -0
- package/bin/libs/sdk/sdk-impl/utils/pack-unpack/pu-types.js +0 -0
- package/bin/libs/sdk/sdk-impl/utils/pack-unpack/pub-json-utils.d.ts +17 -0
- package/bin/libs/sdk/sdk-impl/utils/pack-unpack/pub-json-utils.js +46 -0
- package/bin/libs/sdk/sdk-impl/utils/replacements.d.ts +0 -0
- package/bin/libs/sdk/sdk-impl/utils/replacements.js +0 -0
- package/bin/libs/sdk/sdk-impl/utils/resolve-cross-libs.d.ts +3 -0
- package/bin/libs/sdk/sdk-impl/utils/resolve-cross-libs.js +194 -0
- package/bin/libs/sdk/sdk-impl/utils/utils-build.d.ts +1 -2
- package/bin/libs/sdk/sdk-impl/utils/utils-clean.d.ts +1 -1
- package/bin/libs/sdk/sdk-impl/utils/utils-deps.d.ts +1 -1
- package/bin/libs/sdk/sdk-impl/utils/utils-determine.d.ts +1 -1
- package/bin/libs/sdk/sdk-impl/utils/utils-error-cwd.d.ts +4 -0
- package/bin/libs/sdk/sdk-impl/utils/utils-error-cwd.js +1 -0
- package/bin/libs/sdk/sdk-impl/utils/utils-jsr-json.d.ts +1 -1
- package/bin/libs/sdk/sdk-impl/utils/utils-package-json-libraries.d.ts +1 -1
- package/bin/libs/sdk/sdk-impl/utils/utils-package-json-regular.d.ts +1 -1
- package/bin/libs/sdk/sdk-impl/utils/utils-security.d.ts +1 -3
- package/bin/libs/sdk/sdk-impl/utils/utils-security.js +11 -10
- package/bin/libs/sdk/sdk-mod.d.ts +1 -6
- package/bin/libs/sdk/sdk-mod.js +0 -31
- package/bin/libs/sdk/sdk-types.d.ts +39 -582
- package/bin/mod.d.ts +1 -1
- package/bin/mod.js +1 -1
- package/package.json +12 -4
- package/bin/app/mock/cmd.js +0 -284
- package/bin/app/mock/mock.d.ts +0 -11
- package/bin/app/mock/mock.js +0 -97
- package/bin/libs/sdk/sdk-impl/cfg/default.d.ts +0 -5
- package/bin/libs/sdk/sdk-impl/cfg/define.d.ts +0 -2
- package/bin/libs/sdk/sdk-impl/cfg/define.js +0 -4
- package/bin/libs/sdk/sdk-impl/spell/spell-executors.d.ts +0 -10
- package/bin/libs/sdk/sdk-impl/spell/spell-executors.js +0 -307
- package/bin/libs/sdk/sdk-impl/spell/spell-filesystem.d.ts +0 -7
- package/bin/libs/sdk/sdk-impl/spell/spell-filesystem.js +0 -74
- package/bin/libs/sdk/sdk-impl/spell/spell-mod.d.ts +0 -4
- package/bin/libs/sdk/sdk-impl/spell/spell-mod.js +0 -87
- package/bin/libs/sdk/sdk-impl/spell/spell-parser.d.ts +0 -4
- package/bin/libs/sdk/sdk-impl/spell/spell-parser.js +0 -58
- package/bin/libs/sdk/sdk-impl/spell/spell-types.d.ts +0 -60
- /package/bin/{libs/sdk/sdk-impl/spell/spell-types.js → app/spell/old.d.ts} +0 -0
- /package/bin/libs/sdk/sdk-impl/{cfg → config}/info.d.ts +0 -0
- /package/bin/libs/sdk/sdk-impl/{cfg → config}/init.d.ts +0 -0
|
@@ -0,0 +1,474 @@
|
|
|
1
|
+
import path, { join } from "@reliverse/pathkit";
|
|
2
|
+
import fs, { readdir } from "@reliverse/relifso";
|
|
3
|
+
import { relinka } from "@reliverse/relinka";
|
|
4
|
+
import pMap from "p-map";
|
|
5
|
+
import { isBinaryExt } from "../utils/binary.js";
|
|
6
|
+
import { formatError } from "../utils/utils-error-cwd.js";
|
|
7
|
+
import { evaluateMagicDirective } from "./spells.js";
|
|
8
|
+
const DEBUG_MODE = true;
|
|
9
|
+
const PROCESS_DTS_FILES = true;
|
|
10
|
+
const DEFAULT_OPTIONS = {
|
|
11
|
+
concurrency: 4,
|
|
12
|
+
batchSize: 100,
|
|
13
|
+
stopOnError: false,
|
|
14
|
+
copyFileWithDirectivesFromSrcBeforeProcessing: true
|
|
15
|
+
};
|
|
16
|
+
const DIST_PATHS = {
|
|
17
|
+
"dist-jsr": "dist-jsr/bin",
|
|
18
|
+
"dist-npm": "dist-npm/bin",
|
|
19
|
+
"dist-libs": "dist-libs"
|
|
20
|
+
};
|
|
21
|
+
function validateTargets(targets) {
|
|
22
|
+
const distLibs = /* @__PURE__ */ new Set();
|
|
23
|
+
const specificLibs = /* @__PURE__ */ new Set();
|
|
24
|
+
for (const target of targets) {
|
|
25
|
+
const [dist, lib] = target.split("/");
|
|
26
|
+
if (!dist || !Object.keys(DIST_PATHS).includes(dist)) {
|
|
27
|
+
throw new Error(`Invalid distribution target: ${dist}`);
|
|
28
|
+
}
|
|
29
|
+
if (dist === "dist-libs") {
|
|
30
|
+
if (lib) {
|
|
31
|
+
if (specificLibs.has(lib)) {
|
|
32
|
+
throw new Error(`Duplicate library target: ${target}`);
|
|
33
|
+
}
|
|
34
|
+
specificLibs.add(lib);
|
|
35
|
+
} else {
|
|
36
|
+
if (distLibs.has("dist-libs") || specificLibs.size > 0) {
|
|
37
|
+
throw new Error("Cannot mix 'dist-libs' with specific library targets");
|
|
38
|
+
}
|
|
39
|
+
distLibs.add("dist-libs");
|
|
40
|
+
}
|
|
41
|
+
} else {
|
|
42
|
+
if (distLibs.has(dist)) {
|
|
43
|
+
throw new Error(`Duplicate distribution target: ${dist}`);
|
|
44
|
+
}
|
|
45
|
+
distLibs.add(dist);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export async function applyMagicSpells(targets, options = {}) {
|
|
50
|
+
const result = {
|
|
51
|
+
processedFiles: []
|
|
52
|
+
};
|
|
53
|
+
try {
|
|
54
|
+
validateTargets(targets);
|
|
55
|
+
const srcRoot = path.resolve(process.cwd(), "src");
|
|
56
|
+
const sourceFilesWithDirectives = await scanSourceForMagicDirectives(srcRoot, options);
|
|
57
|
+
if (sourceFilesWithDirectives.length === 0) {
|
|
58
|
+
if (DEBUG_MODE) relinka("log", "[spells] No source files with magic directives found");
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
if (DEBUG_MODE) {
|
|
62
|
+
relinka(
|
|
63
|
+
"log",
|
|
64
|
+
`[spells] Found ${sourceFilesWithDirectives.length} source files with magic directives`
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
await pMap(
|
|
68
|
+
targets,
|
|
69
|
+
async (target) => {
|
|
70
|
+
const [dist, lib] = target.split("/");
|
|
71
|
+
if (dist === "dist-libs") {
|
|
72
|
+
if (!lib) {
|
|
73
|
+
const libDirs = await readdir(DIST_PATHS["dist-libs"]);
|
|
74
|
+
await pMap(
|
|
75
|
+
libDirs,
|
|
76
|
+
async (libDir) => {
|
|
77
|
+
const targetResult = await processDistributionTarget(
|
|
78
|
+
sourceFilesWithDirectives,
|
|
79
|
+
"dist-libs",
|
|
80
|
+
libDir,
|
|
81
|
+
options
|
|
82
|
+
);
|
|
83
|
+
result.processedFiles.push(...targetResult.processedFiles);
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
concurrency: options.concurrency ?? 4,
|
|
87
|
+
stopOnError: options.stopOnError ?? true
|
|
88
|
+
}
|
|
89
|
+
);
|
|
90
|
+
} else {
|
|
91
|
+
const targetResult = await processDistributionTarget(
|
|
92
|
+
sourceFilesWithDirectives,
|
|
93
|
+
"dist-libs",
|
|
94
|
+
lib,
|
|
95
|
+
options
|
|
96
|
+
);
|
|
97
|
+
result.processedFiles.push(...targetResult.processedFiles);
|
|
98
|
+
}
|
|
99
|
+
} else {
|
|
100
|
+
const targetResult = await processDistributionTarget(
|
|
101
|
+
sourceFilesWithDirectives,
|
|
102
|
+
dist,
|
|
103
|
+
void 0,
|
|
104
|
+
options
|
|
105
|
+
);
|
|
106
|
+
result.processedFiles.push(...targetResult.processedFiles);
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
concurrency: options.concurrency ?? 3,
|
|
111
|
+
stopOnError: options.stopOnError ?? true
|
|
112
|
+
}
|
|
113
|
+
);
|
|
114
|
+
return result;
|
|
115
|
+
} catch (error) {
|
|
116
|
+
throw new Error(`Failed to process distribution files: ${formatError(error)}`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
async function scanSourceForMagicDirectives(srcRoot, options = {}) {
|
|
120
|
+
if (DEBUG_MODE) {
|
|
121
|
+
relinka("log", `[spells] \u21D2 scanning src: ${srcRoot}`);
|
|
122
|
+
}
|
|
123
|
+
const sourceFilesWithDirectives = [];
|
|
124
|
+
try {
|
|
125
|
+
for await (const filePath of walkDirectoryTree(srcRoot)) {
|
|
126
|
+
if (await isBinaryExt(filePath)) {
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
const projectRel = path.relative(process.cwd(), filePath).replaceAll(path.sep, "/");
|
|
130
|
+
if (await isSpellImplementationFile(projectRel)) {
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
try {
|
|
134
|
+
const content = await fs.readFile(filePath, "utf8");
|
|
135
|
+
if (containsMagicDirectives(content)) {
|
|
136
|
+
sourceFilesWithDirectives.push(filePath);
|
|
137
|
+
if (DEBUG_MODE) {
|
|
138
|
+
relinka(
|
|
139
|
+
"log",
|
|
140
|
+
`[spells] \u21D2 found directives in ${path.relative(process.cwd(), filePath)}`
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
} catch (error) {
|
|
145
|
+
if (options.stopOnError) {
|
|
146
|
+
throw new Error(`Failed to read source file ${filePath}: ${formatError(error)}`);
|
|
147
|
+
}
|
|
148
|
+
relinka("error", `Failed to read source file ${filePath}: ${formatError(error)}`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
} catch (error) {
|
|
152
|
+
if (options.stopOnError) {
|
|
153
|
+
throw new Error(`Failed to scan source directory: ${formatError(error)}`);
|
|
154
|
+
}
|
|
155
|
+
relinka("error", `Failed to scan source directory: ${formatError(error)}`);
|
|
156
|
+
}
|
|
157
|
+
return sourceFilesWithDirectives;
|
|
158
|
+
}
|
|
159
|
+
async function processDistributionTarget(sourceFilesWithDirectives, dist, libName, options = {}) {
|
|
160
|
+
const { concurrency = DEFAULT_OPTIONS.concurrency, batchSize = DEFAULT_OPTIONS.batchSize } = options;
|
|
161
|
+
const result = {
|
|
162
|
+
processedFiles: []
|
|
163
|
+
};
|
|
164
|
+
if (DEBUG_MODE) {
|
|
165
|
+
const targetName = dist === "dist-libs" && libName ? `${dist}/${libName}` : dist;
|
|
166
|
+
relinka("log", `[spells] \u21D2 processing target: ${targetName}`);
|
|
167
|
+
}
|
|
168
|
+
const distFilesToProcess = [];
|
|
169
|
+
for (const sourceFile of sourceFilesWithDirectives) {
|
|
170
|
+
const distFiles = await findDistributionFiles(sourceFile, dist, libName);
|
|
171
|
+
distFilesToProcess.push(...distFiles);
|
|
172
|
+
}
|
|
173
|
+
if (distFilesToProcess.length === 0) {
|
|
174
|
+
if (DEBUG_MODE) {
|
|
175
|
+
const targetName = dist === "dist-libs" && libName ? `${dist}/${libName}` : dist;
|
|
176
|
+
relinka("log", `[spells] No corresponding dist files found for target: ${targetName}`);
|
|
177
|
+
}
|
|
178
|
+
return result;
|
|
179
|
+
}
|
|
180
|
+
for (let i = 0; i < distFilesToProcess.length; i += batchSize) {
|
|
181
|
+
const batch = distFilesToProcess.slice(i, i + batchSize);
|
|
182
|
+
await pMap(
|
|
183
|
+
batch,
|
|
184
|
+
async (distFilePath) => {
|
|
185
|
+
try {
|
|
186
|
+
const wasProcessed = await processSingleDistFile(distFilePath, options);
|
|
187
|
+
if (wasProcessed) {
|
|
188
|
+
result.processedFiles.push(distFilePath);
|
|
189
|
+
}
|
|
190
|
+
} catch (error) {
|
|
191
|
+
const errorMessage = `Error processing ${distFilePath}: ${formatError(error)}`;
|
|
192
|
+
if (options.stopOnError) {
|
|
193
|
+
throw new Error(errorMessage);
|
|
194
|
+
}
|
|
195
|
+
relinka("error", errorMessage);
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
{ concurrency }
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
return result;
|
|
202
|
+
}
|
|
203
|
+
async function findSourceFile(distFilePath) {
|
|
204
|
+
const projectRel = path.relative(process.cwd(), distFilePath).replaceAll(path.sep, "/");
|
|
205
|
+
const ext = path.extname(distFilePath);
|
|
206
|
+
const baseName = path.basename(distFilePath, ext);
|
|
207
|
+
const dirName = path.dirname(projectRel);
|
|
208
|
+
let sourcePath;
|
|
209
|
+
if (dirName.startsWith("dist-libs/")) {
|
|
210
|
+
const match = dirName.match(/^dist-libs\/([^/]+)(?:\/(?:npm|jsr))?(?:\/bin)?\/?(.*)$/);
|
|
211
|
+
if (match) {
|
|
212
|
+
const [, libName, remainingPath] = match;
|
|
213
|
+
sourcePath = `src/libs/${libName}${remainingPath ? `/${remainingPath}` : ""}`;
|
|
214
|
+
} else {
|
|
215
|
+
sourcePath = dirName.replace(/^dist-libs\//, "src/libs/");
|
|
216
|
+
}
|
|
217
|
+
} else {
|
|
218
|
+
sourcePath = dirName.replace(/^dist-(?:jsr|npm)(?:\/bin)?\/?/, "src/");
|
|
219
|
+
}
|
|
220
|
+
const sourceDir = path.join(process.cwd(), sourcePath);
|
|
221
|
+
if (ext === ".js") {
|
|
222
|
+
const tsFile = path.join(sourceDir, `${baseName}.ts`);
|
|
223
|
+
if (await fs.pathExists(tsFile)) {
|
|
224
|
+
const isDts = tsFile.endsWith(".d.ts");
|
|
225
|
+
if (!isDts) {
|
|
226
|
+
return tsFile;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
const jsFile = path.join(sourceDir, `${baseName}.js`);
|
|
230
|
+
if (await fs.pathExists(jsFile)) {
|
|
231
|
+
return jsFile;
|
|
232
|
+
}
|
|
233
|
+
} else if (ext === ".ts") {
|
|
234
|
+
const isDts = path.basename(distFilePath).endsWith(".d.ts");
|
|
235
|
+
if (isDts && !PROCESS_DTS_FILES) {
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
const sourceFile = path.join(sourceDir, `${baseName}${ext}`);
|
|
239
|
+
if (await fs.pathExists(sourceFile)) {
|
|
240
|
+
return sourceFile;
|
|
241
|
+
}
|
|
242
|
+
} else {
|
|
243
|
+
const sourceFile = path.join(sourceDir, `${baseName}${ext}`);
|
|
244
|
+
if (await fs.pathExists(sourceFile)) {
|
|
245
|
+
return sourceFile;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return null;
|
|
249
|
+
}
|
|
250
|
+
async function processSingleDistFile(filePath, options = {}) {
|
|
251
|
+
const projectRel = path.relative(process.cwd(), filePath).replaceAll(path.sep, "/");
|
|
252
|
+
if (await isBinaryExt(filePath)) {
|
|
253
|
+
if (DEBUG_MODE) relinka("log", `[spells] \u2298 binary ${projectRel}`);
|
|
254
|
+
return false;
|
|
255
|
+
}
|
|
256
|
+
let copiedFromSource = false;
|
|
257
|
+
if (options.copyFileWithDirectivesFromSrcBeforeProcessing ?? DEFAULT_OPTIONS.copyFileWithDirectivesFromSrcBeforeProcessing) {
|
|
258
|
+
const sourceFile = await findSourceFile(filePath);
|
|
259
|
+
if (sourceFile) {
|
|
260
|
+
try {
|
|
261
|
+
await fs.copyFile(sourceFile, filePath);
|
|
262
|
+
copiedFromSource = true;
|
|
263
|
+
if (DEBUG_MODE)
|
|
264
|
+
relinka("log", `[spells] \u21B3 copied from ${path.relative(process.cwd(), sourceFile)}`);
|
|
265
|
+
} catch (error) {
|
|
266
|
+
relinka("error", `Failed to copy from source: ${formatError(error)}`);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
if (copiedFromSource || await fs.pathExists(filePath)) {
|
|
271
|
+
const source = await fs.readFile(filePath, "utf8");
|
|
272
|
+
const ctx = { filePath: projectRel };
|
|
273
|
+
let removeFile = false;
|
|
274
|
+
const processedLines = [];
|
|
275
|
+
for (const line of source.split(/\r?\n/)) {
|
|
276
|
+
const outcome = evaluateMagicDirective(line, ctx);
|
|
277
|
+
if (outcome.removeFile) {
|
|
278
|
+
removeFile = true;
|
|
279
|
+
break;
|
|
280
|
+
}
|
|
281
|
+
if (!outcome.removeLine) {
|
|
282
|
+
processedLines.push(outcome.replacement ?? line);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
if (removeFile) {
|
|
286
|
+
await fs.unlink(filePath);
|
|
287
|
+
if (DEBUG_MODE) relinka("log", `[spells] \u2716 removed ${projectRel}`);
|
|
288
|
+
return false;
|
|
289
|
+
}
|
|
290
|
+
const newContent = processedLines.join("\n");
|
|
291
|
+
if (newContent !== source) {
|
|
292
|
+
await fs.writeFile(filePath, newContent, "utf8");
|
|
293
|
+
if (DEBUG_MODE) relinka("log", `[spells] \u2713 updated ${projectRel}`);
|
|
294
|
+
}
|
|
295
|
+
return true;
|
|
296
|
+
}
|
|
297
|
+
return false;
|
|
298
|
+
}
|
|
299
|
+
async function findDistributionFiles(sourceFilePath, dist, libName) {
|
|
300
|
+
const projectRel = path.relative(process.cwd(), sourceFilePath).replaceAll(path.sep, "/");
|
|
301
|
+
const srcRelativePath = projectRel.replace(/^src\//, "");
|
|
302
|
+
const ext = path.extname(sourceFilePath);
|
|
303
|
+
const baseName = path.basename(sourceFilePath, ext);
|
|
304
|
+
const dirPath = path.dirname(srcRelativePath);
|
|
305
|
+
const isDts = sourceFilePath.endsWith(".d.ts");
|
|
306
|
+
const distFiles = [];
|
|
307
|
+
if (dist === "dist-libs" && libName) {
|
|
308
|
+
const targets = await getAvailableRegistries(libName);
|
|
309
|
+
for (const target of targets) {
|
|
310
|
+
const distPath = join("dist-libs", libName, target, "bin", dirPath === "." ? "" : dirPath);
|
|
311
|
+
let extensions;
|
|
312
|
+
if (isDts && PROCESS_DTS_FILES) {
|
|
313
|
+
extensions = [".d.ts"];
|
|
314
|
+
} else if (ext === ".ts" && !isDts) {
|
|
315
|
+
extensions = [".js", ".ts"];
|
|
316
|
+
} else {
|
|
317
|
+
extensions = [ext];
|
|
318
|
+
}
|
|
319
|
+
for (const distExt of extensions) {
|
|
320
|
+
const distFile = path.join(process.cwd(), distPath, `${baseName}${distExt}`);
|
|
321
|
+
if (await fs.pathExists(distFile)) {
|
|
322
|
+
distFiles.push(distFile);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
} else {
|
|
327
|
+
const basePath = DIST_PATHS[dist];
|
|
328
|
+
const distPath = path.join(basePath, dirPath === "." ? "" : dirPath);
|
|
329
|
+
let extensions;
|
|
330
|
+
if (isDts && PROCESS_DTS_FILES) {
|
|
331
|
+
extensions = [".d.ts"];
|
|
332
|
+
} else if (ext === ".ts" && !isDts) {
|
|
333
|
+
extensions = [".js", ".ts"];
|
|
334
|
+
} else {
|
|
335
|
+
extensions = [ext];
|
|
336
|
+
}
|
|
337
|
+
for (const distExt of extensions) {
|
|
338
|
+
const distFile = path.join(process.cwd(), distPath, `${baseName}${distExt}`);
|
|
339
|
+
if (await fs.pathExists(distFile)) {
|
|
340
|
+
distFiles.push(distFile);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
return distFiles;
|
|
345
|
+
}
|
|
346
|
+
const SPELL_REGEX = /\/\/\s*(?:@ts-expect-error\s+.*?)?<\s*(dler-[^>\s]+)(.*?)>/i;
|
|
347
|
+
let spellImplementationPaths = null;
|
|
348
|
+
async function getSpellImplementationPaths() {
|
|
349
|
+
if (spellImplementationPaths !== null) {
|
|
350
|
+
return spellImplementationPaths;
|
|
351
|
+
}
|
|
352
|
+
const paths = [];
|
|
353
|
+
const distLibsPath = path.join(process.cwd(), "dist-libs");
|
|
354
|
+
try {
|
|
355
|
+
if (await fs.pathExists(distLibsPath)) {
|
|
356
|
+
const libDirs = await fs.readdir(distLibsPath, { withFileTypes: true });
|
|
357
|
+
for (const libDir of libDirs) {
|
|
358
|
+
if (libDir.isDirectory()) {
|
|
359
|
+
const libName = libDir.name;
|
|
360
|
+
paths.push(`/libs/${libName}/sdk-impl/spell/`);
|
|
361
|
+
paths.push(`/${libName}/sdk-impl/spell/`);
|
|
362
|
+
const libPath = path.join(distLibsPath, libName);
|
|
363
|
+
try {
|
|
364
|
+
const registryDirs = await fs.readdir(libPath, { withFileTypes: true });
|
|
365
|
+
for (const registryDir of registryDirs) {
|
|
366
|
+
if (registryDir.isDirectory() && (registryDir.name === "npm" || registryDir.name === "jsr")) {
|
|
367
|
+
const registryName = registryDir.name;
|
|
368
|
+
paths.push(`/libs/${libName}/${registryName}/sdk-impl/spell/`);
|
|
369
|
+
paths.push(`/${libName}/${registryName}/sdk-impl/spell/`);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
} catch (error) {
|
|
373
|
+
if (DEBUG_MODE) {
|
|
374
|
+
relinka("warn", `Failed to read library directory ${libPath}: ${formatError(error)}`);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
} catch (error) {
|
|
381
|
+
if (DEBUG_MODE) {
|
|
382
|
+
relinka("warn", `Failed to read dist-libs directory: ${formatError(error)}`);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
if (paths.length === 0) {
|
|
386
|
+
paths.push("/libs/sdk/sdk-impl/spell/", "/sdk-impl/spell/");
|
|
387
|
+
}
|
|
388
|
+
spellImplementationPaths = paths;
|
|
389
|
+
return paths;
|
|
390
|
+
}
|
|
391
|
+
async function isSpellImplementationFile(projectRelPath) {
|
|
392
|
+
const spellPaths = await getSpellImplementationPaths();
|
|
393
|
+
return spellPaths.some((spellPath) => projectRelPath.includes(spellPath));
|
|
394
|
+
}
|
|
395
|
+
const libraryRegistriesCache = /* @__PURE__ */ new Map();
|
|
396
|
+
async function getAvailableRegistries(libName) {
|
|
397
|
+
const cached = libraryRegistriesCache.get(libName);
|
|
398
|
+
if (cached) {
|
|
399
|
+
return cached;
|
|
400
|
+
}
|
|
401
|
+
const registries = [];
|
|
402
|
+
const libPath = path.join(process.cwd(), "dist-libs", libName);
|
|
403
|
+
try {
|
|
404
|
+
if (await fs.pathExists(libPath)) {
|
|
405
|
+
const entries = await fs.readdir(libPath, { withFileTypes: true });
|
|
406
|
+
for (const entry of entries) {
|
|
407
|
+
if (entry.isDirectory() && (entry.name === "npm" || entry.name === "jsr")) {
|
|
408
|
+
registries.push(entry.name);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
} catch (error) {
|
|
413
|
+
if (DEBUG_MODE) {
|
|
414
|
+
relinka("warn", `Failed to read library registries for ${libName}: ${formatError(error)}`);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
if (registries.length === 0) {
|
|
418
|
+
registries.push("npm", "jsr");
|
|
419
|
+
}
|
|
420
|
+
libraryRegistriesCache.set(libName, registries);
|
|
421
|
+
return registries;
|
|
422
|
+
}
|
|
423
|
+
let allAvailableRegistriesCache = null;
|
|
424
|
+
export async function getAllAvailableRegistries() {
|
|
425
|
+
if (allAvailableRegistriesCache !== null) {
|
|
426
|
+
return allAvailableRegistriesCache;
|
|
427
|
+
}
|
|
428
|
+
const allRegistries = /* @__PURE__ */ new Set();
|
|
429
|
+
const distLibsPath = path.join(process.cwd(), "dist-libs");
|
|
430
|
+
try {
|
|
431
|
+
if (await fs.pathExists(distLibsPath)) {
|
|
432
|
+
const libDirs = await fs.readdir(distLibsPath, { withFileTypes: true });
|
|
433
|
+
for (const libDir of libDirs) {
|
|
434
|
+
if (libDir.isDirectory()) {
|
|
435
|
+
const registries = await getAvailableRegistries(libDir.name);
|
|
436
|
+
for (const registry of registries) {
|
|
437
|
+
allRegistries.add(registry);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
} catch (error) {
|
|
443
|
+
if (DEBUG_MODE) {
|
|
444
|
+
relinka("warn", `Failed to scan all registries: ${formatError(error)}`);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
if (allRegistries.size === 0) {
|
|
448
|
+
allRegistries.add("npm");
|
|
449
|
+
allRegistries.add("jsr");
|
|
450
|
+
}
|
|
451
|
+
allAvailableRegistriesCache = Array.from(allRegistries);
|
|
452
|
+
return allAvailableRegistriesCache;
|
|
453
|
+
}
|
|
454
|
+
function containsMagicDirectives(content) {
|
|
455
|
+
const lines = content.split(/\r?\n/);
|
|
456
|
+
return lines.some((line) => SPELL_REGEX.test(line));
|
|
457
|
+
}
|
|
458
|
+
async function* walkDirectoryTree(dir) {
|
|
459
|
+
try {
|
|
460
|
+
const entries = await fs.readdir(dir, { withFileTypes: true });
|
|
461
|
+
for (const entry of entries) {
|
|
462
|
+
const full = path.join(dir, entry.name);
|
|
463
|
+
if (entry.isDirectory()) {
|
|
464
|
+
yield* walkDirectoryTree(full);
|
|
465
|
+
} else if (entry.isFile()) {
|
|
466
|
+
yield full;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
} catch (error) {
|
|
470
|
+
const errorMessage = `Error walking directory ${dir}: ${formatError(error)}`;
|
|
471
|
+
relinka("error", errorMessage);
|
|
472
|
+
throw new Error(errorMessage);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spell engine – parses and evaluates magic comments embedded
|
|
3
|
+
* in a single line of code.
|
|
4
|
+
*
|
|
5
|
+
* Supported directives:
|
|
6
|
+
* // <dler-replace-line-to `NEW CONTENT` [if 'cond'] [else 'alt']>
|
|
7
|
+
* // <dler-remove-line>
|
|
8
|
+
* // <dler-remove-file>
|
|
9
|
+
*
|
|
10
|
+
* A directive is recognised whether written as:
|
|
11
|
+
* // <dler-…> or
|
|
12
|
+
* // @ts-expect-error * <dler-…>
|
|
13
|
+
*
|
|
14
|
+
* Conditions (if/else) – currently supported:
|
|
15
|
+
* current file path starts with <prefix> [or <prefix> ...]
|
|
16
|
+
*/
|
|
17
|
+
export interface SpellEvaluationContext {
|
|
18
|
+
/** Path relative to project root (slash-separated) */
|
|
19
|
+
filePath: string;
|
|
20
|
+
}
|
|
21
|
+
export interface SpellOutcome {
|
|
22
|
+
replacement?: string;
|
|
23
|
+
removeLine: boolean;
|
|
24
|
+
removeFile: boolean;
|
|
25
|
+
}
|
|
26
|
+
export type SpellDirective = "dler-replace-line-to" | "dler-remove-line" | "dler-remove-file";
|
|
27
|
+
/**
|
|
28
|
+
* Evaluates a single line for magic directives and returns the effect.
|
|
29
|
+
* If no directive is present, returns neutral outcome.
|
|
30
|
+
*/
|
|
31
|
+
export declare function evaluateMagicDirective(line: string, ctx: SpellEvaluationContext): SpellOutcome;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { relinka } from "@reliverse/relinka";
|
|
2
|
+
const SPELL_REGEX = /\/\/\s*(?:@ts-expect-error\s+.*?)?<\s*(dler-[^>\s]+)(.*?)>/i;
|
|
3
|
+
const REPLACEMENT_REGEX = /`([^`]+)`/;
|
|
4
|
+
const IF_CONDITION_REGEX = /\bif\s+['"`]([^'"`]+)['"`]/i;
|
|
5
|
+
const ELSE_CONTENT_REGEX = /\belse\s+['"`]([^'"`]+)['"`]/i;
|
|
6
|
+
const STARTS_WITH_REGEX = /current file path starts with\s+(.+)$/i;
|
|
7
|
+
export function evaluateMagicDirective(line, ctx) {
|
|
8
|
+
const match = line.match(SPELL_REGEX);
|
|
9
|
+
if (!match) return NO_OP;
|
|
10
|
+
const [, directive = "", body] = match;
|
|
11
|
+
if (!isValidMagicDirective(directive)) {
|
|
12
|
+
relinka("warn", `[spells] unknown directive: ${directive}`);
|
|
13
|
+
return NO_OP;
|
|
14
|
+
}
|
|
15
|
+
switch (directive) {
|
|
16
|
+
/* -------------------------------------------------------------- */
|
|
17
|
+
/* dler-remove-file */
|
|
18
|
+
/* -------------------------------------------------------------- */
|
|
19
|
+
case "dler-remove-file": {
|
|
20
|
+
return { removeFile: true, removeLine: true };
|
|
21
|
+
}
|
|
22
|
+
/* -------------------------------------------------------------- */
|
|
23
|
+
/* dler-remove-line */
|
|
24
|
+
/* -------------------------------------------------------------- */
|
|
25
|
+
case "dler-remove-line": {
|
|
26
|
+
return { removeLine: true, removeFile: false };
|
|
27
|
+
}
|
|
28
|
+
/* -------------------------------------------------------------- */
|
|
29
|
+
/* dler-replace-line-to */
|
|
30
|
+
/* -------------------------------------------------------------- */
|
|
31
|
+
case "dler-replace-line-to": {
|
|
32
|
+
const { replacement, elseContent, condition } = parseReplacementDirective(body ?? "");
|
|
33
|
+
if (!replacement) {
|
|
34
|
+
relinka("warn", "[spells] dler-replace-line-to missing replacement content");
|
|
35
|
+
return NO_OP;
|
|
36
|
+
}
|
|
37
|
+
const condMet = condition === void 0 ? true : evaluatePathCondition(condition, ctx);
|
|
38
|
+
if (condMet) {
|
|
39
|
+
return { replacement, removeLine: false, removeFile: false };
|
|
40
|
+
}
|
|
41
|
+
if (elseContent !== void 0) {
|
|
42
|
+
return { replacement: elseContent, removeLine: false, removeFile: false };
|
|
43
|
+
}
|
|
44
|
+
return NO_OP;
|
|
45
|
+
}
|
|
46
|
+
default:
|
|
47
|
+
return NO_OP;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const NO_OP = { removeLine: false, removeFile: false };
|
|
51
|
+
function isValidMagicDirective(directive) {
|
|
52
|
+
return ["dler-replace-line-to", "dler-remove-line", "dler-remove-file"].includes(directive);
|
|
53
|
+
}
|
|
54
|
+
function parseReplacementDirective(body) {
|
|
55
|
+
const parts = {
|
|
56
|
+
replacement: ""
|
|
57
|
+
};
|
|
58
|
+
const replacementMatch = body.match(REPLACEMENT_REGEX);
|
|
59
|
+
if (replacementMatch?.[1]) parts.replacement = replacementMatch[1].trim();
|
|
60
|
+
const ifMatch = body.match(IF_CONDITION_REGEX);
|
|
61
|
+
if (ifMatch?.[1]) {
|
|
62
|
+
parts.condition = ifMatch[1].trim();
|
|
63
|
+
} else {
|
|
64
|
+
parts.condition = "current file path starts with dist-jsr or dist-npm";
|
|
65
|
+
}
|
|
66
|
+
const elseMatch = body.match(ELSE_CONTENT_REGEX);
|
|
67
|
+
if (elseMatch?.[1]) parts.elseContent = elseMatch[1].trim();
|
|
68
|
+
return parts;
|
|
69
|
+
}
|
|
70
|
+
function evaluatePathCondition(condition, ctx) {
|
|
71
|
+
const STARTS_WITH = STARTS_WITH_REGEX.exec(condition)?.[1];
|
|
72
|
+
if (STARTS_WITH) {
|
|
73
|
+
const prefixes = STARTS_WITH.split(/\s+or\s+/i).map(
|
|
74
|
+
(p) => p.replace(/['"`]/g, "").trim().replaceAll("\\", "/")
|
|
75
|
+
);
|
|
76
|
+
return prefixes.some((p) => ctx.filePath.startsWith(p));
|
|
77
|
+
}
|
|
78
|
+
if (condition.trim()) {
|
|
79
|
+
relinka(
|
|
80
|
+
"warn",
|
|
81
|
+
`[spells] unsupported condition "${condition}" - only "current file path starts with <prefix> [or <prefix> ...]" is supported`
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type CommentStyle = "// " | "# " | "-- " | "/* " | "<!-- ";
|
|
2
|
+
export type FileExtension = "js" | "jsx" | "ts" | "tsx" | "c" | "cpp" | "h" | "java" | "go" | "kt" | "swift" | "rs" | "cs" | "json" | "proto" | "dart" | "inc" | "pwn" | "py" | "rb" | "sh" | "pl" | "r" | "yml" | "yaml" | "sql" | "lua" | "css" | "scss" | "less" | "html" | "htm" | "xml" | "md";
|
|
3
|
+
export type CommentMapping = Record<FileExtension, CommentStyle>;
|
|
4
|
+
export declare const DEFAULT_COMMENT: "// ";
|
|
5
|
+
export declare const COMMENT_MAP: CommentMapping;
|
|
6
|
+
export declare const getCommentPrefix: (filePath: string, forceComment?: boolean, customComment?: string) => string;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export const DEFAULT_COMMENT = "// ";
|
|
2
|
+
const createCommentMapping = (extensions, comment) => Object.fromEntries(extensions.map((ext) => [ext, comment]));
|
|
3
|
+
export const COMMENT_MAP = {
|
|
4
|
+
// Single-line comment style //
|
|
5
|
+
...createCommentMapping(
|
|
6
|
+
[
|
|
7
|
+
"js",
|
|
8
|
+
"jsx",
|
|
9
|
+
"ts",
|
|
10
|
+
"tsx",
|
|
11
|
+
"c",
|
|
12
|
+
"cpp",
|
|
13
|
+
"h",
|
|
14
|
+
"java",
|
|
15
|
+
"go",
|
|
16
|
+
"kt",
|
|
17
|
+
"swift",
|
|
18
|
+
"rs",
|
|
19
|
+
"cs",
|
|
20
|
+
"json",
|
|
21
|
+
"proto",
|
|
22
|
+
"dart",
|
|
23
|
+
"inc",
|
|
24
|
+
"pwn"
|
|
25
|
+
],
|
|
26
|
+
"// "
|
|
27
|
+
),
|
|
28
|
+
// Single-line comment style #
|
|
29
|
+
...createCommentMapping(["py", "rb", "sh", "pl", "r", "yml", "yaml"], "# "),
|
|
30
|
+
// Single-line comment style --
|
|
31
|
+
...createCommentMapping(["sql", "lua"], "-- "),
|
|
32
|
+
// Multi-line comment style /* */
|
|
33
|
+
...createCommentMapping(["css", "scss", "less"], "/* "),
|
|
34
|
+
// Multi-line comment style <!-- -->
|
|
35
|
+
...createCommentMapping(["html", "htm", "xml", "md"], "<!-- ")
|
|
36
|
+
};
|
|
37
|
+
export const getCommentPrefix = (filePath, forceComment, customComment) => {
|
|
38
|
+
if (forceComment && customComment) return customComment;
|
|
39
|
+
const ext = filePath.split(".").pop()?.toLowerCase();
|
|
40
|
+
return COMMENT_MAP[ext] ?? customComment ?? DEFAULT_COMMENT;
|
|
41
|
+
};
|
|
@@ -19,6 +19,7 @@ export async function finalizeBuildPub(timer, commonPubPause, libsList, distNpmD
|
|
|
19
19
|
if (!commonPubPause) {
|
|
20
20
|
relinka("success", `\u{1F389} Publish completed successfully (build time: ${transpileFormattedTime})`);
|
|
21
21
|
} else {
|
|
22
|
+
console.log("-".repeat(50));
|
|
22
23
|
relinka("success", `\u{1F389} Build completed successfully (done in: ${transpileFormattedTime})`);
|
|
23
24
|
relinka("info", "\u{1F4DD} Publish process is currently paused in your config file");
|
|
24
25
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const WHITELABEL_DEFAULT = "DLER";
|
|
2
|
+
export declare const JSON_EXTS: Set<string>;
|
|
3
|
+
export declare const TEMPLATE_VAR: (tpl: string, wl: string) => string;
|
|
4
|
+
export declare const TPLS_DIR = "tpls";
|
|
5
|
+
export declare const BINARIES_DIR = "binaries";
|
|
6
|
+
export declare const isJsonExt: (f: string) => boolean;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import path from "@reliverse/pathkit";
|
|
2
|
+
export const WHITELABEL_DEFAULT = "DLER";
|
|
3
|
+
export const JSON_EXTS = /* @__PURE__ */ new Set(["json", "jsonc", "json5", "jsonl"]);
|
|
4
|
+
export const TEMPLATE_VAR = (tpl, wl) => `${tpl.toUpperCase()}_${wl.toUpperCase()}_TEMPLATE`;
|
|
5
|
+
export const TPLS_DIR = "tpls";
|
|
6
|
+
export const BINARIES_DIR = "binaries";
|
|
7
|
+
export const isJsonExt = (f) => JSON_EXTS.has(path.extname(f).slice(1).toLowerCase());
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { FileType, TemplatesFileContent } from "./pu-types";
|
|
2
|
+
export declare const walkDir: (dir: string) => Promise<string[]>;
|
|
3
|
+
export declare const detectFileType: (file: string) => Promise<FileType>;
|
|
4
|
+
export declare const readFileForTemplate: (absPath: string) => Promise<TemplatesFileContent>;
|
|
5
|
+
export declare const escapeTemplateString: (src: string) => string;
|