|
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 | + } |
29 | 14 | } |
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 | +} |
0 commit comments