custom binding function config
This commit is contained in:
parent
6bd3f54842
commit
63315c35c4
8 changed files with 97 additions and 15 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import fs from "fs"
|
||||
import path from "path"
|
||||
// @ts-ignore
|
||||
import { Config } from "../../config.js"
|
||||
import { Config, RetBindingValue } from "../../config.js"
|
||||
import { createRequire } from "module"
|
||||
|
||||
const options: Record<string, unknown> = {}
|
||||
|
|
@ -10,16 +10,43 @@ for (const arg of process.argv) {
|
|||
if (arg.startsWith("--")) options[arg.slice(2)] = true
|
||||
}
|
||||
|
||||
export const isTestMode = options["test"] ?? false
|
||||
export const isTestMode = !fs.existsSync("node_modules/asajs")
|
||||
|
||||
if (!fs.existsSync("asajs.config.js")) {
|
||||
if (isTestMode) {
|
||||
fs.writeFileSync(
|
||||
"asajs.config.js",
|
||||
fs.readFileSync("resources/asajs.config.js", "utf-8").replace("asajs/", "./"),
|
||||
[
|
||||
`export function RandomBindingString(length, base = 32) {
|
||||
const chars = "0123456789abcdefghijklmnopqrstuvwxyz".slice(0, base)
|
||||
const out = new Array()
|
||||
|
||||
try {
|
||||
const buffer = new Uint8Array(length)
|
||||
crypto.getRandomValues(buffer)
|
||||
for (let i = 0; i < length; i++) {
|
||||
out[i] = chars[buffer[i] % base]
|
||||
}
|
||||
} catch {
|
||||
for (let i = 0; i < length; i++) {
|
||||
out[i] = chars[Math.floor(Math.random() * base)]
|
||||
}
|
||||
}
|
||||
|
||||
return \`#$\{out.join("")}\`
|
||||
}\n`,
|
||||
|
||||
fs.readFileSync("resources/asajs.config.js", "utf-8").replace("asajs/", "./"),
|
||||
].join("\n"),
|
||||
)
|
||||
} else {
|
||||
fs.copyFileSync("node_modules/asajs/resources/asajs.config.js", "asajs.config.js")
|
||||
fs.writeFileSync(
|
||||
"asajs.config.js",
|
||||
[
|
||||
'import { RandomBindingString } from "asajs"\n',
|
||||
fs.readFileSync("node_modules/asajs/resources/asajs.config.js", "utf-8"),
|
||||
].join("\n"),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -29,6 +56,8 @@ export const isBuildMode = options["build"] ?? config.compiler?.enabled ?? false
|
|||
export const isLinkMode = options["link"] ?? config.compiler?.autoImport ?? false
|
||||
export const unLinked = options["unlink"] ?? !(config.compiler?.autoImport ?? true)
|
||||
|
||||
export const bindingFuntions = config.binding_functions
|
||||
|
||||
if (!fs.existsSync(".gitignore")) {
|
||||
fs.writeFileSync(".gitignore", `node_modules`, "utf-8")
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue