pterodoc 0.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/CHANGELOG.md +126 -0
- package/LICENCE.md +10 -0
- package/README.md +128 -0
- package/bin/pterodoc.mjs +5 -0
- package/lib/chunks/target-BC_VOAlJ.js +38 -0
- package/lib/chunks/target-BC_VOAlJ.js.map +1 -0
- package/lib/cli/args.d.ts +26 -0
- package/lib/cli/args.d.ts.map +1 -0
- package/lib/cli/reporter.d.ts +23 -0
- package/lib/cli/reporter.d.ts.map +1 -0
- package/lib/cli/run.d.ts +9 -0
- package/lib/cli/run.d.ts.map +1 -0
- package/lib/cli/run.js +447 -0
- package/lib/cli/run.js.map +1 -0
- package/lib/index.d.ts +29 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +8 -0
- package/lib/index.js.map +1 -0
- package/lib/plugin/index.d.ts +47 -0
- package/lib/plugin/index.d.ts.map +1 -0
- package/lib/plugin/index.js +57 -0
- package/lib/plugin/index.js.map +1 -0
- package/lib/target.d.ts +19 -0
- package/lib/target.d.ts.map +1 -0
- package/package.json +73 -0
- package/src/cli/args.ts +159 -0
- package/src/cli/reporter.ts +64 -0
- package/src/cli/run.ts +308 -0
- package/src/index.ts +37 -0
- package/src/plugin/index.ts +97 -0
- package/src/target.ts +37 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Docusaurus plugin.
|
|
3
|
+
*
|
|
4
|
+
* Optional: the command line is the usual way to publish. This exists for a
|
|
5
|
+
* site that would rather publish as part of its build, and it costs nothing
|
|
6
|
+
* extra, because a build has already loaded everything the model needs.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { toSiteModel } from '@pterodoc/docusaurus';
|
|
10
|
+
import type { LoadedSite } from '@pterodoc/docusaurus';
|
|
11
|
+
import { createMemoryReader } from '@pterodoc/core/model';
|
|
12
|
+
import { loadConfig } from '@pterodoc/core';
|
|
13
|
+
import { resolveTarget } from '../target';
|
|
14
|
+
import type { Target } from '@pterodoc/core/target';
|
|
15
|
+
import { runSync } from '@pterodoc/core';
|
|
16
|
+
|
|
17
|
+
/** Options the plugin accepts in `docusaurus.config`. */
|
|
18
|
+
export interface PterodocPluginOptions {
|
|
19
|
+
/** Path to the pterodoc config; discovered beside the site when unset. */
|
|
20
|
+
config?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Publish at the end of `docusaurus build`.
|
|
23
|
+
*
|
|
24
|
+
* Off by default: building a site should not also change another one.
|
|
25
|
+
*/
|
|
26
|
+
runOnBuild?: boolean;
|
|
27
|
+
/** Plan and render without writing, even when `runOnBuild` is set. */
|
|
28
|
+
dryRun?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Publish somewhere other than the configured target.
|
|
31
|
+
*
|
|
32
|
+
* An escape hatch for a test or a second target; the configured one is built
|
|
33
|
+
* when this is absent.
|
|
34
|
+
*/
|
|
35
|
+
target?: Target;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** The part of the Docusaurus plugin contract this uses. */
|
|
39
|
+
interface PluginLike {
|
|
40
|
+
name: string;
|
|
41
|
+
postBuild?: (props: LoadedSite['props']) => Promise<void>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** The part of the Docusaurus context this reads. */
|
|
45
|
+
interface ContextLike {
|
|
46
|
+
siteDir: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Create the plugin.
|
|
51
|
+
*
|
|
52
|
+
* @param context The Docusaurus load context.
|
|
53
|
+
* @param options Plugin options from `docusaurus.config`.
|
|
54
|
+
*/
|
|
55
|
+
export default function pterodocPlugin(
|
|
56
|
+
context: ContextLike,
|
|
57
|
+
options: PterodocPluginOptions = {},
|
|
58
|
+
): PluginLike {
|
|
59
|
+
return {
|
|
60
|
+
name: 'pterodoc',
|
|
61
|
+
|
|
62
|
+
async postBuild(props): Promise<void> {
|
|
63
|
+
if (options.runOnBuild !== true) return;
|
|
64
|
+
|
|
65
|
+
const config = await loadConfig({
|
|
66
|
+
siteDir: context.siteDir,
|
|
67
|
+
config: options.config,
|
|
68
|
+
dryRun: options.dryRun,
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// The build has already run every plugin's content lifecycle, so the
|
|
72
|
+
// model is right here; there is nothing to load a second time.
|
|
73
|
+
const model = toSiteModel({ props }, {
|
|
74
|
+
siteDir: props.siteDir,
|
|
75
|
+
instances: config.instances,
|
|
76
|
+
versions: config.versions,
|
|
77
|
+
includeDrafts: config.includeDrafts,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
const target = options.target ?? resolveTarget(config);
|
|
81
|
+
|
|
82
|
+
const { plan } = await runSync(config, {
|
|
83
|
+
reader: createMemoryReader(model),
|
|
84
|
+
target,
|
|
85
|
+
renderOnly: config.offline,
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
const counts = Object.entries(plan.summary)
|
|
89
|
+
.map(([op, count]) => `${count} ${op}`)
|
|
90
|
+
.join(', ');
|
|
91
|
+
process.stdout.write(`[pterodoc] ${counts || 'nothing to do'}\n`);
|
|
92
|
+
for (const issue of plan.issues.filter((entry) => entry.severity !== 'info')) {
|
|
93
|
+
process.stdout.write(`[pterodoc] ${issue.severity}: ${issue.message}\n`);
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
}
|
package/src/target.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build the target a run publishes to.
|
|
3
|
+
*
|
|
4
|
+
* Both entry points — the command line and the Docusaurus plugin — need the
|
|
5
|
+
* same object built the same way, and having built it in two places once
|
|
6
|
+
* already, the copies drifted apart in how they spelled the URL policy.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type { ResolvedConfig, Target } from '@pterodoc/core';
|
|
10
|
+
import { createWordpressTarget } from '@pterodoc/wordpress';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Build the configured target.
|
|
14
|
+
*
|
|
15
|
+
* Always built, even offline: the target decides what a page's URL is, and a
|
|
16
|
+
* render with the wrong URLs is worse than no render at all. Only opening a
|
|
17
|
+
* session needs credentials.
|
|
18
|
+
*
|
|
19
|
+
* @param config The resolved configuration.
|
|
20
|
+
*/
|
|
21
|
+
export function resolveTarget(config: ResolvedConfig): Target {
|
|
22
|
+
return createWordpressTarget({
|
|
23
|
+
url: config.targetUrl,
|
|
24
|
+
user: config.user,
|
|
25
|
+
appPassword: config.appPassword,
|
|
26
|
+
policy: {
|
|
27
|
+
rootSegments: config.rootSegments,
|
|
28
|
+
baseSegments: config.baseSegments,
|
|
29
|
+
},
|
|
30
|
+
status: config.status,
|
|
31
|
+
template: config.template,
|
|
32
|
+
lang: config.lang,
|
|
33
|
+
mediaSlugPrefix: config.mediaSlugPrefix,
|
|
34
|
+
methodOverride: config.methodOverride,
|
|
35
|
+
retry: config.retry,
|
|
36
|
+
});
|
|
37
|
+
}
|