@alauda/doom 0.6.7 → 0.6.9
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
|
@@ -107,11 +107,16 @@ program
|
|
|
107
107
|
const { config: configFile, prefix, v: version, force, } = this.optsWithGlobals();
|
|
108
108
|
const { config } = await loadConfig(root, configFile, prefix, version, force);
|
|
109
109
|
const docDirectory = config.root;
|
|
110
|
-
|
|
110
|
+
const runBuild = () => build({
|
|
111
111
|
config,
|
|
112
112
|
appDirectory: CWD,
|
|
113
113
|
docDirectory,
|
|
114
114
|
});
|
|
115
|
+
await runBuild();
|
|
116
|
+
if (process.env.__DOOM_REBUILD__ === 'true') {
|
|
117
|
+
logger.info('Rebuilding...');
|
|
118
|
+
await runBuild();
|
|
119
|
+
}
|
|
115
120
|
});
|
|
116
121
|
program
|
|
117
122
|
.command('preview')
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
2
|
import os from 'node:os';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
+
import { isProduction } from '@rspress/core';
|
|
4
5
|
import { logger } from '@rspress/shared/logger';
|
|
5
6
|
import { render } from 'ejs';
|
|
6
|
-
import remarkFrontmatter from 'remark-frontmatter';
|
|
7
|
-
import remarkStringify from 'remark-stringify';
|
|
8
7
|
import { simpleGit } from 'simple-git';
|
|
9
8
|
import { parse, stringify } from 'yaml';
|
|
10
9
|
import { cyan, red } from 'yoctocolors';
|
|
11
10
|
import { parseToc } from './remark-toc.js';
|
|
12
|
-
import { getFrontmatterNode, mdProcessor, mdxProcessor
|
|
11
|
+
import { getFrontmatterNode, mdProcessor, mdxProcessor } from './utils.js';
|
|
13
12
|
const remotesFolder = path.resolve(os.homedir(), '.doom/remotes');
|
|
14
13
|
export const refCache = new Map();
|
|
15
14
|
const resolveReference_ = async (localBasePath, items, refName, force) => {
|
|
@@ -115,7 +114,8 @@ const FIELD_MAPPER = {
|
|
|
115
114
|
zh: 'customfield_13800',
|
|
116
115
|
en: 'customfield_13801',
|
|
117
116
|
};
|
|
118
|
-
const { JIRA_TOKEN, JIRA_USERNAME, JIRA_PASSWORD } = process.env;
|
|
117
|
+
const { CI, JIRA_TOKEN, JIRA_USERNAME, JIRA_PASSWORD } = process.env;
|
|
118
|
+
const isCi = CI !== 'false' && !!CI;
|
|
119
119
|
const issuesToMdast = (issues, lang) => {
|
|
120
120
|
return issues
|
|
121
121
|
.map((issue) => {
|
|
@@ -223,25 +223,23 @@ export const remarkReplace = function ({ lang, localBasePath, root, items, force
|
|
|
223
223
|
if (!maybeHaveRef(filepath, content)) {
|
|
224
224
|
return;
|
|
225
225
|
}
|
|
226
|
-
const
|
|
227
|
-
|
|
228
|
-
.use(remarkStringify, stringifySettings);
|
|
226
|
+
const isMdx = filepath.endsWith('.mdx');
|
|
227
|
+
const processor = isMdx ? mdxProcessor : mdProcessor;
|
|
229
228
|
const originalAst = vfile.data.original
|
|
230
229
|
? ast
|
|
231
230
|
: processor.parse((content = await fs.readFile(filepath, 'utf8')));
|
|
232
231
|
const frontmatterNode = getFrontmatterNode(originalAst);
|
|
233
232
|
let frontmatter = frontmatterNode &&
|
|
234
233
|
parse(frontmatterNode.value);
|
|
235
|
-
const isMdx = filepath.endsWith('.mdx');
|
|
236
|
-
const relativePath = path.relative(root, filepath);
|
|
237
|
-
const currLang = lang === null ? 'zh' : relativePath.split('/')[0];
|
|
238
|
-
const references = [];
|
|
239
234
|
const newAstChildren = [];
|
|
240
235
|
const newContentChildren = [];
|
|
241
236
|
let index = 0;
|
|
242
237
|
let start = null;
|
|
243
238
|
let refName = '';
|
|
244
239
|
let matched;
|
|
240
|
+
let checkContent = false;
|
|
241
|
+
const relativePath = path.relative(root, filepath);
|
|
242
|
+
const currLang = lang === null ? 'zh' : relativePath.split('/')[0];
|
|
245
243
|
for (const node of ast.children) {
|
|
246
244
|
index++;
|
|
247
245
|
if (node.type !== (isMdx ? 'mdxFlowExpression' : 'html')) {
|
|
@@ -256,9 +254,10 @@ export const remarkReplace = function ({ lang, localBasePath, root, items, force
|
|
|
256
254
|
}
|
|
257
255
|
if ((matched = node.value.match(isMdx ? MDX_REF_START_PATTERN : MD_REF_START_COMMENT_PATTERN))) {
|
|
258
256
|
if (start != null) {
|
|
259
|
-
logger.warn(`Invalid reference start block ${node.value}, nested reference blocks are not allowed`);
|
|
257
|
+
logger.warn(`Invalid reference start block ${red(node.value)}, nested reference blocks are not allowed`);
|
|
260
258
|
}
|
|
261
259
|
else {
|
|
260
|
+
checkContent = true;
|
|
262
261
|
start = index;
|
|
263
262
|
refName = matched[1].trim();
|
|
264
263
|
}
|
|
@@ -268,10 +267,9 @@ export const remarkReplace = function ({ lang, localBasePath, root, items, force
|
|
|
268
267
|
}
|
|
269
268
|
if ((isMdx ? MDX_REF_END_PATTERN : MD_REF_END_COMMENT_PATTERN).test(node.value)) {
|
|
270
269
|
if (start == null) {
|
|
271
|
-
logger.warn(`Invalid reference end block ${node.value}, no matching start block found`);
|
|
270
|
+
logger.warn(`Invalid reference end block ${red(node.value)}, no matching start block found`);
|
|
272
271
|
}
|
|
273
272
|
else {
|
|
274
|
-
references.push([start, index]);
|
|
275
273
|
start = null;
|
|
276
274
|
}
|
|
277
275
|
const resolved = await resolveReference(localBasePath, items, refName, force);
|
|
@@ -309,13 +307,19 @@ export const remarkReplace = function ({ lang, localBasePath, root, items, force
|
|
|
309
307
|
continue;
|
|
310
308
|
}
|
|
311
309
|
if ((matched = node.value.match(isMdx ? MDX_RELEASE_PATTERN : MD_RELEASE_COMMENT_PATTERN))) {
|
|
312
|
-
|
|
313
|
-
|
|
310
|
+
if (start != null) {
|
|
311
|
+
logger.warn(`Invalid release-notes-for-bugs comment ${red(refName)}, nested reference blocks are not allowed`);
|
|
312
|
+
newAstChildren.push(node);
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
const releaseContent = await resolveRelease(releaseNotes?.queryTemplates ?? {}, matched[1].trim(), currLang);
|
|
316
|
+
newAstChildren.push(releaseContent ?? node);
|
|
317
|
+
}
|
|
314
318
|
newContentChildren.push(node);
|
|
315
319
|
}
|
|
316
320
|
}
|
|
317
321
|
if (start != null) {
|
|
318
|
-
logger.warn(`Invalid reference start block ${
|
|
322
|
+
logger.warn(`Invalid reference start block ${red(refName)}, no matching end block found, adding for you`);
|
|
319
323
|
newContentChildren.push({
|
|
320
324
|
type: isMdx ? 'mdxFlowExpression' : 'html',
|
|
321
325
|
value: isMdx ? '/* reference-end */' : '<!-- reference-end -->',
|
|
@@ -327,13 +331,24 @@ export const remarkReplace = function ({ lang, localBasePath, root, items, force
|
|
|
327
331
|
value: stringify(frontmatter).trim(),
|
|
328
332
|
});
|
|
329
333
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
334
|
+
if (checkContent) {
|
|
335
|
+
const newContent = processor.stringify({
|
|
336
|
+
...ast,
|
|
337
|
+
children: newContentChildren
|
|
338
|
+
.flat()
|
|
339
|
+
.filter((n) => n.type !== 'mdxjsEsm'),
|
|
340
|
+
});
|
|
341
|
+
if (content !== newContent) {
|
|
342
|
+
await fs.writeFile(filepath, newContent);
|
|
343
|
+
if (!vfile.data.original && isProduction()) {
|
|
344
|
+
const message = `Reference block in \`${cyan(relativePath)}\` has been updated, please commit the changes`;
|
|
345
|
+
if (isCi) {
|
|
346
|
+
process.env.__DOOM_REBUILD__ = 'true';
|
|
347
|
+
}
|
|
348
|
+
logger.warn(message);
|
|
349
|
+
}
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
337
352
|
}
|
|
338
353
|
ast.children = newAstChildren.flat();
|
|
339
354
|
};
|