Skip to content

Commit

Permalink
chore: use vitepress (#154)
Browse files Browse the repository at this point in the history
* chore: use vitepress

* fix

* fix
  • Loading branch information
ota-meshi authored Sep 24, 2023
1 parent f7f8afe commit bdd7f3f
Show file tree
Hide file tree
Showing 46 changed files with 559 additions and 538 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
/dist
/docs/.vuepress/dist
/docs/.vuepress/components/demo/demo-code.js
/docs/.vitepress/cache
/docs/.vitepress/build-system/shim
/lib
!/.github
!/.vscode
!/docs/.vuepress
!/docs/.vitepress
9 changes: 5 additions & 4 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = {
"plugin:@ota-meshi/+node",
"plugin:@ota-meshi/+typescript",
"plugin:@ota-meshi/+eslint-plugin",
"plugin:@ota-meshi/+vue2",
"plugin:@ota-meshi/+vue3",
"plugin:@ota-meshi/+json",
"plugin:@ota-meshi/+yaml",
"plugin:@ota-meshi/+md",
Expand All @@ -33,7 +33,7 @@ module.exports = {
},
overrides: [
{
files: ["*.ts"],
files: ["*.ts", "*.mts"],
parser: "@typescript-eslint/parser",
parserOptions: {
sourceType: "module",
Expand Down Expand Up @@ -103,16 +103,17 @@ module.exports = {
},
},
{
files: ["docs/.vuepress/**"],
files: ["docs/.vitepress/**"],
parserOptions: {
sourceType: "module",
ecmaVersion: 2020,
ecmaVersion: "latest",
},
globals: {
window: true,
},
rules: {
"require-jsdoc": "off",
"n/file-extension-in-import": "off",
},
},
],
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/GHPages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- name: Upload artifact
uses: actions/upload-pages-artifact@v2
with:
path: ./docs/.vuepress/dist
path: ./docs/.vitepress/dist/eslint-plugin-toml
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,5 @@ dist
# docs
/docs/assets
/docs/**/*.html
/docs/.vitepress/cache
/docs/.vitepress/build-system/shim
67 changes: 67 additions & 0 deletions docs/.vitepress/build-system/build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* 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(
// @ts-expect-error -- Cannot change `module` option
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;
3 changes: 3 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,3 @@
import all from "vue-eslint-parser";
export default all;
export const parseForESLint = all.parseForESLint;
144 changes: 144 additions & 0 deletions docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import type { DefaultTheme, UserConfig } from "vitepress";
import { defineConfig } from "vitepress";
import { BUNDLED_LANGUAGES } from "shiki";
import path from "path";
import { fileURLToPath } from "url";
import eslint4b from "vite-plugin-eslint4b";
import type { RuleModule } from "../../src/types.js";
import { viteCommonjs } from "./vite-plugin.mjs";

import "./build-system/build.js";
const dirname = path.dirname(fileURLToPath(import.meta.url));

// Include `json5` as alias for jsonc
const jsonc = BUNDLED_LANGUAGES.find((lang) => lang.id === "jsonc");
if (jsonc) jsonc.aliases = [...(jsonc?.aliases ?? []), "json5"];

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

export default async (): Promise<UserConfig<DefaultTheme.Config>> => {
const a = "../../lib/utils/rules.js";
const { rules } = (await import(a)) as { rules: RuleModule[] };
return defineConfig({
base: "/eslint-plugin-toml/",
title: "eslint-plugin-toml",
outDir: path.join(dirname, "./dist/eslint-plugin-toml"),
description: "ESLint plugin provides linting rules for TOML",
head: [
[
"link",
{
rel: "icon",
href: "/eslint-plugin-toml/logo.svg",
type: "image/svg+xml",
},
],
],

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"),
events: path.join(dirname, "./build-system/shim/events.mjs"),
},
},
define: {
"process.env.NODE_DEBUG": "false",
},
optimizeDeps: {
// exclude: ["vue-eslint-parser"],
},
},

lastUpdated: true,
themeConfig: {
logo: "/logo.svg",
search: {
provider: "local",
options: {
detailedView: true,
},
},
editLink: {
pattern:
"https://github.com/ota-meshi/eslint-plugin-toml/edit/main/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/ota-meshi/eslint-plugin-toml",
},
],
sidebar: {
"/rules/": [
{
text: "Rules",
items: [{ text: "Available Rules", link: "/rules/" }],
},
{
text: "YAML Rules",
collapsed: false,
items: rules
.filter(
(rule) =>
!rule.meta.docs.extensionRule && !rule.meta.deprecated,
)
.map(ruleToSidebarItem),
},
{
text: "Extension Rules",
collapsed: false,
items: rules
.filter(
(rule) => rule.meta.docs.extensionRule && !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,
};
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

0 comments on commit bdd7f3f

Please sign in to comment.