-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
845 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,31 @@ | ||
import fs from 'fs/promises'; | ||
import userscriptMeta from 'userscript-meta'; | ||
import { minify } from 'terser'; | ||
import { exec } from 'child_process'; | ||
import { promisify } from 'util'; | ||
const pmap = (ls, fn) => Promise.all(ls.map(fn)); | ||
await pmap( | ||
|
||
const scriptparser = async (filename) => { | ||
const content = await fs.readFile('./src/' + filename, 'utf8'); | ||
const header = | ||
content | ||
.trim() | ||
.match(/^(?:^\/\/.*\s?)+/gm) | ||
?.join('\n') || ''; | ||
const meta = userscriptMeta.parse(header); | ||
// const header2 = userscriptMeta.stringify(meta); | ||
const _url = `https://raw.githubusercontent.com/snomiao/userscript.js/master/src/${filename}`; | ||
const url = encodeURI(_url); | ||
// console.log('\nminifying ' + filename); | ||
const mincode = (await minify(content, { compress: true })).code; | ||
// console.log(filename, meta, url); | ||
return { filename, content, meta, url, mincode }; | ||
}; | ||
|
||
const sinfo = await pmap( | ||
(await fs.readdir('./src/')).filter((e) => e.match(/\.user\.js$/)), | ||
async (filename) => { | ||
const content = await fs.readFile('./src/' + filename, 'utf8'); | ||
const header = | ||
content | ||
.trim() | ||
.match(/^(?:^\/\/.*\s?)+/gm) | ||
?.join('\n') || ''; | ||
const meta = userscriptMeta.parse(header); | ||
// const header2 = userscriptMeta.stringify(meta); | ||
const _url = `https://raw.githubusercontent.com/snomiao/userscript.js/master/src/${filename}`; | ||
const url = encodeURI(_url); | ||
// console.log('\nminifying ' + filename); | ||
const mincode = (await minify(content, { compress: true })).code; | ||
console.log(url) | ||
// console.log(filename, meta, url); | ||
return { filename, content, meta, url, mincode }; | ||
} | ||
scriptparser | ||
); | ||
|
||
sinfo.map((e) => console.log(e.url)); | ||
await promisify(exec)('https://greasyfork.org/en/import'); |
Oops, something went wrong.