rspress-plugin-gh-pages 0.1.6-beta.0 → 0.1.7-beta.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 DELETED
@@ -1,93 +0,0 @@
1
- import chalk from 'chalk';
2
- import ghpages from 'gh-pages';
3
- import { logger } from '@rspress/shared/logger';
4
-
5
- import type { MarkRequired } from 'rspress-plugin-devkit';
6
- import type { RspressPlugin } from '@rspress/shared';
7
-
8
- const DefaultDocBuildOutput = 'doc_build';
9
-
10
- interface RspressPluginGHPagesOptions
11
- extends MarkRequired<ghpages.PublishOptions, 'repo'> {
12
- directory?: string;
13
- silent?: boolean;
14
- siteBase?: string;
15
- }
16
-
17
- const logPrefix = chalk.green('[gh-pages]');
18
-
19
- function normalizeBase(base: string): string {
20
- return base === '/' || base === ''
21
- ? '/'
22
- : `/${base.replace(/^\/+|\/+$/g, '')}/`;
23
- }
24
-
25
- export default function rspressPluginGHPages(
26
- options: RspressPluginGHPagesOptions,
27
- ): RspressPlugin {
28
- const {
29
- repo,
30
- directory,
31
- branch = 'gh-pages',
32
- silent = false,
33
- siteBase = '',
34
- ...publishOptions
35
- } = options;
36
-
37
- return {
38
- name: 'rspress-plugin-gh-pages',
39
- config(config) {
40
- let baseFromRepo = repo.includes('github.io')
41
- ? '/'
42
- : /\/([^\/]+)\.git$/.exec(repo)?.[1];
43
-
44
- // Use || here to as ?? will consider '' as a valid value
45
- const base = siteBase || baseFromRepo || '';
46
-
47
- if (!base) {
48
- logger.warn(
49
- `${logPrefix} Failed to parse base from repo, site base path will not be updated.`,
50
- );
51
-
52
- return config;
53
- }
54
-
55
- config.base = normalizeBase(base);
56
-
57
- return config;
58
- },
59
- async afterBuild(config, isBuild) {
60
- if (!repo) {
61
- logger.error(
62
- `Option ${chalk.cyan('repo')} is required for rspress-plugin-gh-pages.`,
63
- );
64
- }
65
-
66
- if (!isBuild) return;
67
-
68
- const publishDir = directory ?? config.outDir ?? DefaultDocBuildOutput;
69
-
70
- if (!silent) {
71
- logger.info(
72
- `${logPrefix} Publish directory: ${chalk.cyan(publishDir)}`,
73
- );
74
- logger.info(`${logPrefix} Publish branch: ${chalk.cyan(branch)}`);
75
- }
76
-
77
- try {
78
- await ghpages.publish(publishDir, {
79
- repo,
80
- branch,
81
- ...publishOptions,
82
- });
83
- } catch (error) {
84
- silent
85
- ? void 0
86
- : logger.error(`${logPrefix} Failed to publish: ${error}`);
87
- process.exit(1);
88
- }
89
-
90
- silent ? void 0 : logger.success(`${logPrefix} Page Published.`);
91
- },
92
- };
93
- }
package/tsconfig.json DELETED
@@ -1,10 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "rootDir": "src",
4
- "outDir": "dist",
5
- "module": "NodeNext",
6
- "moduleResolution": "nodenext"
7
- },
8
- "include": ["src"],
9
- "extends": "../../tsconfig.base.json"
10
- }