@reliverse/dler 1.7.15 → 1.7.17
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 +164 -191
- 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 +17 -17
- package/bin/app/merge/cmd.js +70 -310
- 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/pub/pub-library.js +7 -0
- package/bin/libs/sdk/sdk-impl/pub/pub-regular.js +4 -8
- 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 +11 -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,313 @@
|
|
|
1
|
+
import path from "@reliverse/pathkit";
|
|
2
|
+
import { relinka } from "@reliverse/relinka";
|
|
3
|
+
import { defineArgs, defineCommand } from "@reliverse/rempts";
|
|
4
|
+
import { createJiti } from "jiti";
|
|
5
|
+
import { createHash } from "node:crypto";
|
|
6
|
+
import { promises as fs } from "node:fs";
|
|
7
|
+
import {
|
|
8
|
+
WHITELABEL_DEFAULT,
|
|
9
|
+
TEMPLATE_VAR,
|
|
10
|
+
TPLS_DIR,
|
|
11
|
+
BINARIES_DIR
|
|
12
|
+
} from "../../libs/sdk/sdk-impl/utils/pack-unpack/pu-constants.js";
|
|
13
|
+
import {
|
|
14
|
+
escapeTemplateString,
|
|
15
|
+
readFileForTemplate,
|
|
16
|
+
walkDir
|
|
17
|
+
} from "../../libs/sdk/sdk-impl/utils/pack-unpack/pu-file-utils.js";
|
|
18
|
+
const jiti = createJiti(import.meta.url);
|
|
19
|
+
const hashFile = async (file) => {
|
|
20
|
+
const buff = await fs.readFile(file);
|
|
21
|
+
return createHash("sha1").update(buff).digest("hex").slice(0, 10);
|
|
22
|
+
};
|
|
23
|
+
const getFileMetadata = async (file) => {
|
|
24
|
+
const stats = await fs.stat(file);
|
|
25
|
+
const hash = await hashFile(file);
|
|
26
|
+
return {
|
|
27
|
+
updatedAt: stats.mtime.toISOString(),
|
|
28
|
+
updatedHash: hash
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
export default defineCommand({
|
|
32
|
+
meta: {
|
|
33
|
+
name: "pack",
|
|
34
|
+
version: "1.1.0",
|
|
35
|
+
description: "Packs a directory of templates into TS modules"
|
|
36
|
+
},
|
|
37
|
+
args: defineArgs({
|
|
38
|
+
dir: { type: "positional", required: true, description: "Directory to process" },
|
|
39
|
+
output: { type: "string", default: "my-templates", description: "Output dir" },
|
|
40
|
+
whitelabel: { type: "string", default: WHITELABEL_DEFAULT, description: "Rename DLER" },
|
|
41
|
+
cdn: {
|
|
42
|
+
type: "string",
|
|
43
|
+
description: "Remote CDN for binary assets upload (not yet implemented)"
|
|
44
|
+
},
|
|
45
|
+
force: { type: "boolean", default: false, description: "Force overwrite existing files" },
|
|
46
|
+
update: {
|
|
47
|
+
type: "boolean",
|
|
48
|
+
default: true,
|
|
49
|
+
description: "Update existing templates and add new ones if needed (default: true)"
|
|
50
|
+
},
|
|
51
|
+
/**
|
|
52
|
+
* - Without --files: All files are checked and updated if they're newer or have different content
|
|
53
|
+
* - With --files: Only specified files are checked and updated if they're newer or have different content
|
|
54
|
+
*/
|
|
55
|
+
files: {
|
|
56
|
+
type: "string",
|
|
57
|
+
description: "Comma-separated list of specific files to update (relative to template dir)"
|
|
58
|
+
},
|
|
59
|
+
lastUpdate: {
|
|
60
|
+
type: "string",
|
|
61
|
+
description: "Override lastUpdate timestamp (format: 2025-06-06T14:33:09.240Z)"
|
|
62
|
+
}
|
|
63
|
+
}),
|
|
64
|
+
async run({ args }) {
|
|
65
|
+
if (args.cdn) throw new Error("Remote CDN support is not implemented yet.");
|
|
66
|
+
const dirToProcess = path.resolve(args.dir);
|
|
67
|
+
const outDir = path.resolve(args.output);
|
|
68
|
+
const outDirName = path.basename(outDir);
|
|
69
|
+
const typesFile = `${outDirName}-types.ts`;
|
|
70
|
+
const modFile = `${outDirName}-mod.ts`;
|
|
71
|
+
const filesToUpdate = args.files ? new Set(args.files.split(",").map((f) => f.trim())) : null;
|
|
72
|
+
let existingTemplates = {};
|
|
73
|
+
try {
|
|
74
|
+
const files = await fs.readdir(outDir);
|
|
75
|
+
if (files.length > 0) {
|
|
76
|
+
if (!args.force && !args.update) {
|
|
77
|
+
relinka("error", `Error: Output directory '${outDir}' already exists and is not empty.`);
|
|
78
|
+
relinka(
|
|
79
|
+
"error",
|
|
80
|
+
"Use --force to overwrite all files or --update to update existing templates."
|
|
81
|
+
);
|
|
82
|
+
process.exit(1);
|
|
83
|
+
}
|
|
84
|
+
if (args.update) {
|
|
85
|
+
try {
|
|
86
|
+
const modPath = path.join(outDir, modFile);
|
|
87
|
+
const mod2 = await jiti.import(modPath);
|
|
88
|
+
existingTemplates = mod2?.DLER_TEMPLATES || mod2?.default || {};
|
|
89
|
+
} catch (loadError) {
|
|
90
|
+
relinka(
|
|
91
|
+
"warn",
|
|
92
|
+
`Warning: Could not load existing templates from ${modFile}. Will create new ones.`
|
|
93
|
+
);
|
|
94
|
+
relinka("log", `Error details: ${loadError.message}`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
} catch (error) {
|
|
99
|
+
if (error.code !== "ENOENT") {
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
await fs.mkdir(path.join(outDir, TPLS_DIR), { recursive: true });
|
|
104
|
+
const templateDirs = (await fs.readdir(dirToProcess, { withFileTypes: true })).filter((d) => d.isDirectory()).map((d) => d.name);
|
|
105
|
+
try {
|
|
106
|
+
await fs.access(path.join(outDir, typesFile));
|
|
107
|
+
} catch {
|
|
108
|
+
const typesContent = `export type FileContent = string | Record<string, unknown>;
|
|
109
|
+
export type FileType = "text" | "json" | "binary";
|
|
110
|
+
export type FileMetadata = {
|
|
111
|
+
updatedAt?: string;
|
|
112
|
+
updatedHash?: string;
|
|
113
|
+
};
|
|
114
|
+
export type TemplatesFileContent = {
|
|
115
|
+
content: FileContent;
|
|
116
|
+
type: FileType;
|
|
117
|
+
hasError?: boolean;
|
|
118
|
+
jsonComments?: Record<number, string>;
|
|
119
|
+
binaryHash?: string;
|
|
120
|
+
metadata?: FileMetadata;
|
|
121
|
+
};
|
|
122
|
+
export type TemplateConfig = {
|
|
123
|
+
files: Record<string, TemplatesFileContent>;
|
|
124
|
+
};
|
|
125
|
+
export type Template = {
|
|
126
|
+
name: string;
|
|
127
|
+
description: string;
|
|
128
|
+
config: TemplateConfig;
|
|
129
|
+
updatedAt?: string;
|
|
130
|
+
};
|
|
131
|
+
export type Templates = Record<string, Template>;
|
|
132
|
+
`;
|
|
133
|
+
await fs.writeFile(path.join(outDir, typesFile), typesContent);
|
|
134
|
+
}
|
|
135
|
+
const aggregatedImports = [];
|
|
136
|
+
const aggregatedEntries = [];
|
|
137
|
+
const mapEntries = [];
|
|
138
|
+
for (const tplName of templateDirs) {
|
|
139
|
+
const absTplDir = path.join(dirToProcess, tplName);
|
|
140
|
+
const allFiles = await walkDir(absTplDir);
|
|
141
|
+
const filesRecord = {};
|
|
142
|
+
const existingTemplate = args.update ? existingTemplates[tplName] : null;
|
|
143
|
+
const existingFiles = existingTemplate?.config?.files || {};
|
|
144
|
+
for (const absFile of allFiles) {
|
|
145
|
+
const rel = path.relative(dirToProcess, absFile).replace(/\\/g, "/");
|
|
146
|
+
if (filesToUpdate && !filesToUpdate.has(rel)) {
|
|
147
|
+
if (existingFiles[rel]) {
|
|
148
|
+
filesRecord[rel] = existingFiles[rel];
|
|
149
|
+
}
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
const fileMetadata = await getFileMetadata(absFile);
|
|
153
|
+
const existingFile = existingFiles[rel];
|
|
154
|
+
const existingMetadata = existingFile?.metadata;
|
|
155
|
+
if (existingMetadata && (existingMetadata.updatedHash === fileMetadata.updatedHash || fileMetadata.updatedAt <= existingMetadata.updatedAt)) {
|
|
156
|
+
filesRecord[rel] = existingFile;
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
const meta = await readFileForTemplate(absFile);
|
|
160
|
+
if (meta.type === "binary") {
|
|
161
|
+
const hash = await hashFile(absFile);
|
|
162
|
+
const ext = path.extname(absFile);
|
|
163
|
+
const binariesDir = path.join(outDir, TPLS_DIR, BINARIES_DIR);
|
|
164
|
+
const target = path.join(binariesDir, `${hash}${ext}`);
|
|
165
|
+
await fs.mkdir(binariesDir, { recursive: true });
|
|
166
|
+
try {
|
|
167
|
+
await fs.access(target);
|
|
168
|
+
} catch {
|
|
169
|
+
await fs.copyFile(absFile, target);
|
|
170
|
+
}
|
|
171
|
+
filesRecord[rel] = {
|
|
172
|
+
type: "binary",
|
|
173
|
+
content: "",
|
|
174
|
+
binaryHash: hash,
|
|
175
|
+
metadata: fileMetadata
|
|
176
|
+
};
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
if (meta.type === "json") {
|
|
180
|
+
if (rel.endsWith("package.json")) {
|
|
181
|
+
meta.content.__satisfies = "PackageJson";
|
|
182
|
+
}
|
|
183
|
+
if (rel.endsWith("tsconfig.json")) {
|
|
184
|
+
meta.content.__satisfies = "TSConfig";
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
filesRecord[rel] = {
|
|
188
|
+
...meta,
|
|
189
|
+
metadata: fileMetadata
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
const varName = TEMPLATE_VAR(tplName, args.whitelabel);
|
|
193
|
+
const code = [];
|
|
194
|
+
const hasPackageJson = Object.values(filesRecord).some(
|
|
195
|
+
(f) => f.type === "json" && f.content && typeof f.content === "object" && "name" in f.content
|
|
196
|
+
);
|
|
197
|
+
const hasTSConfig = Object.values(filesRecord).some(
|
|
198
|
+
(f) => f.type === "json" && f.content && typeof f.content === "object" && "compilerOptions" in f.content
|
|
199
|
+
);
|
|
200
|
+
if (hasPackageJson || hasTSConfig) {
|
|
201
|
+
const t = [];
|
|
202
|
+
if (hasPackageJson) t.push("PackageJson");
|
|
203
|
+
if (hasTSConfig) t.push("TSConfig");
|
|
204
|
+
code.push(`import type { ${t.join(", ")} } from "pkg-types";`);
|
|
205
|
+
code.push("", `import type { Template } from "../${typesFile}";`);
|
|
206
|
+
} else {
|
|
207
|
+
code.push(`import type { Template } from "../${typesFile}";`);
|
|
208
|
+
}
|
|
209
|
+
code.push("");
|
|
210
|
+
code.push(`export const ${varName}: Template = {`);
|
|
211
|
+
code.push(` name: "${tplName}",`);
|
|
212
|
+
code.push(` description: "Template generated from ${allFiles.length} files",`);
|
|
213
|
+
code.push(` updatedAt: "${(/* @__PURE__ */ new Date()).toISOString()}",`);
|
|
214
|
+
code.push(" config: {");
|
|
215
|
+
code.push(" files: {");
|
|
216
|
+
const fileEntries = Object.entries(filesRecord);
|
|
217
|
+
fileEntries.forEach(([rel, meta], index) => {
|
|
218
|
+
const isLast = index === fileEntries.length - 1;
|
|
219
|
+
code.push(` "${rel}": {`);
|
|
220
|
+
if (meta.jsonComments)
|
|
221
|
+
code.push(` jsonComments: ${JSON.stringify(meta.jsonComments, null, 2)},`);
|
|
222
|
+
if (meta.metadata) {
|
|
223
|
+
const metadataStr = JSON.stringify(meta.metadata, null, 2).replace(/^/gm, " ").replace(/^ {7} {/m, " {").replace(/^ {8}}/m, " }").replace(/"([a-zA-Z0-9_]+)":/g, "$1:").replace(/}$/m, "},");
|
|
224
|
+
code.push(` metadata:${metadataStr}`);
|
|
225
|
+
}
|
|
226
|
+
if (meta.type === "binary") {
|
|
227
|
+
code.push(` content: "",`);
|
|
228
|
+
code.push(` type: "binary",`);
|
|
229
|
+
code.push(` binaryHash: "${meta.binaryHash}",`);
|
|
230
|
+
} else if (meta.type === "text") {
|
|
231
|
+
code.push(` content: \`${escapeTemplateString(meta.content)}\`,`);
|
|
232
|
+
code.push(' type: "text",');
|
|
233
|
+
} else {
|
|
234
|
+
const clone = { ...meta.content };
|
|
235
|
+
let sat = "";
|
|
236
|
+
if (rel.endsWith("package.json")) {
|
|
237
|
+
sat = " satisfies PackageJson";
|
|
238
|
+
} else if (rel.endsWith("tsconfig.json")) {
|
|
239
|
+
sat = " satisfies TSConfig";
|
|
240
|
+
}
|
|
241
|
+
const jsonStr = JSON.stringify(
|
|
242
|
+
clone,
|
|
243
|
+
(key, value) => {
|
|
244
|
+
if (typeof key === "string" && /^[a-zA-Z0-9_]+$/.test(key)) {
|
|
245
|
+
return value;
|
|
246
|
+
}
|
|
247
|
+
return value;
|
|
248
|
+
},
|
|
249
|
+
2
|
|
250
|
+
).split("\n").map((line, i) => {
|
|
251
|
+
if (i === 0) return line;
|
|
252
|
+
return " " + line.replace(/"([a-zA-Z0-9_]+)":/g, "$1:");
|
|
253
|
+
}).join("\n").replace(/}$/m, "},");
|
|
254
|
+
code.push(` content: ${jsonStr}${sat},`);
|
|
255
|
+
code.push(' type: "json",');
|
|
256
|
+
}
|
|
257
|
+
if (meta.hasError) code.push(" hasError: true,");
|
|
258
|
+
code.push(` }${isLast ? "," : ","}`);
|
|
259
|
+
});
|
|
260
|
+
code.push(" },");
|
|
261
|
+
code.push(" },");
|
|
262
|
+
code.push("};");
|
|
263
|
+
code.push("");
|
|
264
|
+
const templatePath = path.join(outDir, TPLS_DIR, `${tplName}.ts`);
|
|
265
|
+
if (args.update && existingTemplates[tplName]) {
|
|
266
|
+
try {
|
|
267
|
+
const existingContent = await fs.readFile(templatePath, "utf8");
|
|
268
|
+
const newContent = code.join("\n");
|
|
269
|
+
if (existingContent !== newContent) {
|
|
270
|
+
if (filesToUpdate) {
|
|
271
|
+
relinka("log", `Updating specific files in template: ${tplName}`);
|
|
272
|
+
} else {
|
|
273
|
+
relinka("log", `Updating template: ${tplName}`);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
} catch (error) {
|
|
277
|
+
if (error.code !== "ENOENT") {
|
|
278
|
+
throw error;
|
|
279
|
+
}
|
|
280
|
+
relinka("log", `Creating new template: ${tplName}`);
|
|
281
|
+
}
|
|
282
|
+
} else if (!args.update) {
|
|
283
|
+
relinka("log", `Creating template: ${tplName}`);
|
|
284
|
+
}
|
|
285
|
+
await fs.writeFile(templatePath, code.join("\n"));
|
|
286
|
+
aggregatedImports.push(`import { ${varName} } from "./${TPLS_DIR}/${tplName}";`);
|
|
287
|
+
aggregatedEntries.push(` ${tplName}: ${varName},`);
|
|
288
|
+
mapEntries.push(` ${varName}: "${tplName}",`);
|
|
289
|
+
}
|
|
290
|
+
const WL = args.whitelabel.toUpperCase();
|
|
291
|
+
const mod = [
|
|
292
|
+
...aggregatedImports,
|
|
293
|
+
"",
|
|
294
|
+
`export const ${WL}_TEMPLATES = {`,
|
|
295
|
+
...aggregatedEntries,
|
|
296
|
+
"} as const;",
|
|
297
|
+
"",
|
|
298
|
+
`export type ${WL}_TEMPLATE_NAMES = keyof typeof ${WL}_TEMPLATES;`,
|
|
299
|
+
"",
|
|
300
|
+
`export const dlerTemplatesMap: Record<string, ${WL}_TEMPLATE_NAMES> = {`,
|
|
301
|
+
...mapEntries,
|
|
302
|
+
"};"
|
|
303
|
+
];
|
|
304
|
+
await fs.writeFile(path.join(outDir, modFile), mod.join("\n") + "\n");
|
|
305
|
+
const templatePaths = templateDirs.map(
|
|
306
|
+
(tpl) => path.relative(process.cwd(), path.join(outDir, TPLS_DIR, `${tpl}.ts`))
|
|
307
|
+
);
|
|
308
|
+
relinka("log", `Packed ${templateDirs.length} templates into ${modFile}:`);
|
|
309
|
+
for (const p of templatePaths) {
|
|
310
|
+
relinka("log", `- ${p}`);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
});
|
package/bin/app/pub/cmd.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defineArgs, defineCommand } from "@reliverse/rempts";
|
|
2
|
-
import { dlerPub } from "
|
|
3
|
-
import { ensureDlerConfig } from "../../libs/sdk/sdk-impl/
|
|
4
|
-
import {
|
|
2
|
+
import { dlerPub } from "./impl.js";
|
|
3
|
+
import { ensureDlerConfig } from "../../libs/sdk/sdk-impl/config/init.js";
|
|
4
|
+
import { getConfigDler } from "../../libs/sdk/sdk-impl/config/load.js";
|
|
5
5
|
import { removeDistFolders } from "../../libs/sdk/sdk-mod.js";
|
|
6
6
|
export default defineCommand({
|
|
7
7
|
meta: {
|
|
@@ -16,7 +16,7 @@ export default defineCommand({
|
|
|
16
16
|
}),
|
|
17
17
|
async run({ args }) {
|
|
18
18
|
await ensureDlerConfig(args.dev);
|
|
19
|
-
const config = await
|
|
19
|
+
const config = await getConfigDler();
|
|
20
20
|
await removeDistFolders(
|
|
21
21
|
config.distNpmDirName,
|
|
22
22
|
config.distJsrDirName,
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { DlerConfig } from "../../libs/sdk/sdk-impl/config/types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Main entry point for the dler build and publish process.
|
|
4
|
+
* Handles building and publishing for both main project and libraries.
|
|
5
|
+
* @see `src/app/build/impl.ts` for build main function implementation.
|
|
6
|
+
*/
|
|
7
|
+
export declare function dlerPub(isDev: boolean, config?: DlerConfig): Promise<void>;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { bumpHandler, isBumpDisabled, setBumpDisabledValueTo } from "@reliverse/bleump";
|
|
2
|
+
import path, { convertImportsAliasToRelative } from "@reliverse/pathkit";
|
|
3
|
+
import fs from "@reliverse/relifso";
|
|
4
|
+
import { relinka } from "@reliverse/relinka";
|
|
5
|
+
import { getConfigDler } from "../../libs/sdk/sdk-impl/config/load.js";
|
|
6
|
+
import { processLibraryFlow } from "../../libs/sdk/sdk-impl/library-flow.js";
|
|
7
|
+
import { processRegularFlow } from "../../libs/sdk/sdk-impl/regular-flow.js";
|
|
8
|
+
import { applyMagicSpells } from "../../libs/sdk/sdk-impl/spell/applyMagicSpells.js";
|
|
9
|
+
import { finalizeBuildPub } from "../../libs/sdk/sdk-impl/utils/finalize.js";
|
|
10
|
+
import { resolveAllCrossLibs } from "../../libs/sdk/sdk-impl/utils/resolve-cross-libs.js";
|
|
11
|
+
import { removeDistFolders } from "../../libs/sdk/sdk-impl/utils/utils-clean.js";
|
|
12
|
+
import { PROJECT_ROOT } from "../../libs/sdk/sdk-impl/utils/utils-consts.js";
|
|
13
|
+
import { handleDlerError } from "../../libs/sdk/sdk-impl/utils/utils-error-cwd.js";
|
|
14
|
+
import { createPerfTimer } from "../../libs/sdk/sdk-impl/utils/utils-perf.js";
|
|
15
|
+
export async function dlerPub(isDev, config) {
|
|
16
|
+
const timer = createPerfTimer();
|
|
17
|
+
let effectiveConfig = config;
|
|
18
|
+
try {
|
|
19
|
+
if (!effectiveConfig) {
|
|
20
|
+
effectiveConfig = await getConfigDler();
|
|
21
|
+
}
|
|
22
|
+
if (effectiveConfig.logsFreshFile) {
|
|
23
|
+
await fs.remove(path.join(PROJECT_ROOT, effectiveConfig.logsFileName));
|
|
24
|
+
}
|
|
25
|
+
await removeDistFolders(
|
|
26
|
+
effectiveConfig.distNpmDirName,
|
|
27
|
+
effectiveConfig.distJsrDirName,
|
|
28
|
+
effectiveConfig.libsDirDist,
|
|
29
|
+
effectiveConfig.libsList
|
|
30
|
+
);
|
|
31
|
+
const bumpIsDisabled = await isBumpDisabled();
|
|
32
|
+
if (!bumpIsDisabled && !effectiveConfig.commonPubPause) {
|
|
33
|
+
try {
|
|
34
|
+
await bumpHandler(
|
|
35
|
+
effectiveConfig.bumpMode,
|
|
36
|
+
false,
|
|
37
|
+
effectiveConfig.bumpFilter,
|
|
38
|
+
effectiveConfig.bumpSet
|
|
39
|
+
);
|
|
40
|
+
await setBumpDisabledValueTo(true);
|
|
41
|
+
} catch {
|
|
42
|
+
throw new Error("[.config/dler.ts] Failed to set bumpDisable to true");
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
await processRegularFlow(timer, isDev, effectiveConfig);
|
|
46
|
+
await processLibraryFlow(timer, isDev, effectiveConfig);
|
|
47
|
+
await resolveAllCrossLibs();
|
|
48
|
+
await applyMagicSpells(["dist-jsr", "dist-npm", "dist-libs"]);
|
|
49
|
+
relinka("log", "[processDistDirectory] dist-npm");
|
|
50
|
+
await processDistDirectory("dist-npm", "~");
|
|
51
|
+
relinka("log", "[processDistDirectory] dist-jsr");
|
|
52
|
+
await processDistDirectory("dist-jsr", "~");
|
|
53
|
+
await finalizeBuildPub(
|
|
54
|
+
timer,
|
|
55
|
+
effectiveConfig.commonPubPause,
|
|
56
|
+
effectiveConfig.libsList,
|
|
57
|
+
effectiveConfig.distNpmDirName,
|
|
58
|
+
effectiveConfig.distJsrDirName,
|
|
59
|
+
effectiveConfig.libsDirDist
|
|
60
|
+
);
|
|
61
|
+
} catch (error) {
|
|
62
|
+
handleDlerError(error);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async function directoryExists(dirPath) {
|
|
66
|
+
try {
|
|
67
|
+
const stat = await fs.stat(dirPath);
|
|
68
|
+
return stat.isDirectory();
|
|
69
|
+
} catch (error) {
|
|
70
|
+
if (error instanceof Error && error.code === "ENOENT") {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
throw error;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async function processDistDirectory(dir, alias) {
|
|
77
|
+
const modifiedFiles = [];
|
|
78
|
+
try {
|
|
79
|
+
const binDir = path.join(dir, "bin");
|
|
80
|
+
const binDirExists = await directoryExists(binDir);
|
|
81
|
+
if (binDirExists) {
|
|
82
|
+
await convertImportsAliasToRelative({
|
|
83
|
+
targetDir: binDir,
|
|
84
|
+
aliasToReplace: alias,
|
|
85
|
+
pathExtFilter: "js-ts-none"
|
|
86
|
+
// displayLogsOnlyFor: [
|
|
87
|
+
// "dist-npm/bin/libs/cfg/cfg-mod.js",
|
|
88
|
+
// "dist-jsr/bin/libs/cfg/cfg-mod.ts",
|
|
89
|
+
// ],
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
} catch (error) {
|
|
93
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
94
|
+
throw error;
|
|
95
|
+
}
|
|
96
|
+
return modifiedFiles;
|
|
97
|
+
}
|
package/bin/app/rename/cmd.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { join, dirname, basename, extname } from "@reliverse/pathkit";
|
|
1
2
|
import { relinka } from "@reliverse/relinka";
|
|
2
3
|
import { defineCommand } from "@reliverse/rempts";
|
|
3
4
|
import { existsSync } from "node:fs";
|
|
4
5
|
import { readFileSync } from "node:fs";
|
|
5
6
|
import { rename, access, readdir } from "node:fs/promises";
|
|
6
|
-
import { join, dirname, basename, extname } from "node:path";
|
|
7
7
|
async function fileExists(path) {
|
|
8
8
|
try {
|
|
9
9
|
await access(path);
|
package/bin/app/spell/cmd.d.ts
CHANGED
|
@@ -1,16 +1,25 @@
|
|
|
1
1
|
declare const _default: import("@reliverse/rempts").Command<{
|
|
2
|
-
|
|
3
|
-
type: "
|
|
2
|
+
targets: {
|
|
3
|
+
type: "array";
|
|
4
4
|
description: string;
|
|
5
|
-
|
|
5
|
+
required: true;
|
|
6
6
|
};
|
|
7
|
-
|
|
7
|
+
lib: {
|
|
8
8
|
type: "string";
|
|
9
9
|
description: string;
|
|
10
10
|
};
|
|
11
|
-
|
|
11
|
+
concurrency: {
|
|
12
|
+
type: "number";
|
|
13
|
+
description: string;
|
|
14
|
+
};
|
|
15
|
+
batchSize: {
|
|
16
|
+
type: "number";
|
|
17
|
+
description: string;
|
|
18
|
+
};
|
|
19
|
+
stopOnError: {
|
|
12
20
|
type: "boolean";
|
|
13
21
|
description: string;
|
|
22
|
+
default: true;
|
|
14
23
|
};
|
|
15
24
|
}>;
|
|
16
25
|
export default _default;
|
package/bin/app/spell/cmd.js
CHANGED
|
@@ -1,47 +1,47 @@
|
|
|
1
1
|
import { defineArgs, defineCommand } from "@reliverse/rempts";
|
|
2
|
-
import {
|
|
2
|
+
import { applyMagicSpells } from "../../libs/sdk/sdk-impl/spell/applyMagicSpells.js";
|
|
3
|
+
import { formatError } from "../../libs/sdk/sdk-impl/utils/utils-error-cwd.js";
|
|
3
4
|
export default defineCommand({
|
|
4
|
-
meta: {
|
|
5
|
-
name: "spells",
|
|
6
|
-
version: "1.0.0",
|
|
7
|
-
description: "Execute magic spells in your codebase"
|
|
8
|
-
},
|
|
9
5
|
args: defineArgs({
|
|
10
|
-
|
|
11
|
-
type: "
|
|
12
|
-
description: "
|
|
13
|
-
|
|
6
|
+
targets: {
|
|
7
|
+
type: "array",
|
|
8
|
+
description: "Distribution types to process",
|
|
9
|
+
required: true
|
|
14
10
|
},
|
|
15
|
-
|
|
11
|
+
lib: {
|
|
16
12
|
type: "string",
|
|
17
|
-
description: "
|
|
13
|
+
description: "Library to process (e.g. cfg, sdk, etc) (for usage with `dist-libs`)"
|
|
14
|
+
},
|
|
15
|
+
concurrency: {
|
|
16
|
+
type: "number",
|
|
17
|
+
description: "Number of files to process in parallel"
|
|
18
18
|
},
|
|
19
|
-
|
|
19
|
+
batchSize: {
|
|
20
|
+
type: "number",
|
|
21
|
+
description: "Number of files to process in each batch"
|
|
22
|
+
},
|
|
23
|
+
stopOnError: {
|
|
20
24
|
type: "boolean",
|
|
21
|
-
description: "
|
|
25
|
+
description: "Stop processing on first error",
|
|
26
|
+
default: true
|
|
22
27
|
}
|
|
23
28
|
}),
|
|
24
29
|
async run({ args }) {
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (files.length) {
|
|
29
|
-
console.log(`On files: ${files.join(", ")}`);
|
|
30
|
-
} else {
|
|
31
|
-
console.log("On all files");
|
|
32
|
-
}
|
|
33
|
-
if (args.dryRun) {
|
|
34
|
-
console.log("DRY RUN - No changes will be applied");
|
|
30
|
+
const { targets, lib, concurrency, batchSize, stopOnError } = args;
|
|
31
|
+
if (lib && !targets?.includes("dist-libs")) {
|
|
32
|
+
throw new Error("The 'lib' parameter can only be used with 'dist-libs' target");
|
|
35
33
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
34
|
+
try {
|
|
35
|
+
const finalTargets = targets?.map(
|
|
36
|
+
(target) => target === "dist-libs" && lib ? `${target}/${lib}` : target
|
|
37
|
+
) ?? [];
|
|
38
|
+
await applyMagicSpells(finalTargets, {
|
|
39
|
+
concurrency,
|
|
40
|
+
batchSize,
|
|
41
|
+
stopOnError
|
|
42
|
+
});
|
|
43
|
+
} catch (error) {
|
|
44
|
+
throw new Error(`\u274C Processing failed: ${formatError(error)}`);
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
});
|
|
File without changes
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
declare const _default: import("@reliverse/rempts").Command<{
|
|
2
|
-
|
|
3
|
-
type: "
|
|
2
|
+
templatesDir: {
|
|
3
|
+
type: "positional";
|
|
4
|
+
required: true;
|
|
4
5
|
description: string;
|
|
5
|
-
default: string;
|
|
6
6
|
};
|
|
7
|
-
|
|
7
|
+
output: {
|
|
8
8
|
type: "string";
|
|
9
|
+
default: string;
|
|
9
10
|
description: string;
|
|
10
11
|
};
|
|
11
|
-
|
|
12
|
+
cdn: {
|
|
12
13
|
type: "string";
|
|
13
14
|
description: string;
|
|
14
15
|
};
|
|
15
|
-
|
|
16
|
+
deleteTemplates: {
|
|
16
17
|
type: "boolean";
|
|
17
18
|
description: string;
|
|
18
19
|
default: false;
|
|
@@ -22,20 +23,15 @@ declare const _default: import("@reliverse/rempts").Command<{
|
|
|
22
23
|
description: string;
|
|
23
24
|
default: false;
|
|
24
25
|
};
|
|
25
|
-
|
|
26
|
+
force: {
|
|
26
27
|
type: "boolean";
|
|
27
28
|
description: string;
|
|
28
29
|
default: false;
|
|
29
30
|
};
|
|
30
|
-
|
|
31
|
-
type: "string";
|
|
32
|
-
description: string;
|
|
33
|
-
default: string;
|
|
34
|
-
};
|
|
35
|
-
force: {
|
|
31
|
+
cleanup: {
|
|
36
32
|
type: "boolean";
|
|
37
33
|
description: string;
|
|
38
|
-
default:
|
|
34
|
+
default: false;
|
|
39
35
|
};
|
|
40
36
|
}>;
|
|
41
37
|
export default _default;
|