memory-extract 0.1.0 → 0.1.2
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/package.json +6 -6
- package/src/index.js +1 -1
- package/src/loadMemory.js +140 -21
- package/src/memoryPlay.js +246 -0
- package/src/payloadFormat.js +4 -1
- package/tools/buildPlayLauncher.mjs +30 -0
- package/tools/hostProject.mjs +129 -11
- package/tools/memoryFormat.mjs +13 -3
- package/tools/pack.mjs +155 -99
- package/tools/play.mjs +177 -0
- package/tools/playDirectory.mjs +156 -0
- package/tools/playLauncher.bundle.js +737 -0
- package/tools/playMemory.mjs +10 -0
- package/tools/unpack.mjs +18 -7
- package/tools/packCache.mjs +0 -62
- package/tools/resizeCover.mjs +0 -55
package/tools/unpack.mjs
CHANGED
|
@@ -7,21 +7,32 @@ import {
|
|
|
7
7
|
listManifestFiles,
|
|
8
8
|
readMemoryFile,
|
|
9
9
|
} from "./memoryFormat.mjs";
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
loadHostProject,
|
|
12
|
+
parseUnpackArgv,
|
|
13
|
+
resolveUnpackDir,
|
|
14
|
+
} from "./hostProject.mjs";
|
|
11
15
|
|
|
12
16
|
const parseArgs = async (argv) => {
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
const host = await loadHostProject(process.cwd());
|
|
18
|
+
const { input, out: explicitOut } = parseUnpackArgv(argv);
|
|
19
|
+
|
|
20
|
+
if (!input) {
|
|
21
|
+
throw new Error("Specify a memory PNG path.");
|
|
22
|
+
}
|
|
17
23
|
|
|
18
|
-
return { input,
|
|
24
|
+
return { input, explicitOut, host };
|
|
19
25
|
};
|
|
20
26
|
|
|
21
27
|
const main = async () => {
|
|
22
|
-
const { input,
|
|
28
|
+
const { input, explicitOut, host } = await parseArgs(process.argv.slice(2));
|
|
23
29
|
const buffer = await readFile(input);
|
|
24
30
|
const { png, manifest, fileBytes, version } = extractMemory(buffer);
|
|
31
|
+
const outDir = resolveUnpackDir({
|
|
32
|
+
manifestSource: manifest.source ?? "",
|
|
33
|
+
explicitOut,
|
|
34
|
+
host,
|
|
35
|
+
});
|
|
25
36
|
|
|
26
37
|
await mkdir(outDir, { recursive: true });
|
|
27
38
|
await writeFile(path.join(outDir, "cover.png"), png);
|
package/tools/packCache.mjs
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
|
-
import { readFile, stat, writeFile } from "node:fs/promises";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import { MEMORY_VERSION } from "./memoryFormat.mjs";
|
|
5
|
-
|
|
6
|
-
export const CACHE_FILE = ".memory-pack-cache.json";
|
|
7
|
-
|
|
8
|
-
export const hashBuffer = (buffer) =>
|
|
9
|
-
createHash("sha256").update(buffer).digest("hex");
|
|
10
|
-
|
|
11
|
-
export const buildPackFingerprint = (options, files, cover) => ({
|
|
12
|
-
cacheVersion: 1,
|
|
13
|
-
formatVersion: MEMORY_VERSION,
|
|
14
|
-
name: options.name,
|
|
15
|
-
entry: options.entry,
|
|
16
|
-
out: path.resolve(options.out),
|
|
17
|
-
exclude: [...options.exclude].sort(),
|
|
18
|
-
coverMaxSize: options.coverMaxSize,
|
|
19
|
-
coverResize: options.coverResize,
|
|
20
|
-
cover: hashBuffer(cover),
|
|
21
|
-
files: Object.fromEntries(
|
|
22
|
-
Object.keys(files)
|
|
23
|
-
.sort()
|
|
24
|
-
.map((filePath) => [filePath, hashBuffer(files[filePath])])
|
|
25
|
-
),
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
export const fingerprintsEqual = (left, right) =>
|
|
29
|
-
JSON.stringify(left) === JSON.stringify(right);
|
|
30
|
-
|
|
31
|
-
export const cachePathFor = (rootDir) => path.join(rootDir, CACHE_FILE);
|
|
32
|
-
|
|
33
|
-
export const loadPackCache = async (rootDir) => {
|
|
34
|
-
try {
|
|
35
|
-
const raw = await readFile(cachePathFor(rootDir), "utf8");
|
|
36
|
-
return JSON.parse(raw);
|
|
37
|
-
} catch {
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
export const savePackCache = async (rootDir, fingerprint) => {
|
|
43
|
-
await writeFile(
|
|
44
|
-
cachePathFor(rootDir),
|
|
45
|
-
`${JSON.stringify({ fingerprint }, null, 2)}\n`
|
|
46
|
-
);
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
export const isPackUpToDate = async (rootDir, fingerprint, outputPath) => {
|
|
50
|
-
try {
|
|
51
|
-
await stat(outputPath);
|
|
52
|
-
} catch {
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const cache = await loadPackCache(rootDir);
|
|
57
|
-
if (!cache?.fingerprint) {
|
|
58
|
-
return false;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return fingerprintsEqual(cache.fingerprint, fingerprint);
|
|
62
|
-
};
|
package/tools/resizeCover.mjs
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import sharp from "sharp";
|
|
2
|
-
import { inspectPng } from "./pngInspect.mjs";
|
|
3
|
-
|
|
4
|
-
const DEFAULT_MAX_BYTES = 512 * 1024;
|
|
5
|
-
|
|
6
|
-
export const prepareCover = async (
|
|
7
|
-
input,
|
|
8
|
-
{ maxSize = 512, resize = true, maxBytes = DEFAULT_MAX_BYTES } = {}
|
|
9
|
-
) => {
|
|
10
|
-
if (!resize || maxSize <= 0) {
|
|
11
|
-
return {
|
|
12
|
-
buffer: input,
|
|
13
|
-
info: inspectPng(input),
|
|
14
|
-
changed: false,
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const metadata = await sharp(input).metadata();
|
|
19
|
-
const original = {
|
|
20
|
-
width: metadata.width ?? 0,
|
|
21
|
-
height: metadata.height ?? 0,
|
|
22
|
-
bytes: input.length,
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const needsResize = original.width > maxSize || original.height > maxSize;
|
|
26
|
-
const needsCompress = original.bytes > maxBytes;
|
|
27
|
-
|
|
28
|
-
if (!needsResize && !needsCompress) {
|
|
29
|
-
return {
|
|
30
|
-
buffer: input,
|
|
31
|
-
info: inspectPng(input),
|
|
32
|
-
changed: false,
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
let pipeline = sharp(input);
|
|
37
|
-
|
|
38
|
-
if (needsResize) {
|
|
39
|
-
pipeline = pipeline.resize(maxSize, maxSize, {
|
|
40
|
-
fit: "inside",
|
|
41
|
-
withoutEnlargement: true,
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const buffer = await pipeline
|
|
46
|
-
.png({ compressionLevel: 9, effort: 10 })
|
|
47
|
-
.toBuffer();
|
|
48
|
-
|
|
49
|
-
return {
|
|
50
|
-
buffer,
|
|
51
|
-
info: inspectPng(buffer),
|
|
52
|
-
changed: true,
|
|
53
|
-
from: original,
|
|
54
|
-
};
|
|
55
|
-
};
|