updated builder
This commit is contained in:
128
esbuild.mjs
128
esbuild.mjs
@@ -1,128 +0,0 @@
|
|||||||
import { build } from 'esbuild'
|
|
||||||
import {
|
|
||||||
lstatSync,
|
|
||||||
readdirSync,
|
|
||||||
readFileSync,
|
|
||||||
unlinkSync,
|
|
||||||
writeFileSync,
|
|
||||||
} from 'fs'
|
|
||||||
|
|
||||||
const BaseUrl = `https://git.zomo.dev/zomo/browser-scripts`
|
|
||||||
const FileUrl = name =>
|
|
||||||
`https://git.zomo.dev/zomo/browser-scripts/raw/branch/main/dist/${name}.user.js`
|
|
||||||
|
|
||||||
function isValueNotEmpty(val) {
|
|
||||||
return (
|
|
||||||
val !== '' &&
|
|
||||||
val !== false &&
|
|
||||||
val !== [] &&
|
|
||||||
val !== undefined &&
|
|
||||||
val !== null
|
|
||||||
)
|
|
||||||
}
|
|
||||||
function padr(str, len) {
|
|
||||||
return str + ' '.repeat(len - str.length)
|
|
||||||
}
|
|
||||||
|
|
||||||
function MetadataArgs(name) {
|
|
||||||
var meta = {
|
|
||||||
name: name,
|
|
||||||
namespace: 'zomo.dev',
|
|
||||||
match: '',
|
|
||||||
excludematch: '',
|
|
||||||
version: '0.0.0',
|
|
||||||
description: '',
|
|
||||||
icon: '',
|
|
||||||
require: '',
|
|
||||||
resource: '',
|
|
||||||
runat: '',
|
|
||||||
noframes: false,
|
|
||||||
grant: '',
|
|
||||||
injectinto: '',
|
|
||||||
downloadURL: FileUrl(name),
|
|
||||||
supportURL: `${BaseUrl}/issues`,
|
|
||||||
homepageURL: BaseUrl,
|
|
||||||
unwrap: false,
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
let args = JSON.parse(
|
|
||||||
readFileSync(`scripts/${name}/meta.json`).toString()
|
|
||||||
)
|
|
||||||
for (let key in meta) {
|
|
||||||
if (isValueNotEmpty(args[key])) {
|
|
||||||
meta[key] = args[key]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.log(e)
|
|
||||||
console.log(
|
|
||||||
`scripts/${name}/meta.json not found, using default metadata`
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
const keyConversion = {
|
|
||||||
injectinto: 'inject-into',
|
|
||||||
excludematch: 'exclude-match',
|
|
||||||
}
|
|
||||||
|
|
||||||
return `// ==UserScript==
|
|
||||||
${Object.keys(meta)
|
|
||||||
.filter(key => isValueNotEmpty(meta[key]))
|
|
||||||
.map(key => {
|
|
||||||
let val = meta[key],
|
|
||||||
key_str = padr(key in keyConversion ? keyConversion[key] : key, 12)
|
|
||||||
if (typeof val === 'boolean') {
|
|
||||||
if (val) return `// @${key_str}`
|
|
||||||
} else if (typeof val === 'string') {
|
|
||||||
return `// @${key_str} ${val}`
|
|
||||||
} else if (Array.isArray(val)) {
|
|
||||||
return val.map(v => `// @${key_str} ${v}`).join('\n')
|
|
||||||
}
|
|
||||||
return ''
|
|
||||||
})
|
|
||||||
.filter(l => l.length)
|
|
||||||
.join('\n')}
|
|
||||||
// ==/UserScript==
|
|
||||||
`
|
|
||||||
}
|
|
||||||
|
|
||||||
async function compileProject(name) {
|
|
||||||
await build({
|
|
||||||
entryPoints: [`scripts/${name}/main.ts`],
|
|
||||||
outfile: `dist/${name}.user.js`,
|
|
||||||
|
|
||||||
target: 'esnext',
|
|
||||||
platform: 'node',
|
|
||||||
format: 'cjs',
|
|
||||||
|
|
||||||
watch: false,
|
|
||||||
bundle: true,
|
|
||||||
minify: false,
|
|
||||||
sourcemap: false,
|
|
||||||
|
|
||||||
define: {
|
|
||||||
UserScriptProjectName: `'${name}'`,
|
|
||||||
UserScriptFileUrl: `'${FileUrl(name)}'`,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
//add UserScript header
|
|
||||||
let meta = MetadataArgs(name)
|
|
||||||
let content = readFileSync(`dist/${name}.user.js`).toString()
|
|
||||||
|
|
||||||
writeFileSync(`dist/${name}.user.js`, meta + content)
|
|
||||||
}
|
|
||||||
|
|
||||||
//delete compiled scripts
|
|
||||||
readdirSync('dist').forEach(file => unlinkSync(`dist/${file}`))
|
|
||||||
|
|
||||||
//compile scripts
|
|
||||||
readdirSync('scripts').forEach(name => {
|
|
||||||
if (
|
|
||||||
lstatSync(`scripts/${name}`).isDirectory() &&
|
|
||||||
lstatSync(`scripts/${name}/main.ts`).isFile()
|
|
||||||
) {
|
|
||||||
compileProject(name)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"prettier": "prettier --write .",
|
"prettier": "prettier --write .",
|
||||||
"build": "npm run prettier && node esbuild.mjs"
|
"build": "npm run prettier && bsbuild"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -13,9 +13,9 @@
|
|||||||
},
|
},
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"devDependencies": {
|
||||||
"@types/greasemonkey": "^4.0.3",
|
"@types/greasemonkey": "^4.0.3",
|
||||||
"esbuild": "^0.14.42",
|
"browser-scripts-builder": "git+ssh://git@git.zomo.dev:zomo/browser-scripts-builder.git",
|
||||||
"eslint": "^8.17.0",
|
"eslint": "^8.17.0",
|
||||||
"prettier": "^2.6.2",
|
"prettier": "^2.6.2",
|
||||||
"typescript": "^4.7.3"
|
"typescript": "^4.7.3"
|
||||||
|
|||||||
743
pnpm-lock.yaml
generated
743
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
2
scripts/index.d.ts
vendored
2
scripts/index.d.ts
vendored
@@ -1,2 +0,0 @@
|
|||||||
declare const UserScriptProjectName: string
|
|
||||||
declare const UserScriptFileUrl: string
|
|
||||||
@@ -1,86 +0,0 @@
|
|||||||
{
|
|
||||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
|
||||||
"title": "UserScriptMeta",
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"name": {
|
|
||||||
"description": "Script Name",
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"namespace": {
|
|
||||||
"description": "Author namespace",
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"match": {
|
|
||||||
"description": "",
|
|
||||||
"type": ["string", "array"],
|
|
||||||
"minItems": 1,
|
|
||||||
"uniqueItems": true
|
|
||||||
},
|
|
||||||
"excludematch": {
|
|
||||||
"description": "",
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"version": {
|
|
||||||
"description": "",
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"description": {
|
|
||||||
"description": "",
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"icon": {
|
|
||||||
"description": "",
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"require": {
|
|
||||||
"description": "",
|
|
||||||
"type": ["string", "array"],
|
|
||||||
"minItems": 1,
|
|
||||||
"uniqueItems": true
|
|
||||||
},
|
|
||||||
"resource": {
|
|
||||||
"description": "",
|
|
||||||
"type": ["string", "array"],
|
|
||||||
"minItems": 1,
|
|
||||||
"uniqueItems": true
|
|
||||||
},
|
|
||||||
"runat": {
|
|
||||||
"description": "",
|
|
||||||
"type": "string",
|
|
||||||
"enum": ["document-start", "document-end", "document-idle"]
|
|
||||||
},
|
|
||||||
"noframes": {
|
|
||||||
"description": "",
|
|
||||||
"type": "boolean"
|
|
||||||
},
|
|
||||||
"grant": {
|
|
||||||
"description": "",
|
|
||||||
"type": ["string", "array"],
|
|
||||||
"minItems": 1,
|
|
||||||
"uniqueItems": true
|
|
||||||
},
|
|
||||||
"injectinto": {
|
|
||||||
"description": "",
|
|
||||||
"type": "string",
|
|
||||||
"enum": ["page", "content", "auto"]
|
|
||||||
},
|
|
||||||
"downloadURL": {
|
|
||||||
"description": "",
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"supportURL": {
|
|
||||||
"description": "",
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"homepageURL": {
|
|
||||||
"description": "",
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"unwrap": {
|
|
||||||
"description": "",
|
|
||||||
"type": "boolean"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"required": ["name", "namespace", "version"]
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"$schema": "../meta.schema.json",
|
"$schema": "https://git.zomo.dev/zomo/browser-scripts-builder/raw/branch/main/meta.schema.json",
|
||||||
"name": "OptiFine Download Links",
|
"name": "OptiFine Download Links",
|
||||||
"namespace": "zomo.dev",
|
"namespace": "zomo.dev",
|
||||||
"match": "https://optifine.net/*",
|
"match": "https://optifine.net/*",
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
"strict": true,
|
"strict": true,
|
||||||
"noImplicitReturns": true,
|
"noImplicitReturns": true,
|
||||||
"noUnusedLocals": true,
|
"noUnusedLocals": true,
|
||||||
"noUnusedParameters": true
|
"noUnusedParameters": true,
|
||||||
|
"types": ["../../node_modules/browser-scripts-builder"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,3 +13,4 @@ addEventListener('load', () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
UserScriptName
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"$schema": "../meta.schema.json",
|
"$schema": "https://git.zomo.dev/zomo/browser-scripts-builder/raw/branch/main/meta.schema.json",
|
||||||
"name": "twitch click to mute",
|
"name": "twitch click to mute",
|
||||||
"namespace": "zomo.dev",
|
"namespace": "zomo.dev",
|
||||||
"match": "https://www.twitch.tv/*",
|
"match": "https://www.twitch.tv/*",
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
"strict": true,
|
"strict": true,
|
||||||
"noImplicitReturns": true,
|
"noImplicitReturns": true,
|
||||||
"noUnusedLocals": true,
|
"noUnusedLocals": true,
|
||||||
"noUnusedParameters": true
|
"noUnusedParameters": true,
|
||||||
|
"types": ["../../node_modules/browser-scripts-builder"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user