@alauda/doom 0.6.11 → 0.6.12

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/new.js CHANGED
@@ -79,7 +79,7 @@ const resolveScaffoldings = async (name, force) => {
79
79
  for (const branch of branches) {
80
80
  if (branch === currentBranch) {
81
81
  logger.info(`Pulling latest changes from branch \`${cyan(branch)}\`...`);
82
- await git.pull([...options, '--rebase']);
82
+ await git.pull([...options, '--rebase', '--allow-unrelated-histories']);
83
83
  }
84
84
  else {
85
85
  logger.info(`Switching to branch \`${cyan(branch)}\`...`);
@@ -169,7 +169,9 @@ export const newCommand = new Command('new')
169
169
  });
170
170
  const files = new Set(dirents
171
171
  .filter((d) => d.isFile())
172
- .map((d) => path.relative(source, path.resolve(d.parentPath, d.name))));
172
+ .map((d) => path.relative(source, path.resolve(d.parentPath ||
173
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
174
+ d.path, d.name))));
173
175
  for (const matcher of layout.matchers || []) {
174
176
  const matched = await glob(matcher.match.map((m) => render(m, { parameters })), { cwd: source });
175
177
  for (const file of matched) {
@@ -1,7 +1,6 @@
1
1
  import fs from 'node:fs/promises';
2
2
  import { logger } from '@rspress/shared/logger';
3
3
  import { MD_RELEASE_COMMENT_PATTERN, MDX_RELEASE_COMMENT_PATTERN, refCache, releaseCache, remarkReplace, } from './remark-replace.js';
4
- import { remarkPluginToc } from './remark-toc.js';
5
4
  import { mdProcessor, mdxProcessor, normalizeReferenceItems } from './utils.js';
6
5
  export const referencePlugin = ({ root, lang, localBasePath, items = [], force, releaseNotes, }) => {
7
6
  const normalizedItems = normalizeReferenceItems(items);
@@ -38,17 +37,14 @@ export const referencePlugin = ({ root, lang, localBasePath, items = [], force,
38
37
  return;
39
38
  }
40
39
  const processor = isMdx ? mdxProcessor : mdProcessor;
41
- const compiler = processor()
42
- .data('pageMeta', {})
43
- .use(remarkReplace, {
40
+ const compiler = processor().data('pageMeta', {}).use(remarkReplace, {
44
41
  lang,
45
42
  localBasePath,
46
43
  root,
47
44
  items: normalizedItems,
48
45
  force,
49
46
  releaseNotes,
50
- })
51
- .use(remarkPluginToc);
47
+ });
52
48
  const vfile = await compiler.process({
53
49
  path: filepath,
54
50
  value: content,
@@ -56,9 +52,6 @@ export const referencePlugin = ({ root, lang, localBasePath, items = [], force,
56
52
  original: true,
57
53
  },
58
54
  });
59
- const { toc, title } = compiler.data('pageMeta');
60
- page.title = title;
61
- page.toc = toc;
62
55
  page.content = vfile.toString();
63
56
  }));
64
57
  for (const result of results) {
@@ -0,0 +1,17 @@
1
+ import type { Root } from 'mdast';
2
+ export interface TocItem {
3
+ id: string;
4
+ text: string;
5
+ depth: number;
6
+ index: number;
7
+ }
8
+ export interface PageMeta {
9
+ toc: TocItem[];
10
+ title: string;
11
+ headingTitle: string;
12
+ frontmatter?: Record<string, unknown>;
13
+ }
14
+ export declare const parseToc: (tree: Root, allDepths?: boolean) => {
15
+ title: string;
16
+ toc: TocItem[];
17
+ };
@@ -0,0 +1,51 @@
1
+ import Slugger from 'github-slugger';
2
+ import { visitChildren } from 'unist-util-visit-children';
3
+ import { extractTextAndId } from './utils.js';
4
+ export const parseToc = (tree, allDepths) => {
5
+ let title = '';
6
+ const toc = [];
7
+ const slugger = new Slugger();
8
+ visitChildren((node, index) => {
9
+ if (node.type !== 'heading' || !node.depth || !node.children) {
10
+ return;
11
+ }
12
+ // Collect h1 ~ h4 by default
13
+ if (allDepths || node.depth < 5) {
14
+ let customId = '';
15
+ const text = node.children
16
+ .map((child) => {
17
+ if (child.type === 'link') {
18
+ return child.children?.map((item) => item.value).join('');
19
+ }
20
+ if (child.type === 'strong') {
21
+ return `**${child.children?.map((item) => item.value).join('')}**`;
22
+ }
23
+ if (child.type === 'text') {
24
+ const [textPart, idPart] = extractTextAndId(child.value);
25
+ customId = idPart;
26
+ return textPart;
27
+ }
28
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
29
+ if (child.type === 'inlineCode') {
30
+ return `\`${child.value}\``;
31
+ }
32
+ return '';
33
+ })
34
+ .join('');
35
+ if (!allDepths && node.depth === 1) {
36
+ if (!title) {
37
+ title = text;
38
+ }
39
+ }
40
+ else {
41
+ const id = customId ? customId : slugger.slug(text);
42
+ const { depth } = node;
43
+ toc.push({ id, text, depth, index });
44
+ }
45
+ }
46
+ })(tree);
47
+ return {
48
+ title,
49
+ toc,
50
+ };
51
+ };
@@ -7,7 +7,7 @@ import { render } from 'ejs';
7
7
  import { simpleGit } from 'simple-git';
8
8
  import { parse, stringify } from 'yaml';
9
9
  import { cyan, red } from 'yoctocolors';
10
- import { parseToc } from './remark-toc.js';
10
+ import { parseToc } from './parse-toc.js';
11
11
  import { getFrontmatterNode, mdProcessor, mdxProcessor } from './utils.js';
12
12
  const remotesFolder = path.resolve(os.homedir(), '.doom/remotes');
13
13
  export const refCache = new Map();
@@ -41,7 +41,13 @@ const resolveReference_ = async (localBasePath, items, refName, force) => {
41
41
  }
42
42
  if (force) {
43
43
  logger.info(`Pulling latest changes for \`${cyan(source.slug)}\`...`);
44
- await git.pull(['--depth', '1', '--force', '--rebase']);
44
+ await git.pull([
45
+ '--depth',
46
+ '1',
47
+ '--force',
48
+ '--rebase',
49
+ '--allow-unrelated-histories',
50
+ ]);
45
51
  }
46
52
  sourcePath = path.resolve(repoFolder, sourcePath);
47
53
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alauda/doom",
3
- "version": "0.6.11",
3
+ "version": "0.6.12",
4
4
  "type": "module",
5
5
  "description": "Doctor Doom making docs.",
6
6
  "repository": {
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "packageManager": "yarn@4.5.0",
11
11
  "engines": {
12
- "node": ">=18.20.0 <20 || >=20.1.0"
12
+ "node": ">=18.17.0 <20 || >=20.1.0"
13
13
  },
14
14
  "bin": "lib/cli/index.js",
15
15
  "exports": {