@bendyline/squisq-cli 1.1.5 → 1.2.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/dist/api.d.ts +45 -14
- package/dist/api.js +482 -301
- package/dist/api.js.map +1 -1
- package/dist/index.d.ts +2 -12
- package/dist/index.js +889 -20
- package/dist/index.js.map +1 -1
- package/package.json +8 -7
- package/dist/__tests__/convert.test.d.ts +0 -7
- package/dist/__tests__/convert.test.d.ts.map +0 -1
- package/dist/__tests__/convert.test.js +0 -127
- package/dist/__tests__/convert.test.js.map +0 -1
- package/dist/__tests__/html-export.test.d.ts +0 -8
- package/dist/__tests__/html-export.test.d.ts.map +0 -1
- package/dist/__tests__/html-export.test.js +0 -126
- package/dist/__tests__/html-export.test.js.map +0 -1
- package/dist/__tests__/readInput.test.d.ts +0 -5
- package/dist/__tests__/readInput.test.d.ts.map +0 -1
- package/dist/__tests__/readInput.test.js +0 -120
- package/dist/__tests__/readInput.test.js.map +0 -1
- package/dist/api.d.ts.map +0 -1
- package/dist/commands/convert.d.ts +0 -15
- package/dist/commands/convert.d.ts.map +0 -1
- package/dist/commands/convert.js +0 -264
- package/dist/commands/convert.js.map +0 -1
- package/dist/commands/video.d.ts +0 -12
- package/dist/commands/video.d.ts.map +0 -1
- package/dist/commands/video.js +0 -122
- package/dist/commands/video.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/util/detectFfmpeg.d.ts +0 -15
- package/dist/util/detectFfmpeg.d.ts.map +0 -1
- package/dist/util/detectFfmpeg.js +0 -29
- package/dist/util/detectFfmpeg.js.map +0 -1
- package/dist/util/nativeEncoder.d.ts +0 -27
- package/dist/util/nativeEncoder.d.ts.map +0 -1
- package/dist/util/nativeEncoder.js +0 -106
- package/dist/util/nativeEncoder.js.map +0 -1
- package/dist/util/readInput.d.ts +0 -31
- package/dist/util/readInput.d.ts.map +0 -1
- package/dist/util/readInput.js +0 -142
- package/dist/util/readInput.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"detectFfmpeg.js","sourceRoot":"","sources":["../../src/util/detectFfmpeg.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY;IAChC,MAAM,OAAO,GAAG,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC;IAEjE,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,QAAQ,CAAC,OAAO,EAAE,CAAC,QAAQ,CAAC,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE;YAC/D,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC;gBAC1B,OAAO,CAAC,IAAI,CAAC,CAAC;gBACd,OAAO;YACT,CAAC;YACD,gEAAgE;YAChE,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;YACjD,OAAO,CAAC,IAAI,CAAC,CAAC;QAChB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Native FFmpeg Encoder
|
|
3
|
-
*
|
|
4
|
-
* Encodes PNG frames to MP4 using a locally installed ffmpeg binary.
|
|
5
|
-
* Writes frames to a temporary directory, invokes ffmpeg as a child process,
|
|
6
|
-
* and reads the resulting MP4.
|
|
7
|
-
*
|
|
8
|
-
* This is the fast path — used when native ffmpeg is detected on the system.
|
|
9
|
-
* Falls back to the WASM encoder (in @bendyline/squisq-video) when unavailable.
|
|
10
|
-
*/
|
|
11
|
-
import type { VideoExportOptions } from '@bendyline/squisq-video';
|
|
12
|
-
/**
|
|
13
|
-
* Encode frame PNGs to MP4 using native ffmpeg.
|
|
14
|
-
*
|
|
15
|
-
* @param ffmpegPath - Absolute path to the ffmpeg binary
|
|
16
|
-
* @param frames - Array of PNG image bytes (one per frame)
|
|
17
|
-
* @param audio - Optional audio file bytes to mux
|
|
18
|
-
* @param outputPath - Where to write the final MP4
|
|
19
|
-
* @param options - Encoding options (fps, quality, dimensions, progress)
|
|
20
|
-
*/
|
|
21
|
-
export declare function framesToMp4Native(ffmpegPath: string, frames: Uint8Array[], audio: Uint8Array | null, outputPath: string, options?: VideoExportOptions): Promise<void>;
|
|
22
|
-
/**
|
|
23
|
-
* Encode frames using native ffmpeg and return the MP4 bytes (instead of writing to disk).
|
|
24
|
-
* Useful when the caller needs the bytes in memory.
|
|
25
|
-
*/
|
|
26
|
-
export declare function framesToMp4NativeBytes(ffmpegPath: string, frames: Uint8Array[], audio: Uint8Array | null, options?: VideoExportOptions): Promise<Uint8Array>;
|
|
27
|
-
//# sourceMappingURL=nativeEncoder.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"nativeEncoder.d.ts","sourceRoot":"","sources":["../../src/util/nativeEncoder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAQH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAGlE;;;;;;;;GAQG;AACH,wBAAsB,iBAAiB,CACrC,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,UAAU,EAAE,EACpB,KAAK,EAAE,UAAU,GAAG,IAAI,EACxB,UAAU,EAAE,MAAM,EAClB,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,IAAI,CAAC,CAuFf;AAED;;;GAGG;AACH,wBAAsB,sBAAsB,CAC1C,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,UAAU,EAAE,EACpB,KAAK,EAAE,UAAU,GAAG,IAAI,EACxB,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,UAAU,CAAC,CAWrB"}
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Native FFmpeg Encoder
|
|
3
|
-
*
|
|
4
|
-
* Encodes PNG frames to MP4 using a locally installed ffmpeg binary.
|
|
5
|
-
* Writes frames to a temporary directory, invokes ffmpeg as a child process,
|
|
6
|
-
* and reads the resulting MP4.
|
|
7
|
-
*
|
|
8
|
-
* This is the fast path — used when native ffmpeg is detected on the system.
|
|
9
|
-
* Falls back to the WASM encoder (in @bendyline/squisq-video) when unavailable.
|
|
10
|
-
*/
|
|
11
|
-
import { execFile } from 'node:child_process';
|
|
12
|
-
import { writeFile, readFile, mkdir, rm } from 'node:fs/promises';
|
|
13
|
-
import { join } from 'node:path';
|
|
14
|
-
import { tmpdir } from 'node:os';
|
|
15
|
-
import { randomBytes } from 'node:crypto';
|
|
16
|
-
import { QUALITY_PRESETS, resolveDimensions } from '@bendyline/squisq-video';
|
|
17
|
-
/**
|
|
18
|
-
* Encode frame PNGs to MP4 using native ffmpeg.
|
|
19
|
-
*
|
|
20
|
-
* @param ffmpegPath - Absolute path to the ffmpeg binary
|
|
21
|
-
* @param frames - Array of PNG image bytes (one per frame)
|
|
22
|
-
* @param audio - Optional audio file bytes to mux
|
|
23
|
-
* @param outputPath - Where to write the final MP4
|
|
24
|
-
* @param options - Encoding options (fps, quality, dimensions, progress)
|
|
25
|
-
*/
|
|
26
|
-
export async function framesToMp4Native(ffmpegPath, frames, audio, outputPath, options = {}) {
|
|
27
|
-
const fps = options.fps ?? 30;
|
|
28
|
-
const quality = options.quality ?? 'normal';
|
|
29
|
-
const { width, height } = resolveDimensions(options);
|
|
30
|
-
const preset = QUALITY_PRESETS[quality];
|
|
31
|
-
const onProgress = options.onProgress;
|
|
32
|
-
if (frames.length === 0) {
|
|
33
|
-
throw new Error('No frames provided for encoding');
|
|
34
|
-
}
|
|
35
|
-
// Create a temp working directory
|
|
36
|
-
const tmpId = randomBytes(8).toString('hex');
|
|
37
|
-
const workDir = join(tmpdir(), `squisq-video-${tmpId}`);
|
|
38
|
-
await mkdir(workDir, { recursive: true });
|
|
39
|
-
try {
|
|
40
|
-
onProgress?.(0, 'writing frames');
|
|
41
|
-
// Write frame PNGs to temp directory
|
|
42
|
-
const padLen = String(frames.length).length;
|
|
43
|
-
for (let i = 0; i < frames.length; i++) {
|
|
44
|
-
const name = `frame-${String(i + 1).padStart(padLen, '0')}.png`;
|
|
45
|
-
await writeFile(join(workDir, name), frames[i]);
|
|
46
|
-
if (onProgress && i % 10 === 0) {
|
|
47
|
-
onProgress(Math.round((i / frames.length) * 30), 'writing frames');
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
// Write audio if provided
|
|
51
|
-
let audioPath = null;
|
|
52
|
-
if (audio) {
|
|
53
|
-
audioPath = join(workDir, 'audio-input');
|
|
54
|
-
await writeFile(audioPath, audio);
|
|
55
|
-
}
|
|
56
|
-
onProgress?.(30, 'encoding');
|
|
57
|
-
// Build ffmpeg arguments
|
|
58
|
-
const padPattern = join(workDir, `frame-%0${padLen}d.png`);
|
|
59
|
-
const args = ['-y', '-framerate', String(fps), '-i', padPattern];
|
|
60
|
-
if (audioPath) {
|
|
61
|
-
args.push('-i', audioPath);
|
|
62
|
-
}
|
|
63
|
-
args.push('-c:v', 'libx264', '-preset', preset.preset, '-crf', String(preset.crf), '-pix_fmt', 'yuv420p', '-vf', `scale=${width}:${height}:force_original_aspect_ratio=decrease,pad=${width}:${height}:(ow-iw)/2:(oh-ih)/2`);
|
|
64
|
-
if (audioPath) {
|
|
65
|
-
args.push('-c:a', 'aac', '-b:a', '128k', '-shortest');
|
|
66
|
-
}
|
|
67
|
-
args.push(outputPath);
|
|
68
|
-
// Run ffmpeg
|
|
69
|
-
await new Promise((resolve, reject) => {
|
|
70
|
-
const proc = execFile(ffmpegPath, args, { timeout: 600000 }, (err) => {
|
|
71
|
-
if (err) {
|
|
72
|
-
reject(new Error(`ffmpeg failed: ${err.message}`));
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
resolve();
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
// ffmpeg writes progress to stderr
|
|
79
|
-
proc.stderr?.on('data', () => {
|
|
80
|
-
// Could parse ffmpeg progress output here in the future
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
onProgress?.(100, 'done');
|
|
84
|
-
}
|
|
85
|
-
finally {
|
|
86
|
-
// Clean up temp directory
|
|
87
|
-
await rm(workDir, { recursive: true, force: true });
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Encode frames using native ffmpeg and return the MP4 bytes (instead of writing to disk).
|
|
92
|
-
* Useful when the caller needs the bytes in memory.
|
|
93
|
-
*/
|
|
94
|
-
export async function framesToMp4NativeBytes(ffmpegPath, frames, audio, options = {}) {
|
|
95
|
-
const tmpId = randomBytes(8).toString('hex');
|
|
96
|
-
const tmpOutput = join(tmpdir(), `squisq-video-out-${tmpId}.mp4`);
|
|
97
|
-
try {
|
|
98
|
-
await framesToMp4Native(ffmpegPath, frames, audio, tmpOutput, options);
|
|
99
|
-
const data = await readFile(tmpOutput);
|
|
100
|
-
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
101
|
-
}
|
|
102
|
-
finally {
|
|
103
|
-
await rm(tmpOutput, { force: true });
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
//# sourceMappingURL=nativeEncoder.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"nativeEncoder.js","sourceRoot":"","sources":["../../src/util/nativeEncoder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAAE,IAAI,EA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AM,SAAS,GAAG,IAAI,CAAC,MAAM,EAAE,EAAE,oBAAoB,KAAK,MAAM,CAAC,CAAC;IAElE,IAAI,CAAC;QACH,MAAM,iBAAiB,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;QACvE,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,SAAS,CAAC,CAAC;QACvC,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IACvE,CAAC;YAAS,CAAC;QACT,MAAM,EAAE,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACvC,CAAC;AACH,CAAC"}
|
package/dist/util/readInput.d.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* readInput
|
|
3
|
-
*
|
|
4
|
-
* Unified input reader for the CLI. Accepts a path to a .md file, .json file
|
|
5
|
-
* (Doc schema), .zip/.dbk container, or a folder and returns a MemoryContentContainer
|
|
6
|
-
* (virtual file system) plus either the parsed MarkdownDocument or a pre-built Doc.
|
|
7
|
-
*
|
|
8
|
-
* When a .json file or a container/folder containing doc.json is provided, the
|
|
9
|
-
* Doc is returned directly and markdownDoc will be null. Callers should check
|
|
10
|
-
* result.doc first; when present, skip markdownToDoc() and use it directly.
|
|
11
|
-
*/
|
|
12
|
-
import type { MarkdownDocument } from '@bendyline/squisq/markdown';
|
|
13
|
-
import type { Doc } from '@bendyline/squisq/schemas';
|
|
14
|
-
import { MemoryContentContainer } from '@bendyline/squisq/storage';
|
|
15
|
-
export interface ReadInputResult {
|
|
16
|
-
container: MemoryContentContainer;
|
|
17
|
-
/** Parsed markdown document. Null when input is a Doc JSON file. */
|
|
18
|
-
markdownDoc: MarkdownDocument | null;
|
|
19
|
-
/** Pre-built Doc from JSON input. Present when input is .json or contains doc.json. */
|
|
20
|
-
doc?: Doc;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Read input from a file path (markdown, JSON Doc, ZIP/DBK container, or folder)
|
|
24
|
-
* and return a populated ContentContainer + parsed MarkdownDocument or Doc.
|
|
25
|
-
*
|
|
26
|
-
* When the input is a .json file (or a container/folder containing doc.json),
|
|
27
|
-
* the result will have `doc` populated and `markdownDoc` set to null.
|
|
28
|
-
* Otherwise, `markdownDoc` is populated and `doc` is undefined.
|
|
29
|
-
*/
|
|
30
|
-
export declare function readInput(inputPath: string): Promise<ReadInputResult>;
|
|
31
|
-
//# sourceMappingURL=readInput.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"readInput.d.ts","sourceRoot":"","sources":["../../src/util/readInput.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAKH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,2BAA2B,CAAC;AACrD,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAGnE,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,sBAAsB,CAAC;IAClC,oEAAoE;IACpE,WAAW,EAAE,gBAAgB,GAAG,IAAI,CAAC;IACrC,uFAAuF;IACvF,GAAG,CAAC,EAAE,GAAG,CAAC;CACX;AA2CD;;;;;;;GAOG;AACH,wBAAsB,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAkB3E"}
|
package/dist/util/readInput.js
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* readInput
|
|
3
|
-
*
|
|
4
|
-
* Unified input reader for the CLI. Accepts a path to a .md file, .json file
|
|
5
|
-
* (Doc schema), .zip/.dbk container, or a folder and returns a MemoryContentContainer
|
|
6
|
-
* (virtual file system) plus either the parsed MarkdownDocument or a pre-built Doc.
|
|
7
|
-
*
|
|
8
|
-
* When a .json file or a container/folder containing doc.json is provided, the
|
|
9
|
-
* Doc is returned directly and markdownDoc will be null. Callers should check
|
|
10
|
-
* result.doc first; when present, skip markdownToDoc() and use it directly.
|
|
11
|
-
*/
|
|
12
|
-
import { readFile, readdir, stat } from 'node:fs/promises';
|
|
13
|
-
import { join, extname } from 'node:path';
|
|
14
|
-
import { parseMarkdown } from '@bendyline/squisq/markdown';
|
|
15
|
-
import { MemoryContentContainer } from '@bendyline/squisq/storage';
|
|
16
|
-
import { zipToContainer } from '@bendyline/squisq-formats/container';
|
|
17
|
-
/** MIME type lookup by extension (common content types) */
|
|
18
|
-
const MIME_TYPES = {
|
|
19
|
-
'.md': 'text/markdown',
|
|
20
|
-
'.txt': 'text/plain',
|
|
21
|
-
'.json': 'application/json',
|
|
22
|
-
'.jpg': 'image/jpeg',
|
|
23
|
-
'.jpeg': 'image/jpeg',
|
|
24
|
-
'.png': 'image/png',
|
|
25
|
-
'.gif': 'image/gif',
|
|
26
|
-
'.webp': 'image/webp',
|
|
27
|
-
'.svg': 'image/svg+xml',
|
|
28
|
-
'.mp3': 'audio/mpeg',
|
|
29
|
-
'.wav': 'audio/wav',
|
|
30
|
-
'.ogg': 'audio/ogg',
|
|
31
|
-
'.mp4': 'video/mp4',
|
|
32
|
-
'.webm': 'video/webm',
|
|
33
|
-
};
|
|
34
|
-
function mimeFromExt(filePath) {
|
|
35
|
-
return MIME_TYPES[extname(filePath).toLowerCase()] ?? 'application/octet-stream';
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Recursively walk a directory and return all file paths (relative to root).
|
|
39
|
-
*/
|
|
40
|
-
async function walkDir(root, prefix = '') {
|
|
41
|
-
const entries = await readdir(root, { withFileTypes: true });
|
|
42
|
-
const paths = [];
|
|
43
|
-
for (const entry of entries) {
|
|
44
|
-
const relPath = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
45
|
-
if (entry.isDirectory()) {
|
|
46
|
-
paths.push(...(await walkDir(join(root, entry.name), relPath)));
|
|
47
|
-
}
|
|
48
|
-
else if (entry.isFile()) {
|
|
49
|
-
paths.push(relPath);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return paths;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Read input from a file path (markdown, JSON Doc, ZIP/DBK container, or folder)
|
|
56
|
-
* and return a populated ContentContainer + parsed MarkdownDocument or Doc.
|
|
57
|
-
*
|
|
58
|
-
* When the input is a .json file (or a container/folder containing doc.json),
|
|
59
|
-
* the result will have `doc` populated and `markdownDoc` set to null.
|
|
60
|
-
* Otherwise, `markdownDoc` is populated and `doc` is undefined.
|
|
61
|
-
*/
|
|
62
|
-
export async function readInput(inputPath) {
|
|
63
|
-
const info = await stat(inputPath);
|
|
64
|
-
if (info.isDirectory()) {
|
|
65
|
-
return readFolder(inputPath);
|
|
66
|
-
}
|
|
67
|
-
const ext = extname(inputPath).toLowerCase();
|
|
68
|
-
if (ext === '.zip' || ext === '.dbk') {
|
|
69
|
-
return readContainer(inputPath);
|
|
70
|
-
}
|
|
71
|
-
if (ext === '.json') {
|
|
72
|
-
return readDocJsonFile(inputPath);
|
|
73
|
-
}
|
|
74
|
-
// Default: treat as a markdown file
|
|
75
|
-
return readMarkdownFile(inputPath);
|
|
76
|
-
}
|
|
77
|
-
async function readMarkdownFile(filePath) {
|
|
78
|
-
const content = await readFile(filePath, 'utf-8');
|
|
79
|
-
const container = new MemoryContentContainer();
|
|
80
|
-
await container.writeDocument(content);
|
|
81
|
-
const markdownDoc = parseMarkdown(content);
|
|
82
|
-
return { container, markdownDoc };
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Read a standalone Doc JSON file. The container is empty (no media bundled);
|
|
86
|
-
* callers should populate it or set basePath for media resolution.
|
|
87
|
-
*/
|
|
88
|
-
async function readDocJsonFile(filePath) {
|
|
89
|
-
const content = await readFile(filePath, 'utf-8');
|
|
90
|
-
const doc = JSON.parse(content);
|
|
91
|
-
const container = new MemoryContentContainer();
|
|
92
|
-
return { container, markdownDoc: null, doc };
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Known filenames for Doc JSON inside containers and folders.
|
|
96
|
-
* Checked in priority order before falling back to markdown discovery.
|
|
97
|
-
*/
|
|
98
|
-
const DOC_JSON_NAMES = ['doc.json', 'story.json'];
|
|
99
|
-
async function readContainer(filePath) {
|
|
100
|
-
const data = await readFile(filePath);
|
|
101
|
-
const container = await zipToContainer(data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength));
|
|
102
|
-
// Check for Doc JSON inside the container first
|
|
103
|
-
for (const name of DOC_JSON_NAMES) {
|
|
104
|
-
const jsonData = await container.readFile(name);
|
|
105
|
-
if (jsonData) {
|
|
106
|
-
const decoder = new TextDecoder();
|
|
107
|
-
const doc = JSON.parse(decoder.decode(jsonData));
|
|
108
|
-
return { container, markdownDoc: null, doc };
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
const markdown = await container.readDocument();
|
|
112
|
-
if (!markdown) {
|
|
113
|
-
throw new Error(`No markdown document or doc.json found in container: ${filePath}`);
|
|
114
|
-
}
|
|
115
|
-
const markdownDoc = parseMarkdown(markdown);
|
|
116
|
-
return { container, markdownDoc };
|
|
117
|
-
}
|
|
118
|
-
async function readFolder(dirPath) {
|
|
119
|
-
const container = new MemoryContentContainer();
|
|
120
|
-
const files = await walkDir(dirPath);
|
|
121
|
-
for (const relPath of files) {
|
|
122
|
-
const absPath = join(dirPath, relPath);
|
|
123
|
-
const data = await readFile(absPath);
|
|
124
|
-
await container.writeFile(relPath, new Uint8Array(data.buffer, data.byteOffset, data.byteLength), mimeFromExt(relPath));
|
|
125
|
-
}
|
|
126
|
-
// Check for Doc JSON inside the folder first
|
|
127
|
-
for (const name of DOC_JSON_NAMES) {
|
|
128
|
-
const jsonData = await container.readFile(name);
|
|
129
|
-
if (jsonData) {
|
|
130
|
-
const decoder = new TextDecoder();
|
|
131
|
-
const doc = JSON.parse(decoder.decode(jsonData));
|
|
132
|
-
return { container, markdownDoc: null, doc };
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
const markdown = await container.readDocument();
|
|
136
|
-
if (!markdown) {
|
|
137
|
-
throw new Error(`No markdown document or doc.json found in folder: ${dirPath}`);
|
|
138
|
-
}
|
|
139
|
-
const markdownDoc = parseMarkdown(markdown);
|
|
140
|
-
return { container, markdownDoc };
|
|
141
|
-
}
|
|
142
|
-
//# sourceMappingURL=readInput.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"readInput.js","sourceRoot":"","sources":["../../src/util/readInput.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAG3D,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AAUrE,2DAA2D;AAC3D,MAAM,UAAU,GAA2B;IACzC,KAAK,EAAE,eAAe;IACtB,MAAM,EAAE,YAAY;IACpB,OAAO,EAAE,kBAAkB;IAC3B,MAAM,EAAE,YAAY;IACpB,OAAO,EAAE,YAAY;IACrB,MAAM,EAAE,WAAW;IACnB,MAAM,EAAE,WAAW;IACnB,OAAO,EAAE,YAAY;IACrB,MAAM,EAAE,eAAe;IACvB,MAAM,EAAE,YAAY;IACpB,MAAM,EAAE,WAAW;IACnB,MAAM,EAAE,WAAW;IACnB,MAAM,EAAE,WAAW;IACnB,OAAO,EAAE,YAAY;CACtB,CAAC;AAEF,SAAS,WAAW,CAAC,QAAgB;IACnC,OAAO,UAAU,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE,CAAC,IAAI,0BAA0B,CAAC;AAC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