Skip to content

Commit 6f8c970

Browse files
authored
chore: use vitepress (#264)
1 parent eabeb1b commit 6f8c970

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+583
-381
lines changed

.eslintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
/dist-ts
55
/docs/.vuepress/dist
66
/docs/.vuepress/components/demo/demo-code.js
7+
/docs/.vitepress/cache
8+
/docs/.vitepress/build-system/shim
79
/node_modules
810
/tests/fixtures/integrations
911
/tests/fixtures/**/*.vue
@@ -17,3 +19,4 @@
1719
!/.github
1820
!/.vscode
1921
!/docs/.vuepress
22+
!/docs/.vitepress

.eslintrc.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = {
88
"plugin:@ota-meshi/+node",
99
"plugin:@ota-meshi/+typescript",
1010
"plugin:@ota-meshi/+eslint-plugin",
11-
"plugin:@ota-meshi/+vue2",
11+
"plugin:@ota-meshi/+vue3",
1212
"plugin:@ota-meshi/+json",
1313
"plugin:@ota-meshi/+package-json",
1414
"plugin:@ota-meshi/+yaml",
@@ -41,7 +41,7 @@ module.exports = {
4141
},
4242
overrides: [
4343
{
44-
files: ["*.ts"],
44+
files: ["*.ts", "*.mts"],
4545
rules: {
4646
"@typescript-eslint/naming-convention": "off",
4747
},

.github/workflows/GHPages.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,13 @@ jobs:
3232
run: npm install
3333
- name: Build docs
3434
run: |+
35-
export NODE_OPTIONS=--openssl-legacy-provider
3635
npm run docs:build
3736
- name: Setup Pages
3837
uses: actions/configure-pages@v3
3938
- name: Upload artifact
4039
uses: actions/upload-pages-artifact@v2
4140
with:
42-
path: ./docs/.vuepress/dist
41+
path: ./docs/.vitepress/dist/eslint-plugin-jsonc
4342
- name: Deploy to GitHub Pages
4443
id: deployment
4544
uses: actions/deploy-pages@v2

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,5 @@ dist
115115
/playground
116116
/rules
117117
/user-guide
118+
/docs/.vitepress/cache
119+
/docs/.vitepress/build-system/shim
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module.exports = {
22
rules: {
33
"require-jsdoc": "off",
4+
"n/file-extension-in-import": "off",
45
},
56
};
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/**
2+
* Pre-build cjs packages that cannot be bundled well.
3+
*/
4+
import esbuild from "esbuild";
5+
import path from "path";
6+
import fs from "fs";
7+
import { fileURLToPath } from "url";
8+
9+
const dirname = path.dirname(
10+
fileURLToPath(
11+
// @ts-expect-error -- Cannot change `module` option
12+
import.meta.url,
13+
),
14+
);
15+
16+
build(
17+
path.join(dirname, "./src/vue-eslint-parser.mjs"),
18+
path.join(dirname, "./shim/vue-eslint-parser.mjs"),
19+
["eslint", "path", "module", "events"],
20+
);
21+
build(
22+
path.join(dirname, "./src/events.mjs"),
23+
path.join(dirname, "./shim/events.mjs"),
24+
[],
25+
);
26+
27+
function build(input: string, out: string, injects: string[] = []) {
28+
// eslint-disable-next-line no-console -- ignore
29+
console.log(`build@ ${input}`);
30+
let code = bundle(input, injects);
31+
code = transform(code, injects);
32+
fs.mkdirSync(path.dirname(out), { recursive: true });
33+
fs.writeFileSync(out, code, "utf8");
34+
}
35+
36+
function bundle(entryPoint: string, externals: string[]) {
37+
const result = esbuild.buildSync({
38+
entryPoints: [entryPoint],
39+
format: "esm",
40+
bundle: true,
41+
external: externals,
42+
write: false,
43+
});
44+
45+
return `${result.outputFiles[0].text}`;
46+
}
47+
48+
function transform(code: string, injects: string[]) {
49+
const newCode = code.replace(/"[a-z]+" = "[a-z]+";/u, "");
50+
return `
51+
${injects
52+
.map(
53+
(inject) =>
54+
`import $inject_${inject.replace(/-/gu, "_")}$ from '${inject}';`,
55+
)
56+
.join("\n")}
57+
const $_injects_$ = {${injects
58+
.map((inject) => `${inject.replace(/-/gu, "_")}:$inject_${inject}$`)
59+
.join(",\n")}};
60+
function require(module, ...args) {
61+
return $_injects_$[module] || {}
62+
}
63+
${newCode}
64+
65+
if (typeof __require !== 'undefined') __require.cache = {};
66+
`;
67+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import all from "events";
2+
export default all;
3+
export const EventEmitter = all.EventEmitter;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import all from "vue-eslint-parser";
2+
export default all;
3+
export const parseForESLint = all.parseForESLint;

docs/.vitepress/config.mts

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
import type { DefaultTheme, UserConfig } from "vitepress";
2+
import { defineConfig } from "vitepress";
3+
import { BUNDLED_LANGUAGES } from "shiki";
4+
import path from "path";
5+
import { fileURLToPath } from "url";
6+
import eslint4b from "vite-plugin-eslint4b";
7+
import type { RuleModule } from "../../lib/types.js";
8+
import { viteCommonjs, vitePluginAutoRule } from "./vite-plugin.mjs";
9+
10+
import "./build-system/build.js";
11+
const dirname = path.dirname(fileURLToPath(import.meta.url));
12+
13+
// Include `json5` as alias for jsonc
14+
const jsonc = BUNDLED_LANGUAGES.find((lang) => lang.id === "jsonc");
15+
if (jsonc) jsonc.aliases = [...(jsonc?.aliases ?? []), "json5"];
16+
17+
function ruleToSidebarItem({
18+
meta: {
19+
docs: { ruleId, ruleName },
20+
},
21+
}: RuleModule): DefaultTheme.SidebarItem {
22+
return {
23+
text: ruleId,
24+
link: `/rules/${ruleName}`,
25+
};
26+
}
27+
28+
export default async (): Promise<UserConfig<DefaultTheme.Config>> => {
29+
const a = "../../dist/utils/rules.js";
30+
const { rules } = (await import(a)) as { rules: RuleModule[] };
31+
return defineConfig({
32+
base: "/eslint-plugin-jsonc/",
33+
title: "eslint-plugin-jsonc",
34+
outDir: path.join(dirname, "./dist/eslint-plugin-jsonc"),
35+
description:
36+
"ESLint plugin for finding RegExp mistakes and RegExp style guide violations.",
37+
head: [
38+
[
39+
"link",
40+
{
41+
rel: "icon",
42+
href: "/eslint-plugin-jsonc/logo.svg",
43+
type: "image/svg+xml",
44+
},
45+
],
46+
],
47+
48+
vite: {
49+
plugins: [viteCommonjs(), vitePluginAutoRule(), eslint4b()],
50+
resolve: {
51+
alias: {
52+
"vue-eslint-parser": path.join(
53+
dirname,
54+
"./build-system/shim/vue-eslint-parser.mjs",
55+
),
56+
module: path.join(dirname, "./shim/module.mjs"),
57+
events: path.join(dirname, "./build-system/shim/events.mjs"),
58+
},
59+
},
60+
define: {
61+
"process.env.NODE_DEBUG": "false",
62+
},
63+
optimizeDeps: {
64+
// exclude: ["vue-eslint-parser"],
65+
},
66+
},
67+
68+
lastUpdated: true,
69+
themeConfig: {
70+
logo: "/logo.svg",
71+
search: {
72+
provider: "local",
73+
options: {
74+
detailedView: true,
75+
},
76+
},
77+
editLink: {
78+
pattern:
79+
"https://github.com/ota-meshi/eslint-plugin-jsonc/edit/master/docs/:path",
80+
},
81+
nav: [
82+
{ text: "Introduction", link: "/" },
83+
{ text: "User Guide", link: "/user-guide/" },
84+
{ text: "Rules", link: "/rules/" },
85+
{ text: "Playground", link: "/playground/" },
86+
],
87+
socialLinks: [
88+
{
89+
icon: "github",
90+
link: "https://github.com/ota-meshi/eslint-plugin-jsonc",
91+
},
92+
],
93+
sidebar: {
94+
"/rules/": [
95+
{
96+
text: "Rules",
97+
items: [{ text: "Available Rules", link: "/rules/" }],
98+
},
99+
{
100+
text: "JSONC Rules",
101+
collapsed: false,
102+
items: rules
103+
.filter(
104+
(rule) =>
105+
!rule.meta.docs.extensionRule && !rule.meta.deprecated,
106+
)
107+
.map(ruleToSidebarItem),
108+
},
109+
{
110+
text: "Extension Rules",
111+
collapsed: false,
112+
items: rules
113+
.filter(
114+
(rule) => rule.meta.docs.extensionRule && !rule.meta.deprecated,
115+
)
116+
.map(ruleToSidebarItem),
117+
},
118+
119+
// Rules in no category.
120+
...(rules.some((rule) => rule.meta.deprecated)
121+
? [
122+
{
123+
text: "Deprecated",
124+
collapsed: false,
125+
items: rules
126+
.filter((rule) => rule.meta.deprecated)
127+
.map(ruleToSidebarItem),
128+
},
129+
]
130+
: []),
131+
],
132+
"/": [
133+
{
134+
text: "Guide",
135+
items: [
136+
{ text: "Introduction", link: "/" },
137+
{ text: "User Guide", link: "/user-guide/" },
138+
{ text: "Rules", link: "/rules/" },
139+
],
140+
},
141+
],
142+
},
143+
},
144+
});
145+
};

docs/.vitepress/shim/module.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export function createRequire() {
2+
// noop
3+
}
4+
export default {
5+
createRequire,
6+
};

0 commit comments

Comments
 (0)