Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ComiR authored Oct 23, 2022
0 parents commit 8fb8242
Show file tree
Hide file tree
Showing 21 changed files with 6,162 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
13 changes: 13 additions & 0 deletions .github/renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": ["schedule:monthly", ":masterIssue", "config:base"],
"prHourlyLimit": 0,
"lockFileMaintenance": {
"extends": ["schedule:weekly"],
"automerge": true,
"enabled": 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@v3
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: "lts/*"
cache: "npm"

- run: npm ci
- run: npm run build
36 changes: 36 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: deploy

on:
push:
branches:
- master
tags:
- "v*"

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

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

- run: npm ci
- run: npm run build

- run: |
sudo apt-get install tree -y
tree -H '.' -L 1 --noreport --charset utf-8 ./dist | tee dist/index.html
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./dist
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;
42 changes: 42 additions & 0 deletions config/webpack.config.dev.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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;
28 changes: 28 additions & 0 deletions config/webpack.config.prod.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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 8fb8242

Please sign in to comment.