Skip to content

Commit 75bda3d

Browse files
authored
Native Windows Support (OpenDroneMap#82)
* Winbundle support * Fix config-default, paths * Add libcurl * Include libs contents
1 parent d95432d commit 75bda3d

File tree

4 files changed

+141
-3
lines changed

4 files changed

+141
-3
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Publish Windows Bundle
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
tags:
8+
- v*
9+
10+
jobs:
11+
build:
12+
runs-on: windows-latest
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v2
16+
- name: Setup NodeJS
17+
uses: actions/setup-node@v2
18+
with:
19+
node-version: '12'
20+
- name: Setup Env
21+
run: |
22+
npm i
23+
npm i -g nexe
24+
- name: Build bundle
25+
run: |
26+
npm run winbundle
27+
- name: Upload Bundle File
28+
uses: actions/upload-artifact@v2
29+
with:
30+
name: Bundle
31+
path: dist\*.zip
32+
- name: Upload Bundle to Release
33+
uses: svenstaro/upload-release-action@v2
34+
if: startsWith(github.ref, 'refs/tags/')
35+
with:
36+
repo_token: ${{ secrets.GITHUB_TOKEN }}
37+
file: dist\*.zip
38+
file_glob: true
39+
tag: ${{ github.ref }}
40+
overwrite: true
41+

config-default.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616
"stale-uploads-timeout": 0,
1717
"ssl-key": "",
1818
"ssl-cert": "",
19-
"asr": "",
19+
"asr": ""
2020
}

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
22
"name": "ClusterODM",
3-
"version": "1.5.2",
3+
"version": "1.5.3",
44
"description": "",
55
"main": "index.js",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
7+
"test": "echo \"Error: no test specified\" && exit 1",
8+
"winbundle": "node winbundle.js"
89
},
910
"repository": {
1011
"type": "git",
@@ -28,5 +29,8 @@
2829
"tree-kill": "^1.2.1",
2930
"uuid": "^3.3.2",
3031
"winston": "^3.3.3"
32+
},
33+
"devDependencies": {
34+
"archiver": "^3.0.0"
3135
}
3236
}

winbundle.js

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
const fs = require('fs');
2+
const spawnSync = require('child_process').spawnSync;
3+
const path = require('path');
4+
const async = require('async');
5+
const archiver = require('archiver');
6+
7+
const bundleName = "clusterodm-windows-x64.zip";
8+
9+
async.series([
10+
cb => {
11+
// Cleanup directories
12+
console.log("Cleaning up folders");
13+
for (let dir of ["data", "tmp"]){
14+
for (let entry of fs.readdirSync(dir)){
15+
if (entry !== ".gitignore"){
16+
const e = path.join(dir, entry);
17+
console.log(`Removing ${e}`);
18+
if (fs.lstatSync(e).isDirectory()){
19+
fs.rmdirSync(e, { recursive: true });
20+
}else{
21+
fs.unlinkSync(e);
22+
}
23+
}
24+
}
25+
}
26+
cb();
27+
},
28+
29+
cb => {
30+
console.log("Building executable");
31+
const code = spawnSync('nexe.cmd', ['index.js', '-t', 'windows-x64-12.16.3', '-o', 'clusterodm.exe', '-r', 'libs/**'], { stdio: "pipe"}).status;
32+
33+
if (code === 0) cb();
34+
else cb(new Error(`nexe returned non-zero error code: ${code}`));
35+
},
36+
cb => {
37+
// Zip
38+
const outFile = path.join("dist", bundleName);
39+
if (!fs.existsSync("dist")) fs.mkdirSync("dist");
40+
if (fs.existsSync(outFile)) fs.unlinkSync(outFile);
41+
42+
let output = fs.createWriteStream(outFile);
43+
let archive = archiver.create('zip', {
44+
zlib: { level: 5 } // Sets the compression level (1 = best speed since most assets are already compressed)
45+
});
46+
47+
archive.on('finish', () => {
48+
console.log("Done!");
49+
cb();
50+
});
51+
52+
archive.on('error', err => {
53+
console.error(`Could not archive .zip file: ${err.message}`);
54+
cb(err);
55+
});
56+
57+
const files = [
58+
"data",
59+
"docs",
60+
"letsencrypt",
61+
"public",
62+
"tmp",
63+
"config-default.json",
64+
"LICENSE",
65+
"package.json",
66+
"clusterodm.exe"
67+
];
68+
69+
archive.pipe(output);
70+
files.forEach(file => {
71+
console.log(`Adding ${file}`);
72+
let stat = fs.lstatSync(file);
73+
if (stat.isFile()){
74+
archive.file(file, {name: path.basename(file)});
75+
}else if (stat.isDirectory()){
76+
archive.directory(file, path.basename(file));
77+
}else{
78+
logger.error(`Could not add ${file}`);
79+
}
80+
});
81+
82+
// Plus node-libcurl
83+
console.log("Adding node_modules/node-libcurl")
84+
archive.directory(path.join("node_modules", "node-libcurl"), path.join("node_modules", "node-libcurl"));
85+
86+
archive.finalize();
87+
}
88+
], (err) => {
89+
if (err) console.log(`Bundle failed: ${err}`);
90+
else console.log(`Bundle ==> dist/${bundleName}`);
91+
});
92+
93+

0 commit comments

Comments
 (0)