Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
FrostBy authored Nov 15, 2024
0 parents commit 7798a8d
Show file tree
Hide file tree
Showing 22 changed files with 4,032 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[*]
charset=utf-8
end_of_line=lf
trim_trailing_whitespace=true
insert_final_newline=true
indent_style=space
indent_size=4

[{.babelrc,.stylelintrc,.eslintrc,jest.config,*.bowerrc,*.jsb3,*.jsb2,*.json,*.yaml,*.yml}]
indent_style=space
indent_size=2

[{*.js,*.vue,*.ts,*.cjs,.swcrc}]
indent_style=space
indent_size=2
14 changes: 14 additions & 0 deletions .github/renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": ["schedule:monthly", ":masterIssue", "config:base"],
"prHourlyLimit": 0,
"lockFileMaintenance": {
"extends": ["schedule:weekly"],
"automerge": true,
"enabled": true
},
"automerge": true,
"postUpdateOptions": ["npmDedupe"],
"separateMajorMinor": false,
"updateNotScheduled": false,
"rangeStrategy": "bump"
}
22 changes: 22 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: ci

on:
push:
branches-ignore:
- gh-pages
- "renovate/**"
pull_request:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: "lts/*"
cache: "npm"

- run: npm ci
- run: npm run build
35 changes: 35 additions & 0 deletions .github/workflows/deploy-preview.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# this workflow build from master branch and upload dist directory to "preview-dist" branch
# remove this if you don't need it.

name: deploy-preview

on:
push:
branches:
- master

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup node
uses: actions/setup-node@v4
with:
node-version: "lts/*"
cache: "npm"

- run: npm ci
- run: npm run build

- name: Deploy
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./dist
publish_branch: preview-dist
commit_message: deploy ${{ github.ref }}
enable_jekyll: true
user_name: github-actions[bot]
user_email: github-actions[bot]@users.noreply.github.com
32 changes: 32 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# build latest v* tag and upload dist diectory to gh-pages branch.
name: deploy

on:
push:
branches:
- v*

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup node
uses: actions/setup-node@v4
with:
node-version: "lts/*"
cache: "npm"

- run: npm ci
- run: npm run build

- name: Deploy
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./dist
enable_jekyll: true
commit_message: deploy ${{ github.ref }}
user_name: github-actions[bot]
user_email: github-actions[bot]@users.noreply.github.com
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
.idea
.vscode
dist
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run lint-staged
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/
13 changes: 13 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004

Copyright (C) 2020-2022 Trim21 <[email protected]>

Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.

DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

0. You just DO WHAT THE FUCK YOU WANT TO.
5 changes: 5 additions & 0 deletions config/empty.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**
* This is an empty javascript file for webpack to generate a development UserScript without real code.
* So we could make UserScript manager load script file from local file path.
* See webpack.config.dev.js for more details.
*/
26 changes: 26 additions & 0 deletions config/metadata.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const {
author,
dependencies,
repository,
version,
} = require("../package.json");

module.exports = {
name: {
$: "webpack-userscript-template",
cn: "中文名",
en: "english name",
},
namespace: "https://trim21.me/",
version: version,
author: author,
source: repository.url,
// 'license': 'MIT',
match: ["*://www.example.com/", "*://example.com/*"],
require: [
`https://cdn.jsdelivr.net/npm/jquery@${dependencies.jquery}/dist/jquery.min.js`,
],
grant: ["GM.xmlHttpRequest"],
connect: ["httpbin.org"],
"run-at": "document-end",
};
42 changes: 42 additions & 0 deletions config/webpack.config.base.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const path = require("path");

const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");

const webpackConfig = {
resolve: {
extensions: [".js", ".ts"],
},
optimization: {
minimize: false,
moduleIds: "named",
},
entry: "./src/index.ts",
output: {
path: path.resolve(__dirname, "../dist"),
},
target: "web",
externals: {
jquery: "$",
},
module: {
rules: [
{
test: /\.m?ts$/,
use: {
loader: "ts-loader",
},
},
{
test: /\.less$/,
use: ["style-loader", "css-loader", "less-loader"],
},
{
test: /\.css$/,
use: ["style-loader", "css-loader"],
},
],
},
plugins: process.env.npm_config_report ? [new BundleAnalyzerPlugin()] : [],
};

module.exports = webpackConfig;
44 changes: 44 additions & 0 deletions config/webpack.config.dev.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const path = require("path");
const { merge } = require("webpack-merge");
const LiveReloadPlugin = require("webpack-livereload-plugin");
const {
UserScriptMetaDataPlugin,
} = require("userscript-metadata-webpack-plugin");

const metadata = require("./metadata.cjs");
const webpackConfig = require("./webpack.config.base.cjs");

metadata.require.push(
"file://" + path.resolve(__dirname, "../dist/index.debug.js")
);

const cfg = merge(webpackConfig, {
mode: "development",
cache: {
type: "filesystem",
name: "dev",
},
entry: {
debug: webpackConfig.entry,
"dev.user": path.resolve(__dirname, "./empty.cjs"),
},
output: {
filename: "index.[name].js",
path: path.resolve(__dirname, "../dist"),
},
devtool: "eval-source-map",
watch: true,
watchOptions: {
ignored: /node_modules/,
},
plugins: [
new LiveReloadPlugin({
delay: 500,
}),
new UserScriptMetaDataPlugin({
metadata,
}),
],
});

module.exports = cfg;
30 changes: 30 additions & 0 deletions config/webpack.config.prod.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const { merge } = require("webpack-merge");
const {
UserScriptMetaDataPlugin,
} = require("userscript-metadata-webpack-plugin");

const metadata = require("./metadata.cjs");
const webpackConfig = require("./webpack.config.base.cjs");

const cfg = merge(webpackConfig, {
mode: "production",
output: {
filename: "index.prod.user.js",
},
optimization: {
// if you need minimize, you need to config minimizer to keep all comments
// to keep userscript meta.
minimize: false,
},
cache: {
type: "filesystem",
name: "prod",
},
plugins: [
new UserScriptMetaDataPlugin({
metadata,
}),
],
});

module.exports = cfg;
Loading

0 comments on commit 7798a8d

Please sign in to comment.