Skip to content

chore: use vitepress #340

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
/dist
/node_modules
/assets
/docs/.vuepress/dist
!/docs/.vitepress
/docs/.vitepress/dist
/docs/.vitepress/cache
/docs/.vitepress/build-system/shim
/fixtures
/tests/lib/styles/fixtures
/package-lock.json
!/.github
!/.vscode
!/docs/.vuepress
21 changes: 18 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ module.exports = {
},
overrides: [
{
files: ["*.ts"],
files: ["*.ts", "*.mts"],
parser: "@typescript-eslint/parser",
rules: {
"@typescript-eslint/no-require-imports": "off",
Expand Down Expand Up @@ -148,12 +148,16 @@ module.exports = {
},
},
{
files: ["docs/.vuepress/**"],
files: ["docs/.vitepress/**"],
parserOptions: {
sourceType: "module",
ecmaVersion: 2020,
},
extends: ["plugin:@ota-meshi/+vue2", "plugin:@ota-meshi/+prettier"],
extends: [
"plugin:@ota-meshi/+vue3",
"plugin:@ota-meshi/+prettier",
"plugin:@typescript-eslint/disable-type-checked",
],
globals: {
window: true,
},
Expand All @@ -162,6 +166,17 @@ module.exports = {
"n/no-unsupported-features/es-syntax": "off",
"n/no-missing-import": "off",
"n/no-missing-require": "off",
"n/file-extension-in-import": "off",
"n/no-extraneous-import": "off",
},
},
{
files: ["docs/.vitepress/**/*.mts", "docs/.vitepress/**/*.ts"],
parser: "@typescript-eslint/parser",
parserOptions: {
sourceType: "module",
ecmaVersion: 2020,
project: null,
},
},
],
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/GHPages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./docs/.vuepress/dist
path: ./docs/.vitepress/dist/eslint-plugin-vue-scoped-css
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/node_modules
/docs/.vuepress/dist
/docs/.vitepress/dist
/docs/.vitepress/cache
/docs/.vitepress/build-system/shim
/dist
/.nyc_output
/coverage
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Use `eslint.config.js` file to configure rules. See also: <https://eslint.org/do

Example **eslint.config.js**:

```mjs
```js
import eslintPluginVueScopedCSS from 'eslint-plugin-vue-scoped-css';
export default [
// add more generic rule sets here, such as:
Expand Down
66 changes: 66 additions & 0 deletions docs/.vitepress/build-system/build.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* Pre-build cjs packages that cannot be bundled well.
*/
import esbuild from "esbuild";
import path from "path";
import fs from "fs";
import { fileURLToPath } from "url";

const dirname = path.dirname(
fileURLToPath(
import.meta.url,
),
);

build(
path.join(dirname, "./src/vue-eslint-parser.mjs"),
path.join(dirname, "./shim/vue-eslint-parser.mjs"),
["eslint", "path", "module", "events"],
);
build(
path.join(dirname, "./src/events.mjs"),
path.join(dirname, "./shim/events.mjs"),
[],
);

function build(input: string, out: string, injects: string[] = []) {
// eslint-disable-next-line no-console -- ignore
console.log(`build@ ${input}`);
let code = bundle(input, injects);
code = transform(code, injects);
fs.mkdirSync(path.dirname(out), { recursive: true });
fs.writeFileSync(out, code, "utf8");
}

function bundle(entryPoint: string, externals: string[]) {
const result = esbuild.buildSync({
entryPoints: [entryPoint],
format: "esm",
bundle: true,
external: externals,
write: false,
});

return `${result.outputFiles[0].text}`;
}

function transform(code: string, injects: string[]) {
const newCode = code.replace(/"[a-z]+" = "[a-z]+";/u, "");
return `
${injects
.map(
(inject) =>
`import $inject_${inject.replace(/-/gu, "_")}$ from '${inject}';`,
)
.join("\n")}
const $_injects_$ = {${injects
.map((inject) => `${inject.replace(/-/gu, "_")}:$inject_${inject}$`)
.join(",\n")}};
function require(module, ...args) {
return $_injects_$[module] || {}
}
${newCode}

if (typeof __require !== 'undefined') __require.cache = {};
`;
}
3 changes: 3 additions & 0 deletions docs/.vitepress/build-system/src/events.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import all from "events";
export default all;
export const EventEmitter = all.EventEmitter;
4 changes: 4 additions & 0 deletions docs/.vitepress/build-system/src/vue-eslint-parser.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import all from "vue-eslint-parser";
export default all;
export const parseForESLint = all.parseForESLint;
export const AST = all.AST;
125 changes: 125 additions & 0 deletions docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import type { DefaultTheme, UserConfig } from "vitepress";
import { defineConfig } from "vitepress";
import path from "path";
import { fileURLToPath } from "url";
import eslint4b from "vite-plugin-eslint4b";
import { viteCommonjs } from "./vite-plugin.mjs";

import "./build-system/build.mts";

type RuleModule = {meta:{docs:{ruleId:string,ruleName:string},deprecated?:boolean}};

const dirname = path.dirname(fileURLToPath(import.meta.url));

function ruleToSidebarItem({
meta: {
docs: { ruleId, ruleName },
},
}: RuleModule): DefaultTheme.SidebarItem {
return {
text: ruleId,
link: `/rules/${ruleName}`,
};
}

export default async (): Promise<UserConfig<DefaultTheme.Config>> => {
const a = "../../dist/utils/rules.js";
const { rules } = (await import(a)) as { rules: RuleModule[] };
return defineConfig({
base: "/eslint-plugin-vue-scoped-css/",
title: "eslint-plugin-vue-scoped-css",
outDir: path.join(dirname, "./dist/eslint-plugin-vue-scoped-css"),
description: "ESLint plugin for Scoped CSS in Vue.js",
head: [],

vite: {
plugins: [viteCommonjs(), eslint4b()],
resolve: {
alias: {
"vue-eslint-parser": path.join(
dirname,
"./build-system/shim/vue-eslint-parser.mjs",
),
module: path.join(dirname, "./shim/module.mjs"),
'safer-buffer': path.join(dirname, "./shim/module.mjs"),
'sax': path.join(dirname, "./shim/sax.mjs"),
events: path.join(dirname, "./build-system/shim/events.mjs"),
stylus: path.join(dirname, "../../node_modules/stylus/lib/browserify.js"),
},
},
define: {
"process.env.NODE_DEBUG": "false",
},
optimizeDeps: {
// exclude: ["vue-eslint-parser"],
},
},

lastUpdated: true,
themeConfig: {
search: {
provider: "local",
options: {
detailedView: true,
},
},
editLink: {
pattern:
"https://github.com/future-architect/eslint-plugin-vue-scoped-css/edit/master/docs/:path",
},
nav: [
{ text: "Introduction", link: "/" },
{ text: "User Guide", link: "/user-guide/" },
{ text: "Rules", link: "/rules/" },
{ text: "Playground", link: "/playground/" },
],
socialLinks: [
{
icon: "github",
link: "https://github.com/future-architect/eslint-plugin-vue-scoped-css",
},
],
sidebar: {
"/rules/": [
{
text: "Rules",
items: [{ text: "Available Rules", link: "/rules/" }],
},
{
text: "Vue Scoped CSS Rules",
collapsed: false,
items: rules
.filter(
(rule) =>
!rule.meta.deprecated,
)
.map(ruleToSidebarItem),
},

// Rules in no category.
...(rules.some((rule) => rule.meta.deprecated)
? [
{
text: "Deprecated",
collapsed: false,
items: rules
.filter((rule) => rule.meta.deprecated)
.map(ruleToSidebarItem),
},
]
: []),
],
"/": [
{
text: "Guide",
items: [
{ text: "Introduction", link: "/" },
{ text: "User Guide", link: "/user-guide/" },
{ text: "Rules", link: "/rules/" },
],
},
],
},
},
});
};
6 changes: 6 additions & 0 deletions docs/.vitepress/shim/module.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export function createRequire() {
// noop
}
export default {
createRequire,
};
1 change: 1 addition & 0 deletions docs/.vitepress/shim/safer-buffer.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
1 change: 1 addition & 0 deletions docs/.vitepress/shim/sax.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
module.exports = {
extends: ["stylelint-config-standard", "stylelint-stylus/standard"],
extends: ["stylelint-config-standard-vue"],
rules: {
"no-descending-specificity": null,
"selector-class-pattern": null,
"value-keyword-case": null,

// Conflict with Prettier
indentation: null,
},
};
Loading