Skip to content

Commit

Permalink
Merge du Code V2 (Luuxis)
Browse files Browse the repository at this point in the history
  • Loading branch information
LeWarpy committed Mar 4, 2024
1 parent 07df74c commit 2ada41f
Show file tree
Hide file tree
Showing 62 changed files with 6,215 additions and 4,923 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ app
test
dist
node-v*
AppData
data
.DS_Store
10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"files.exclude": {
"**/.github": true,
"**/node_modules": true,
"**/package-lock.json": true,
"**/dist": true,
"**/app": true,
"**/.gitignore": true
}
}
119 changes: 100 additions & 19 deletions build.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,74 @@
const fs = require("fs");

const builder = require('electron-builder')
const JavaScriptObfuscator = require('javascript-obfuscator');
const nodeFetch = require('node-fetch')
const fs = require("fs");
const png2icons = require('png2icons');
const Jimp = require('jimp');
const { preductname } = require('./package.json')

const { preductname } = require('./package.json');

class Index {
async build() {
async init() {
this.obf = true
this.Fileslist = []
process.argv.forEach(async val => {
if (val.startsWith('--icon')) {
return this.iconSet(val.split('=')[1])
}

if (val.startsWith('--obf')) {
this.obf = JSON.parse(val.split('=')[1])
this.Fileslist = this.getFiles("src");
}

if (val.startsWith('--build')) {
let buildType = val.split('=')[1]
if (buildType == 'platform') return await this.buildPlatform()
}
});
}

async Obfuscate() {
if (fs.existsSync("./app")) fs.rmSync("./app", { recursive: true })

for (let path of this.Fileslist) {
let fileName = path.split('/').pop()
let extFile = fileName.split(".").pop()
let folder = path.replace(`/${fileName}`, '').replace('src', 'app')

if (!fs.existsSync(folder)) fs.mkdirSync(folder, { recursive: true })

if (extFile == 'js') {
let code = fs.readFileSync(path, "utf8");
code = code.replace(/src\//g, 'app/');
if (this.obf) {
await new Promise((resolve) => {
console.log(`Obfuscate ${path}`);
let obf = JavaScriptObfuscator.obfuscate(code, { optionsPreset: 'medium-obfuscation', disableConsoleOutput: false });
resolve(fs.writeFileSync(`${folder}/${fileName}`, obf.getObfuscatedCode(), { encoding: "utf-8" }));
})
} else {
console.log(`Copy ${path}`);
fs.writeFileSync(`${folder}/${fileName}`, code, { encoding: "utf-8" });
}
} else {
fs.copyFileSync(path, `${folder}/${fileName}`);
}
}
}

async buildPlatform() {
await this.Obfuscate();
builder.build({
config: {
generateUpdatesFilesForAllChannels: false,
appId: preductname,
productName: preductname,
copyright: 'Copyright © 2020-2024 Luuxis',
artifactName: "${productName}-${os}-${arch}.${ext}",
files: ["src/**/*", "package.json", "LICENSE.md"],
extraMetadata: { main: 'app/app.js' },
files: ["app/**/*", "package.json", "LICENSE.md"],
directories: { "output": "dist" },
compression: 'maximum',
asar: true,
Expand All @@ -22,11 +77,11 @@ class Index {
releaseType: 'release',
}],
win: {
icon: "./src/assets/images/icon.ico",
icon: "./app/assets/images/icon.ico",
target: [{
target: "nsis",
arch: ["x64"]
}],
arch: "x64"
}]
},
nsis: {
oneClick: true,
Expand All @@ -35,21 +90,39 @@ class Index {
runAfterFinish: true
},
mac: {
icon: "./src/assets/images/icon.icns",
icon: "./app/assets/images/icon.icns",
category: "public.app-category.games",
identity: null,
target: [{
target: "dmg",
arch: ["x64", "arm64"]
arch: "x64"
},
{
target: "zip",
arch: "x64"
},
{
target: "dmg",
arch: "arm64"
}, {
target: "zip",
arch: "arm64"
}]
},
linux: {
icon: "./src/assets/images/icon.png",
icon: "./app/assets/images/icon.png",
target: [{
target: "AppImage",
arch: ["x64"]
arch: "x64"
}, {
target: "deb",
arch: "x64"
}, {
target: "tar.gz",
arch: ["x64"]
arch: "x64"
}, {
target: "zip",
arch: "x64"
}]
}
}
Expand All @@ -60,6 +133,19 @@ class Index {
})
}

getFiles(path, file = []) {
if (fs.existsSync(path)) {
let files = fs.readdirSync(path);
if (files.length == 0) file.push(path);
for (let i in files) {
let name = `${path}/${files[i]}`;
if (fs.statSync(name).isDirectory()) this.getFiles(name, file);
else file.push(name);
}
}
return file;
}

async iconSet(url) {
let Buffer = await nodeFetch(url)
if (Buffer.status == 200) {
Expand All @@ -69,16 +155,11 @@ class Index {
fs.writeFileSync("src/assets/images/icon.icns", png2icons.createICNS(Buffer, png2icons.BILINEAR, 0));
fs.writeFileSync("src/assets/images/icon.ico", png2icons.createICO(Buffer, png2icons.HERMITE, 0, false));
fs.writeFileSync("src/assets/images/icon.png", Buffer);
console.log('new icon set')
} else {
console.log('connection error')
}
}
}

process.argv.forEach(val => {
if (val.startsWith('--icon')) {
return new Index().iconSet(val.split('=')[1])
} else if (val.startsWith('--build')) {
new Index().build()
}
});
new Index().init();
Loading

0 comments on commit 2ada41f

Please sign in to comment.