rspress-plugin-gh-pages 0.1.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/src/index.ts ADDED
@@ -0,0 +1,66 @@
1
+ import path from 'node:path';
2
+
3
+ import chalk from 'chalk';
4
+ import ghpages from 'gh-pages';
5
+ import { logger } from '@rspress/shared/logger';
6
+
7
+ import { PresetConfigMutator, type StrictOmit } from 'rspress-plugin-devkit';
8
+ import type { RspressPlugin } from '@rspress/shared';
9
+
10
+ export const componentsPath = path.join(__dirname, './components');
11
+
12
+ const DefaultDocBuildOutput = 'doc_build';
13
+
14
+ interface RspressPluginGHPagesOptions extends ghpages.PublishOptions {
15
+ directory?: string;
16
+ silent?: boolean;
17
+ }
18
+
19
+ export default function rspressPluginGHPages(
20
+ options: RspressPluginGHPagesOptions = {},
21
+ ): RspressPlugin {
22
+ const {
23
+ directory,
24
+ repo,
25
+ branch = 'gh-pages',
26
+ silent = false,
27
+ ...publishOptions
28
+ } = options;
29
+
30
+ return {
31
+ name: 'rspress-plugin-gh-pages',
32
+ config(config) {
33
+ config.base = '/rspress-plugins/';
34
+ return new PresetConfigMutator(config).toConfig();
35
+ },
36
+ async afterBuild(config, isBuild) {
37
+ if (!isBuild) return;
38
+
39
+ const publishDir = directory ?? config.outDir ?? DefaultDocBuildOutput;
40
+
41
+ const logPrefix = chalk.green('[rspress-plugin-gh-pages]');
42
+
43
+ if (!silent) {
44
+ logger.info(
45
+ `${logPrefix} Publish directory: ${chalk.cyan(publishDir)}`,
46
+ );
47
+ logger.info(`${logPrefix} Publish branch: ${chalk.cyan(branch)}`);
48
+ }
49
+
50
+ try {
51
+ await ghpages.publish(publishDir, {
52
+ repo,
53
+ branch,
54
+ ...publishOptions,
55
+ });
56
+ } catch (error) {
57
+ silent
58
+ ? void 0
59
+ : logger.error(`${logPrefix} Failed to publish: ${error}`);
60
+ process.exit(1);
61
+ }
62
+
63
+ silent ? void 0 : logger.success(`${logPrefix} Page Published.`);
64
+ },
65
+ };
66
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "compilerOptions": {
3
+ "rootDir": "src",
4
+ "outDir": "dist"
5
+ },
6
+ "include": ["src"],
7
+ "extends": "../../tsconfig.base.json"
8
+ }