it compiled
This commit is contained in:
83
src/main.ts
83
src/main.ts
@@ -1,4 +1,4 @@
|
||||
import { build } from 'esbuild'
|
||||
import { build, BuildFailure } from 'esbuild'
|
||||
import {
|
||||
lstatSync,
|
||||
readdirSync,
|
||||
@@ -7,39 +7,51 @@ import {
|
||||
writeFileSync,
|
||||
} from 'fs'
|
||||
import { DistBase, DistPath, ScriptBase, ScriptPath } from './paths'
|
||||
import { readmeData, updateReadmeFile } from './readmefile'
|
||||
import readMeta from './readmeta'
|
||||
import { UserScriptMetaFull } from './types'
|
||||
|
||||
async function compileProject(name: string) {
|
||||
async function compileProject(
|
||||
name: string
|
||||
): Promise<[UserScriptMetaFull, null | string]> {
|
||||
//read meta file
|
||||
let [metaJson, metaString] = readMeta(name)
|
||||
let outPath = DistPath(name)
|
||||
|
||||
await build({
|
||||
entryPoints: [ScriptPath(name).main],
|
||||
outfile: outPath,
|
||||
let error: null | string = null
|
||||
|
||||
target: 'esnext',
|
||||
platform: 'node',
|
||||
format: 'esm',
|
||||
try {
|
||||
await build({
|
||||
entryPoints: [ScriptPath(name).main],
|
||||
outfile: outPath,
|
||||
|
||||
bundle: true,
|
||||
minify: false,
|
||||
target: 'esnext',
|
||||
platform: 'node',
|
||||
format: 'esm',
|
||||
|
||||
define: {
|
||||
UserScriptName: `'${metaJson.name}'`,
|
||||
UserScriptNamespace: `'${metaJson.namespace}'`,
|
||||
UserScriptVersion: `'${metaJson.version}'`,
|
||||
bundle: true,
|
||||
minify: false,
|
||||
|
||||
UserScriptDownloadURL: `'${metaJson.downloadURL}'`,
|
||||
UserScriptSupportURL: `'${metaJson.supportURL}'`,
|
||||
UserScriptHomepageURL: `'${metaJson.homepageURL}'`,
|
||||
},
|
||||
})
|
||||
define: {
|
||||
UserScriptName: `'${metaJson.name}'`,
|
||||
UserScriptNamespace: `'${metaJson.namespace}'`,
|
||||
UserScriptVersion: `'${metaJson.version}'`,
|
||||
|
||||
UserScriptDownloadURL: `'${metaJson.downloadURL}'`,
|
||||
UserScriptSupportURL: `'${metaJson.supportURL}'`,
|
||||
UserScriptHomepageURL: `'${metaJson.homepageURL}'`,
|
||||
},
|
||||
})
|
||||
} catch (e) {
|
||||
error = (e as BuildFailure).message
|
||||
}
|
||||
|
||||
//add UserScript header
|
||||
let content = readFileSync(outPath).toString()
|
||||
|
||||
writeFileSync(outPath, metaString + content)
|
||||
|
||||
return [metaJson, error]
|
||||
}
|
||||
|
||||
if (!lstatSync('package.json').isFile()) {
|
||||
@@ -51,14 +63,29 @@ if (!lstatSync('package.json').isFile()) {
|
||||
readdirSync(DistBase).forEach(file => unlinkSync(`${DistBase}/${file}`))
|
||||
|
||||
//compile scripts
|
||||
readdirSync(ScriptBase).forEach(name => {
|
||||
let path = ScriptPath(name)
|
||||
;(async () => {
|
||||
let scripts = readdirSync(ScriptBase)
|
||||
// let scriptMeta: {
|
||||
// [name: string]: [UserScriptMetaFull, string | null]
|
||||
// } = {}
|
||||
|
||||
if (
|
||||
!name.endsWith('_') &&
|
||||
lstatSync(path.dir).isDirectory() &&
|
||||
lstatSync(path.main).isFile()
|
||||
) {
|
||||
compileProject(name)
|
||||
let scriptMeta: readmeData[] = []
|
||||
|
||||
for (let name of scripts) {
|
||||
let path = ScriptPath(name)
|
||||
|
||||
if (
|
||||
!name.endsWith('_') &&
|
||||
lstatSync(path.dir).isDirectory() &&
|
||||
lstatSync(path.main).isFile()
|
||||
) {
|
||||
let [meta, error] = await compileProject(name)
|
||||
scriptMeta.push({
|
||||
meta,
|
||||
error,
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
updateReadmeFile(scriptMeta)
|
||||
})()
|
||||
|
||||
Reference in New Issue
Block a user