Skip to content

Commit 06e8ea4

Browse files
authored
chore: use vitepress (#340)
* chore: use vitepress * update * fix * update * update * update
1 parent 7711a7b commit 06e8ea4

Some content is hidden

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

51 files changed

+15541
-40433
lines changed

.eslintignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
/dist
44
/node_modules
55
/assets
6-
/docs/.vuepress/dist
6+
!/docs/.vitepress
7+
/docs/.vitepress/dist
8+
/docs/.vitepress/cache
9+
/docs/.vitepress/build-system/shim
710
/fixtures
811
/tests/lib/styles/fixtures
912
/package-lock.json
1013
!/.github
1114
!/.vscode
12-
!/docs/.vuepress

.eslintrc.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ module.exports = {
7676
},
7777
overrides: [
7878
{
79-
files: ["*.ts"],
79+
files: ["*.ts", "*.mts"],
8080
parser: "@typescript-eslint/parser",
8181
rules: {
8282
"@typescript-eslint/no-require-imports": "off",
@@ -148,12 +148,16 @@ module.exports = {
148148
},
149149
},
150150
{
151-
files: ["docs/.vuepress/**"],
151+
files: ["docs/.vitepress/**"],
152152
parserOptions: {
153153
sourceType: "module",
154154
ecmaVersion: 2020,
155155
},
156-
extends: ["plugin:@ota-meshi/+vue2", "plugin:@ota-meshi/+prettier"],
156+
extends: [
157+
"plugin:@ota-meshi/+vue3",
158+
"plugin:@ota-meshi/+prettier",
159+
"plugin:@typescript-eslint/disable-type-checked",
160+
],
157161
globals: {
158162
window: true,
159163
},
@@ -162,6 +166,17 @@ module.exports = {
162166
"n/no-unsupported-features/es-syntax": "off",
163167
"n/no-missing-import": "off",
164168
"n/no-missing-require": "off",
169+
"n/file-extension-in-import": "off",
170+
"n/no-extraneous-import": "off",
171+
},
172+
},
173+
{
174+
files: ["docs/.vitepress/**/*.mts", "docs/.vitepress/**/*.ts"],
175+
parser: "@typescript-eslint/parser",
176+
parserOptions: {
177+
sourceType: "module",
178+
ecmaVersion: 2020,
179+
project: null,
165180
},
166181
},
167182
],

.github/workflows/GHPages.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
- name: Upload artifact
3838
uses: actions/upload-pages-artifact@v3
3939
with:
40-
path: ./docs/.vuepress/dist
40+
path: ./docs/.vitepress/dist/eslint-plugin-vue-scoped-css
4141
- name: Deploy to GitHub Pages
4242
id: deployment
4343
uses: actions/deploy-pages@v4

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/node_modules
2-
/docs/.vuepress/dist
2+
/docs/.vitepress/dist
3+
/docs/.vitepress/cache
4+
/docs/.vitepress/build-system/shim
35
/dist
46
/.nyc_output
57
/coverage

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Use `eslint.config.js` file to configure rules. See also: <https://eslint.org/do
5757

5858
Example **eslint.config.js**:
5959

60-
```mjs
60+
```js
6161
import eslintPluginVueScopedCSS from 'eslint-plugin-vue-scoped-css';
6262
export default [
6363
// add more generic rule sets here, such as:
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
import.meta.url,
12+
),
13+
);
14+
15+
build(
16+
path.join(dirname, "./src/vue-eslint-parser.mjs"),
17+
path.join(dirname, "./shim/vue-eslint-parser.mjs"),
18+
["eslint", "path", "module", "events"],
19+
);
20+
build(
21+
path.join(dirname, "./src/events.mjs"),
22+
path.join(dirname, "./shim/events.mjs"),
23+
[],
24+
);
25+
26+
function build(input: string, out: string, injects: string[] = []) {
27+
// eslint-disable-next-line no-console -- ignore
28+
console.log(`build@ ${input}`);
29+
let code = bundle(input, injects);
30+
code = transform(code, injects);
31+
fs.mkdirSync(path.dirname(out), { recursive: true });
32+
fs.writeFileSync(out, code, "utf8");
33+
}
34+
35+
function bundle(entryPoint: string, externals: string[]) {
36+
const result = esbuild.buildSync({
37+
entryPoints: [entryPoint],
38+
format: "esm",
39+
bundle: true,
40+
external: externals,
41+
write: false,
42+
});
43+
44+
return `${result.outputFiles[0].text}`;
45+
}
46+
47+
function transform(code: string, injects: string[]) {
48+
const newCode = code.replace(/"[a-z]+" = "[a-z]+";/u, "");
49+
return `
50+
${injects
51+
.map(
52+
(inject) =>
53+
`import $inject_${inject.replace(/-/gu, "_")}$ from '${inject}';`,
54+
)
55+
.join("\n")}
56+
const $_injects_$ = {${injects
57+
.map((inject) => `${inject.replace(/-/gu, "_")}:$inject_${inject}$`)
58+
.join(",\n")}};
59+
function require(module, ...args) {
60+
return $_injects_$[module] || {}
61+
}
62+
${newCode}
63+
64+
if (typeof __require !== 'undefined') __require.cache = {};
65+
`;
66+
}
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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import all from "vue-eslint-parser";
2+
export default all;
3+
export const parseForESLint = all.parseForESLint;
4+
export const AST = all.AST;

docs/.vitepress/config.mts

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

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+
};

docs/.vitepress/shim/safer-buffer.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {};

docs/.vitepress/shim/sax.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {};
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
module.exports = {
2-
extends: ["stylelint-config-standard", "stylelint-stylus/standard"],
2+
extends: ["stylelint-config-standard-vue"],
33
rules: {
44
"no-descending-specificity": null,
55
"selector-class-pattern": null,
66
"value-keyword-case": null,
7+
8+
// Conflict with Prettier
9+
indentation: null,
710
},
811
};

0 commit comments

Comments
 (0)