Skip to content

Commit fbdc752

Browse files
committed
🎉 Init typescript
1 parent 44fffef commit fbdc752

16 files changed

+4963
-5606
lines changed

.browserslistrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cover 95%

.prettierignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dist/
2+
lib/
3+
node_modules/

.prettierrc.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"semi": false,
3+
"singleQuote": true,
4+
"printWidth": 120,
5+
"trailingComma": "none"
6+
}

index.ts

Whitespace-only changes.

monkey.config.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/// <reference path="./types/monkey.d.ts" />
2+
3+
export default {
4+
name: 'Good Monkey',
5+
description: 'A good monkey',
6+
version: '1.0.0',
7+
match: ['http*://*.google.com/*', 'http*://google.com/*'],
8+
grant: ['GM_addStyle']
9+
} as Monkey.Metadata

package-lock.json

-5,575
This file was deleted.

package.json

+24-15
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
"name": "webpack-tampermonkey",
33
"version": "1.0.0",
44
"description": "",
5-
"main": "index.js",
5+
"main": "dist/good-monkey.user.js",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
7+
"build": "webpack",
8+
"dev": "webpack -c webpack.dev.config.ts",
9+
"format": "prettier --write **/*.ts"
810
},
911
"repository": {
1012
"type": "git",
@@ -19,20 +21,27 @@
1921
"bugs": {
2022
"url": "https://github.com/SettingDust/webpack-tampermonkey/issues"
2123
},
22-
"prettier": {
23-
"semi": false,
24-
"singleQuote": true,
25-
"printWidth": 150
26-
},
2724
"homepage": "https://github.com/SettingDust/webpack-tampermonkey#readme",
2825
"devDependencies": {
29-
"@types/node": "^14.0.13",
30-
"@types/webpack": "^4.41.17",
31-
"@types/webpack-dev-server": "^3.11.0",
32-
"ts-node": "^8.10.2",
33-
"typescript": "^3.9.5",
34-
"webpack": "^4.43.0",
35-
"webpack-cli": "^3.3.11",
36-
"webpack-dev-server": "^3.11.0"
26+
"@tsconfig/recommended": "^1.0.1",
27+
"@types/node": "^15.12.1",
28+
"@types/webpack-dev-server": "^3.11.4",
29+
"autoprefixer": "^10.2.6",
30+
"chalk": "^4.1.1",
31+
"css-loader": "^5.2.6",
32+
"cssnano": "^5.0.5",
33+
"postcss": "^8.3.0",
34+
"postcss-loader": "^5.3.0",
35+
"prettier": "^2.3.0",
36+
"sass": "^1.34.1",
37+
"sass-loader": "^12.0.0",
38+
"to-string-loader": "github:gajus/to-string-loader",
39+
"ts-loader": "^9.2.2",
40+
"ts-node": "^10.0.0",
41+
"typescript": "^4.3.2",
42+
"url-loader": "^4.1.1",
43+
"webpack": "^5.38.1",
44+
"webpack-cli": "^4.7.0",
45+
"webpack-dev-server": "^3.11.2"
3746
}
3847
}

postcss.config.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
plugins: [
3+
require('cssnano'),
4+
require('autoprefixer')
5+
]
6+
}

scripts/banner.ts

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import metadata from '../monkey.config'
2+
3+
const paddingLength =
4+
1 + Object.keys(metadata).reduce((prev, curr) => (curr.length > prev ? curr.length : prev), 0)
5+
6+
const prefix = (arr: string[]): string[] => {
7+
const newArr = arr.map((it) => `// ${it}`)
8+
newArr.push('')
9+
return newArr
10+
}
11+
12+
const wrapMeta = (arr: string[]): string[] => arr.map((it) => (it.length ? `@${it}` : it))
13+
14+
const sign = (arr: string[]): string[] => {
15+
arr.push('==/UserScript==')
16+
return ['==UserScript=='].concat(arr)
17+
}
18+
19+
export default (dev: boolean = false): string => {
20+
const metas: string[] = []
21+
if (dev) {
22+
if (!metadata.require)
23+
metadata.require = []
24+
metadata.require.push('file://' + __dirname + '\\build\\' + metadata.name.toLowerCase().replace(' ', '-') + '.js')
25+
}
26+
for (const [key, value] of Object.entries(metadata)) {
27+
if (Array.isArray(value) && value.length) {
28+
metas.push('')
29+
for (const element of value) metas.push(key.padEnd(paddingLength) + element)
30+
} else metas.push(key.padEnd(paddingLength) + value)
31+
}
32+
return prefix(sign(wrapMeta(metas))).join('\n')
33+
}

src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
GM_addStyle(require('./styles/style.scss'))

src/styles/style.scss

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
body {
2+
background: aqua;
3+
}

tsconfig.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
2+
"extends": "@tsconfig/recommended/tsconfig.json",
23
"compilerOptions": {
3-
"outDir": "./dist/",
4-
"module": "es6",
5-
"target": "es5",
6-
"sourceMap": true
4+
"typeRoots": [
5+
"./types",
6+
"./node_modules/@types"
7+
]
78
}
89
}

0 commit comments

Comments
 (0)