create-asciidoc-multi-book-workspace 0.1.0 → 0.1.1
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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.1 - 2026-06-06
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- Add maintainer preview commands for rebuilding the default sample workspace locally.
|
|
8
|
+
- Keep routine template previews fast by using the maintainer AsciiDoc toolchain, while `preview:fresh` still verifies the generated workspace's own dependency installation.
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- Use `build/template-preview/workspace/build/html/index.html` as the single preview HTML output path.
|
|
13
|
+
- Keep preview source and tests out of the npm package boundary while publishing the compiled script referenced by maintainer commands.
|
|
14
|
+
|
|
3
15
|
## 0.1.0 - 2026-06-04
|
|
4
16
|
|
|
5
17
|
### Added
|
package/README.md
CHANGED
|
@@ -19,6 +19,10 @@ npm users can run:
|
|
|
19
19
|
npm create asciidoc-multi-book-workspace@latest my-books
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
+
```bash
|
|
23
|
+
npx create-asciidoc-multi-book-workspace@latest my-books
|
|
24
|
+
```
|
|
25
|
+
|
|
22
26
|
The generated workspace contains:
|
|
23
27
|
|
|
24
28
|
```text
|
|
@@ -75,6 +79,8 @@ The seven sample books live only under `templates/default-workspace/books/`.
|
|
|
75
79
|
```bash
|
|
76
80
|
pnpm install
|
|
77
81
|
pnpm run build
|
|
82
|
+
pnpm run preview:build
|
|
83
|
+
pnpm run preview:fresh
|
|
78
84
|
pnpm run test
|
|
79
85
|
pnpm run check
|
|
80
86
|
pnpm pack --dry-run
|
|
@@ -82,6 +88,14 @@ pnpm pack --dry-run
|
|
|
82
88
|
|
|
83
89
|
`pnpm run check` builds TypeScript, runs maintainer tests, and checks the npm package boundary.
|
|
84
90
|
|
|
91
|
+
`pnpm run preview:build` updates a generated sample workspace under `build/template-preview/workspace`,
|
|
92
|
+
builds the sample books with the maintainer repository's installed AsciiDoc toolchain, and writes HTML to
|
|
93
|
+
`build/template-preview/workspace/build/html/index.html`.
|
|
94
|
+
|
|
95
|
+
`pnpm run preview:fresh` recompiles the maintainer runtime and recreates the preview workspace from scratch.
|
|
96
|
+
It installs the generated workspace's own dependencies, so use it after changing `src/`, dependency declarations,
|
|
97
|
+
or the initializer contract. Use `pnpm run preview:build` for normal template edits under `templates/default-workspace/`.
|
|
98
|
+
|
|
85
99
|
## Releases
|
|
86
100
|
|
|
87
101
|
Release Please manages release pull requests and `CHANGELOG.md`.
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { mkdir, readFile, rm, stat, writeFile } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { spawn } from "node:child_process";
|
|
6
|
+
import { initWorkspace } from "./init-workspace.js";
|
|
7
|
+
const sourceDir = path.dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
const packageRoot = path.resolve(sourceDir, "..");
|
|
9
|
+
const defaultPreviewRoot = path.join(packageRoot, "build", "template-preview");
|
|
10
|
+
const templateWorkspacePaths = ["README.md", "catalog.adoc", "package.json", ".gitignore", "books", "shared", "tools"];
|
|
11
|
+
async function exists(filePath) {
|
|
12
|
+
try {
|
|
13
|
+
await stat(filePath);
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
async function defaultRunCommand(command, args, options) {
|
|
21
|
+
await new Promise((resolve, reject) => {
|
|
22
|
+
const child = spawn(command, args, {
|
|
23
|
+
cwd: options.cwd,
|
|
24
|
+
shell: process.platform === "win32",
|
|
25
|
+
stdio: "inherit"
|
|
26
|
+
});
|
|
27
|
+
child.on("error", reject);
|
|
28
|
+
child.on("exit", (code) => {
|
|
29
|
+
if (code === 0) {
|
|
30
|
+
resolve();
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
reject(new Error(`${command} ${args.join(" ")} exited with code ${code ?? "unknown"}`));
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
export async function buildTemplatePreview(options = {}) {
|
|
38
|
+
const previewRoot = path.resolve(options.previewRoot ?? defaultPreviewRoot);
|
|
39
|
+
const workspaceDir = path.join(previewRoot, "workspace");
|
|
40
|
+
const htmlDir = path.join(workspaceDir, "build", "html");
|
|
41
|
+
const legacyHtmlMirrorDir = path.join(previewRoot, "html");
|
|
42
|
+
const installStamp = path.join(previewRoot, ".installed-package.json");
|
|
43
|
+
const runCommand = options.runCommand ?? defaultRunCommand;
|
|
44
|
+
const installDependencies = options.install === true || options.fresh === true;
|
|
45
|
+
if (options.fresh)
|
|
46
|
+
await rm(previewRoot, { force: true, recursive: true });
|
|
47
|
+
await mkdir(previewRoot, { recursive: true });
|
|
48
|
+
await mkdir(workspaceDir, { recursive: true });
|
|
49
|
+
for (const name of templateWorkspacePaths) {
|
|
50
|
+
await rm(path.join(workspaceDir, name), { force: true, recursive: true });
|
|
51
|
+
}
|
|
52
|
+
await initWorkspace({ targetDir: workspaceDir, force: true });
|
|
53
|
+
if (installDependencies) {
|
|
54
|
+
const packageJson = await readFile(path.join(workspaceDir, "package.json"), "utf8");
|
|
55
|
+
const installedPackageJson = await exists(installStamp) ? await readFile(installStamp, "utf8") : "";
|
|
56
|
+
if (!await exists(path.join(workspaceDir, "node_modules")) ||
|
|
57
|
+
!await exists(path.join(workspaceDir, "pnpm-lock.yaml")) ||
|
|
58
|
+
installedPackageJson !== packageJson) {
|
|
59
|
+
await runCommand("pnpm", ["install", "--ignore-workspace"], { cwd: workspaceDir });
|
|
60
|
+
await writeFile(installStamp, packageJson, "utf8");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (installDependencies) {
|
|
64
|
+
await runCommand("pnpm", ["run", "build"], { cwd: workspaceDir });
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
await runCommand("node", ["tools/adoc-books.mjs", "build"], { cwd: workspaceDir });
|
|
68
|
+
}
|
|
69
|
+
await rm(legacyHtmlMirrorDir, { force: true, recursive: true });
|
|
70
|
+
return { previewRoot, workspaceDir, htmlDir };
|
|
71
|
+
}
|
|
72
|
+
async function main() {
|
|
73
|
+
const fresh = process.argv.includes("--fresh");
|
|
74
|
+
const result = await buildTemplatePreview({
|
|
75
|
+
fresh,
|
|
76
|
+
install: fresh || process.argv.includes("--install")
|
|
77
|
+
});
|
|
78
|
+
const displayIndex = path.relative(process.cwd(), path.join(result.htmlDir, "index.html")) || "index.html";
|
|
79
|
+
console.log(`Built template preview at ${displayIndex}`);
|
|
80
|
+
}
|
|
81
|
+
const executedPath = process.argv[1] ? path.resolve(process.argv[1]) : "";
|
|
82
|
+
const modulePath = fileURLToPath(import.meta.url);
|
|
83
|
+
if (executedPath === modulePath) {
|
|
84
|
+
main().catch((error) => {
|
|
85
|
+
console.error(error instanceof Error ? error.message : error);
|
|
86
|
+
process.exitCode = 1;
|
|
87
|
+
});
|
|
88
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-asciidoc-multi-book-workspace",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Create a complete AsciiDoc multi-book workspace.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -29,7 +29,11 @@
|
|
|
29
29
|
"create-asciidoc-multi-book-workspace": "dist/create.js"
|
|
30
30
|
},
|
|
31
31
|
"files": [
|
|
32
|
-
"dist/",
|
|
32
|
+
"dist/build-template-preview.js",
|
|
33
|
+
"dist/create.js",
|
|
34
|
+
"dist/init-workspace.js",
|
|
35
|
+
"dist/runtime/adoc-books.mjs",
|
|
36
|
+
"dist/template-manifest.js",
|
|
33
37
|
"templates/",
|
|
34
38
|
"README.md",
|
|
35
39
|
"CHANGELOG.md",
|
|
@@ -47,6 +51,8 @@
|
|
|
47
51
|
},
|
|
48
52
|
"scripts": {
|
|
49
53
|
"build": "tsc -p tsconfig.json",
|
|
54
|
+
"preview:build": "node dist/build-template-preview.js",
|
|
55
|
+
"preview:fresh": "pnpm run build && node dist/build-template-preview.js --fresh",
|
|
50
56
|
"test": "pnpm run build && node --test test/*.test.mjs",
|
|
51
57
|
"pack:check": "pnpm pack --dry-run",
|
|
52
58
|
"check": "pnpm run test && pnpm run pack:check",
|
|
@@ -4,15 +4,21 @@
|
|
|
4
4
|
|===
|
|
5
5
|
|写法 |含义
|
|
6
6
|
|
|
7
|
-
|`=
|
|
8
|
-
|
|
|
9
|
-
|
|
10
|
-
|`= 第一部`
|
|
11
|
-
|book doctype 中的 part。
|
|
7
|
+
|`= 书名或文档名`
|
|
8
|
+
|Document title(文档标题,Level 0)。在 book 文档类型中也可作为 Part(部)。
|
|
12
9
|
|
|
13
10
|
|`== 章`
|
|
14
|
-
|
|
|
11
|
+
|Level 1 Section(一级章节)。在 book 文档类型中通常作为 Chapter(章)。
|
|
15
12
|
|
|
16
13
|
|`=== 节`
|
|
17
|
-
|
|
|
14
|
+
|Level 2 Section(二级章节 / 节)。
|
|
15
|
+
|
|
16
|
+
|`==== 小节`
|
|
17
|
+
|Level 3 Section(三级章节 / 小节)。
|
|
18
|
+
|
|
19
|
+
|`===== 次小节`
|
|
20
|
+
|Level 4 Section(四级章节)。
|
|
21
|
+
|
|
22
|
+
|`====== 最底层级`
|
|
23
|
+
|Level 5 Section(五级章节)。AsciiDoc 支持的最深层级。
|
|
18
24
|
|===
|