updated builder

This commit is contained in:
2022-06-06 21:25:09 -05:00
parent bfbc2cdbde
commit c5627e318c
12 changed files with 793 additions and 1305 deletions

View File

@@ -1,12 +1,12 @@
// ==UserScript==
// @name OptiFine Download Links
// @namespace zomo.dev
// @match https://optifine.net/*
// @version 1.0
// @description automatically grab optifine links through the ads
// @downloadURL https://git.zomo.dev/zomo/browser-scripts/raw/branch/main/dist/optifine-download-links.user.js
// @supportURL https://git.zomo.dev/zomo/browser-scripts/issues
// @homepageURL https://git.zomo.dev/zomo/browser-scripts
// @ name OptiFine Download Links
// @ namespace zomo.dev
// @ match https://optifine.net/*
// @ version 1.0
// @ description automatically grab optifine links through the ads
// @ downloadURL https://git.zomo.dev/zomo/browser-scripts/raw/branch/main/dist/optifine-download-links.user.js
// @ supportURL https://git.zomo.dev/zomo/browser-scripts/issues
// @ homepageURL https://git.zomo.dev/zomo/browser-scripts
// ==/UserScript==
// scripts/optifine-download-links/main.ts
var onhover = false;

View File

@@ -1,12 +1,12 @@
// ==UserScript==
// @name twitch click to mute
// @namespace zomo.dev
// @match https://www.twitch.tv/*
// @version 1.0
// @description click to mute/unmute
// @downloadURL https://git.zomo.dev/zomo/browser-scripts/raw/branch/main/dist/twitch-click-mute.user.js
// @supportURL https://git.zomo.dev/zomo/browser-scripts/issues
// @homepageURL https://git.zomo.dev/zomo/browser-scripts
// @ name twitch click to mute
// @ namespace zomo.dev
// @ match https://www.twitch.tv/*
// @ version 1.0
// @ description click to mute/unmute
// @ downloadURL https://git.zomo.dev/zomo/browser-scripts/raw/branch/main/dist/twitch-click-mute.user.js
// @ supportURL https://git.zomo.dev/zomo/browser-scripts/issues
// @ homepageURL https://git.zomo.dev/zomo/browser-scripts
// ==/UserScript==
// scripts/twitch-click-mute/main.ts
addEventListener("load", () => {

View File

@@ -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)
}
})

View File

@@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"prettier": "prettier --write .",
"build": "npm run prettier && node esbuild.mjs"
"build": "npm run prettier && bsbuild"
},
"repository": {
"type": "git",
@@ -13,9 +13,9 @@
},
"author": "",
"license": "ISC",
"dependencies": {
"devDependencies": {
"@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",
"prettier": "^2.6.2",
"typescript": "^4.7.3"

1833
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

2
scripts/index.d.ts vendored
View File

@@ -1,2 +0,0 @@
declare const UserScriptProjectName: string
declare const UserScriptFileUrl: string

View File

@@ -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"]
}

View File

@@ -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",
"namespace": "zomo.dev",
"match": "https://optifine.net/*",

View File

@@ -8,6 +8,7 @@
"strict": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"noUnusedParameters": true
"noUnusedParameters": true,
"types": ["../../node_modules/browser-scripts-builder"]
}
}

View File

@@ -13,3 +13,4 @@ addEventListener('load', () => {
}
})
})
UserScriptName

View File

@@ -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",
"namespace": "zomo.dev",
"match": "https://www.twitch.tv/*",

View File

@@ -8,6 +8,7 @@
"strict": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"noUnusedParameters": true
"noUnusedParameters": true,
"types": ["../../node_modules/browser-scripts-builder"]
}
}