|
| 1 | +import fs from "fs-extra"; |
| 2 | +import path from "path"; |
| 3 | +import { spawn } from "child_process"; |
| 4 | +//@ts-ignore |
| 5 | +import qode from "@nodegui/qode"; |
| 6 | +const cwd = process.cwd(); |
| 7 | +const deployDirectory = path.resolve(cwd, "deploy"); |
| 8 | +const configFile = path.resolve(deployDirectory, "config.json"); |
| 9 | + |
| 10 | +const copyQode = async (dest: string) => { |
| 11 | + const qodeBinaryFile = qode.qodePath; |
| 12 | + await fs.chmod(qodeBinaryFile, "755"); |
| 13 | + await fs.copyFile(qodeBinaryFile, path.resolve(dest, "qode")); |
| 14 | +}; |
| 15 | + |
| 16 | +const copyAppDist = async (distPath: string, resourceDir: string) => { |
| 17 | + await fs.copy(distPath, path.resolve(resourceDir, "dist"), { |
| 18 | + recursive: true |
| 19 | + }); |
| 20 | +}; |
| 21 | + |
| 22 | +const runLinuxDeployQt = async (appName: string, buildDir: string) => { |
| 23 | + const qtHome = process.env.QT_INSTALL_DIR || qode.qtHome; //linux qt build doesnt have linuxdeployqt |
| 24 | + const linuxDeployQtBin = path.resolve(qode.qtHome, "bin", "linuxdeployqt.AppImage"); |
| 25 | + try { |
| 26 | + await fs.chmod(linuxDeployQtBin, "755"); |
| 27 | + } catch (err) { |
| 28 | + console.warn(`Warning: Tried to fix permission for linuxdeployqt but failed`); |
| 29 | + } |
| 30 | + |
| 31 | + const linuxDeployQt = spawn( |
| 32 | + linuxDeployQtBin, |
| 33 | + [`qode`, "-verbose=2","-unsupported-bundle-everything","-appimage",`-qmake=${path.resolve(qtHome,'bin','qmake')}`], |
| 34 | + { cwd: buildDir} |
| 35 | + ); |
| 36 | + |
| 37 | + return new Promise((resolve, reject) => { |
| 38 | + linuxDeployQt.stdout.on("data", function(data) { |
| 39 | + console.log("stdout: " + data.toString()); |
| 40 | + }); |
| 41 | + |
| 42 | + linuxDeployQt.stderr.on("data", function(data) { |
| 43 | + console.log("stderr: " + data.toString()); |
| 44 | + }); |
| 45 | + |
| 46 | + linuxDeployQt.on("exit", function(code) { |
| 47 | + if (!code) { |
| 48 | + return resolve(); |
| 49 | + } |
| 50 | + return reject("child process exited with code " + code); |
| 51 | + }); |
| 52 | + }); |
| 53 | +}; |
| 54 | + |
| 55 | +export const init = async (appName: string) => { |
| 56 | + const config = { |
| 57 | + appName: null |
| 58 | + }; |
| 59 | + const templateDirectory = path.resolve(__dirname, "../../template/linux"); |
| 60 | + const userTemplate = path.resolve(deployDirectory, "linux"); |
| 61 | + const appDir = path.resolve(userTemplate, appName); |
| 62 | + await fs.mkdirp(path.resolve(userTemplate, appDir)); |
| 63 | + await fs.copy(templateDirectory, appDir, { recursive: true }); |
| 64 | + Object.assign(config, { appName }); |
| 65 | + await fs.writeJSON(configFile, config); |
| 66 | +}; |
| 67 | + |
| 68 | +export const pack = async (distPath: string) => { |
| 69 | + const config = await fs.readJSON( |
| 70 | + path.resolve(deployDirectory, "config.json") |
| 71 | + ); |
| 72 | + const { appName } = config; |
| 73 | + const usertemplate = path.resolve(deployDirectory, "linux"); |
| 74 | + const templateAppDir = path.resolve(usertemplate, appName); |
| 75 | + const buildDir = path.resolve(usertemplate, "build"); |
| 76 | + const buildAppPackage = path.resolve(buildDir, appName); |
| 77 | + |
| 78 | + console.log(`cleaning build directory at ${buildDir}`); |
| 79 | + await fs.remove(buildDir); |
| 80 | + console.log(`creating build directory at ${buildDir}`); |
| 81 | + await fs.copy(templateAppDir, buildAppPackage, { recursive: true }); |
| 82 | + console.log(`copying qode`); |
| 83 | + await copyQode(buildAppPackage); |
| 84 | + console.log(`copying dist`); |
| 85 | + await copyAppDist(distPath, buildAppPackage); |
| 86 | + console.log(`running linuxdeployqt`); |
| 87 | + await runLinuxDeployQt(appName, buildAppPackage); |
| 88 | + console.log(`Build successful. Find the app at ${buildDir}`); |
| 89 | +}; |
0 commit comments