mirror of
https://github.com/Lightcord/Lightcord.git
synced 2025-04-12 00:55:40 +02:00
build, probably gonna remove them or whatever
This commit is contained in:
parent
341e079c57
commit
d008d04c6f
2
BetterDiscordApp/dist/index.min.js
vendored
2
BetterDiscordApp/dist/index.min.js
vendored
File diff suppressed because one or more lines are too long
2
BetterDiscordApp/dist/index.min.js.map
vendored
2
BetterDiscordApp/dist/index.min.js.map
vendored
File diff suppressed because one or more lines are too long
3
BetterDiscordApp/dist/style.min.css
vendored
3
BetterDiscordApp/dist/style.min.css
vendored
File diff suppressed because one or more lines are too long
2
BetterDiscordApp/dist/style.min.css.map
vendored
2
BetterDiscordApp/dist/style.min.css.map
vendored
File diff suppressed because one or more lines are too long
@ -7,14 +7,17 @@ function minify(){
|
||||
console.log(`\x1b[33mMinifying...\x1b[0m`)
|
||||
const css = fs.readFileSync(path.join(__dirname, "./src/styles/index.css"), "utf-8")
|
||||
fs.writeFileSync(path.join(__dirname, "./dist/style.css"), css)
|
||||
const output = new CleanCSS().minify(css)
|
||||
const output = new CleanCSS({
|
||||
sourceMap: true
|
||||
}).minify(css)
|
||||
if(output.errors.length > 0){
|
||||
console.error("\x1b[31m"+output.errors.join("\n")+"\x1b[0m")
|
||||
}
|
||||
if(output.warnings.length > 0){
|
||||
console.warn("\x1b[33m"+output.warnings.join("\n")+"\x1b[0m")
|
||||
}
|
||||
fs.writeFileSync(path.join(__dirname, "./dist/style.min.css"), output.styles)
|
||||
fs.writeFileSync(path.join(__dirname, "./dist/style.min.css"), output.styles+"\n/*# sourceMappingURL=style.min.css.map */")
|
||||
fs.writeFileSync(path.join(__dirname, "./dist/style.min.css.map"), output.sourceMap)
|
||||
console.log(`\x1b[32mMinified in ${(Date.now() - start)}ms. Minified by ${Math.floor(output.stats.efficiency*100)}%\x1b[0m`)
|
||||
}
|
||||
module.exports.minify = minify
|
||||
|
@ -15,6 +15,7 @@
|
||||
"./js/**",
|
||||
"./webpack.config.js",
|
||||
"./dist/**",
|
||||
"./prod.config.js"
|
||||
"./prod.config.js",
|
||||
"./docs"
|
||||
]
|
||||
}
|
@ -3,43 +3,57 @@ const fsAsync = fs.promises
|
||||
const yazl = require("yazl")
|
||||
const __path = require("path")
|
||||
|
||||
fs.unlinkSync(__path.join(__dirname, "builds", "lightcord-win32-ia32.zip"))
|
||||
fs.unlinkSync(__path.join(__dirname, "builds", "lightcord-linux-x64.zip"))
|
||||
const buildsPaths = __path.join(__dirname, "builds")
|
||||
const folders = [
|
||||
"lightcord-win32-ia32",
|
||||
"lightcord-linux-x64",
|
||||
"lightcord-darwin-x64"
|
||||
]
|
||||
folders.forEach(folder => {
|
||||
const path = __path.join(buildsPaths, folder)
|
||||
if(!fs.existsSync(path))return console.warn(`\x1b[33mCan't pack build ${folder} because it doesn't exist.\x1b[0m`)
|
||||
const zipPath = __path.join(buildsPaths, folder+".zip")
|
||||
if(fs.existsSync(zipPath)){
|
||||
console.warn(`Deleting ${zipPath}.`)
|
||||
fs.unlinkSync(zipPath)
|
||||
}
|
||||
const zip = new yazl.ZipFile()
|
||||
zip.outputStream.pipe(fs.createWriteStream(zipPath))
|
||||
|
||||
const winZip = new yazl.ZipFile()
|
||||
winZip.outputStream.pipe(fs.createWriteStream(__path.join(__dirname, "builds", "lightcord-win32-ia32.zip")))
|
||||
const platform = folder.split("-")[1]
|
||||
processNextDir(path, zip, platform)
|
||||
.then(() => {
|
||||
console.log(`Zipped ${platform}.`)
|
||||
zip.end()
|
||||
})
|
||||
})
|
||||
|
||||
const linuxZip = new yazl.ZipFile()
|
||||
linuxZip.outputStream.pipe(fs.createWriteStream(__path.join(__dirname, "builds", "lightcord-linux-x64.zip")))
|
||||
|
||||
const darwinZip = new yazl.ZipFile()
|
||||
darwinZip.outputStream.pipe(fs.createWriteStream(__path.join(__dirname, "builds", "lightcord-darwin-x64.zip")))
|
||||
|
||||
async function processNextDir(dir, zip, bpath, platform){
|
||||
if(!bpath)bpath = dir
|
||||
async function processNextDir(dir, zip, platform, bpath = dir){
|
||||
if(dir.replace(bpath, ""))zip.addEmptyDirectory(dir.replace(bpath, "").slice(1))
|
||||
await Promise.all(fs.readdirSync(dir, {withFileTypes: true})
|
||||
.map(async file => {
|
||||
let path = __path.join(dir, file.name)
|
||||
if(file.isDirectory()){
|
||||
return await processNextDir(path, zip, bpath, platform)
|
||||
return await processNextDir(path, zip, platform, bpath)
|
||||
}else if(file.isFile()){
|
||||
if(!path.includes("node_modules")){
|
||||
if(platform === "win"){
|
||||
if(platform === "win32"){
|
||||
if(file.name.endsWith("_linux.node"))return
|
||||
if(file.name.endsWith("_darwin.node"))return
|
||||
}else if(platform === "lin"){
|
||||
if(file.name.endsWith(".node")){
|
||||
if(!file.name.endsWith("_linux.node"))return
|
||||
}else if(platform === "dar"){
|
||||
if(file.name.endsWith(".node")){
|
||||
if(!file.name.endsWith("_darwin.node"))return
|
||||
}
|
||||
}
|
||||
if(file.name.endsWith(".dylib"))return
|
||||
if(file.name.endsWith(".so.4"))return
|
||||
}else if(platform === "linux"){
|
||||
if(file.name.endsWith("_win32.node"))return
|
||||
if(file.name.endsWith("_darwin.node"))return
|
||||
if(file.name.endsWith(".dylib"))return
|
||||
if(file.name.endsWith(".dll"))return
|
||||
}else if(platform === "darwin"){
|
||||
if(file.name.endsWith("_linux.node"))return
|
||||
if(file.name.endsWith("_win32.node"))return
|
||||
if(file.name.endsWith(".dll"))return
|
||||
if(file.name.endsWith(".so.4"))return
|
||||
}
|
||||
}
|
||||
console.log("Adding "+file.name+" to "+platform)
|
||||
let stat = fs.statSync(path)
|
||||
zip.addBuffer(await fsAsync.readFile(path), __path.relative(bpath, path), {
|
||||
mode: stat.mode,
|
||||
@ -47,22 +61,4 @@ async function processNextDir(dir, zip, bpath, platform){
|
||||
})
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
||||
processNextDir(__path.join(__dirname, "builds", "lightcord-win32-ia32"), winZip, undefined, "win")
|
||||
.then(() => {
|
||||
console.log(`Zipped win32.`)
|
||||
winZip.end()
|
||||
})
|
||||
|
||||
processNextDir(__path.join(__dirname, "builds", "lightcord-linux-x64"), linuxZip, undefined, "lin")
|
||||
.then(() => {
|
||||
console.log(`Zipped linux.`)
|
||||
linuxZip.end()
|
||||
})
|
||||
|
||||
processNextDir(__path.join(__dirname, "builds", "lightcord-darwin-x64", darwinZip, undefined, "dar"))
|
||||
.then(()=> {
|
||||
console.log('Zipped Darwin')
|
||||
darwinZip.end()
|
||||
})
|
||||
}
|
240
build.js
240
build.js
@ -4,6 +4,7 @@ const terser = require("terser")
|
||||
const util = require("util")
|
||||
|
||||
const production = true
|
||||
const includeSourcesMaps = true
|
||||
|
||||
let fs = require("fs")
|
||||
|
||||
@ -15,6 +16,87 @@ console.info = (...args) => {
|
||||
}
|
||||
let commit = child_process.execSync("git rev-parse HEAD").toString().split("\n")[0].trim()
|
||||
console.info(`Obtained commit ${commit} for the build`)
|
||||
|
||||
async function processNextDir(folder, folders, predicate, compile, ignoreModules){
|
||||
if(typeof ignoreModules === "undefined")ignoreModules = false
|
||||
let files = fs.readdirSync(folder, {withFileTypes: true})
|
||||
for(let file of files){
|
||||
if(file.isFile()){
|
||||
let isMinified = file.name.endsWith(".min.js") || file.name.endsWith(".min.css")
|
||||
let filepath = path.join(folder, file.name)
|
||||
let type = file.name.split(".").pop().toLowerCase()
|
||||
if(type === file.name)type = ""
|
||||
if([
|
||||
"ts",
|
||||
"md",
|
||||
"gitignore",
|
||||
"map"
|
||||
].includes(type)){
|
||||
console.warn(`\x1b[33mIgnored file ${path.relative(folders.startDir, filepath)} because of type ${type}\x1b[0m`)
|
||||
continue
|
||||
}
|
||||
if([
|
||||
"tsconfig.json",
|
||||
"webpack.config.js"
|
||||
].includes(file.name)){
|
||||
console.warn(`\x1b[33mIgnored file ${path.relative(folders.startDir, filepath)} because of name ${file.name}\x1b[0m`)
|
||||
continue
|
||||
}
|
||||
if(folders.exclude && folders.exclude.test(filepath)){
|
||||
console.warn(`\x1b[33mIgnored file ${path.relative(folders.startDir, filepath)} because regex\x1b[0m`)
|
||||
continue
|
||||
}
|
||||
let hasMinifiedVersion = (type === "js" || type === "css") && !isMinified && files.find(f => {
|
||||
return f.name === file.name.split(".").slice(0, -1).join(".")+".min."+type
|
||||
})
|
||||
if(hasMinifiedVersion){
|
||||
console.warn(`\x1b[33mIgnored file ${path.relative(folders.startDir, filepath)} because it has a minified version.\x1b[0m`)
|
||||
continue
|
||||
}
|
||||
if(!isMinified && predicate(filepath) && filepath.split(/[\\/]+/).reverse()[1] !== "js"){
|
||||
await compile(filepath, path.join(filepath.replace(folders.startDir, folders.newDir)), "..")
|
||||
}else{
|
||||
if(["js", "css"].includes(type)){
|
||||
if(!includeSourcesMaps){
|
||||
console.log(`We don't include sourcemap for this build. Skipping ${file.name}.`)
|
||||
return await fs.promises.copyFile(filepath, filepath.replace(folders.startDir, folders.newDir))
|
||||
}
|
||||
let fileContent = (await fs.promises.readFile(filepath, "utf8"))
|
||||
let sourceMap = fileContent.split(/[\n\r]+/g).pop()
|
||||
if(!sourceMap || !sourceMap.startsWith("//# sourceMappingURL=")){
|
||||
console.log(`This file doesn't have sourcemap. ${file.name}.`)
|
||||
await fs.promises.copyFile(filepath, filepath.replace(folders.startDir, folders.newDir))
|
||||
continue
|
||||
}
|
||||
let sourceMapContent
|
||||
if(sourceMap.slice(21).startsWith("data:")){
|
||||
console.log(`Extracting sourcemap from data uri. From file ${file.name}.`)
|
||||
sourceMapContent = Buffer.from(sourceMap.split("=").slice(1).join("="), "base64").toString("utf-8")
|
||||
}else{
|
||||
console.log(`Extracting sourcemap from file ${file.name}.map.`)
|
||||
await fs.promises.copyFile(filepath, filepath.replace(folders.startDir, folders.newDir))
|
||||
sourceMapContent = await fs.promises.readFile(path.join(folder, sourceMap.slice(21)), "utf8")
|
||||
}
|
||||
sourceMapContent = JSON.parse(sourceMapContent)
|
||||
sourceMapContent.sourcesContent = []
|
||||
let sourceMapPath = filepath + ".map"
|
||||
fileContent = fileContent
|
||||
// source map
|
||||
.replace(sourceMap, "//# sourceMappingURL="+filepath.split(/[\\\/]+/g).pop()+".map")
|
||||
await fs.promises.writeFile(filepath.replace(folders.startDir, folders.newDir), fileContent)
|
||||
await fs.promises.writeFile(filepath.replace(folders.startDir, folders.newDir)+".map", JSON.stringify(sourceMapContent))
|
||||
}else{
|
||||
await fs.promises.copyFile(filepath, filepath.replace(folders.startDir, folders.newDir))
|
||||
}
|
||||
}
|
||||
}else if(file.isDirectory()){
|
||||
if(ignoreModules && file.name === "node_modules")continue
|
||||
if(folders.exclude && folders.exclude.test(path.join(folder, file.name)))continue
|
||||
await fs.promises.mkdir(path.join(folder, file.name).replace(folders.startDir, folders.newDir), {recursive: true})
|
||||
await processNextDir(path.join(folder, file.name), ...Array.from(arguments).slice(1))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function main(){
|
||||
let startTimestamp = Date.now()
|
||||
@ -25,91 +107,19 @@ async function main(){
|
||||
await fs.promises.mkdir(__dirname+"/distApp/dist", {"recursive": true})
|
||||
|
||||
console.info("Executing command `npm run compile`")
|
||||
console.log(child_process.execSync("npm run compile", {encoding: "binary"}))
|
||||
child_process.execSync("npm run compile", {
|
||||
encoding: "binary",
|
||||
stdio: "inherit"
|
||||
})
|
||||
|
||||
let startDir = path.join(__dirname, "./dist")
|
||||
let newDir = path.join(__dirname, "./distApp/dist")
|
||||
console.info("No error detected. Copying files from "+startDir+".")
|
||||
await fs.promises.mkdir(startDir, {recursive: true})
|
||||
|
||||
async function processNextDir(folder, folders, predicate, compile, ignoreModules){
|
||||
if(typeof ignoreModules === "undefined")ignoreModules = false
|
||||
let files = fs.readdirSync(folder, {withFileTypes: true})
|
||||
for(let file of files){
|
||||
if(file.isFile()){
|
||||
let isMinified = file.name.endsWith(".min.js") || file.name.endsWith(".min.css")
|
||||
let filepath = path.join(folder, file.name)
|
||||
let type = file.name.split(".").pop().toLowerCase()
|
||||
if(type === file.name)type = ""
|
||||
if([
|
||||
"ts",
|
||||
"md",
|
||||
"gitignore",
|
||||
"map"
|
||||
].includes(type)){
|
||||
console.warn(`\x1b[33mIgnored file ${path.relative(folders.startDir, filepath)} because of type ${type}\x1b[0m`)
|
||||
continue
|
||||
}
|
||||
if([
|
||||
"tsconfig.json",
|
||||
"webpack.config.js"
|
||||
].includes(file.name)){
|
||||
console.warn(`\x1b[33mIgnored file ${path.relative(folders.startDir, filepath)} because of name ${file.name}\x1b[0m`)
|
||||
continue
|
||||
}
|
||||
if(folders.exclude && folders.exclude.test(filepath)){
|
||||
console.warn(`\x1b[33mIgnored file ${path.relative(folders.startDir, filepath)} because regex\x1b[0m`)
|
||||
continue
|
||||
}
|
||||
let hasMinifiedVersion = (type === "js" || type === "css") && !isMinified && files.find(f => {
|
||||
return f.name === file.name.split(".").slice(0, -1).join(".")+".min."+type
|
||||
})
|
||||
if(hasMinifiedVersion){
|
||||
console.warn(`\x1b[33mIgnored file ${path.relative(folders.startDir, filepath)} because it has a minified version.\x1b[0m`)
|
||||
continue
|
||||
}
|
||||
if(!isMinified && predicate(filepath) && filepath.split(/[\\/]+/).reverse()[1] !== "js"){
|
||||
await compile(filepath, path.join(filepath.replace(folders.startDir, folders.newDir)), "..")
|
||||
}else{
|
||||
if(["js", "css"].includes(type)){
|
||||
let fileContent = (await fs.promises.readFile(filepath, "utf8"))
|
||||
let sourceMap = fileContent.split(/[\n\r]+/g).pop()
|
||||
if(!sourceMap.startsWith("//# sourceMappingURL=")){
|
||||
await fs.promises.copyFile(filepath, filepath.replace(folders.startDir, folders.newDir))
|
||||
continue
|
||||
}
|
||||
let sourceMapContent
|
||||
if(sourceMap.slice(21).startsWith("data:")){
|
||||
sourceMapContent= Buffer.from(sourceMap.split("=").slice(1).join("="), "base64")
|
||||
}else{
|
||||
await fs.promises.copyFile(filepath, filepath.replace(folders.startDir, folders.newDir))
|
||||
continue
|
||||
//let file = path.dirname(filepath)+"/"+sourceMap.slice(21)
|
||||
//sourceMapContent = fs.readFileSync(file)
|
||||
}
|
||||
let sourceMapPath = filepath + ".map"
|
||||
let pth = path.posix.resolve(sourceMapPath.replace(__dirname, "").replace(/\\/g, "/"))
|
||||
fileContent = fileContent
|
||||
// source map
|
||||
.replace(sourceMap, "//# sourceMappingURL=https://rawcdn.githack.com/Lightcord/Lightcord/"+commit+pth)
|
||||
await fs.promises.writeFile(filepath.replace(folders.startDir, folders.newDir), fileContent)
|
||||
await fs.promises.writeFile(sourceMapPath, sourceMapContent)
|
||||
}else{
|
||||
await fs.promises.copyFile(filepath, filepath.replace(folders.startDir, folders.newDir))
|
||||
}
|
||||
}
|
||||
}else if(file.isDirectory()){
|
||||
if(ignoreModules && file.name === "node_modules")continue
|
||||
if(folders.exclude && folders.exclude.test(path.join(folder, file.name)))continue
|
||||
await fs.promises.mkdir(path.join(folder, file.name).replace(folders.startDir, folders.newDir), {recursive: true})
|
||||
await processNextDir(path.join(folder, file.name), ...Array.from(arguments).slice(1))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await processNextDir(startDir, {
|
||||
startDir,
|
||||
newDir,
|
||||
exclude: /node_modules/g
|
||||
newDir
|
||||
}, ((filepath) => filepath.endsWith(".js")), async (filepath, newpath) => {
|
||||
console.info(`Minifying ${filepath} to ${newpath}`)
|
||||
|
||||
@ -118,14 +128,14 @@ async function main(){
|
||||
}else{
|
||||
await fs.promises.writeFile(newpath, terser.minify(await fs.promises.readFile(filepath, "utf8")).code, "utf8")
|
||||
}
|
||||
}).then(() => {
|
||||
}, true).then(() => {
|
||||
console.info(`Copied files and minified them from ${startDir}.`)
|
||||
})
|
||||
|
||||
await processNextDir(path.join(__dirname, "modules"), {
|
||||
startDir: path.join(__dirname, "modules"),
|
||||
newDir: path.join(__dirname, "distApp", "modules"),
|
||||
exclude: /node_modules/g
|
||||
exclude: /discord_spellcheck/g
|
||||
}, ((filepath) => filepath.endsWith(".js")), async (filepath, newpath) => {
|
||||
console.info(`Minifying ${filepath} to ${newpath}`)
|
||||
await fs.promises.writeFile(newpath, terser.minify(await fs.promises.readFile(filepath, "utf8")).code, "utf8")
|
||||
@ -145,31 +155,39 @@ async function main(){
|
||||
}
|
||||
|
||||
console.info(`Installing modules for ${mdl}`)
|
||||
console.log(child_process.execSync("npm install --only=prod", {
|
||||
child_process.execSync("npm install --only=prod", {
|
||||
encoding: "binary",
|
||||
cwd: dir
|
||||
}))
|
||||
cwd: dir,
|
||||
stdio: "inherit"
|
||||
})
|
||||
}))
|
||||
|
||||
await fs.promises.mkdir(path.join(__dirname, "distApp", "modules", "discord_spellcheck"), {recursive: true})
|
||||
await processNextDir(path.join(__dirname, "modules", "discord_spellcheck"), {
|
||||
startDir: path.join(__dirname, "modules", "discord_spellcheck"),
|
||||
newDir: path.join(__dirname, "distApp", "modules", "discord_spellcheck")
|
||||
}, ((filepath) => filepath.endsWith(".js")), async (filepath, newpath) => {
|
||||
console.info(`Minifying ${filepath} to ${newpath}`)
|
||||
await fs.promises.writeFile(newpath, terser.minify(await fs.promises.readFile(filepath, "utf8")).code, "utf8")
|
||||
}, false).then(() => {
|
||||
console.info(`Copied files and minified them from ${path.join(__dirname, "modules")}.`)
|
||||
})
|
||||
|
||||
await processNextDir(path.join(__dirname, "LightcordApi"), {
|
||||
startDir: path.join(__dirname, "LightcordApi"),
|
||||
newDir: path.join(__dirname, "distApp", "LightcordApi"),
|
||||
exclude: /(src|webpack\.config\.js|tsconfig\.json|dist)/g
|
||||
exclude: /(src|webpack\.config\.js|tsconfig\.json|dist|docs)/g
|
||||
}, ((filepath) => filepath.endsWith(".js") && (!production ? !filepath.includes("node_modules") : true)), async (filepath, newpath) => {
|
||||
if(filepath.includes("node_modules"))return // don't minify node_modules, and don't include them at all. Installing later
|
||||
console.info(`Minifying ${filepath} to ${newpath}`)
|
||||
let fileContent = (await fs.promises.readFile(filepath, "utf8"))
|
||||
// source map
|
||||
.replace(/\/\/# sourceMappingURL=/, "//# sourceMappingURL=https://raw.githubusercontent.com/Lightcord/Lightcord/"+commit+"/LightcordApi/js/")
|
||||
await fs.promises.writeFile(newpath, fileContent, "utf8")
|
||||
await fs.promises.copyFile(filepath, newpath)
|
||||
}, true).then(() => {
|
||||
console.info(`Copied files and minified them from ${path.join(__dirname, "LightcordApi")}.`)
|
||||
})
|
||||
|
||||
console.log(child_process.execSync("npm install --only=prod", {
|
||||
child_process.execSync("npm install --only=prod", {
|
||||
encoding: "binary",
|
||||
cwd: path.join(__dirname, "distApp", "LightcordApi")
|
||||
}))
|
||||
cwd: path.join(__dirname, "distApp", "LightcordApi"),
|
||||
stdio: "inherit"
|
||||
})
|
||||
|
||||
function processDJS(dir){
|
||||
fs.mkdirSync(path.join(__dirname, "distApp", "DiscordJS", dir), {recursive: true})
|
||||
@ -191,17 +209,34 @@ async function main(){
|
||||
await processDJS("dist")
|
||||
await copyFileDJS("package.json")
|
||||
|
||||
console.log(child_process.execSync("npm install --only=prod", {
|
||||
child_process.execSync("npm install --only=prod", {
|
||||
encoding: "binary",
|
||||
cwd: path.join(__dirname, "distApp", "DiscordJS")
|
||||
}))
|
||||
cwd: path.join(__dirname, "distApp", "DiscordJS"),
|
||||
stdio: "inherit"
|
||||
})
|
||||
|
||||
fs.mkdirSync(path.join(__dirname, "distApp", "BetterDiscordApp", "dist"), {recursive: true})
|
||||
const BDPackageJSON = require("./BetterDiscordApp/package.json")
|
||||
fs.writeFileSync(path.join(__dirname, "distApp", "BetterDiscordApp", "package.json"), JSON.stringify(BDPackageJSON), "utf8")
|
||||
fs.writeFileSync(path.join(__dirname, "distApp", "BetterDiscordApp", "dist", "style.min.css"), fs.readFileSync(path.join(__dirname, "BetterDiscordApp", "dist", "style.min.css")))
|
||||
fs.writeFileSync(path.join(__dirname, "distApp", "BetterDiscordApp", "dist", "index.min.js"), fs.readFileSync(path.join(__dirname, "BetterDiscordApp", "dist", "index.min.js")))
|
||||
|
||||
const files = [
|
||||
"index.min.js",
|
||||
"style.min.css"
|
||||
]
|
||||
files.forEach(e => {
|
||||
files.push(e + ".map")
|
||||
})
|
||||
files.forEach(e => {
|
||||
const pth = path.join(__dirname, "BetterDiscordApp", "dist", e)
|
||||
if(!fs.existsSync(pth))return console.error(`\x1b[31mFile ${pth} from betterdiscord does not exist.\x1b[0m`)
|
||||
if(e.endsWith(".map")){
|
||||
const data = JSON.parse(fs.readFileSync(pth, "utf8"))
|
||||
data.sourcesContent = []
|
||||
fs.writeFileSync(path.join(__dirname, "distApp", "BetterDiscordApp", "dist", e), JSON.stringify(data))
|
||||
}else{
|
||||
fs.copyFileSync(pth, path.join(__dirname, "distApp", "BetterDiscordApp", "dist", e))
|
||||
}
|
||||
})
|
||||
|
||||
await fs.promises.mkdir(path.join(__dirname, "distApp", "splash", "videos"), {recursive: true})
|
||||
await processNextDir(path.join(__dirname, "splash"), {
|
||||
startDir: path.join(__dirname, "splash"),
|
||||
@ -226,10 +261,11 @@ async function main(){
|
||||
fs.writeFileSync(path.join(__dirname, "distApp", "package.json"), JSON.stringify(packageJSON), "utf8")
|
||||
|
||||
console.info(`Installing ${Object.keys(packageJSON.dependencies).length} packages...`)
|
||||
console.log(child_process.execSync("npm install --only=prod", {
|
||||
child_process.execSync("npm install --only=prod", {
|
||||
encoding: "binary",
|
||||
cwd: path.join(__dirname, "distApp")
|
||||
}))
|
||||
cwd: path.join(__dirname, "distApp"),
|
||||
stdio: "inherit"
|
||||
})
|
||||
console.info("Build took "+(Date.now() - startTimestamp) +"ms.")
|
||||
}
|
||||
main()
|
||||
|
119
build_electron.js
Normal file
119
build_electron.js
Normal file
@ -0,0 +1,119 @@
|
||||
const spawn = require("cross-spawn")
|
||||
const path = require("path")
|
||||
const { existsSync, promises: fsPromises } = require("fs")
|
||||
|
||||
const supportedPlatforms = []
|
||||
const Platforms = {
|
||||
linux: {
|
||||
name: "linux",
|
||||
run: () => {
|
||||
return awaitExec("npm", ["run", "build:electron_linux"])
|
||||
}
|
||||
},
|
||||
win: {
|
||||
name: "win",
|
||||
run: () => {
|
||||
return awaitExec("npm", ["run", "build:electron_win"])
|
||||
}
|
||||
},
|
||||
mac: {
|
||||
name: "mac",
|
||||
run: () => {
|
||||
return awaitExec("npm", ["run", "build:electron_darwin"])
|
||||
}
|
||||
},
|
||||
mac_experimental: {
|
||||
name: "mac",
|
||||
experimental: true,
|
||||
run: async () => {
|
||||
const basePath = path.join(__dirname, "..", "lightcord-darwin-x64")
|
||||
const nextPath = path.join(__dirname, "builds", "lightcord-darwin-x64")
|
||||
if(existsSync(nextPath)){
|
||||
console.log(`Cleaning ${nextPath}.`)
|
||||
await fsPromises.rmdir(nextPath, {recursive: true})
|
||||
}
|
||||
console.log(`Copying files from ${basePath}.`)
|
||||
let nextDir = async (pth) => {
|
||||
const newPath = pth.replace(basePath, nextPath)
|
||||
await fsPromises.mkdir(newPath)
|
||||
for(let file of await fsPromises.readdir(pth, {withFileTypes: true})){
|
||||
const filePath = path.join(pth, file.name)
|
||||
const newFilePath = path.join(newPath, file.name)
|
||||
if(file.isFile()){
|
||||
await fsPromises.copyFile(filePath, newFilePath)
|
||||
}else if(file.isDirectory()){
|
||||
await nextDir(filePath)
|
||||
}
|
||||
}
|
||||
}
|
||||
await nextDir(basePath)
|
||||
console.log(`Files are copied. Erasing current bundle if existing.`)
|
||||
const asarPath = path.join(nextPath, "lightcord.app", "Contents", "Resources", "app.asar")
|
||||
if(existsSync(asarPath))await fsPromises.unlink(asarPath)
|
||||
const asarUnpackPath = path.join(nextPath, "lightcord.app", "Contents", "Resources", "app.asar.unpacked")
|
||||
if(existsSync(asarUnpackPath))await fsPromises.rmdir(asarUnpackPath, {recursive: true})
|
||||
const asar = require("asar")
|
||||
await asar.createPackageWithOptions(path.join(__dirname, "distApp"), asarPath, {
|
||||
unpack: "*.{node,dylib,so.4,dll}",
|
||||
unpackDir: asarUnpackPath
|
||||
})
|
||||
const iconPath = path.join(__dirname, "app_icon_darwin.icns")
|
||||
if(existsSync(iconPath)){
|
||||
console.log(`Setting icon.`)
|
||||
const newIconPath = path.join(nextPath, "lightcord.app", "Contents", "Resources", "electron.icns")
|
||||
await fsPromises.copyFile(iconPath, newIconPath)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch(process.platform){
|
||||
case "win32":
|
||||
supportedPlatforms.push(Platforms.win)
|
||||
supportedPlatforms.push(Platforms.linux)
|
||||
if(existsSync(path.join(__dirname, "..", "lightcord-darwin-x64"))){
|
||||
supportedPlatforms.push(Platforms.mac_experimental)
|
||||
}
|
||||
break
|
||||
case "linux":
|
||||
supportedPlatforms.push(Platforms.linux)
|
||||
if(existsSync(path.join(__dirname, "..", "lightcord-darwin-x64"))){
|
||||
supportedPlatforms.push(Platforms.mac_experimental)
|
||||
}
|
||||
break
|
||||
case "darwin":
|
||||
supportedPlatforms.push(Platforms.mac)
|
||||
supportedPlatforms.push(Platforms.linux)
|
||||
break
|
||||
}
|
||||
|
||||
(async function(){
|
||||
console.log(`[\x1b[33mINFO\x1b[0m] Will build platforms \x1b[34m${supportedPlatforms.map(e => e.name).join("\x1b[0m, \x1b[34m")}\x1b[0m`)
|
||||
for(let platform of supportedPlatforms){
|
||||
console.log(`[\x1b[33mINFO\x1b[0m] Building platform ${platform.name}`)
|
||||
if(platform.experimental)console.warn(`[\x1b[33mWARN\x1b[0m] This platform is experimental`)
|
||||
await platform.run()
|
||||
}
|
||||
})().catch(err => {
|
||||
console.error(`Couldn't package app for electrons. Error: ${err}`)
|
||||
})
|
||||
|
||||
function awaitExec(command, args = []){
|
||||
return new Promise((resolve, reject) => {
|
||||
const child = spawn.spawn(command, args, {
|
||||
env: process.env,
|
||||
cwd: process.cwd(),
|
||||
stdio: "inherit"
|
||||
})
|
||||
child.on("close", (code) => {
|
||||
console.log()
|
||||
console.log()
|
||||
console.log(`Command ${command}${args.length > 0 ? " " + args.join(" ") : ""} ended with code ${code}.`)
|
||||
if(code !== 0){
|
||||
console.error("\x1b[31mFAILURE\x1b[0m Command failed. See logs above.")
|
||||
return reject(code)
|
||||
}
|
||||
resolve()
|
||||
})
|
||||
})
|
||||
}
|
@ -17,4 +17,4 @@ discord links are on [Lightcord's support server](https://discord.gg/7eFff2A)
|
||||
- [ ] Fixing #21
|
||||
- [ ] Update electron version to fix spellchecker problems.
|
||||
- [ ] fix all the shit with folders structure (native addons, building, etc)
|
||||
- [ ] update glasstron to the latest version.
|
||||
- [x] update glasstron to the latest version.
|
Loading…
x
Reference in New Issue
Block a user