Skip to content

Commit 95a8438

Browse files
committed
Fixes linux builder
1 parent 39655a8 commit 95a8438

9 files changed

Lines changed: 493 additions & 13 deletions

File tree

package-lock.json

Lines changed: 385 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
"author": "atulanand94@gmail.com",
1818
"license": "MIT",
1919
"devDependencies": {
20-
"@nodegui/qode": "^1.0.4",
20+
"@nodegui/qode": "^1.0.3",
2121
"@types/fs-extra": "^8.0.0",
22+
"@types/node": "^12.7.3",
2223
"typescript": "^3.5.3"
2324
},
2425
"peerDependencies": {

src/darwin/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ export const init = async (appName: string) => {
5656
const config = {
5757
appName: null
5858
};
59-
const templateDirectory = path.resolve(__dirname, "../../template/win32");
60-
const userTemplate = path.resolve(deployDirectory, "win32");
59+
const templateDirectory = path.resolve(__dirname, "../../template/darwin");
60+
const userTemplate = path.resolve(deployDirectory, "darwin");
6161
const appDir = path.resolve(userTemplate, `${appName}.app`);
6262
await fs.mkdirp(path.resolve(userTemplate, appDir));
6363
await fs.copy(templateDirectory, appDir, { recursive: true });

src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ export const getPacker = (platformName: string)=>{
88
case 'win32': {
99
return require('./win32');
1010
}
11+
case 'linux': {
12+
return require('./linux');
13+
}
1114
default: {
1215
throw new Error(`Unsupported platform ${process.platform}`)
1316
}

src/linux/index.ts

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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+
};

src/win32/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ export const pack = async (distPath: string) => {
7070
const templateAppDir = path.resolve(usertemplate, appName);
7171
const buildDir = path.resolve(usertemplate, "build");
7272
const buildAppPackage = path.resolve(buildDir, appName);
73-
const bin = path.resolve(buildAppPackage, "bin");
74-
// const Resources = path.resolve(Contents, "Resources");
7573
console.log(`cleaning build directory at ${buildDir}`);
7674
await fs.remove(buildDir);
7775
console.log(`creating build directory at ${buildDir}`);
@@ -82,5 +80,5 @@ export const pack = async (distPath: string) => {
8280
await copyAppDist(distPath, buildAppPackage);
8381
console.log(`running windeployqt`);
8482
await runWinDeployQt(appName, buildAppPackage);
85-
console.log(`Build successful. Find the dmg/app at ${buildDir}`);
83+
console.log(`Build successful. Find the app at ${buildDir}`);
8684
};

template/linux/default.desktop

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[Desktop Entry]
2+
Type=Application
3+
Name=Application
4+
Exec=AppRun %F
5+
Icon=default
6+
Comment=Edit this default file
7+
Terminal=true
8+
Categories=Utility;

template/linux/default.png

Loading

template/linux/qode.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"distPath": "./dist"
3+
}

0 commit comments

Comments
 (0)