Skip to content

Commit

Permalink
use vitepress v1 (#308)
Browse files Browse the repository at this point in the history
* use vitepress v1

* fix
  • Loading branch information
ota-meshi committed Mar 24, 2024
1 parent 1424a6e commit 9dc4250
Show file tree
Hide file tree
Showing 56 changed files with 1,092 additions and 878 deletions.
7 changes: 4 additions & 3 deletions .eslintignore
Expand Up @@ -2,13 +2,14 @@
/.nyc_output
/coverage
/dist
/docs/.vuepress/dist
/docs/.vuepress/components/demo/demo-code.js
!/docs/.vitepress
/docs/.vitepress/dist
/docs/.vitepress/cache
/docs/.vitepress/build-system/shim
/lib
/node_modules
/schemastore
/tests/fixtures/integrations
/assets
!/.github
!/.vscode
!/docs/.vuepress
17 changes: 14 additions & 3 deletions .eslintrc.js
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/+package-json",
"plugin:@ota-meshi/+json",
"plugin:@ota-meshi/+yaml",
Expand Down Expand Up @@ -100,7 +100,7 @@ module.exports = {
},
overrides: [
{
files: ["*.ts"],
files: ["*.ts", "*.mts"],
parser: "@typescript-eslint/parser",
parserOptions: {
sourceType: "module",
Expand Down Expand Up @@ -170,7 +170,8 @@ module.exports = {
},
},
{
files: ["docs/.vuepress/**"],
files: ["docs/.vitepress/**/*.*", "docs/.vitepress/*.*"],
extends: ["plugin:@typescript-eslint/disable-type-checked"],
parserOptions: {
sourceType: "module",
ecmaVersion: 2020,
Expand All @@ -186,6 +187,13 @@ module.exports = {
"eslint-plugin/prefer-message-ids": "off",
"eslint-plugin/prefer-object-rule": "off",
"eslint-plugin/require-meta-schema": "off",
"n/no-extraneous-import": "off",
},
},
{
files: ["docs/.vitepress/**/*.ts", "docs/.vitepress/**/*.mts"],
parserOptions: {
project: null,
},
},
{
Expand All @@ -196,6 +204,9 @@ module.exports = {
},
{
files: ["*.md/**", "**/*.md/**"],
parserOptions: {
sourceType: "module",
},
rules: {
"n/no-missing-import": "off",
},
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/GHPages.yml
Expand Up @@ -38,7 +38,7 @@ jobs:
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./docs/.vuepress/dist
path: ./docs/.vitepress/dist/eslint-plugin-json-schema-validator
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
6 changes: 6 additions & 0 deletions .gitignore
Expand Up @@ -91,6 +91,10 @@ dist
# vuepress build output
.vuepress/dist

# vitepress build output
docs/.vitepress/dist
docs/.vitepress/cache

# Serverless directories
.serverless/

Expand All @@ -115,3 +119,5 @@ dist
/.cached_schemastore

/yarn.lock

/docs/.vitepress/build-system/shim
2 changes: 0 additions & 2 deletions .vscode/settings.json
Expand Up @@ -13,8 +13,6 @@
],
"typescript.validate.enable": true,
"javascript.validate.enable": false,
"vetur.validation.script": false,
"vetur.validation.style": false,
"css.validate": false,
"typescript.tsdk": "node_modules/typescript/lib",
"editor.codeActionsOnSave": {
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -49,7 +49,7 @@ Use `eslint.config.js` file to configure rules. See also: <https://eslint.org/do

Example **eslint.config.js**:

```mjs
```js
import eslintPluginJsonSchemaValidator from 'eslint-plugin-json-schema-validator';
export default [
// add more generic rule sets here, such as:
Expand Down
62 changes: 62 additions & 0 deletions docs/.vitepress/build-system/build.mts
@@ -0,0 +1,62 @@
/**
* 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
@@ -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
@@ -0,0 +1,4 @@
import all from "vue-eslint-parser";
export default all;
export const parseForESLint = all.parseForESLint;
export const AST = all.AST;
148 changes: 148 additions & 0 deletions docs/.vitepress/config.mts
@@ -0,0 +1,148 @@
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 schemaPath = "../../lib/utils/schema.js";
const schema = (await import(
schemaPath
// eslint-disable-next-line @typescript-eslint/consistent-type-imports -- ignore
)) as typeof import("../../src/utils/schema.js");

// Generate a schema store cache and include it in the bundle.
schema.loadJson(
"https://www.schemastore.org/api/json/catalog.json",
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- ignore
{} as any,
);
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- ignore
schema.loadSchema("https://json.schemastore.org/eslintrc.json", {} as any);
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- ignore
schema.loadSchema("https://json.schemastore.org/prettierrc.json", {} as any);
schema.loadSchema(
"https://json.schemastore.org/partial-eslint-plugins.json",
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- ignore
{} as any,
);
const rulesPath = "../../lib/utils/rules.js";
const { rules } = (await import(rulesPath)) as { rules: RuleModule[] };
return defineConfig({
base: "/eslint-plugin-json-schema-validator/",
title: "eslint-plugin-json-schema-validator",
outDir: path.join(dirname, "./dist/eslint-plugin-json-schema-validator"),
description:
"ESLint plugin that validates data using JSON Schema Validator",
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"),
fs: path.join(dirname, "./shim/fs.mjs"),
synckit: path.join(dirname, "./shim/synckit.mjs"),
"tunnel-agent": path.join(dirname, "./shim/tunnel-agent.mjs"),
events: path.join(dirname, "./build-system/shim/events.mjs"),
},
},
define: {
"process.env.NODE_DEBUG": "false",
"process.platform": JSON.stringify(process.platform),
"process.version": JSON.stringify(process.version),
},
optimizeDeps: {
// exclude: ["vue-eslint-parser"],
},
},

lastUpdated: true,
themeConfig: {
search: {
provider: "local",
options: {
detailedView: true,
},
},
editLink: {
pattern:
"https://github.com/ota-meshi/eslint-plugin-json-schema-validator/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-json-schema-validator",
},
],
sidebar: {
"/rules/": [
{
text: "Rules",
items: [{ text: "Available Rules", link: "/rules/" }],
},
{
text: "JSON Schema Validator 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/" },
],
},
],
},
},
});
};
7 changes: 7 additions & 0 deletions docs/.vitepress/shim/fs.mjs
@@ -0,0 +1,7 @@
export function existsSync(arg) {
return arg === "/";
}
export function mkdirSync() {
// noop
}
export default { existsSync, mkdirSync };
6 changes: 6 additions & 0 deletions docs/.vitepress/shim/module.mjs
@@ -0,0 +1,6 @@
export function createRequire() {
// noop
}
export default {
createRequire,
};
32 changes: 32 additions & 0 deletions docs/.vitepress/shim/require-from-cache.mjs
@@ -0,0 +1,32 @@
import catalog from "../../../.cached_schemastore/www.schemastore.org/api/json/catalog.json";
import eslintrc from "../../../.cached_schemastore/json.schemastore.org/eslintrc.json";
import partialEslintPlugins from "../../../.cached_schemastore/json.schemastore.org/partial-eslint-plugins.json";
import prettierrc from "../../../.cached_schemastore/json.schemastore.org/prettierrc.json";

/**
* @param {string} p
*/
export default function fakeRequire(p) {
if (
p.endsWith(".cached_schemastore/www.schemastore.org/api/json/catalog.json")
) {
return { ...catalog, timestamp: Infinity };
}
if (p.endsWith(".cached_schemastore/json.schemastore.org/eslintrc.json")) {
return { ...eslintrc, timestamp: Infinity };
}
if (
p.endsWith(
".cached_schemastore/json.schemastore.org/partial-eslint-plugins.json",
)
) {
return { ...partialEslintPlugins, timestamp: Infinity };
}
if (p.endsWith(".cached_schemastore/json.schemastore.org/prettierrc.json")) {
return { ...prettierrc, timestamp: Infinity };
}
console.log(`unknown:${p}`);
return {};
}

fakeRequire.resolve = () => "";
5 changes: 5 additions & 0 deletions docs/.vitepress/shim/synckit.mjs
@@ -0,0 +1,5 @@
export function createSyncFn() {
return function () {
// noop
};
}
2 changes: 2 additions & 0 deletions docs/.vitepress/shim/tunnel-agent.mjs
@@ -0,0 +1,2 @@
export {};
export default {};

0 comments on commit 9dc4250

Please sign in to comment.