@markii/pack-build 0.17.0-next.4 → 0.17.0-next.5
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 +73 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -7,4 +7,77 @@ esbuild's WebAssembly build, writes the prebuilt form, or produces a
|
|
|
7
7
|
toolchain, for authoring hosts and pack build scripts; an app that only
|
|
8
8
|
installs prebuilt packs does not need it. Node only.
|
|
9
9
|
|
|
10
|
+
## Entry points
|
|
11
|
+
|
|
12
|
+
- `buildPackRegistrationScript(pack, cacheDir, options?)` compiles the
|
|
13
|
+
pack's React sources into one registration script, `webview.js`, and an
|
|
14
|
+
optional stylesheet. It caches the result under `cacheDir`, which must
|
|
15
|
+
be a folder you own and never the pack's own folder.
|
|
16
|
+
- `buildPackTerminalScript(pack, cacheDir, options?)` does the same for
|
|
17
|
+
the pack's `ansi` sources and produces `terminal.js`. It reports
|
|
18
|
+
`skipped` when no component names an `ansi` source.
|
|
19
|
+
- `exportPackArchive({ pack, cacheDir, build, buildTerminal?, fs })`
|
|
20
|
+
builds through those functions and returns the bytes of a
|
|
21
|
+
`<name>-<version>.mkp` archive. It writes nothing itself.
|
|
22
|
+
- `exportPack` writes the prebuilt form into a destination folder instead
|
|
23
|
+
of an archive.
|
|
24
|
+
- `lintPackCss` returns the class-prefix and color warnings for a
|
|
25
|
+
stylesheet.
|
|
26
|
+
|
|
27
|
+
Every build function returns an outcome and never throws. The outcome is
|
|
28
|
+
`built`, `failed` with a reason, or `skipped`.
|
|
29
|
+
|
|
30
|
+
## The pack source
|
|
31
|
+
|
|
32
|
+
Each function takes a pack as `discoverPacks` from `@markii/host`
|
|
33
|
+
returns it. A discovered pack carries its `folder`, its parsed
|
|
34
|
+
`manifest`, the `manifestText`, the absolute `componentPaths` of its
|
|
35
|
+
React sources, `componentPathsByEngine` for other engines, and its
|
|
36
|
+
`scriptsDir` for shared Lua. `discoverPacks(folders, readFile,
|
|
37
|
+
listDirectory)` takes the folders to scan and two read functions.
|
|
38
|
+
`createNodePackDiscoveryIo()` from `@markii/host/node` supplies both.
|
|
39
|
+
|
|
40
|
+
## Example
|
|
41
|
+
|
|
42
|
+
This script discovers the packs in a folder and writes one `.mkp` archive
|
|
43
|
+
for each.
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
import { mkdir, readdir, readFile, writeFile } from 'node:fs/promises';
|
|
47
|
+
import { join } from 'node:path';
|
|
48
|
+
import { discoverPacks } from '@markii/host';
|
|
49
|
+
import { createNodePackDiscoveryIo } from '@markii/host/node';
|
|
50
|
+
import {
|
|
51
|
+
buildPackRegistrationScript,
|
|
52
|
+
buildPackTerminalScript,
|
|
53
|
+
exportPackArchive,
|
|
54
|
+
} from '@markii/pack-build';
|
|
55
|
+
|
|
56
|
+
const cacheDir = join(process.cwd(), '.pack-cache');
|
|
57
|
+
await mkdir(cacheDir, { recursive: true });
|
|
58
|
+
|
|
59
|
+
const io = createNodePackDiscoveryIo();
|
|
60
|
+
const { packs, skipped } = await discoverPacks(
|
|
61
|
+
['./packs'],
|
|
62
|
+
io.readFile,
|
|
63
|
+
io.listDirectory,
|
|
64
|
+
);
|
|
65
|
+
for (const folder of skipped) console.warn(folder);
|
|
66
|
+
|
|
67
|
+
for (const pack of packs) {
|
|
68
|
+
const result = await exportPackArchive({
|
|
69
|
+
pack,
|
|
70
|
+
cacheDir,
|
|
71
|
+
build: buildPackRegistrationScript,
|
|
72
|
+
buildTerminal: buildPackTerminalScript,
|
|
73
|
+
fs: {
|
|
74
|
+
readFile: (path) => readFile(path, 'utf8').catch(() => undefined),
|
|
75
|
+
listDirectory: (path) => readdir(path).catch(() => []),
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
if (result.kind === 'failed') throw new Error(result.reason);
|
|
79
|
+
await writeFile(result.fileName, result.bytes);
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
10
83
|
See `docs/packs.md` in the repository for the pack contract.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markii/pack-build",
|
|
3
|
-
"version": "0.17.0-next.
|
|
3
|
+
"version": "0.17.0-next.5",
|
|
4
4
|
"description": "Pack compilation for Markii authoring hosts: compiles a pack's component sources (and imported CSS) with esbuild-wasm's in-process path, and writes the prebuilt form or a .mkp archive. Node only.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"markdown",
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"build:dist": "rm -rf dist && tsc -p tsconfig.build.json"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@markii/host": "^0.17.0-next.
|
|
43
|
-
"@markii/pack": "^0.17.0-next.
|
|
42
|
+
"@markii/host": "^0.17.0-next.5",
|
|
43
|
+
"@markii/pack": "^0.17.0-next.5",
|
|
44
44
|
"esbuild-wasm": "^0.28.2",
|
|
45
45
|
"fflate": "^0.8.3"
|
|
46
46
|
},
|