chore: merge branch from AnYiEE/AwesomeGadgets

这个提交包含在:
安忆 2023-10-29 17:49:13 +08:00 提交者 WaitSpring
父节点 41dad83b91
当前提交 b6508cc748
共有 14 个文件被更改,包括 653 次插入163 次删除

查看文件

@ -12,5 +12,5 @@
}
]
],
"plugins": ["array-includes", "transform-object-hasown"]
"plugins": ["array-includes", "transform-object-hasown", "@babel/plugin-transform-property-literals"]
}

5
.commitlintrc 普通文件
查看文件

@ -0,0 +1,5 @@
{
"extends": [
"@commitlint/config-conventional"
]
}

查看文件

@ -22,33 +22,22 @@
}
],
"no-await-in-loop": "off",
"no-constant-binary-expression": "error",
"no-constructor-return": "error",
"no-duplicate-imports": "error",
"no-new-native-nonconstructor": "error",
"no-promise-executor-return": "error",
"no-self-compare": "error",
"no-template-curly-in-string": "error",
"no-unmodified-loop-condition": "error",
"no-unreachable-loop": "error",
"no-unused-private-class-members": "error",
"no-use-before-define": "off",
"require-atomic-updates": "off",
"accessor-pairs": "error",
"arrow-body-style": ["error", "always"],
"block-scoped-var": "error",
"camelcase": "off",
"capitalized-comments": "off",
"class-methods-use-this": "error",
"complexity": "off",
"consistent-return": "off",
"consistent-this": "off",
"curly": "error",
"default-case": "off",
"default-case-last": "error",
"default-param-last": "error",
"dot-notation": "off",
"eqeqeq": "error",
"func-name-matching": "error",
"func-names": "off",
"func-style": "error",
@ -67,100 +56,61 @@
"max-params": "off",
"max-statements": "off",
"multiline-comment-style": "off",
"new-cap": "error",
"no-alert": "off",
"no-array-constructor": "error",
"no-bitwise": "error",
"no-caller": "error",
"no-confusing-arrow": "error",
"no-console": "off",
"no-continue": "off",
"no-div-regex": "error",
"no-else-return": "error",
"no-empty-function": ["error", {"allow": ["arrowFunctions"]}],
"no-empty-function": [
"error",
{
"allow": ["arrowFunctions"]
}
],
"no-empty-static-block": "error",
"no-eq-null": "error",
"no-eval": "error",
"no-extend-native": "error",
"no-extra-bind": "error",
"no-extra-label": "error",
"no-floating-decimal": "error",
"no-implicit-coercion": "error",
"no-implicit-globals": "error",
"no-implied-eval": "error",
"no-inline-comments": "off",
"no-invalid-this": "off",
"no-iterator": "error",
"no-label-var": "error",
"no-labels": "error",
"no-lone-blocks": "error",
"no-lonely-if": "error",
"no-loop-func": "error",
"no-magic-numbers": "off",
"no-mixed-operators": "off",
"no-multi-assign": "error",
"no-multi-str": "error",
"no-negated-condition": "error",
"no-nested-ternary": "off",
"no-new": "error",
"no-new-func": "error",
"no-new-wrappers": "error",
"no-object-constructor": "error",
"no-octal-escape": "error",
"no-param-reassign": "off",
"no-plusplus": "off",
"no-proto": "error",
"no-restricted-exports": "error",
"no-restricted-globals": "error",
"no-restricted-imports": "error",
"no-restricted-properties": "error",
"no-restricted-syntax": "error",
"no-return-assign": "error",
"no-script-url": "error",
"no-sequences": "error",
"no-shadow": "error",
"no-ternary": "off",
"no-throw-literal": "error",
"no-undef-init": "error",
"no-undefined": "off",
"no-underscore-dangle": "off",
"no-unneeded-ternary": "error",
"no-unused-expressions": "off",
"no-useless-call": "error",
"no-useless-computed-key": "error",
"no-useless-concat": "error",
"no-useless-constructor": "error",
"no-useless-rename": "error",
"no-useless-return": "error",
"no-var": "error",
"no-void": "error",
"no-warning-comments": "off",
"object-shorthand": "error",
"one-var": "off",
"one-var-declaration-per-line": "error",
"operator-assignment": "error",
"prefer-arrow-callback": ["error", {"allowNamedFunctions": true}],
"prefer-const": "error",
"prefer-arrow-callback": [
"error",
{
"allowNamedFunctions": true
}
],
"prefer-destructuring": "error",
"prefer-exponentiation-operator": "error",
"prefer-named-capture-group": "off",
"prefer-numeric-literals": "error",
"prefer-object-has-own": "error",
"prefer-object-spread": "error",
"prefer-promise-reject-errors": "off",
"prefer-regex-literals": "error",
"prefer-rest-params": "error",
"prefer-spread": "error",
"prefer-template": "error",
"quote-props": [
"error",
"as-needed",
{
"keywords": true,
"unnecessary": true,
"numbers": false
}
],
"radix": "error",
"require-await": "error",
"require-unicode-regexp": "off",
@ -170,8 +120,6 @@
"spaced-comment": "off",
"strict": "off",
"symbol-description": "error",
"vars-on-top": "error",
"yoda": "error",
"@typescript-eslint/ban-ts-comment": "warn",
"@typescript-eslint/no-empty-function": [
@ -248,14 +196,18 @@
"unicorn/string-content": "off",
"unicorn/switch-case-braces": ["error", "avoid"],
"getter-return": ["error", {"allowImplicit": true}],
"getter-return": [
"error",
{
"allowImplicit": true
}
],
"no-control-regex": "off",
"quotes": [
"error",
"single",
{
"avoidEscape": true,
"allowTemplateLiterals": true
"avoidEscape": true
}
]
}

1
.gitignore vendored
查看文件

@ -1,3 +1,4 @@
dist
node_modules
script/credentials.json
.*cache

4
.husky/commit-msg 普通文件
查看文件

@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npx --no -- commitlint --edit ${1}

4
.husky/pre-commit 普通文件
查看文件

@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npx lint-staged

查看文件

@ -1,10 +1,8 @@
{
"arrowParens": "always",
"bracketSpacing": false,
"endOfLine": "auto",
"printWidth": 120,
"quoteProps": "as-needed",
"semi": true,
"singleQuote": true,
"tabWidth": 4,
"trailingComma": "es5",

查看文件

@ -44,7 +44,7 @@
"explorer.fileNesting.enabled": true,
"explorer.fileNesting.expand": false,
"explorer.fileNesting.patterns": {
"package.json": ".babel*, .browserslist*, .editorConfig, .eslint*, .git*, pnpm-lock.yaml, .prettier*, .stylelint*, commitlinterrc.json, esbuild.config.js, tsconfig.json, LICENCE",
"package.json": ".babel*, .browserslist*, .commitlint*, .editorConfig, .eslint*, .git*, pnpm-lock.yaml, .prettier*, .stylelint*, esbuild.config.js, tsconfig.json, LICENCE",
"readme*": "*.md"
},
"json.schemas": [

查看文件

@ -14,7 +14,7 @@ Awesome Gadgets 是面向 MediaWiki 网站,用以统一存储、管理并编
**对于小工具开发者:**
1. Fork 仓库
1. Fork 由目标 MediaWiki 网站所维护的仓库
2. 在`src`文件夹下以小工具名新建文件夹
@ -86,6 +86,10 @@ Awesome Gadgets 是面向 MediaWiki 网站,用以统一存储、管理并编
5. 运行`pnpm run deploy`以检查语法、格式化代码、编译源码、并向网站部署
> 请网站维护者注意:在 Fork 本仓库后,本仓库的 Actions 将自动同步上游变更。这意味着在一般情况下,不需要改动除了`src`文件夹和`script/constant.js`之外的东西,以免发生合并冲突。
>
> 建议网站维护者只接受 Pull request,以便 Actions 自动检查并指出代码语法和格式的错误。如果检查未能通过,也不应修改本仓库的相关规则。未通过意味着代码本身存在问题,而不应该将问题归咎于严格的规则。
[qiuwenbaike]: https://www.qiuwenbaike.cn/
[styles]: https://www.qiuwenbaike.cn/wiki/Help:%E7%95%8C%E9%9D%A2%E6%A0%B7%E5%BC%8F%E4%B8%8E%E8%84%9A%E6%9C%AC#%E7%95%8C%E9%9D%A2%E6%A0%B7%E5%BC%8F
[scripts]: https://www.qiuwenbaike.cn/wiki/Help:%E7%95%8C%E9%9D%A2%E6%A0%B7%E5%BC%8F%E4%B8%8E%E8%84%9A%E6%9C%AC#%E7%95%8C%E9%9D%A2%E8%84%9A%E6%9C%AC

查看文件

@ -1,3 +0,0 @@
{
"lang": "zh-CN"
}

查看文件

@ -5,28 +5,35 @@
"type": "git",
"url": "https://github.com/AnYiEE/AwesomeGadgets"
},
"version": "0.0.0",
"version": "1.1.1",
"description": "Storage, compile, and auto deploy gadgets.",
"type": "module",
"scripts": {
"build": "pnpm format && node script/only-build.js",
"deploy": "pnpm format && node esbuild.config.js",
"format": "prettier --write . && pnpm lint:fix",
"eslint": "eslint .",
"eslint:fix": "eslint . --fix",
"stylelint": "stylelint src/**/*.{css,less} --allow-empty-input",
"stylelint:fix": "stylelint src/**/*.{css,less} --allow-empty-input --fix",
"format": "prettier --cache --write . && pnpm lint:fix",
"eslint": "eslint --cache .",
"eslint:fix": "eslint --cache --fix .",
"stylelint": "stylelint --allow-empty-input --cache src/**/*.{css,less} ",
"stylelint:fix": "stylelint --allow-empty-input --cache --fix src/**/*.{css,less} ",
"lint": "pnpm eslint && pnpm stylelint",
"lint:fix": "pnpm eslint:fix && pnpm stylelint:fix"
"lint:fix": "pnpm eslint:fix && pnpm stylelint:fix",
"preinstall": "npx only-allow pnpm",
"prepare": "husky install"
},
"keywords": [
"MediaWiki"
"MediaWiki",
"MediaWiki Gadget",
"Wikipedia"
],
"author": "安忆 <i@anyi.in>",
"license": "GPL-3.0-or-later",
"devDependencies": {
"@babel/core": "^7.23.2",
"@babel/plugin-transform-property-literals": "^7.22.5",
"@babel/preset-env": "^7.23.2",
"@commitlint/cli": "^18.2.0",
"@commitlint/config-conventional": "^18.1.0",
"@types/jqueryui": "^1.12.19",
"@types/oojs-ui": "^0.47.3",
"@typescript-eslint/eslint-plugin": "^5.62.0",
@ -40,8 +47,8 @@
"eslint-config-prettier": "^9.0.0",
"eslint-config-wikimedia": "^0.25.1",
"eslint-plugin-unicorn": "^48.0.1",
"git-commit-msg-linter": "^5.0.4",
"happy-dom": "^12.10.3",
"husky": "^8.0.3",
"mwn": "^2.0.1",
"postcss-less": "^6.0.0",
"prettier": "^3.0.3",
@ -50,5 +57,16 @@
"stylelint-config-wikimedia": "^0.16.1",
"types-mediawiki": "github:AnYiEE/types-mediawiki",
"typescript": "^5.2.2"
},
"lint-staged": {
"*.{css,less}": [
"prettier --cache --write",
"stylelint --allow-empty-input --cache --fix"
],
"*.{cjs,js,ts}": [
"prettier --cache --write",
"eslint --cache --fix"
],
"*": "prettier --cache --ignore-unknown --write"
}
}

文件差异内容过多而无法显示 加载差异

查看文件

@ -31,11 +31,11 @@ const DEFAULT_DEFINITION = {
section: '', // 回落值为appear
actions: [],
contentModels: [],
'default': false,
default: false,
dependencies: [],
hidden: false,
namespaces: false,
'package': false,
package: false,
peers: [],
rights: [],
skins: [],
@ -44,7 +44,13 @@ const DEFAULT_DEFINITION = {
// type: 'general' | 'styles' -> 自动识别,无需指定
};
/** @type {Record<string, string | undefined>} */
/**
* 指定`MediaWiki:Gadget-section-${DEFAULT_DEFINITION.section}`页面的文本即小工具章节名
*
* 可自行添加回落值为`DEFAULT_DEFINITION.section`的值
*
* @type {Record<string, string>}
*/
const DEFINITION_SECTION_MAP = {
appear: '显示类小工具',
browser: '浏览类小工具',
@ -56,8 +62,14 @@ const DEFINITION_SECTION_MAP = {
/** @type {string} */
const DEPLOY_USER_AGENT = 'AnYiEE/AwesomeGadgets (https://github.com/AnYiEE/AwesomeGadgets; i@anyi.in)';
/** @type {boolean} */
const IS_CONVERT_DESCRIPTION_VARIANT = true;
/**
* 是否自动转换`MediaWiki:Gadget-${gadgetName}``MediaWiki:Gadget-section-${DEFAULT_DEFINITION.section}`页面的语言变体
*
* 需要目标 MediaWiki 网站存在 NoteTA 模板和IT以及MediaWiki公共转换组
*
* @type {boolean}
*/
const IS_CONVERT_VARIANT = false;
export {
HEADER,
@ -67,5 +79,5 @@ export {
DEFAULT_DEFINITION,
DEFINITION_SECTION_MAP,
DEPLOY_USER_AGENT,
IS_CONVERT_DESCRIPTION_VARIANT,
IS_CONVERT_VARIANT,
};

查看文件

@ -3,7 +3,7 @@ import prompts from 'prompts';
import {execSync} from 'node:child_process';
import fsPromises from 'node:fs/promises';
import path from 'node:path';
import {BANNER, DEFINITION_SECTION_MAP, IS_CONVERT_DESCRIPTION_VARIANT} from './constant.js';
import {BANNER, DEFINITION_SECTION_MAP, IS_CONVERT_VARIANT} from './constant.js';
import {Mwn as _Mwn} from 'mwn';
import {Window} from 'happy-dom';
const __dirname = path.resolve();
@ -160,7 +160,7 @@ const readFileText = async (name, file) => {
* @param {string} definitionText The MediaWiki:Gadgets-definition content
*/
const setDefinition = async (definitionText) => {
const definitionPath = path.join(__dirname, `dist/definition.txt`);
const definitionPath = path.join(__dirname, 'dist/definition.txt');
// eslint-disable-next-line security/detect-non-literal-fs-filename
const fileHandle = await fsPromises.open(definitionPath, 'w');
await fileHandle.writeFile(definitionText);
@ -219,7 +219,7 @@ const saveDefinitionSectionPage = async (definitionText, {api, editSummary}) =>
try {
await api.save(pageTitle, sectionText, editSummary);
log('green', `✔ Successfully saved ${pageTitle}`);
if (!IS_CONVERT_DESCRIPTION_VARIANT) {
if (!IS_CONVERT_VARIANT) {
continue;
}
try {
@ -267,7 +267,7 @@ const saveDescription = async (name, {api, description, editSummary}) => {
try {
await api.save(descriptionPageTitle, description, editSummary);
log('green', `✔ Successfully saved ${name} description`);
if (!IS_CONVERT_DESCRIPTION_VARIANT) {
if (!IS_CONVERT_VARIANT) {
return;
}
try {