@edenapp/genesis 0.12.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -2
- package/dist/archive.d.ts +15 -0
- package/dist/archive.d.ts.map +1 -0
- package/dist/archive.js +160 -0
- package/dist/archive.js.map +1 -0
- package/dist/build.d.ts +6 -0
- package/dist/build.d.ts.map +1 -0
- package/dist/build.js +67 -0
- package/dist/build.js.map +1 -0
- package/dist/bundler.d.ts +6 -22
- package/dist/bundler.d.ts.map +1 -1
- package/dist/bundler.js +63 -524
- package/dist/bundler.js.map +1 -1
- package/dist/bundler.test.js +233 -0
- package/dist/bundler.test.js.map +1 -1
- package/dist/cli.js +20 -8
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/manifest.d.ts +37 -0
- package/dist/manifest.d.ts.map +1 -0
- package/dist/manifest.js +358 -0
- package/dist/manifest.js.map +1 -0
- package/dist/package-files.d.ts +5 -0
- package/dist/package-files.d.ts.map +1 -0
- package/dist/package-files.js +92 -0
- package/dist/package-files.js.map +1 -0
- package/dist/writer.d.ts +15 -0
- package/dist/writer.d.ts.map +1 -0
- package/dist/writer.js +104 -0
- package/dist/writer.js.map +1 -0
- package/package.json +4 -2
package/dist/bundler.js
CHANGED
|
@@ -32,535 +32,77 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
32
32
|
return result;
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.executeBuild =
|
|
40
|
-
exports.validateManifestObject = validateManifestObject;
|
|
41
|
-
exports.validateManifest = validateManifest;
|
|
42
|
-
exports.verifyFiles = verifyFiles;
|
|
36
|
+
exports.verifyFiles = exports.validatePackageManifestObject = exports.validateManifestObject = exports.validateManifest = exports.validateDlcManifestObject = exports.validateAppManifestObject = exports.validateAppManifest = exports.isDlcCompatible = exports.executeBuild = void 0;
|
|
43
37
|
exports.bundle = bundle;
|
|
44
38
|
exports.getInfo = getInfo;
|
|
45
39
|
exports.extract = extract;
|
|
46
|
-
const node_child_process_1 = require("node:child_process");
|
|
47
|
-
const crypto = __importStar(require("node:crypto"));
|
|
48
|
-
const node_fs_1 = require("node:fs");
|
|
49
40
|
const fs = __importStar(require("node:fs/promises"));
|
|
50
41
|
const path = __importStar(require("node:path"));
|
|
51
|
-
const promises_1 = require("node:stream/promises");
|
|
52
42
|
const node_util_1 = require("node:util");
|
|
53
|
-
const
|
|
54
|
-
const
|
|
43
|
+
const archive_1 = require("./archive");
|
|
44
|
+
const build_1 = require("./build");
|
|
55
45
|
const compression_1 = require("./compression");
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
const
|
|
46
|
+
const manifest_1 = require("./manifest");
|
|
47
|
+
const package_files_1 = require("./package-files");
|
|
48
|
+
const writer_1 = require("./writer");
|
|
59
49
|
const compressor = compression_1.DEFAULT_COMPRESSOR;
|
|
60
|
-
let
|
|
61
|
-
|
|
62
|
-
return error instanceof Error ? error.message : String(error);
|
|
63
|
-
}
|
|
50
|
+
let initialized = false;
|
|
51
|
+
const errorMessage = (error) => error instanceof Error ? error.message : String(error);
|
|
64
52
|
async function initCompressor() {
|
|
65
|
-
if (
|
|
53
|
+
if (initialized)
|
|
66
54
|
return;
|
|
67
55
|
await compressor.initialize();
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
function isRemoteEntry(entry) {
|
|
71
|
-
return !!entry && /^https?:\/\//i.test(entry);
|
|
72
|
-
}
|
|
73
|
-
async function readArchiveMetadata(edenitePath) {
|
|
74
|
-
const file = await fs.open(edenitePath, "r");
|
|
75
|
-
try {
|
|
76
|
-
const lengthBuffer = Buffer.alloc(4);
|
|
77
|
-
const { bytesRead } = await file.read(lengthBuffer, 0, 4, 0);
|
|
78
|
-
if (bytesRead !== 4) {
|
|
79
|
-
throw new Error("Invalid .edenite file: missing metadata length");
|
|
80
|
-
}
|
|
81
|
-
const metadataLength = lengthBuffer.readUInt32BE(0);
|
|
82
|
-
const metadataBuffer = Buffer.alloc(metadataLength);
|
|
83
|
-
const metadataRead = await file.read(metadataBuffer, 0, metadataLength, 4);
|
|
84
|
-
if (metadataRead.bytesRead !== metadataLength) {
|
|
85
|
-
throw new Error("Invalid .edenite file: incomplete metadata");
|
|
86
|
-
}
|
|
87
|
-
return {
|
|
88
|
-
metadata: JSON.parse(metadataBuffer.toString("utf-8")),
|
|
89
|
-
payloadOffset: 4 + metadataLength,
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
finally {
|
|
93
|
-
await file.close();
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
async function calculateFileChecksum(filePath, start) {
|
|
97
|
-
const hash = crypto.createHash("sha256");
|
|
98
|
-
const stream = (0, node_fs_1.createReadStream)(filePath, { start });
|
|
99
|
-
return new Promise((resolve, reject) => {
|
|
100
|
-
stream.on("data", (chunk) => hash.update(chunk));
|
|
101
|
-
stream.on("error", reject);
|
|
102
|
-
stream.on("end", () => resolve(hash.digest("hex")));
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
async function extractWithSystemZstd(edenitePath, payloadOffset, outputDirectory) {
|
|
106
|
-
const zstd = (0, node_child_process_1.spawn)("zstd", ["-dc"], {
|
|
107
|
-
stdio: ["pipe", "pipe", "pipe"],
|
|
108
|
-
});
|
|
109
|
-
let stderr = "";
|
|
110
|
-
zstd.stderr.setEncoding("utf-8");
|
|
111
|
-
zstd.stderr.on("data", (chunk) => {
|
|
112
|
-
stderr += chunk;
|
|
113
|
-
});
|
|
114
|
-
const compressedStream = (0, node_fs_1.createReadStream)(edenitePath, {
|
|
115
|
-
start: payloadOffset,
|
|
116
|
-
});
|
|
117
|
-
const tarStream = tar.extract({ cwd: outputDirectory });
|
|
118
|
-
const zstdExit = new Promise((resolve, reject) => {
|
|
119
|
-
zstd.on("error", (error) => {
|
|
120
|
-
if (error.code === "ENOENT") {
|
|
121
|
-
reject(new Error("System zstd executable not found. Install zstd to extract .edenite archives."));
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
reject(error);
|
|
125
|
-
});
|
|
126
|
-
zstd.on("close", (code) => {
|
|
127
|
-
if (code === 0) {
|
|
128
|
-
resolve();
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
reject(new Error(`zstd decompression failed with exit code ${code}: ${stderr.trim()}`));
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
await Promise.all([
|
|
136
|
-
(0, promises_1.pipeline)(compressedStream, zstd.stdin),
|
|
137
|
-
(0, promises_1.pipeline)(zstd.stdout, tarStream),
|
|
138
|
-
zstdExit,
|
|
139
|
-
]);
|
|
140
|
-
}
|
|
141
|
-
async function executeBuild(appDirectory, manifest, verbose) {
|
|
142
|
-
if (!manifest.build?.command) {
|
|
143
|
-
return { success: true }; // No build command defined, skip
|
|
144
|
-
}
|
|
145
|
-
try {
|
|
146
|
-
const buildCwd = manifest.build.cwd
|
|
147
|
-
? path.join(appDirectory, manifest.build.cwd)
|
|
148
|
-
: appDirectory;
|
|
149
|
-
if (verbose) {
|
|
150
|
-
console.log(`🔨 Running build command: ${manifest.build.command}`);
|
|
151
|
-
console.log(` Working directory: ${buildCwd}`);
|
|
152
|
-
}
|
|
153
|
-
const { stdout, stderr } = await execAsync(manifest.build.command, {
|
|
154
|
-
cwd: buildCwd,
|
|
155
|
-
env: { ...process.env },
|
|
156
|
-
});
|
|
157
|
-
if (verbose && stdout) {
|
|
158
|
-
console.log(` ${stdout.trim()}`);
|
|
159
|
-
}
|
|
160
|
-
if (stderr && verbose) {
|
|
161
|
-
console.log(` ${stderr.trim()}`);
|
|
162
|
-
}
|
|
163
|
-
if (verbose) {
|
|
164
|
-
console.log("✓ Build completed successfully");
|
|
165
|
-
}
|
|
166
|
-
return { success: true };
|
|
167
|
-
}
|
|
168
|
-
catch (error) {
|
|
169
|
-
return {
|
|
170
|
-
success: false,
|
|
171
|
-
error: `Build failed: ${getErrorMessage(error)}`,
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
function validateManifestObject(manifest) {
|
|
176
|
-
const errors = [];
|
|
177
|
-
// Required fields
|
|
178
|
-
if (!manifest.id)
|
|
179
|
-
errors.push("Missing required field: id");
|
|
180
|
-
if (!manifest.name)
|
|
181
|
-
errors.push("Missing required field: name");
|
|
182
|
-
if (!manifest.version)
|
|
183
|
-
errors.push("Missing required field: version");
|
|
184
|
-
// Validate ID format
|
|
185
|
-
if (manifest.id && !/^[a-z0-9.-]+$/.test(manifest.id)) {
|
|
186
|
-
errors.push("Invalid ID format. Use lowercase letters, numbers, dots, and hyphens only.");
|
|
187
|
-
}
|
|
188
|
-
// Backend validation (optional, but ensure entry if provided)
|
|
189
|
-
if (manifest.backend && !manifest.backend.entry) {
|
|
190
|
-
errors.push("Missing required field: backend.entry");
|
|
191
|
-
}
|
|
192
|
-
// Frontend validation (optional, but entry required if frontend exists)
|
|
193
|
-
if (manifest.frontend && !manifest.frontend.entry) {
|
|
194
|
-
errors.push("Missing required field: frontend.entry");
|
|
195
|
-
}
|
|
196
|
-
else if (manifest.frontend &&
|
|
197
|
-
!isRemoteEntry(manifest.frontend.entry) &&
|
|
198
|
-
manifest.frontend.entry.startsWith("http")) {
|
|
199
|
-
errors.push("Invalid frontend.entry URL");
|
|
200
|
-
}
|
|
201
|
-
if (manifest.build?.concurrent !== undefined &&
|
|
202
|
-
typeof manifest.build.concurrent !== "boolean") {
|
|
203
|
-
errors.push("build.concurrent must be a boolean");
|
|
204
|
-
}
|
|
205
|
-
if (manifest.fileHandlers) {
|
|
206
|
-
for (const [index, handler] of manifest.fileHandlers.entries()) {
|
|
207
|
-
if (!handler.name) {
|
|
208
|
-
errors.push(`Missing required field: fileHandlers[${index}].name`);
|
|
209
|
-
}
|
|
210
|
-
const hasExtensions = Array.isArray(handler.extensions) && handler.extensions.length > 0;
|
|
211
|
-
const hasMimeTypes = Array.isArray(handler.mimeTypes) && handler.mimeTypes.length > 0;
|
|
212
|
-
if (!hasExtensions && !hasMimeTypes && !handler.directories) {
|
|
213
|
-
errors.push(`fileHandlers[${index}] must declare extensions, mimeTypes, or directories`);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
if (manifest.settings) {
|
|
218
|
-
for (const [categoryIndex, category] of manifest.settings.entries()) {
|
|
219
|
-
for (const [settingIndex, setting] of category.settings.entries()) {
|
|
220
|
-
if (setting.sharedWith === undefined)
|
|
221
|
-
continue;
|
|
222
|
-
if (!Array.isArray(setting.sharedWith)) {
|
|
223
|
-
errors.push(`settings[${categoryIndex}].settings[${settingIndex}].sharedWith must be an array`);
|
|
224
|
-
continue;
|
|
225
|
-
}
|
|
226
|
-
const seenReaders = new Set();
|
|
227
|
-
for (const [readerIndex, readerAppId] of setting.sharedWith.entries()) {
|
|
228
|
-
const field = `settings[${categoryIndex}].settings[${settingIndex}]` +
|
|
229
|
-
`.sharedWith[${readerIndex}]`;
|
|
230
|
-
if (!/^[a-z0-9.-]+$/.test(readerAppId)) {
|
|
231
|
-
errors.push(`${field} must be a valid app ID`);
|
|
232
|
-
}
|
|
233
|
-
else if (readerAppId === manifest.id) {
|
|
234
|
-
errors.push(`${field} cannot reference the owning app`);
|
|
235
|
-
}
|
|
236
|
-
else if (seenReaders.has(readerAppId)) {
|
|
237
|
-
errors.push(`${field} duplicates app ID "${readerAppId}"`);
|
|
238
|
-
}
|
|
239
|
-
seenReaders.add(readerAppId);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
// Must have at least frontend or backend
|
|
245
|
-
if (!manifest.frontend && !manifest.backend) {
|
|
246
|
-
errors.push("App must have at least a frontend or backend entry");
|
|
247
|
-
}
|
|
248
|
-
return {
|
|
249
|
-
valid: errors.length === 0,
|
|
250
|
-
errors,
|
|
251
|
-
manifest: errors.length === 0 ? manifest : undefined,
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
async function validateManifest(manifestPath) {
|
|
255
|
-
try {
|
|
256
|
-
const content = await fs.readFile(manifestPath, "utf-8");
|
|
257
|
-
const manifest = JSON.parse(content);
|
|
258
|
-
return validateManifestObject(manifest);
|
|
259
|
-
}
|
|
260
|
-
catch (error) {
|
|
261
|
-
return {
|
|
262
|
-
valid: false,
|
|
263
|
-
errors: [`Failed to read/parse manifest: ${getErrorMessage(error)}`],
|
|
264
|
-
};
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
async function verifyFiles(appDirectory, manifest) {
|
|
268
|
-
const errors = [];
|
|
269
|
-
// Check backend entry if defined
|
|
270
|
-
if (manifest.backend?.entry) {
|
|
271
|
-
const backendPath = path.join(appDirectory, manifest.backend.entry);
|
|
272
|
-
try {
|
|
273
|
-
await fs.access(backendPath);
|
|
274
|
-
}
|
|
275
|
-
catch {
|
|
276
|
-
errors.push(`Backend entry file not found: ${manifest.backend.entry}`);
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
// Check frontend entry if defined and not a remote URL
|
|
280
|
-
if (manifest.frontend?.entry && !isRemoteEntry(manifest.frontend.entry)) {
|
|
281
|
-
const frontendPath = path.join(appDirectory, manifest.frontend.entry);
|
|
282
|
-
try {
|
|
283
|
-
await fs.access(frontendPath);
|
|
284
|
-
}
|
|
285
|
-
catch {
|
|
286
|
-
errors.push(`Frontend entry file not found: ${manifest.frontend.entry}`);
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
// Check icon if specified (warn but don't fail)
|
|
290
|
-
if (manifest.icon) {
|
|
291
|
-
const iconPath = path.join(appDirectory, manifest.icon);
|
|
292
|
-
try {
|
|
293
|
-
await fs.access(iconPath);
|
|
294
|
-
}
|
|
295
|
-
catch {
|
|
296
|
-
// Icon is optional, so just warn in verbose mode
|
|
297
|
-
// Don't add to errors array
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
return { valid: errors.length === 0, errors };
|
|
301
|
-
}
|
|
302
|
-
function shouldExcludeFile(filePath, manifest) {
|
|
303
|
-
// Check if this path is explicitly included via manifest
|
|
304
|
-
if (manifest?.include) {
|
|
305
|
-
for (const includePath of manifest.include) {
|
|
306
|
-
// Normalize paths for comparison
|
|
307
|
-
const normalizedInclude = includePath.replace(/\\/g, "/");
|
|
308
|
-
const normalizedFile = filePath.replace(/\\/g, "/");
|
|
309
|
-
// Check if the file path starts with or equals the include path
|
|
310
|
-
if (normalizedFile === normalizedInclude ||
|
|
311
|
-
normalizedFile.startsWith(`${normalizedInclude}/`)) {
|
|
312
|
-
return false; // Don't exclude - explicitly included
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
const excludePatterns = [
|
|
317
|
-
// Dependencies
|
|
318
|
-
/^node_modules\//,
|
|
319
|
-
/^node_modules$/,
|
|
320
|
-
// Source files (we only want the built output)
|
|
321
|
-
/^src\//,
|
|
322
|
-
/^src$/,
|
|
323
|
-
// Config files
|
|
324
|
-
/^tsconfig\.json$/,
|
|
325
|
-
/^tsconfig\..+\.json$/,
|
|
326
|
-
/^vite\.config\..+$/,
|
|
327
|
-
/^\.eslintrc/,
|
|
328
|
-
/^\.prettierrc/,
|
|
329
|
-
/^\.gitignore$/,
|
|
330
|
-
/^\.git\//,
|
|
331
|
-
/^\.DS_Store$/,
|
|
332
|
-
// Lock files
|
|
333
|
-
/^package-lock\.json$/,
|
|
334
|
-
/^pnpm-lock\.yaml$/,
|
|
335
|
-
/^yarn\.lock$/,
|
|
336
|
-
// Build artifacts that shouldn't be included
|
|
337
|
-
/^\.vite\//,
|
|
338
|
-
/^\.cache\//,
|
|
339
|
-
// Test files
|
|
340
|
-
/^__tests__\//,
|
|
341
|
-
/\.test\.[jt]sx?$/,
|
|
342
|
-
/\.spec\.[jt]sx?$/,
|
|
343
|
-
];
|
|
344
|
-
return excludePatterns.some((pattern) => pattern.test(filePath));
|
|
345
|
-
}
|
|
346
|
-
async function extractToDirectory(appDirectory, targetDir, manifest, verbose) {
|
|
347
|
-
const resolvedTarget = path.resolve(targetDir);
|
|
348
|
-
if (verbose)
|
|
349
|
-
console.log(`📁 Copying files to: ${resolvedTarget}`);
|
|
350
|
-
// Ensure target directory exists
|
|
351
|
-
await fs.mkdir(resolvedTarget, { recursive: true });
|
|
352
|
-
// Copy all files from the app directory (excluding development files)
|
|
353
|
-
const files = await fs.readdir(appDirectory, { recursive: true });
|
|
354
|
-
let copiedCount = 0;
|
|
355
|
-
let skippedCount = 0;
|
|
356
|
-
for (const file of files) {
|
|
357
|
-
const fileStr = file;
|
|
358
|
-
// Skip excluded files
|
|
359
|
-
if (shouldExcludeFile(fileStr, manifest)) {
|
|
360
|
-
skippedCount++;
|
|
361
|
-
continue;
|
|
362
|
-
}
|
|
363
|
-
const sourcePath = path.join(appDirectory, fileStr);
|
|
364
|
-
const stat = await fs.stat(sourcePath);
|
|
365
|
-
if (stat.isFile()) {
|
|
366
|
-
const targetPath = path.join(resolvedTarget, fileStr);
|
|
367
|
-
const targetFileDir = path.dirname(targetPath);
|
|
368
|
-
// Ensure subdirectory exists
|
|
369
|
-
await fs.mkdir(targetFileDir, { recursive: true });
|
|
370
|
-
// Copy file
|
|
371
|
-
await fs.copyFile(sourcePath, targetPath);
|
|
372
|
-
copiedCount++;
|
|
373
|
-
if (verbose)
|
|
374
|
-
console.log(` + ${fileStr}`);
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
if (verbose) {
|
|
378
|
-
console.log(`✓ Files copied to: ${resolvedTarget}`);
|
|
379
|
-
console.log(` Copied: ${copiedCount} files, Skipped: ${skippedCount} (dev files)`);
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
async function createArchive(appDirectory, manifest, outputPath, verbose, compressionLevel = 11) {
|
|
383
|
-
await initCompressor();
|
|
384
|
-
const finalOutputPath = outputPath ||
|
|
385
|
-
path.join(process.cwd(), `${manifest.id}-${manifest.version}.edenite`);
|
|
386
|
-
// Create temporary tar file
|
|
387
|
-
const tempTarPath = `${finalOutputPath}.tmp.tar`;
|
|
388
|
-
if (verbose)
|
|
389
|
-
console.log("📦 Creating TAR archive...");
|
|
390
|
-
let progressBar = null;
|
|
391
|
-
// Get file list for progress tracking (excluding development files)
|
|
392
|
-
const allFiles = await fs.readdir(appDirectory, { recursive: true });
|
|
393
|
-
const fileList = [];
|
|
394
|
-
for (const file of allFiles) {
|
|
395
|
-
const fileStr = file;
|
|
396
|
-
// Skip excluded files
|
|
397
|
-
if (shouldExcludeFile(fileStr, manifest)) {
|
|
398
|
-
continue;
|
|
399
|
-
}
|
|
400
|
-
const filePath = path.join(appDirectory, fileStr);
|
|
401
|
-
const stat = await fs.stat(filePath);
|
|
402
|
-
if (stat.isFile()) {
|
|
403
|
-
fileList.push(fileStr);
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
if (verbose && fileList.length > 50) {
|
|
407
|
-
progressBar = new cli_progress_1.default.SingleBar({
|
|
408
|
-
format: " Progress |{bar}| {percentage}% | {value}/{total} files",
|
|
409
|
-
barCompleteChar: "\u2588",
|
|
410
|
-
barIncompleteChar: "\u2591",
|
|
411
|
-
hideCursor: true,
|
|
412
|
-
});
|
|
413
|
-
progressBar.start(fileList.length, 0);
|
|
414
|
-
}
|
|
415
|
-
let processedFiles = 0;
|
|
416
|
-
// Create TAR archive
|
|
417
|
-
await tar.create({
|
|
418
|
-
file: tempTarPath,
|
|
419
|
-
cwd: appDirectory,
|
|
420
|
-
gzip: false,
|
|
421
|
-
portable: true,
|
|
422
|
-
filter: (entryPath, _stat) => {
|
|
423
|
-
if (verbose && progressBar) {
|
|
424
|
-
processedFiles++;
|
|
425
|
-
progressBar.update(processedFiles);
|
|
426
|
-
}
|
|
427
|
-
else if (verbose) {
|
|
428
|
-
console.log(` + ${entryPath}`);
|
|
429
|
-
}
|
|
430
|
-
return true;
|
|
431
|
-
},
|
|
432
|
-
}, fileList);
|
|
433
|
-
if (progressBar) {
|
|
434
|
-
progressBar.stop();
|
|
435
|
-
}
|
|
436
|
-
if (verbose)
|
|
437
|
-
console.log("🗜️ Compressing with Zstandard...");
|
|
438
|
-
// Create temporary file for compressed output
|
|
439
|
-
const tempCompressedPath = `${tempTarPath}.zst`;
|
|
440
|
-
// Compress with configured compressor using streaming to disk
|
|
441
|
-
const { checksum } = await compressor.compressFileStreaming(tempTarPath, tempCompressedPath, compressionLevel);
|
|
442
|
-
// Create metadata
|
|
443
|
-
const metadata = {
|
|
444
|
-
version: ARCHIVE_FORMAT_VERSION,
|
|
445
|
-
checksum,
|
|
446
|
-
created: new Date().toISOString(),
|
|
447
|
-
manifest,
|
|
448
|
-
};
|
|
449
|
-
// Combine metadata + compressed data
|
|
450
|
-
// Format: [4 bytes metadata length][metadata JSON][compressed stream]
|
|
451
|
-
const metadataJson = JSON.stringify(metadata);
|
|
452
|
-
const metadataBuffer = Buffer.from(metadataJson, "utf-8");
|
|
453
|
-
const metadataLength = Buffer.alloc(4);
|
|
454
|
-
metadataLength.writeUInt32BE(metadataBuffer.length, 0);
|
|
455
|
-
const finalWriteStream = (0, node_fs_1.createWriteStream)(finalOutputPath);
|
|
456
|
-
// Write metadata length and buffer
|
|
457
|
-
finalWriteStream.write(metadataLength);
|
|
458
|
-
finalWriteStream.write(metadataBuffer);
|
|
459
|
-
// Stream compressed content to final file
|
|
460
|
-
const compressedReadStream = (0, node_fs_1.createReadStream)(tempCompressedPath);
|
|
461
|
-
await new Promise((resolve, reject) => {
|
|
462
|
-
compressedReadStream.pipe(finalWriteStream);
|
|
463
|
-
compressedReadStream.on("error", reject);
|
|
464
|
-
finalWriteStream.on("error", reject);
|
|
465
|
-
finalWriteStream.on("finish", resolve);
|
|
466
|
-
});
|
|
467
|
-
// Get stats for logging
|
|
468
|
-
const tarStats = await fs.stat(tempTarPath);
|
|
469
|
-
const finalStats = await fs.stat(finalOutputPath);
|
|
470
|
-
// Clean up temp files
|
|
471
|
-
await fs.unlink(tempTarPath);
|
|
472
|
-
await fs.unlink(tempCompressedPath);
|
|
473
|
-
if (verbose) {
|
|
474
|
-
const originalSize = tarStats.size;
|
|
475
|
-
const finalSize = finalStats.size;
|
|
476
|
-
const metadataSize = metadataLength.length + metadataBuffer.length;
|
|
477
|
-
const compressedSize = finalSize - metadataSize; // Approximate
|
|
478
|
-
console.log(`✓ Archive created: ${finalOutputPath}`);
|
|
479
|
-
console.log(` Original size: ${(originalSize / 1024).toFixed(2)} KB`);
|
|
480
|
-
console.log(` Compressed size: ${(compressedSize / 1024).toFixed(2)} KB`);
|
|
481
|
-
console.log(` Compression ratio: ${((1 - compressedSize / originalSize) * 100).toFixed(1)}%`);
|
|
482
|
-
console.log(` SHA256: ${checksum}`);
|
|
483
|
-
}
|
|
484
|
-
return {
|
|
485
|
-
path: finalOutputPath,
|
|
486
|
-
checksum,
|
|
487
|
-
size: finalStats.size,
|
|
488
|
-
};
|
|
56
|
+
initialized = true;
|
|
489
57
|
}
|
|
490
58
|
async function bundle(options) {
|
|
491
|
-
const { appDirectory, outputPath, extractToDirectory
|
|
59
|
+
const { appDirectory, outputPath, extractToDirectory, verbose, dryRun = false, compressionLevel = 11, } = options;
|
|
492
60
|
try {
|
|
493
|
-
// Initialize compressor
|
|
494
61
|
await initCompressor();
|
|
495
62
|
if (verbose)
|
|
496
|
-
console.log(`📦 Bundling
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
}
|
|
501
|
-
catch {
|
|
502
|
-
return {
|
|
503
|
-
success: false,
|
|
504
|
-
error: `App directory not found: ${appDirectory}`,
|
|
505
|
-
};
|
|
506
|
-
}
|
|
507
|
-
// Read and validate manifest
|
|
508
|
-
const manifestPath = path.join(appDirectory, "manifest.json");
|
|
509
|
-
const validation = await validateManifest(manifestPath);
|
|
510
|
-
if (!validation.valid) {
|
|
63
|
+
console.log(`📦 Bundling package from: ${appDirectory}`);
|
|
64
|
+
await fs.access(appDirectory);
|
|
65
|
+
const validation = await (0, manifest_1.validateManifest)(path.join(appDirectory, "manifest.json"));
|
|
66
|
+
if (!validation.valid || !validation.manifest) {
|
|
511
67
|
return {
|
|
512
68
|
success: false,
|
|
513
69
|
error: `Invalid manifest:\n${validation.errors.join("\n")}`,
|
|
514
70
|
};
|
|
515
71
|
}
|
|
516
72
|
const manifest = validation.manifest;
|
|
517
|
-
if (!manifest) {
|
|
518
|
-
return {
|
|
519
|
-
success: false,
|
|
520
|
-
error: "Manifest validation succeeded but manifest is missing",
|
|
521
|
-
};
|
|
522
|
-
}
|
|
523
73
|
if (verbose) {
|
|
524
|
-
console.log(`✓ Manifest valid: ${manifest.name} v${manifest.version}`);
|
|
74
|
+
console.log(`✓ Manifest valid: ${String(manifest.name)} v${manifest.version}`);
|
|
525
75
|
}
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
manifest,
|
|
533
|
-
};
|
|
76
|
+
if (dryRun)
|
|
77
|
+
return { success: true, manifest };
|
|
78
|
+
if (manifest.kind !== "dlc") {
|
|
79
|
+
const buildResult = await (0, build_1.executeBuild)(appDirectory, manifest, verbose);
|
|
80
|
+
if (!buildResult.success)
|
|
81
|
+
return buildResult;
|
|
534
82
|
}
|
|
535
|
-
|
|
536
|
-
const buildResult = await executeBuild(appDirectory, manifest, verbose);
|
|
537
|
-
if (!buildResult.success) {
|
|
538
|
-
return {
|
|
539
|
-
success: false,
|
|
540
|
-
error: buildResult.error,
|
|
541
|
-
};
|
|
542
|
-
}
|
|
543
|
-
// Verify required files exist (after build)
|
|
544
|
-
const fileCheck = await verifyFiles(appDirectory, manifest);
|
|
83
|
+
const fileCheck = await (0, manifest_1.verifyFiles)(appDirectory, manifest);
|
|
545
84
|
if (!fileCheck.valid) {
|
|
546
85
|
return {
|
|
547
86
|
success: false,
|
|
548
87
|
error: `Missing files:\n${fileCheck.errors.join("\n")}`,
|
|
549
88
|
};
|
|
550
89
|
}
|
|
551
|
-
if (
|
|
552
|
-
|
|
553
|
-
// If extractToDirectory is provided, copy files directly
|
|
554
|
-
if (extractTarget) {
|
|
555
|
-
await extractToDirectory(appDirectory, extractTarget, manifest, verbose);
|
|
90
|
+
if (extractToDirectory) {
|
|
91
|
+
await (0, package_files_1.copyPackageFiles)(appDirectory, extractToDirectory, manifest, verbose);
|
|
556
92
|
return {
|
|
557
93
|
success: true,
|
|
558
|
-
outputPath: path.resolve(
|
|
94
|
+
outputPath: path.resolve(extractToDirectory),
|
|
559
95
|
manifest,
|
|
560
96
|
};
|
|
561
97
|
}
|
|
562
|
-
|
|
563
|
-
|
|
98
|
+
const result = await (0, writer_1.createArchive)({
|
|
99
|
+
packageDirectory: appDirectory,
|
|
100
|
+
manifest,
|
|
101
|
+
outputPath,
|
|
102
|
+
verbose,
|
|
103
|
+
compressionLevel,
|
|
104
|
+
compressor,
|
|
105
|
+
});
|
|
564
106
|
return {
|
|
565
107
|
success: true,
|
|
566
108
|
outputPath: result.path,
|
|
@@ -570,15 +112,12 @@ async function bundle(options) {
|
|
|
570
112
|
};
|
|
571
113
|
}
|
|
572
114
|
catch (error) {
|
|
573
|
-
return {
|
|
574
|
-
success: false,
|
|
575
|
-
error: `Bundle failed: ${getErrorMessage(error)}`,
|
|
576
|
-
};
|
|
115
|
+
return { success: false, error: `Bundle failed: ${errorMessage(error)}` };
|
|
577
116
|
}
|
|
578
117
|
}
|
|
579
118
|
async function getInfo(edenitePath) {
|
|
580
119
|
try {
|
|
581
|
-
const { metadata } = await readArchiveMetadata(edenitePath);
|
|
120
|
+
const { metadata } = await (0, archive_1.readArchiveMetadata)(edenitePath);
|
|
582
121
|
return {
|
|
583
122
|
success: true,
|
|
584
123
|
manifest: metadata.manifest,
|
|
@@ -588,49 +127,49 @@ async function getInfo(edenitePath) {
|
|
|
588
127
|
catch (error) {
|
|
589
128
|
return {
|
|
590
129
|
success: false,
|
|
591
|
-
error: `Failed to read archive: ${
|
|
130
|
+
error: `Failed to read archive: ${errorMessage(error)}`,
|
|
592
131
|
};
|
|
593
132
|
}
|
|
594
133
|
}
|
|
595
134
|
async function extract(options) {
|
|
596
135
|
const { edenitePath, outputDirectory, verbose, verifyChecksum = true, } = options;
|
|
597
136
|
try {
|
|
598
|
-
|
|
599
|
-
console.log(`📂 Extracting: ${edenitePath}`);
|
|
600
|
-
const { metadata, payloadOffset } = await readArchiveMetadata(edenitePath);
|
|
601
|
-
if (verbose) {
|
|
602
|
-
console.log(`✓ Archive format version: ${metadata.version}`);
|
|
603
|
-
console.log(`✓ Created: ${metadata.created}`);
|
|
604
|
-
}
|
|
605
|
-
// Verify checksum if requested
|
|
137
|
+
const { metadata, payloadOffset } = await (0, archive_1.readArchiveMetadata)(edenitePath);
|
|
606
138
|
if (verifyChecksum) {
|
|
607
|
-
const
|
|
608
|
-
if (
|
|
609
|
-
|
|
610
|
-
success: false,
|
|
611
|
-
error: `Checksum mismatch! Archive may be corrupted.\nExpected: ${metadata.checksum}\nActual: ${actualChecksum}`,
|
|
612
|
-
};
|
|
139
|
+
const checksum = await (0, archive_1.calculateFileChecksum)(edenitePath, payloadOffset);
|
|
140
|
+
if (checksum !== metadata.checksum) {
|
|
141
|
+
throw new Error(`Checksum mismatch: expected ${metadata.checksum}, received ${checksum}`);
|
|
613
142
|
}
|
|
614
|
-
if (verbose)
|
|
615
|
-
console.log("✓ Checksum verified");
|
|
616
143
|
}
|
|
617
|
-
if (verbose)
|
|
618
|
-
console.log("🗜️ Decompressing...");
|
|
619
144
|
await fs.mkdir(outputDirectory, { recursive: true });
|
|
620
|
-
await
|
|
621
|
-
|
|
622
|
-
|
|
145
|
+
await (0, archive_1.extractArchivePayload)(edenitePath, payloadOffset, outputDirectory);
|
|
146
|
+
const extracted = await (0, manifest_1.validateManifest)(path.join(outputDirectory, "manifest.json"));
|
|
147
|
+
if (!extracted.valid || !extracted.manifest) {
|
|
148
|
+
throw new Error(`Extracted manifest is invalid: ${extracted.errors.join("; ")}`);
|
|
623
149
|
}
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
150
|
+
if (!(0, node_util_1.isDeepStrictEqual)(extracted.manifest, metadata.manifest)) {
|
|
151
|
+
throw new Error("Extracted manifest does not match the archive metadata manifest");
|
|
152
|
+
}
|
|
153
|
+
if (verbose)
|
|
154
|
+
console.log(`✓ Extracted to: ${outputDirectory}`);
|
|
155
|
+
return { success: true, manifest: metadata.manifest };
|
|
628
156
|
}
|
|
629
157
|
catch (error) {
|
|
630
158
|
return {
|
|
631
159
|
success: false,
|
|
632
|
-
error: `Extraction failed: ${
|
|
160
|
+
error: `Extraction failed: ${errorMessage(error)}`,
|
|
633
161
|
};
|
|
634
162
|
}
|
|
635
163
|
}
|
|
164
|
+
var build_2 = require("./build");
|
|
165
|
+
Object.defineProperty(exports, "executeBuild", { enumerable: true, get: function () { return build_2.executeBuild; } });
|
|
166
|
+
var manifest_2 = require("./manifest");
|
|
167
|
+
Object.defineProperty(exports, "isDlcCompatible", { enumerable: true, get: function () { return manifest_2.isDlcCompatible; } });
|
|
168
|
+
Object.defineProperty(exports, "validateAppManifest", { enumerable: true, get: function () { return manifest_2.validateAppManifest; } });
|
|
169
|
+
Object.defineProperty(exports, "validateAppManifestObject", { enumerable: true, get: function () { return manifest_2.validateAppManifestObject; } });
|
|
170
|
+
Object.defineProperty(exports, "validateDlcManifestObject", { enumerable: true, get: function () { return manifest_2.validateDlcManifestObject; } });
|
|
171
|
+
Object.defineProperty(exports, "validateManifest", { enumerable: true, get: function () { return manifest_2.validateManifest; } });
|
|
172
|
+
Object.defineProperty(exports, "validateManifestObject", { enumerable: true, get: function () { return manifest_2.validateManifestObject; } });
|
|
173
|
+
Object.defineProperty(exports, "validatePackageManifestObject", { enumerable: true, get: function () { return manifest_2.validatePackageManifestObject; } });
|
|
174
|
+
Object.defineProperty(exports, "verifyFiles", { enumerable: true, get: function () { return manifest_2.verifyFiles; } });
|
|
636
175
|
//# sourceMappingURL=bundler.js.map
|