Skip to content

Commit c790d95

Browse files
committed
Added packer for windows
1 parent 8dd49b8 commit c790d95

9 files changed

Lines changed: 207 additions & 476 deletions

File tree

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"author": "atulanand94@gmail.com",
1818
"license": "MIT",
1919
"devDependencies": {
20-
"@nodegui/qode": "^1.0.3",
20+
"@nodegui/qode": "^1.0.4",
2121
"@types/fs-extra": "^8.0.0",
2222
"typescript": "^3.5.3"
2323
},

src/cli.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/usr/bin/env node
22

33
import program from "commander";
4-
import { init, pack } from "./index";
4+
import process from "process";
5+
import { getPacker } from "./index";
56

67
program
78
.option("-i, --init <name>", "Creates initial deploy files")
@@ -10,10 +11,13 @@ program
1011
program.parse(process.argv);
1112
const options = program.opts();
1213

14+
const platformName = process.platform;
15+
const packer = getPacker(platformName);
16+
1317
if (program.init) {
14-
init(options.init);
18+
packer.init(options.init);
1519
}
1620

1721
if (program.pack) {
18-
pack(options.pack);
22+
packer.pack(options.pack);
1923
}

src/darwin/index.ts

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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 runMacDeployQt = async (appName: string, buildDir: string) => {
23+
const qtHome = process.env.QT_INSTALL_DIR || qode.qtHome;
24+
const macDeployQtBin = path.resolve(qtHome, "bin", "macdeployqt");
25+
try {
26+
await fs.chmod(macDeployQtBin, "755");
27+
} catch (err) {
28+
console.warn(`Warning: Tried to fix permission for macdeployqt but failed`);
29+
}
30+
31+
const macDeployQt = spawn(
32+
macDeployQtBin,
33+
[`${appName}.app`, "-dmg", "-verbose=3", `-libpath ${qode.qtHome}`],
34+
{ cwd: buildDir }
35+
);
36+
37+
return new Promise((resolve, reject) => {
38+
macDeployQt.stdout.on("data", function(data) {
39+
console.log("stdout: " + data.toString());
40+
});
41+
42+
macDeployQt.stderr.on("data", function(data) {
43+
console.log("stderr: " + data.toString());
44+
});
45+
46+
macDeployQt.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/win32");
60+
const userTemplate = path.resolve(deployDirectory, "win32");
61+
const appDir = path.resolve(userTemplate, `${appName}.app`);
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, "darwin");
74+
const templateAppDir = path.resolve(usertemplate, `${appName}.app`);
75+
const buildDir = path.resolve(usertemplate, "build");
76+
const buildAppPackage = path.resolve(buildDir, `${appName}.app`);
77+
const Contents = path.resolve(buildAppPackage, "Contents");
78+
const MacOs = path.resolve(Contents, "MacOs");
79+
const Resources = path.resolve(Contents, "Resources");
80+
console.log(`cleaning build directory at ${buildDir}`);
81+
await fs.remove(buildDir);
82+
console.log(`creating build directory at ${buildDir}`);
83+
await fs.copy(templateAppDir, buildAppPackage, { recursive: true });
84+
console.log(`copying qode`);
85+
await copyQode(MacOs);
86+
console.log(`copying dist`);
87+
await copyAppDist(distPath, Resources);
88+
console.log(`running macdeployqt`);
89+
await runMacDeployQt(appName, buildDir);
90+
console.log(`Build successful. Find the dmg/app at ${buildDir}`);
91+
};

src/index.ts

Lines changed: 14 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,15 @@
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 runMacDeployQt = async (appName: string, buildDir: string) => {
23-
const qtHome = process.env.QT_INSTALL_DIR || qode.qtHome;
24-
const macDeployQtBin = path.resolve(qtHome, "bin", "macdeployqt");
25-
try {
26-
await fs.chmod(macDeployQtBin, "755");
27-
} catch (err) {
28-
console.warn(`Warning: Tried to fix permission for macdeployqt but failed`);
1+
import process from 'process';
2+
3+
export const getPacker = (platformName: string)=>{
4+
switch(platformName){
5+
case 'darwin': {
6+
return require('./darwin');
7+
}
8+
case 'win32': {
9+
return require('./win32');
10+
}
11+
default: {
12+
throw new Error(`Unsupported platform ${process.platform}`)
13+
}
2914
}
30-
31-
const macDeployQt = spawn(
32-
macDeployQtBin,
33-
[`${appName}.app`, "-dmg", "-verbose=3", `-libpath ${qode.qtHome}`],
34-
{ cwd: buildDir }
35-
);
36-
37-
return new Promise((resolve, reject) => {
38-
macDeployQt.stdout.on("data", function(data) {
39-
console.log("stdout: " + data.toString());
40-
});
41-
42-
macDeployQt.stderr.on("data", function(data) {
43-
console.log("stderr: " + data.toString());
44-
});
45-
46-
macDeployQt.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/darwin");
60-
const userTemplate = path.resolve(deployDirectory, "darwin");
61-
const appDir = path.resolve(userTemplate, `${appName}.app`);
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, "darwin");
74-
const templateAppDir = path.resolve(usertemplate, `${appName}.app`);
75-
const buildDir = path.resolve(usertemplate, "build");
76-
const buildAppPackage = path.resolve(buildDir, `${appName}.app`);
77-
const Contents = path.resolve(buildAppPackage, "Contents");
78-
const MacOs = path.resolve(Contents, "MacOs");
79-
const Resources = path.resolve(Contents, "Resources");
80-
console.log(`cleaning build directory at ${buildDir}`);
81-
await fs.remove(buildDir);
82-
console.log(`creating build directory at ${buildDir}`);
83-
await fs.copy(templateAppDir, buildAppPackage, { recursive: true });
84-
console.log(`copying qode`);
85-
await copyQode(MacOs);
86-
console.log(`copying dist`);
87-
await copyAppDist(distPath, Resources);
88-
console.log(`running macdeployqt`);
89-
await runMacDeployQt(appName, buildDir);
90-
console.log(`Build successful. Find the dmg/app at ${buildDir}`);
91-
};
15+
}

src/win32/index.ts

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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.exe"));
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 runWinDeployQt = async (appName: string, buildDir: string) => {
23+
const qtHome = process.env.QT_INSTALL_DIR || qode.qtHome;
24+
const winDeployQtBin = path.resolve(qtHome, "windeployqt.exe");
25+
const winDeployQt = spawn(
26+
winDeployQtBin,
27+
[`qode.exe`, "--verbose=2", "--release", "--no-translations"],
28+
{
29+
cwd: buildDir
30+
}
31+
);
32+
33+
return new Promise((resolve, reject) => {
34+
winDeployQt.stdout.on("data", function(data) {
35+
console.log("stdout: " + data.toString());
36+
});
37+
38+
winDeployQt.stderr.on("data", function(data) {
39+
console.log("stderr: " + data.toString());
40+
});
41+
42+
winDeployQt.on("exit", function(code) {
43+
if (!code) {
44+
return resolve();
45+
}
46+
return reject("child process exited with code " + code);
47+
});
48+
});
49+
};
50+
51+
export const init = async (appName: string) => {
52+
const config = {
53+
appName: null
54+
};
55+
const templateDirectory = path.resolve(__dirname, "../../template/win32");
56+
const userTemplate = path.resolve(deployDirectory, "win32");
57+
const appDir = path.resolve(userTemplate, appName);
58+
await fs.mkdirp(path.resolve(userTemplate, appDir));
59+
await fs.copy(templateDirectory, appDir, { recursive: true });
60+
Object.assign(config, { appName });
61+
await fs.writeJSON(configFile, config);
62+
};
63+
64+
export const pack = async (distPath: string) => {
65+
const config = await fs.readJSON(
66+
path.resolve(deployDirectory, "config.json")
67+
);
68+
const { appName } = config;
69+
const usertemplate = path.resolve(deployDirectory, "win32");
70+
const templateAppDir = path.resolve(usertemplate, appName);
71+
const buildDir = path.resolve(usertemplate, "build");
72+
const buildAppPackage = path.resolve(buildDir, appName);
73+
const bin = path.resolve(buildAppPackage, "bin");
74+
// const Resources = path.resolve(Contents, "Resources");
75+
console.log(`cleaning build directory at ${buildDir}`);
76+
await fs.remove(buildDir);
77+
console.log(`creating build directory at ${buildDir}`);
78+
await fs.copy(templateAppDir, buildAppPackage, { recursive: true });
79+
console.log(`copying qode`);
80+
await copyQode(buildAppPackage);
81+
console.log(`copying dist`);
82+
await copyAppDist(distPath, buildAppPackage);
83+
console.log(`running windeployqt`);
84+
await runWinDeployQt(appName, buildAppPackage);
85+
console.log(`Build successful. Find the dmg/app at ${buildDir}`);
86+
};

template/win32/platforms/.gitkeep

Whitespace-only changes.

template/win32/qode.json

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

template/win32/styles/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)