@dogsbay/dita-ot-plugin 0.0.0-stage → 0.2.0-beta.117

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 CHANGED
@@ -1,3 +1,43 @@
1
- # Temporary Holding Version
1
+ # @dogsbay/dita-ot-plugin
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The DITA-OT plugin `com.dogsbay.publish`: publish a DITA map as a dogsbay site with DITA-OT, from a terminal or CI.
4
+
5
+ | Transtype | Produces |
6
+ | --- | --- |
7
+ | `dogsbay` | A dogsbay site project: `content/*.md`, `content/nav.yml`, `dogsbay.config.yml`, `publish-report.md` |
8
+ | `dogsbay-site` | The same project, then the built site (needs the dogsbay CLI and npm) |
9
+
10
+ ## Requirements
11
+
12
+ - DITA-OT 4 (tested with 4.3.5), with Java 17 or later
13
+ - Node.js 20 or later
14
+
15
+ ## Install
16
+
17
+ ```bash
18
+ npx -y @dogsbay/dita-ot-plugin@beta install /path/to/dita-ot-4.3.5
19
+ ```
20
+
21
+ This copies the plugin into DITA-OT's `plugins/` folder and runs `dita install`. Other commands:
22
+
23
+ - `npx -y @dogsbay/dita-ot-plugin@beta zip` prints the path of the plugin zip, for `dita install <zip>`.
24
+ - `npx -y @dogsbay/dita-ot-plugin@beta path` prints the path of the plugin folder.
25
+
26
+ DITA-OT can also install the zip from npm's CDN: `dita install https://cdn.jsdelivr.net/npm/@dogsbay/dita-ot-plugin@<version>/dist/com.dogsbay.publish-<version>.zip`.
27
+
28
+ ## Publish
29
+
30
+ ```bash
31
+ dita -i guide.ditamap -f dogsbay -o site
32
+ dita -i guide.ditamap -f dogsbay --args.filter=release.ditaval --args.gen.task.lbl=YES -o site
33
+ ```
34
+
35
+ Parameters and details: the plugin's README (`dist/com.dogsbay.publish/README.md`), and "Publishing DITA" in the dogsbay docs.
36
+
37
+ ## Development
38
+
39
+ - `pnpm turbo build --filter=@dogsbay/dita-ot-plugin...` builds the plugin and the packages its converter comes from (`plugin/` sources, the converter bundled from `packages/dita-publish`) into `dist/`, with the zip and its SHA-256.
40
+ - `pnpm --filter @dogsbay/dita-ot-plugin test` checks the zip and the installer.
41
+ - `scripts/smoke.sh` downloads DITA-OT, installs the plugin (with `dita install <zip>` and with this package's installer) and publishes a sample, as CI would (`--from-npm <version>` tests a release).
42
+ - `tools/` compares the plugin's output with DITA-OT's `html5` output (see `tools/README.md`).
43
+ - Developer notes: `docs-dev/dita-ot-plugin.md`. Plan: `plans/dita-ot-plugin-release.md`.
package/bin/cli.js ADDED
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * dogsbay-dita-ot-plugin: install the DITA-OT plugin com.dogsbay.publish.
4
+ *
5
+ * npx -y @dogsbay/dita-ot-plugin@beta install <dita-ot-dir> [--no-integrate]
6
+ * npx -y @dogsbay/dita-ot-plugin@beta zip prints the plugin zip's path
7
+ * npx -y @dogsbay/dita-ot-plugin@beta path prints the plugin folder's path
8
+ */
9
+ import { installPlugin, pluginDir, pluginZip, version } from "../lib/index.js";
10
+
11
+ const [command, ...rest] = process.argv.slice(2);
12
+ const usage = `Usage: dogsbay-dita-ot-plugin <command>
13
+
14
+ Commands:
15
+ install <dita-ot-dir> [--no-integrate] Copy com.dogsbay.publish ${version} into DITA-OT's plugins/
16
+ and run its "dita install"
17
+ zip Print the path of the plugin zip (for "dita install <zip>")
18
+ path Print the path of the plugin folder
19
+ `;
20
+
21
+ try {
22
+ const unknown = rest.filter((a) => a.startsWith("-") && !(command === "install" && a === "--no-integrate"));
23
+ if (unknown.length > 0) throw new Error(`Unknown option: ${unknown.join(" ")}\n\n${usage}`);
24
+ if (command === "install") {
25
+ const ditaOt = rest.find((a) => !a.startsWith("--"));
26
+ if (!ditaOt) throw new Error(`install needs the DITA-OT folder\n\n${usage}`);
27
+ const { target, integrated } = installPlugin(ditaOt, { integrate: !rest.includes("--no-integrate") });
28
+ console.log(`Installed com.dogsbay.publish ${version} in ${target}${integrated ? "" : " (not integrated: run dita install)"}`);
29
+ } else if (command === "zip") {
30
+ console.log(pluginZip);
31
+ } else if (command === "path") {
32
+ console.log(pluginDir);
33
+ } else if (command === undefined || command === "--help" || command === "-h") {
34
+ console.log(usage);
35
+ } else {
36
+ throw new Error(`Unknown command: ${command}\n\n${usage}`);
37
+ }
38
+ } catch (error) {
39
+ console.error(error instanceof Error ? error.message : String(error));
40
+ process.exitCode = 1;
41
+ }
@@ -0,0 +1,67 @@
1
+ # com.dogsbay.publish
2
+
3
+ A DITA-OT plugin that publishes a DITA deliverable as a dogsbay site. DITA stays the source; each publish regenerates the site's `content/` folder (pages of topics removed from the map do not survive), and keeps an existing `dogsbay.config.yml`.
4
+
5
+ | Transtype | Produces |
6
+ | --- | --- |
7
+ | `dogsbay` | A dogsbay site project: `content/*.md`, `content/nav.yml`, `content/index.md`, `dogsbay.config.yml` (when missing), and `publish-report.md` |
8
+ | `dogsbay-site` | `dogsbay`, then the built site in `astro/dist`: `dogsbay site init --scaffold-only` when the output folder has no Astro project yet, `dogsbay site build`, a package install (unless `dogsbay.site.install=no`), and the Astro build with Pagefind search |
9
+
10
+ Conditions are resolved by DITA-OT with `--args.filter`, as for any output; each run is one deliverable.
11
+
12
+ DogsBay XML ships this plugin in its built-in DITA-OT; see the editor's `docs/dita-publishing.md`.
13
+
14
+ ## Requirements
15
+
16
+ - DITA-OT 4 (tested with 4.3.5)
17
+ - Node.js 20 or later
18
+ - `dogsbay-site` only: the dogsbay CLI and npm (or pnpm or yarn), with network access for the package install
19
+
20
+ The converter itself is in the plugin: `converter/publish-dita.mjs` is dogsbay's `publish-dita` command bundled into one file, so `dogsbay` needs no dogsbay CLI install. `converter/VERSION` records the dogsbay version and commit it was built from.
21
+
22
+ ## Install
23
+
24
+ With Node.js (from npm, the same package that builds this plugin):
25
+
26
+ ```bash
27
+ npx -y @dogsbay/dita-ot-plugin@beta install <dita-ot>
28
+ ```
29
+
30
+ With DITA-OT's installer, from the plugin zip:
31
+
32
+ ```bash
33
+ <dita-ot>/bin/dita install https://cdn.jsdelivr.net/npm/@dogsbay/dita-ot-plugin@<version>/dist/com.dogsbay.publish-<version>.zip
34
+ ```
35
+
36
+ The plugin's own version in `plugin.xml` is DITA-OT's form of the dogsbay version: `0.2.0-beta.116` becomes `0.2.0.beta-116`, since DITA-OT allows no dots in a version qualifier.
37
+
38
+ ## Use
39
+
40
+ ```bash
41
+ dita -i guide.ditamap -f dogsbay -o site
42
+ dita -i guide.ditamap -f dogsbay --dogsbay.node=/usr/local/bin/node -o site
43
+ dita -i guide.ditamap -f dogsbay-site --dogsbay.cli=/path/to/dogsbay/packages/cli/bin/cli.js -o site
44
+ dita -i guide.ditamap -f dogsbay --dogsbay.converter=/path/to/dogsbay/packages/dita-publish/bin/cli.js -o site
45
+ ```
46
+
47
+ | Parameter | Default | Meaning |
48
+ | --- | --- | --- |
49
+ | `dogsbay.node` | `node` | The Node.js executable that runs a script converter or `dogsbay.cli`: a command on the PATH or a path |
50
+ | `dogsbay.cli` | `dogsbay` | The dogsbay CLI: a command on the PATH (`dogsbay.cmd` on Windows), or an absolute path to a `.js`, `.mjs` or `.cjs` bin script (run with `dogsbay.node`). `dogsbay-site` uses it for `site init` and `site build` |
51
+ | `dogsbay.converter` | the plugin's `converter/publish-dita.mjs` | The `publish-dita` converter, instead of the plugin's own: a command (`dogsbay-dita`, from `npm i -g @dogsbay/dita-publish`) or a script path, such as the dogsbay repo's `packages/dita-publish/bin/cli.js` |
52
+ | `dogsbay.site.install` | `yes` | `dogsbay-site`: install the site's packages before building |
53
+ | `dogsbay.site.npm` | `npm` | `dogsbay-site`: the package manager that installs and builds the site (`npm`, `pnpm`, `yarn`) |
54
+ | `dogsbay.family.links` | `no` | `yes` adds the parent, previous and next topic links after each topic, as `html5` has them (a dogsbay site has previous/next buttons and a sidebar instead) |
55
+ | `dogsbay.numbering` | `yes` | Number titled tables and figures ("Table 1. ", "Figure 1. ") per topic, as `html5` does, with DITA-OT's localized words |
56
+ | `args.gen.task.lbl` | `NO` | DITA-OT's parameter; `YES` adds task section headings, as in `html5` |
57
+ | `args.rellinks` | all | DITA-OT's parameter; which related links preprocessing keeps |
58
+
59
+ ## How it works
60
+
61
+ `build_dogsbay.xml` adds the target `dita2dogsbay`, which depends on DITA-OT's `build-init` and `preprocess2` (the same preprocessing as `html5`), then runs the converter, `publish-dita ${dita.temp.dir} -o ${output.dir}`. The converter reads the preprocessed temp files before DITA-OT cleans them up.
62
+
63
+ The plugin is built and released from the dogsbay repo, `packages/dita-ot-plugin` (`@dogsbay/dita-ot-plugin` on npm). The converter's source is `@dogsbay/dita-publish` (`publishDitaTemp`, over `@dogsbay/format-dita`), bundled with its `bundle:publish-dita`. Developer notes: `docs-dev/dita-ot-plugin.md` and `docs-dev/format-dita-publish.md` in the dogsbay repo.
64
+
65
+ ## Checking the output
66
+
67
+ `packages/dita-ot-plugin/tools/compare_outputs.py` in the dogsbay repo compares a DITA-OT `html5` build with the built dogsbay site. See the `tools/README.md` next to it.
@@ -0,0 +1,149 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project name="com.dogsbay.publish" xmlns:if="ant:if" xmlns:unless="ant:unless">
3
+
4
+ <target name="dogsbay.init">
5
+ <dirname property="dogsbay.plugin.dir" file="${ant.file.com.dogsbay.publish}"/>
6
+ <!-- The converter: dogsbay.converter when given (for development, the dogsbay repo's
7
+ packages/dita-publish/bin/cli.js); otherwise the single-file bundle of `publish-dita`
8
+ the plugin carries; otherwise `dogsbay-dita` on the PATH. The published dogsbay CLI
9
+ has no publish-dita. dogsbay-site also needs the dogsbay CLI (dogsbay.cli, default
10
+ `dogsbay`) for site init and site build. -->
11
+ <condition property="dogsbay.converter" value="${dogsbay.plugin.dir}/converter/publish-dita.mjs">
12
+ <available file="${dogsbay.plugin.dir}/converter/publish-dita.mjs"/>
13
+ </condition>
14
+ <property name="dogsbay.converter" value="dogsbay-dita"/>
15
+ <property name="dogsbay.cli" value="dogsbay"/>
16
+ <property name="dogsbay.node" value="node"/>
17
+ <property name="dogsbay.site.install" value="yes"/>
18
+ <property name="dogsbay.site.npm" value="npm"/>
19
+ <condition property="dogsbay.site.npm.command" value="${dogsbay.site.npm}.cmd" else="${dogsbay.site.npm}">
20
+ <and>
21
+ <os family="windows"/>
22
+ <not><matches string="${dogsbay.site.npm}" pattern="\.(cmd|bat|exe)$"/></not>
23
+ </and>
24
+ </condition>
25
+ <dogsbay-program name="converter"/>
26
+ <dogsbay-program name="cli"/>
27
+ <condition property="dogsbay.no.numbering">
28
+ <equals arg1="${dogsbay.numbering}" arg2="no" casesensitive="false"/>
29
+ </condition>
30
+ <condition property="dogsbay.family.links.on">
31
+ <equals arg1="${dogsbay.family.links}" arg2="yes" casesensitive="false"/>
32
+ </condition>
33
+ <condition property="dogsbay.task.labels">
34
+ <equals arg1="${args.gen.task.lbl}" arg2="YES" casesensitive="false"/>
35
+ </condition>
36
+ <condition property="dogsbay.site.do.install">
37
+ <equals arg1="${dogsbay.site.install}" arg2="yes" casesensitive="false"/>
38
+ </condition>
39
+ </target>
40
+
41
+ <!-- How to run dogsbay.@{name}: a script (dogsbay.@{name}.is.script, run with dogsbay.node) or a
42
+ command (dogsbay.@{name}.command) -->
43
+ <macrodef name="dogsbay-program">
44
+ <attribute name="name"/>
45
+ <sequential>
46
+ <condition property="dogsbay.@{name}.is.script">
47
+ <matches string="${dogsbay.@{name}}" pattern="\.[cm]?js$"/>
48
+ </condition>
49
+ <!-- A relative script path would resolve against DITA-OT's folders, not the directory
50
+ dita was run from (which Ant cannot see), so it must be absolute -->
51
+ <fail message="dogsbay.@{name} must be an absolute path to the script: ${dogsbay.@{name}}">
52
+ <condition>
53
+ <and>
54
+ <isset property="dogsbay.@{name}.is.script"/>
55
+ <not><matches string="${dogsbay.@{name}}" pattern="^(/|[A-Za-z]:[\\/]|\\\\)"/></not>
56
+ </and>
57
+ </condition>
58
+ </fail>
59
+ <!-- On Windows an npm-installed command is a .cmd shim, which exec does not find by name -->
60
+ <condition property="dogsbay.@{name}.command" value="${dogsbay.@{name}}.cmd" else="${dogsbay.@{name}}">
61
+ <and>
62
+ <os family="windows"/>
63
+ <not><matches string="${dogsbay.@{name}}" pattern="\.(cmd|bat|exe)$"/></not>
64
+ </and>
65
+ </condition>
66
+ </sequential>
67
+ </macrodef>
68
+
69
+ <!-- Runs dogsbay.@{program} (converter or cli) with the nested args -->
70
+ <macrodef name="dogsbay-run">
71
+ <attribute name="program"/>
72
+ <attribute name="dir" default="${output.dir}"/>
73
+ <element name="run-args" implicit="true"/>
74
+ <sequential>
75
+ <exec executable="${dogsbay.node}" dir="@{dir}" failonerror="true" searchpath="true" if:set="dogsbay.@{program}.is.script">
76
+ <arg file="${dogsbay.@{program}}"/>
77
+ <run-args/>
78
+ </exec>
79
+ <exec executable="${dogsbay.@{program}.command}" dir="@{dir}" failonerror="true" searchpath="true" unless:set="dogsbay.@{program}.is.script">
80
+ <run-args/>
81
+ </exec>
82
+ </sequential>
83
+ </macrodef>
84
+
85
+ <!-- Site project (Markdown, navigation, config) from DITA-OT's preprocessed temp folder. -->
86
+ <target name="dita2dogsbay" depends="dogsbay.init, build-init, preprocess2, dogsbay.convert"/>
87
+
88
+ <target name="dogsbay.convert">
89
+ <echo level="info">publish-dita ${dita.temp.dir} -o ${output.dir} (${dogsbay.converter})</echo>
90
+ <mkdir dir="${output.dir}"/>
91
+ <dogsbay-run program="converter">
92
+ <arg value="publish-dita"/>
93
+ <arg file="${dita.temp.dir}"/>
94
+ <arg value="-o"/>
95
+ <arg file="${output.dir}"/>
96
+ <arg value="--report"/>
97
+ <arg file="${output.dir}/publish-report.md"/>
98
+ <arg value="--task-labels" if:set="dogsbay.task.labels"/>
99
+ <arg value="--family-links" if:set="dogsbay.family.links.on"/>
100
+ <arg value="--no-numbering" if:set="dogsbay.no.numbering"/>
101
+ <arg value="--dita-dir"/>
102
+ <arg file="${dita.dir}"/>
103
+ <!-- build-init always sets default.language (en); topics' xml:lang still wins -->
104
+ <arg value="--default-language" if:set="default.language"/>
105
+ <arg value="${default.language}" if:set="default.language"/>
106
+ </dogsbay-run>
107
+ </target>
108
+
109
+ <!-- The built site: scaffold when missing, dogsbay site build, then the Astro build with Pagefind. -->
110
+ <target name="dita2dogsbay-site" depends="dita2dogsbay, dogsbay.site"/>
111
+
112
+ <!-- The site steps are separate targets, so a build can time each one -->
113
+ <target name="dogsbay.site" depends="dogsbay.site.init, dogsbay.site.generate, dogsbay.site.install, dogsbay.site.astro"/>
114
+
115
+ <!-- Scaffold the Astro project when the output folder has none yet -->
116
+ <target name="dogsbay.site.init">
117
+ <available file="${output.dir}/astro/package.json" property="dogsbay.site.scaffolded"/>
118
+ <dogsbay-run program="cli" unless:set="dogsbay.site.scaffolded">
119
+ <arg value="site"/>
120
+ <arg value="init"/>
121
+ <arg value="."/>
122
+ <arg value="--yes"/>
123
+ <arg value="--scaffold-only"/>
124
+ </dogsbay-run>
125
+ </target>
126
+
127
+ <!-- dogsbay site build: the Astro source from content/ -->
128
+ <target name="dogsbay.site.generate">
129
+ <dogsbay-run program="cli">
130
+ <arg value="site"/>
131
+ <arg value="build"/>
132
+ </dogsbay-run>
133
+ </target>
134
+
135
+ <!-- The site's package install (dogsbay.site.install=yes, the default) -->
136
+ <target name="dogsbay.site.install" if="dogsbay.site.do.install">
137
+ <exec executable="${dogsbay.site.npm.command}" dir="${output.dir}/astro" failonerror="true" searchpath="true">
138
+ <arg value="install"/>
139
+ </exec>
140
+ </target>
141
+
142
+ <!-- The Astro build and the Pagefind search index -->
143
+ <target name="dogsbay.site.astro">
144
+ <exec executable="${dogsbay.site.npm.command}" dir="${output.dir}/astro" failonerror="true" searchpath="true">
145
+ <arg value="run"/>
146
+ <arg value="build"/>
147
+ </exec>
148
+ </target>
149
+ </project>
@@ -0,0 +1 @@
1
+ 0.2.0-beta.117