Version 1.8 (#5)
This commit is contained in:
@@ -7,23 +7,33 @@
|
||||
//Dirname
|
||||
const __dirname = path.join(path.dirname(url.fileURLToPath(import.meta.url)), "..", "action")
|
||||
|
||||
//Build code
|
||||
let {code} = await ncc(`${__dirname}/index.mjs`, {
|
||||
minify:true,
|
||||
sourceMap:false,
|
||||
sourceMapRegister:false,
|
||||
})
|
||||
/** Build function */
|
||||
export default async function build() {
|
||||
//Build code
|
||||
let {code} = await ncc(`${__dirname}/index.mjs`, {
|
||||
minify:true,
|
||||
sourceMap:false,
|
||||
sourceMapRegister:false,
|
||||
})
|
||||
|
||||
//Perform static includes
|
||||
for (const match of [...code.match(/(?<=`)<#include (.+?)>(?=`)/g)]) {
|
||||
const file = match.match(/<#include (.+?)>/)[1]
|
||||
code = code.replace(`<#include ${file}>`, `${await fs.promises.readFile(path.join(__dirname, "..", "src", file))}`.replace(/([$`])/g, "\\$1"))
|
||||
console.log(`Included ${file}`)
|
||||
//Perform static includes
|
||||
for (const match of [...code.match(/(?<=`)<#include (.+?)>(?=`)/g)]) {
|
||||
const file = match.match(/<#include (.+?)>/)[1]
|
||||
code = code.replace(`<#include ${file}>`, `${await fs.promises.readFile(path.join(__dirname, "..", "src", file))}`.replace(/([$`])/g, "\\$1"))
|
||||
console.log(`Included ${file}`)
|
||||
}
|
||||
|
||||
//Perform version include
|
||||
const version = JSON.parse(await fs.promises.readFile(path.join(__dirname, "..", "package.json"))).version
|
||||
code = code.replace(`<#version>`, version)
|
||||
|
||||
//Code
|
||||
return code
|
||||
}
|
||||
|
||||
//Perform version include
|
||||
const version = JSON.parse(await fs.promises.readFile(path.join(__dirname, "..", "package.json"))).version
|
||||
code = code.replace(`<#version>`, version)
|
||||
|
||||
//Save build
|
||||
await fs.promises.writeFile(`${__dirname}/dist/index.js`, code)
|
||||
//Main
|
||||
if (/build.mjs/.test(process.argv[1])) {
|
||||
//Save build
|
||||
await fs.promises.writeFile(`${__dirname}/dist/index.js`, await build())
|
||||
console.log("Build successful !")
|
||||
}
|
||||
Reference in New Issue
Block a user