lint: добавление линтера #5

Merged
arswarog merged 4 commits from format into master 2026-06-18 13:33:29 +03:00
9 changed files with 205 additions and 196 deletions
Showing only changes of commit 436e425119 - Show all commits
+3 -3
View File
@@ -1,4 +1,4 @@
title: "Title example" title: 'Title example'
project: project:
org: "example" org: 'example'
repo: "example" repo: 'example'
+4 -2
View File
@@ -14,7 +14,8 @@ yarn
yarn start yarn start
``` ```
This command starts a local development server and opens up a browser window. Most changes are reflected live without having to restart the server. This command starts a local development server and opens up a browser window. Most changes are
reflected live without having to restart the server.
## Build ## Build
@@ -22,4 +23,5 @@ This command starts a local development server and opens up a browser window. Mo
yarn build yarn build
``` ```
This command generates static content into the `build` directory and can be served using any static contents hosting service. This command generates static content into the `build` directory and can be served using any static
contents hosting service.
+104 -104
View File
@@ -2,120 +2,120 @@ name: 'Docusaurus Deploy'
description: 'Builds Docusaurus docs from repo and deploys to S3' description: 'Builds Docusaurus docs from repo and deploys to S3'
inputs: inputs:
docs-path: docs-path:
description: 'Path to docs directory in calling repo' description: 'Path to docs directory in calling repo'
default: 'docs' default: 'docs'
on-broken-links: on-broken-links:
description: 'Behavior on broken links: throw, warn, or ignore' description: 'Behavior on broken links: throw, warn, or ignore'
default: 'throw' default: 'throw'
prefix: prefix:
description: 'Prefix for S3 path' description: 'Prefix for S3 path'
default: '' default: ''
runs: runs:
using: 'composite' using: 'composite'
steps: steps:
- name: Compute target URL - name: Compute target URL
shell: bash shell: bash
run: | run: |
REF="${{ github.head_ref || github.ref_name }}" REF="${{ github.head_ref || github.ref_name }}"
REPO="${{ github.event.repository.name }}" REPO="${{ github.event.repository.name }}"
ORG="${{ github.repository_owner }}" ORG="${{ github.repository_owner }}"
if [[ "$REF" == "main" || "$REF" == "master" ]]; then if [[ "$REF" == "main" || "$REF" == "master" ]]; then
URL="http://${REPO}.${ORG}.jt4d-wiki.ru.net" URL="http://${REPO}.${ORG}.jt4d-wiki.ru.net"
S3_PATH="${ORG}.${REPO}" S3_PATH="${ORG}.${REPO}"
else else
URL="http://${REF}.${REPO}.${ORG}.jt4d-wiki.ru.net" URL="http://${REF}.${REPO}.${ORG}.jt4d-wiki.ru.net"
S3_PATH="${ORG}.${REPO}.${REF}" S3_PATH="${ORG}.${REPO}.${REF}"
fi fi
PREFIX="${{ inputs.prefix }}" PREFIX="${{ inputs.prefix }}"
if [[ -n "$PREFIX" ]]; then if [[ -n "$PREFIX" ]]; then
S3_PATH="${PREFIX}/${S3_PATH}" S3_PATH="${PREFIX}/${S3_PATH}"
fi fi
echo "TARGET_URL=$URL" >> $GITHUB_ENV echo "TARGET_URL=$URL" >> $GITHUB_ENV
echo "S3_PATH=$S3_PATH" >> $GITHUB_ENV echo "S3_PATH=$S3_PATH" >> $GITHUB_ENV
- name: Set docs status pending - name: Set docs status pending
shell: bash shell: bash
run: | run: |
curl -s -X POST \ curl -s -X POST \
-H "Authorization: token ${{ github.token }}" \ -H "Authorization: token ${{ github.token }}" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d '{ -d '{
"state": "pending", "state": "pending",
"context": "Docs", "context": "Docs",
"description": "building", "description": "building",
"target_url": "${{ env.TARGET_URL }}" "target_url": "${{ env.TARGET_URL }}"
}' \ }' \
"${{ github.server_url }}/api/v1/repos/${{ github.repository }}/statuses/${{ github.sha }}" "${{ github.server_url }}/api/v1/repos/${{ github.repository }}/statuses/${{ github.sha }}"
- name: Copy docs into Docusaurus - name: Copy docs into Docusaurus
shell: bash shell: bash
run: | run: |
DOCUSAURUS_DIR="${{ github.action_path }}" DOCUSAURUS_DIR="${{ github.action_path }}"
rm -rf "${DOCUSAURUS_DIR}/docs" rm -rf "${DOCUSAURUS_DIR}/docs"
cp -r "${{ inputs.docs-path }}" "${DOCUSAURUS_DIR}/docs" cp -r "${{ inputs.docs-path }}" "${DOCUSAURUS_DIR}/docs"
cp "${{ github.workspace }}/.docuservix.yml" "${DOCUSAURUS_DIR}" cp "${{ github.workspace }}/.docuservix.yml" "${DOCUSAURUS_DIR}"
- name: Prepare docs - name: Prepare docs
shell: bash shell: bash
working-directory: ${{ github.action_path }} working-directory: ${{ github.action_path }}
run: node scripts/prepare-docs.mjs run: node scripts/prepare-docs.mjs
- name: Install Docusaurus dependencies - name: Install Docusaurus dependencies
shell: bash shell: bash
working-directory: ${{ github.action_path }} working-directory: ${{ github.action_path }}
run: yarn install --frozen-lockfile run: yarn install --frozen-lockfile
- name: Build docs - name: Build docs
shell: bash shell: bash
working-directory: ${{ github.action_path }} working-directory: ${{ github.action_path }}
env: env:
DOCUSERVIX_ON_BROKEN_LINKS: ${{ inputs.on-broken-links }} DOCUSERVIX_ON_BROKEN_LINKS: ${{ inputs.on-broken-links }}
DOCUSERVIX_URL: ${{ env.TARGET_URL }} DOCUSERVIX_URL: ${{ env.TARGET_URL }}
run: yarn docusaurus build --out-dir ${{ github.workspace }}/generated-docs run: yarn docusaurus build --out-dir ${{ github.workspace }}/generated-docs
- name: Upload to S3 - name: Upload to S3
shell: bash shell: bash
env: env:
AWS_ACCESS_KEY_ID: ${{ vars.DOCUSERVIX_S3_ACCESS }} AWS_ACCESS_KEY_ID: ${{ vars.DOCUSERVIX_S3_ACCESS }}
AWS_SECRET_ACCESS_KEY: ${{ vars.DOCUSERVIX_S3_SECRET }} AWS_SECRET_ACCESS_KEY: ${{ vars.DOCUSERVIX_S3_SECRET }}
run: | run: |
aws s3 sync generated-docs/ \ aws s3 sync generated-docs/ \
s3://${{ vars.DOCUSERVIX_S3_BUCKET }}/${{ env.S3_PATH }}\ s3://${{ vars.DOCUSERVIX_S3_BUCKET }}/${{ env.S3_PATH }}\
--endpoint-url ${{ vars.DOCUSERVIX_S3_URL }} \ --endpoint-url ${{ vars.DOCUSERVIX_S3_URL }} \
--acl public-read \ --acl public-read \
--delete --delete
- name: Set docs status success - name: Set docs status success
if: success() if: success()
shell: bash shell: bash
run: | run: |
curl -s -X POST \ curl -s -X POST \
-H "Authorization: token ${{ github.token }}" \ -H "Authorization: token ${{ github.token }}" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d '{ -d '{
"state": "success", "state": "success",
"context": "Docs", "context": "Docs",
"description": "deployed", "description": "deployed",
"target_url": "${{ env.TARGET_URL }}" "target_url": "${{ env.TARGET_URL }}"
}' \ }' \
"${{ github.server_url }}/api/v1/repos/${{ github.repository }}/statuses/${{ github.sha }}" "${{ github.server_url }}/api/v1/repos/${{ github.repository }}/statuses/${{ github.sha }}"
- name: Set docs status failure - name: Set docs status failure
if: failure() if: failure()
shell: bash shell: bash
run: | run: |
curl -s -X POST \ curl -s -X POST \
-H "Authorization: token ${{ github.token }}" \ -H "Authorization: token ${{ github.token }}" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d '{ -d '{
"state": "failure", "state": "failure",
"context": "Docs", "context": "Docs",
"description": "build failed", "description": "build failed",
"target_url": "${{ env.TARGET_URL }}" "target_url": "${{ env.TARGET_URL }}"
}' \ }' \
"${{ github.server_url }}/api/v1/repos/${{ github.repository }}/statuses/${{ github.sha }}" "${{ github.server_url }}/api/v1/repos/${{ github.repository }}/statuses/${{ github.sha }}"
+1 -1
View File
@@ -1,3 +1,3 @@
# Добро пожаловать в Docuservix! # Добро пожаловать в Docuservix!
Вам надо настроить публикацию документации по инструкции в https://git.jt4d.ru/jt4d/docuservix Вам надо настроить публикацию документации по инструкции в https://git.jt4d.ru/jt4d/docuservix
+15 -20
View File
@@ -1,9 +1,9 @@
import fs from 'fs'; import fs from 'fs';
import yaml from 'js-yaml'; import yaml from 'js-yaml';
import {themes as prismThemes} from 'prism-react-renderer'; import { themes as prismThemes } from 'prism-react-renderer';
import type {Config} from '@docusaurus/types'; import type { Config } from '@docusaurus/types';
import type * as Preset from '@docusaurus/preset-classic'; import type * as Preset from '@docusaurus/preset-classic';
import type {NavbarItem} from '@docusaurus/theme-common' import type { NavbarItem } from '@docusaurus/theme-common';
interface DocsConfig { interface DocsConfig {
title: string; title: string;
@@ -13,24 +13,17 @@ interface DocsConfig {
const docsConfig = yaml.load(fs.readFileSync('./.docuservix.yml', 'utf8')) as DocsConfig; const docsConfig = yaml.load(fs.readFileSync('./.docuservix.yml', 'utf8')) as DocsConfig;
const { const { title } = docsConfig;
title,
} = docsConfig
const url = process.env.DOCUSERVIX_URL; const url = process.env.DOCUSERVIX_URL;
const { const { org, repo } = docsConfig.project;
org,
repo
} = docsConfig.project
const { const { docs: docsDir = 'docs', blog: blogDir } = docsConfig.dirs || {};
docs: docsDir = 'docs',
blog: blogDir
} = docsConfig.dirs || {}
const giteaUrl = 'https://git.jt4d.ru'; const giteaUrl = 'https://git.jt4d.ru';
const onBrokenLinks = (process.env.DOCUSERVIX_ON_BROKEN_LINKS as Config['onBrokenLinks']) || 'throw'; const onBrokenLinks =
(process.env.DOCUSERVIX_ON_BROKEN_LINKS as Config['onBrokenLinks']) || 'throw';
const config: Config = { const config: Config = {
title, title,
@@ -107,11 +100,13 @@ const config: Config = {
label: 'Документация', label: 'Документация',
position: 'left', position: 'left',
}, },
blogDir ? { blogDir
to: '/blog', ? {
label: 'Блог', to: '/blog',
position: 'left' label: 'Блог',
} : undefined, position: 'left',
}
: undefined,
{ {
href: `${giteaUrl}/${org}/${repo}`, href: `${giteaUrl}/${org}/${repo}`,
label: 'Gitea', label: 'Gitea',
+21 -18
View File
@@ -3,20 +3,35 @@
"version": "0.0.0", "version": "0.0.0",
"private": true, "private": true,
"scripts": { "scripts": {
"docusaurus": "docusaurus",
"start": "docusaurus start",
"build": "docusaurus build", "build": "docusaurus build",
"swizzle": "docusaurus swizzle",
"deploy": "docusaurus deploy",
"clear": "docusaurus clear", "clear": "docusaurus clear",
"deploy": "docusaurus deploy",
"docusaurus": "docusaurus",
"prepare": "husky",
"prettier:check": "prettier --check \"**/*.{ts,tsx,js,mjs,json,yml,yaml,md,mdx}\"",
"prettier:fix": "prettier --write \"**/*.{ts,tsx,js,mjs,json,yml,yaml,md,mdx}\"",
"serve": "docusaurus serve", "serve": "docusaurus serve",
"write-translations": "docusaurus write-translations", "start": "docusaurus start",
"swizzle": "docusaurus swizzle",
"typecheck": "tsc",
"write-heading-ids": "docusaurus write-heading-ids", "write-heading-ids": "docusaurus write-heading-ids",
"typecheck": "tsc" "write-translations": "docusaurus write-translations"
}, },
"lint-staged": { "lint-staged": {
"*.{json,ts,tsx,js,jsx,js,mjs,md,mdx,yaml,yml}": "prettier --write" "*.{json,ts,tsx,js,jsx,js,mjs,md,mdx,yaml,yml}": "prettier --write"
}, },
"browserslist": {
"production": [
">0.5%",
"not dead",
"not op_mini all"
],
"development": [
"last 3 chrome version",
"last 3 firefox version",
"last 5 safari version"
]
},
"dependencies": { "dependencies": {
"@docusaurus/core": "3.10.1", "@docusaurus/core": "3.10.1",
"@docusaurus/faster": "3.10.1", "@docusaurus/faster": "3.10.1",
@@ -40,18 +55,6 @@
"prettier": "^3.8.4", "prettier": "^3.8.4",
"typescript": "~6.0.2" "typescript": "~6.0.2"
}, },
"browserslist": {
"production": [
">0.5%",
"not dead",
"not op_mini all"
],
"development": [
"last 3 chrome version",
"last 3 firefox version",
"last 5 safari version"
]
},
"engines": { "engines": {
"node": ">=20.0" "node": ">=20.0"
} }
+15 -14
View File
@@ -9,23 +9,24 @@ pinIndexToTop();
* Гарантирует наличие sidebar_position: 0 в front matter файла index.md * Гарантирует наличие sidebar_position: 0 в front matter файла index.md
*/ */
function pinIndexToTop() { function pinIndexToTop() {
const indexPath = path.join(docsDir, 'index.md'); const indexPath = path.join(docsDir, 'index.md');
if (!fs.existsSync(indexPath)) return; if (!fs.existsSync(indexPath)) return;
let content = fs.readFileSync(indexPath, 'utf8'); let content = fs.readFileSync(indexPath, 'utf8');
if (content.startsWith('---\n')) { if (content.startsWith('---\n')) {
const endIdx = content.indexOf('\n---\n', 4); const endIdx = content.indexOf('\n---\n', 4);
if (endIdx === -1) return; if (endIdx === -1) return;
const frontMatter = content.slice(4, endIdx); const frontMatter = content.slice(4, endIdx);
if (/^sidebar_position\s*:/m.test(frontMatter)) return; if (/^sidebar_position\s*:/m.test(frontMatter)) return;
content = '---\nsidebar_position: 0\n' + frontMatter + '\n---\n' + content.slice(endIdx + 5); content =
} else { '---\nsidebar_position: 0\n' + frontMatter + '\n---\n' + content.slice(endIdx + 5);
content = '---\nsidebar_position: 0\n---\n' + content; } else {
} content = '---\nsidebar_position: 0\n---\n' + content;
}
fs.writeFileSync(indexPath, content); fs.writeFileSync(indexPath, content);
console.log('prepare-docs: pinned index.md to sidebar top'); console.log('prepare-docs: pinned index.md to sidebar top');
} }
+32 -27
View File
@@ -1,4 +1,4 @@
import type {ReactNode} from 'react'; import type { ReactNode } from 'react';
import clsx from 'clsx'; import clsx from 'clsx';
import Link from '@docusaurus/Link'; import Link from '@docusaurus/Link';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
@@ -8,33 +8,38 @@ import Heading from '@theme/Heading';
import styles from './index.module.css'; import styles from './index.module.css';
function HomepageHeader() { function HomepageHeader() {
const {siteConfig} = useDocusaurusContext(); const { siteConfig } = useDocusaurusContext();
return ( return (
<header className={clsx('hero hero--primary', styles.heroBanner)}> <header className={clsx('hero hero--primary', styles.heroBanner)}>
<div className="container"> <div className="container">
<Heading as="h1" className="hero__title"> <Heading
{siteConfig.title} as="h1"
</Heading> className="hero__title"
<p className="hero__subtitle">{siteConfig.tagline}</p> >
<div className={styles.buttons}> {siteConfig.title}
<Link </Heading>
className="button button--secondary button--lg" <p className="hero__subtitle">{siteConfig.tagline}</p>
to="/docs"> <div className={styles.buttons}>
Документация <Link
</Link> className="button button--secondary button--lg"
</div> to="/docs"
</div> >
</header> Документация
); </Link>
</div>
</div>
</header>
);
} }
export default function Home(): ReactNode { export default function Home(): ReactNode {
const {siteConfig} = useDocusaurusContext(); const { siteConfig } = useDocusaurusContext();
return ( return (
<Layout <Layout
title={`Hello from ${siteConfig.title}`} title={`Hello from ${siteConfig.title}`}
description="Description will go into a meta tag in <head />"> description="Description will go into a meta tag in <head />"
<HomepageHeader /> >
</Layout> <HomepageHeader />
); </Layout>
);
} }
+10 -7
View File
@@ -2,11 +2,14 @@
// It is here to improve your IDE experience (type-checking, autocompletion...), // It is here to improve your IDE experience (type-checking, autocompletion...),
// and can also run the package.json "typecheck" script manually. // and can also run the package.json "typecheck" script manually.
{ {
"extends": "@docusaurus/tsconfig", "extends": "@docusaurus/tsconfig",
"compilerOptions": { "compilerOptions": {
"baseUrl": ".", "baseUrl": ".",
"ignoreDeprecations": "6.0", "ignoreDeprecations": "6.0",
"strict": true "strict": true
}, },
"exclude": [".docusaurus", "build"] "exclude": [
".docusaurus",
"build"
]
} }