Skip to content

Commit

Permalink
docs: ts config (DIYgod#13690)
Browse files Browse the repository at this point in the history
* docs: ts config

* chore: esm format script

* chore: bring back ast based formatting

* chore: revert 7b0493f

* chore: update dependabot config

* docs: rename to mdx extension

* fix: unused import

* docs: fix search build

* chore: remove deps changes
  • Loading branch information
TonyRL authored Nov 3, 2023
1 parent d6056e2 commit 06721a0
Show file tree
Hide file tree
Showing 52 changed files with 389 additions and 481 deletions.
1 change: 1 addition & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"deepscan.vscode-deepscan",
"rangav.vscode-thunder-client",
"SonarSource.sonarlint-vscode",
"unifiedjs.vscode-mdx",
"ZihanLi.at-helper"
]
}
Expand Down
16 changes: 0 additions & 16 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,6 @@ updates:
open-pull-requests-limit: 10
labels:
- dependencies
ignore:
# ESM only packages
- dependency-name: remark
versions: ['>=14.0.0']
- dependency-name: remark-frontmatter
versions: ['>=4.0.0']
- dependency-name: remark-gfm
versions: ['>=2.0.0']
- dependency-name: remark-parse
versions: ['>=10.0.0']
- dependency-name: remark-preset-prettier
versions: ['>=1.0.0']
- dependency-name: remark-stringify
versions: ['>=10.0.0']
- dependency-name: string-width
versions: ['>=5.0.0']
groups:
docusaurus:
patterns:
Expand Down
1 change: 1 addition & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ vscode:
- deepscan.vscode-deepscan
- rangav.vscode-thunder-client
- sonarsource.sonarlint-vscode
- unifiedjs.vscode-mdx
# - ZihanLi.at-helper not available on Open VSX
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"build:maintainer": "node scripts/workflow/build-maintainer.js",
"build:radar": "node scripts/workflow/build-radar.js",
"dev": "cross-env NODE_ENV=dev nodemon --inspect lib/index.js",
"format": "eslint --cache --fix \"**/*.{js,yml}\" && node website/docs/.format/format.js && prettier \"**/*.{js,json}\" --write",
"format": "eslint --cache --fix \"**/*.{js,yml}\" && node website/docs/.format/format.mjs && prettier \"**/*.{js,json}\" --write",
"format:check": "eslint --cache \"**/*.{js,yml}\" && prettier \"**/*.{js,json}\" --check",
"format:staged": "lint-staged",
"jest": "cross-env NODE_ENV=test jest --runInBand --forceExit --detectOpenHandles",
Expand All @@ -41,7 +41,7 @@
"eslint --cache --fix",
"prettier --ignore-unknown --ignore-path ./.gitignore --write"
],
"*.md": "node website/docs/.format/format.js --staged",
"*.md": "node website/docs/.format/format.mjs --staged",
"*.yml": "eslint --cache --fix"
},
"nodemonConfig": {
Expand Down
6 changes: 3 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
30 changes: 0 additions & 30 deletions website/docs/.format/chineseFormat.js

This file was deleted.

34 changes: 34 additions & 0 deletions website/docs/.format/chineseFormat.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import file from './file.mjs';
import width from 'string-width';
import { remark } from 'remark';
import pangu from 'remark-pangu';
import frontmatter from 'remark-frontmatter';
import remarkDirective from 'remark-directive';
import stringify from 'remark-stringify';
import gfm from 'remark-gfm';
import prettier from 'remark-preset-prettier';
import remarkMdx from 'remark-mdx';

export default {
rules: (list) => list.filter((e) => e.lang === file.LANG_EN),
handler: async (doc) => {
const result = await remark()
.use(remarkMdx)
.use(frontmatter)
.use(remarkDirective)
.use(pangu, {
inlineCode: false,
link: false,
})
.use(stringify, {
bullet: '-',
ruleSpaces: true,
})
.use(prettier)
.use(gfm, {
stringLength: width,
})
.process(doc);
return String(result);
},
};
11 changes: 0 additions & 11 deletions website/docs/.format/file.js

This file was deleted.

11 changes: 11 additions & 0 deletions website/docs/.format/file.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import fs from 'fs/promises';

export default {
ROUTE_TYPE: 'route',
GUIDE_TYPE: 'guide',
NAV_TYPE: 'nav',
LANG_CN: 'zh-CN',
LANG_EN: 'en-US',
readFile: async (filePath) => await fs.readFile(filePath, { encoding: 'utf8' }),
writeFile: async (filePath, data) => await fs.writeFile(filePath, data, { encoding: 'utf8' }),
};
25 changes: 12 additions & 13 deletions website/docs/.format/format.js → website/docs/.format/format.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const file = require('./file');
const sgf = require('staged-git-files');
const path = require('path');
const sortByHeading = require('./sortByHeading');
const slugId = require('./slugId');
// const chineseFormat = require('./chineseFormat');
const util = require('util');
const exec = util.promisify(require('child_process').exec);
import file from './file.mjs';
import sgf from 'staged-git-files';
import sortByHeading from './sortByHeading.mjs';
import slugId from './slugId.mjs';
// import chineseFormat from './chineseFormat.mjs';
import { exec } from 'child_process';
import { fileURLToPath } from 'url';
import sidebars from '../../sidebars.mjs';

/**
* Processors are objects contains two methods:
Expand Down Expand Up @@ -55,10 +55,9 @@ const processors = [sortByHeading, slugId];
}
*/
const buildFileList = async () => {
const config = require(`../../sidebars.js`);
const fileList = config.guideSidebar[2].items.map(({ id }) => ({
const fileList = sidebars.guideSidebar[2].items.map(({ id }) => ({
type: file.ROUTE_TYPE,
path: path.resolve(__dirname, '..', `./${id}.md`),
path: fileURLToPath(new URL(`../${id}.mdx`, import.meta.url)),
lang: file.LANG_EN,
}));
// let fileList = [];
Expand Down Expand Up @@ -88,7 +87,7 @@ const buildStagedList = async () => {
// stagedFileList.push(e.filename);
// }
// });
const stagedFileList = stagedFiles.filter((e) => e.filename.endsWith('.md')).map((e) => e.filename);
const stagedFileList = stagedFiles.filter((e) => e.filename.endsWith('.md') || e.filename.endsWith('.mdx')).map((e) => e.filename);
const fullFileList = await buildFileList();
// const result = [];
// stagedFileList.forEach((e) => {
Expand All @@ -103,7 +102,7 @@ const buildStagedList = async () => {
};

/** Entry
* Usage: node format.js --full/--staged
* Usage: node format.mjs --full/--staged
*/
(async () => {
// Mode
Expand Down
126 changes: 0 additions & 126 deletions website/docs/.format/md/hierarchySlug.js

This file was deleted.

26 changes: 26 additions & 0 deletions website/docs/.format/removeHeadingId.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export default {
rules: (list) => list.filter((e) => e),
handler: async (data) => {
const content = data.split('\n');
let lastH2 = '';
let lastH3 = '';

for (let i = 0; i < content.length; i++) {
if (content[i].startsWith('## ')) {
lastH2 = content[i].match(`## (([^{])*)`)?.[1].trim();

content[i] = `## ${lastH2}`;
} else if (content[i].startsWith('### ')) {
lastH3 = content[i].match(`### (([^{])*)`)?.[1].trim();

content[i] = `### ${lastH3}`;
} else if (content[i].startsWith('#### ')) {
const title = content[i].match(`#### (([^{])*)`)?.[1].trim();

content[i] = `#### ${title}`;
}
}

return Promise.resolve(content.join('\n'));
},
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { pinyin } = require('pinyin-pro');
import { pinyin } from 'pinyin-pro';

const slugify = (s) => {
s = s?.replace(/[#&'()+,/:[\]|’“”、「」・().:|]/g, '-');
Expand All @@ -18,7 +18,7 @@ const slugify = (s) => {
);
};

module.exports = {
export default {
rules: (list) => list.filter((e) => e),
handler: async (data) => {
const content = data.split('\n');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const file = require('./file');
import file from './file.mjs';
const pinyinCompare = new Intl.Collator('zh-Hans-CN-u-co-pinyin').compare;
const isASCII = (str) => /^[\x00-\x7F]*$/.test(str);

module.exports = {
export default {
rules: (list) => list.filter((e) => e.type === file.ROUTE_TYPE),
handler: async (data) => {
const content = data.split('\n');
Expand Down
Loading

0 comments on commit 06721a0

Please sign in to comment.