@alauda/doom 0.6.4 → 0.6.6
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/lib/cli/index.js
CHANGED
|
@@ -11,6 +11,7 @@ import { program } from 'commander';
|
|
|
11
11
|
import { green } from 'yoctocolors';
|
|
12
12
|
import { CWD, DEFAULT_CONFIGS, I18N_FILE, SITES_FILE } from './constants.js';
|
|
13
13
|
import { loadConfig } from './load-config.js';
|
|
14
|
+
import { newCommand } from './new.js';
|
|
14
15
|
const META_FILE = '_meta.json';
|
|
15
16
|
const CONFIG_FILES = [...DEFAULT_CONFIGS, I18N_FILE, SITES_FILE];
|
|
16
17
|
const setNodeEnv = (env) => {
|
|
@@ -28,7 +29,7 @@ program
|
|
|
28
29
|
.option('-c, --config [config]', 'Specify the path to the config file')
|
|
29
30
|
.option('-v <version>', 'Specify the version of the documentation')
|
|
30
31
|
.option('-p, --prefix <prefix>', 'Specify the prefix of the documentation base')
|
|
31
|
-
.option('-f, --force [boolean]', 'Force to fetch latest reference remotes, otherwise use local cache', (value) => !!value && value !== 'false', false)
|
|
32
|
+
.option('-f, --force [boolean]', 'Force to fetch latest reference remotes or scaffolding templates, otherwise use local cache', (value) => !!value && value !== 'false', false)
|
|
32
33
|
.command('dev', { isDefault: true })
|
|
33
34
|
.description('Start the development server')
|
|
34
35
|
.argument('[root]', 'Root directory of the documentation')
|
|
@@ -128,7 +129,10 @@ program
|
|
|
128
129
|
...server,
|
|
129
130
|
});
|
|
130
131
|
});
|
|
131
|
-
program.
|
|
132
|
-
|
|
132
|
+
program.addCommand(newCommand);
|
|
133
|
+
program.parseAsync().catch((err) => {
|
|
134
|
+
if (err instanceof Error && err.name === 'ExitPromptError') {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
logger.error(err);
|
|
133
138
|
});
|
|
134
|
-
program.parseAsync().catch(console.error);
|
package/lib/cli/new.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as prompts from '@inquirer/prompts';
|
|
2
|
+
import { Command } from 'commander';
|
|
2
3
|
export declare const DEFAULT_PATH = "templates/scaffolding.yaml";
|
|
3
4
|
export interface ScaffoldingTemplate {
|
|
4
5
|
repo: string;
|
|
@@ -42,4 +43,5 @@ export interface Scaffolding {
|
|
|
42
43
|
parameters?: ScaffoldingParameter[];
|
|
43
44
|
layout?: ScaffoldingLayout[];
|
|
44
45
|
}
|
|
46
|
+
export declare const newCommand: Command;
|
|
45
47
|
export {};
|
package/lib/cli/new.js
CHANGED
|
@@ -3,7 +3,7 @@ import os from 'node:os';
|
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import * as prompts from '@inquirer/prompts';
|
|
5
5
|
import { logger } from '@rsbuild/core';
|
|
6
|
-
import {
|
|
6
|
+
import { Command } from 'commander';
|
|
7
7
|
import { render } from 'ejs';
|
|
8
8
|
import { simpleGit } from 'simple-git';
|
|
9
9
|
import { glob } from 'tinyglobby';
|
|
@@ -110,14 +110,14 @@ const handleTemplateFile = async ({ source, target, processors, parameters, writ
|
|
|
110
110
|
await fs.mkdir(path.dirname(target), { recursive: true });
|
|
111
111
|
await fs[`${writeMode}File`](target, content);
|
|
112
112
|
};
|
|
113
|
-
|
|
113
|
+
export const newCommand = new Command('new')
|
|
114
114
|
.argument('[template]', 'Scaffolding template name, format: `[name][:type]`')
|
|
115
|
-
.
|
|
116
|
-
.action(async (template = '', { force }) => {
|
|
115
|
+
.action(async function (template = '') {
|
|
117
116
|
let [name, type] = template.split(':');
|
|
118
117
|
if (!name) {
|
|
119
118
|
name = 'product-doc';
|
|
120
119
|
}
|
|
120
|
+
const { force } = this.optsWithGlobals();
|
|
121
121
|
const { base, scaffoldings } = (await resolveScaffoldings(name, force)) || {};
|
|
122
122
|
if (!scaffoldings) {
|
|
123
123
|
logger.error(`Unable to resolve any scaffoldings, if you are sure the template \`${magenta(name)}\` exists, try to use the \`--force\` option, or event remove the local cache at ${magenta(path.resolve(scaffoldingsFolder, name))} and try again`);
|
|
@@ -194,11 +194,4 @@ program
|
|
|
194
194
|
}
|
|
195
195
|
}
|
|
196
196
|
logger.success('Scaffolding generated successfully!');
|
|
197
|
-
})
|
|
198
|
-
.parseAsync(process.argv)
|
|
199
|
-
.catch((err) => {
|
|
200
|
-
if (err instanceof Error && err.name === 'ExitPromptError') {
|
|
201
|
-
return;
|
|
202
|
-
}
|
|
203
|
-
logger.error(err);
|
|
204
197
|
});
|
|
@@ -2,6 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { Link, renderInlineMarkdown, useSidebarData } from '@rspress/core/theme';
|
|
3
3
|
import { isEqualPath, normalizeHrefInRuntime as normalizeHref, usePageData, withBase, } from '@rspress/runtime';
|
|
4
4
|
import { Fragment, useMemo } from 'react';
|
|
5
|
+
import { findItemByRoutePath } from './_utils.js';
|
|
5
6
|
import classes from '../../../styles/overview.module.scss';
|
|
6
7
|
// The sidebar data include two types: sidebar item and sidebar group.
|
|
7
8
|
// In overpage page, we select all the related sidebar groups and show the groups in the page.
|
|
@@ -23,24 +24,13 @@ export function Overview(props) {
|
|
|
23
24
|
}
|
|
24
25
|
return '';
|
|
25
26
|
};
|
|
26
|
-
const findItemByRoutePath = (items, routePath, originalItems) => {
|
|
27
|
-
for (const item of items) {
|
|
28
|
-
if ('link' in item && withBase(item.link) === routePath) {
|
|
29
|
-
return [item];
|
|
30
|
-
}
|
|
31
|
-
if ('items' in item) {
|
|
32
|
-
return findItemByRoutePath(item.items, routePath, originalItems);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return originalItems;
|
|
36
|
-
};
|
|
37
27
|
const { pages } = siteData;
|
|
38
28
|
const overviewModules = pages.filter((page) => subFilter(page.routePath));
|
|
39
29
|
let { items: overviewSidebarGroups } = useSidebarData();
|
|
40
30
|
if (overviewSidebarGroups[0] &&
|
|
41
31
|
'link' in overviewSidebarGroups[0] &&
|
|
42
32
|
overviewSidebarGroups[0]?.link !== routePath) {
|
|
43
|
-
overviewSidebarGroups = findItemByRoutePath(overviewSidebarGroups, routePath
|
|
33
|
+
overviewSidebarGroups = findItemByRoutePath(overviewSidebarGroups, routePath);
|
|
44
34
|
}
|
|
45
35
|
function normalizeSidebarItem(item, sidebarGroup, frontmatter) {
|
|
46
36
|
if ('dividerType' in item) {
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { NormalizedSidebarGroup, SidebarDivider, SidebarItem, SidebarSectionHeader } from '@rspress/shared';
|
|
2
|
+
export declare const isSidebarDivider: (item: NormalizedSidebarGroup | SidebarItem | SidebarDivider | SidebarSectionHeader) => item is SidebarDivider;
|
|
3
|
+
/**
|
|
4
|
+
* @zh_CN 如果 index 在 sidebar items 中, 则返回所有平级 item, 如果 index 在 dir 上, 则返回 items
|
|
5
|
+
* @example
|
|
6
|
+
*/
|
|
7
|
+
export declare function findItemByRoutePath(items: (SidebarItem | NormalizedSidebarGroup | SidebarDivider)[], routePath: string): (SidebarItem | NormalizedSidebarGroup)[];
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { withBase } from '@rspress/core/runtime';
|
|
2
|
+
function removeIndex(link) {
|
|
3
|
+
if (link.endsWith('/index')) {
|
|
4
|
+
return link.slice(0, -5);
|
|
5
|
+
}
|
|
6
|
+
return link;
|
|
7
|
+
}
|
|
8
|
+
export const isSidebarDivider = (item) => {
|
|
9
|
+
return 'dividerType' in item;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* @zh_CN 如果 index 在 sidebar items 中, 则返回所有平级 item, 如果 index 在 dir 上, 则返回 items
|
|
13
|
+
* @example
|
|
14
|
+
*/
|
|
15
|
+
export function findItemByRoutePath(items, routePath) {
|
|
16
|
+
function isRoutePathMatch(item) {
|
|
17
|
+
if (isSidebarDivider(item)) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
const withBaseUrl = withBase(item.link);
|
|
21
|
+
const removeIndexUrl = removeIndex(withBaseUrl);
|
|
22
|
+
const removeBackSlashedRoutePath = routePath.replace(/\/$/, '');
|
|
23
|
+
return (
|
|
24
|
+
// FIXME: 😅 we should refactor all the path logic, /index.html / or no /, l
|
|
25
|
+
withBaseUrl === routePath ||
|
|
26
|
+
removeIndexUrl === routePath ||
|
|
27
|
+
withBaseUrl === removeBackSlashedRoutePath ||
|
|
28
|
+
removeIndexUrl === removeBackSlashedRoutePath);
|
|
29
|
+
}
|
|
30
|
+
const matchRoutePathItemIndex = items.findIndex((item) => {
|
|
31
|
+
return isRoutePathMatch(item);
|
|
32
|
+
});
|
|
33
|
+
if (matchRoutePathItemIndex === -1) {
|
|
34
|
+
return items
|
|
35
|
+
.map((item) => {
|
|
36
|
+
if (!('items' in item)) {
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
39
|
+
return findItemByRoutePath(item.items, routePath);
|
|
40
|
+
})
|
|
41
|
+
.flat();
|
|
42
|
+
}
|
|
43
|
+
const matchRoutePathItem = items[matchRoutePathItemIndex];
|
|
44
|
+
const isArray = (i) => Array.isArray(i) && i.length >= 1;
|
|
45
|
+
// 1. if isDir(item) return item.items
|
|
46
|
+
if ('items' in matchRoutePathItem && isArray(matchRoutePathItem.items)) {
|
|
47
|
+
// 2. if isDir(item) && item.items is all files, style is different
|
|
48
|
+
if (matchRoutePathItem.items.every((item) => !('items' in item))) {
|
|
49
|
+
return [matchRoutePathItem];
|
|
50
|
+
}
|
|
51
|
+
return matchRoutePathItem.items.filter((item) => !isSidebarDivider(item));
|
|
52
|
+
}
|
|
53
|
+
// 3. if matchRoutePathItem is a item, return other items in same level (/api/index.md is in the child sidebar)
|
|
54
|
+
const result = [...items];
|
|
55
|
+
if (!('items' in matchRoutePathItem)) {
|
|
56
|
+
result.splice(matchRoutePathItemIndex, 1);
|
|
57
|
+
}
|
|
58
|
+
const res = result.filter((item) => !isSidebarDivider(item));
|
|
59
|
+
return res;
|
|
60
|
+
}
|