@utils-code/front-end 1.0.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 ADDED
@@ -0,0 +1,9 @@
1
+ # @utils-code/front-end
2
+
3
+ This package installs the archive segments. To create the original ZIP:
4
+
5
+ ```bash
6
+ npx utils-code-front-end assemble ./code.zip
7
+ ```
8
+
9
+ No install lifecycle script runs automatically.
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env node
2
+ import { createHash } from 'node:crypto';
3
+ import { createReadStream, createWriteStream } from 'node:fs';
4
+ import { access, mkdir, readFile, rename, rm } from 'node:fs/promises';
5
+ import { createRequire } from 'node:module';
6
+ import { dirname, resolve } from 'node:path';
7
+ import { finished } from 'node:stream/promises';
8
+
9
+ const require = createRequire(import.meta.url);
10
+ const output = resolve(process.argv[3] ?? process.argv[2] ?? './code.zip');
11
+ if (process.argv[2] && process.argv[2] !== 'assemble') {
12
+ console.error('Usage: utils-code-front-end assemble [output.zip]');
13
+ process.exit(1);
14
+ }
15
+ try {
16
+ await access(output);
17
+ throw new Error(`Refusing to overwrite ${output}`);
18
+ } catch (error) {
19
+ if (String(error.message).startsWith('Refusing')) throw error;
20
+ }
21
+
22
+ const manifest = JSON.parse(await readFile(new URL('../manifest.json', import.meta.url)));
23
+ await mkdir(dirname(output), { recursive: true });
24
+ const temporary = `${output}.partial`;
25
+ await rm(temporary, { force: true });
26
+ const target = createWriteStream(temporary, { flags: 'wx' });
27
+ const hash = createHash('sha256');
28
+ for (const part of manifest.parts) {
29
+ const chunkNumber = String(Math.floor(Number(part.file.slice(-4)) / 10) + 1).padStart(3, '0');
30
+ const packageRoot = dirname(require.resolve(`@utils-code/front-end-parts-${chunkNumber}/package.json`));
31
+ const source = createReadStream(resolve(packageRoot, 'parts', part.file));
32
+ source.on('data', (buffer) => hash.update(buffer));
33
+ source.pipe(target, { end: false });
34
+ await finished(source);
35
+ }
36
+ target.end();
37
+ await finished(target);
38
+ await rename(temporary, output);
39
+ console.log(`Created ${output} (${hash.digest('hex')}).`);