Skip to content

Commit

Permalink
Native Windows Support (#82)
Browse files Browse the repository at this point in the history
* Winbundle support

* Fix config-default, paths

* Add libcurl

* Include libs contents
  • Loading branch information
pierotofy authored Jun 3, 2021
1 parent d95432d commit 75bda3d
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 3 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/publish-windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Publish Windows Bundle

on:
push:
branches:
- master
tags:
- v*

jobs:
build:
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup NodeJS
uses: actions/setup-node@v2
with:
node-version: '12'
- name: Setup Env
run: |
npm i
npm i -g nexe
- name: Build bundle
run: |
npm run winbundle
- name: Upload Bundle File
uses: actions/upload-artifact@v2
with:
name: Bundle
path: dist\*.zip
- name: Upload Bundle to Release
uses: svenstaro/upload-release-action@v2
if: startsWith(github.ref, 'refs/tags/')
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: dist\*.zip
file_glob: true
tag: ${{ github.ref }}
overwrite: true

2 changes: 1 addition & 1 deletion config-default.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
"stale-uploads-timeout": 0,
"ssl-key": "",
"ssl-cert": "",
"asr": "",
"asr": ""
}
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"name": "ClusterODM",
"version": "1.5.2",
"version": "1.5.3",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"winbundle": "node winbundle.js"
},
"repository": {
"type": "git",
Expand All @@ -28,5 +29,8 @@
"tree-kill": "^1.2.1",
"uuid": "^3.3.2",
"winston": "^3.3.3"
},
"devDependencies": {
"archiver": "^3.0.0"
}
}
93 changes: 93 additions & 0 deletions winbundle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
const fs = require('fs');
const spawnSync = require('child_process').spawnSync;
const path = require('path');
const async = require('async');
const archiver = require('archiver');

const bundleName = "clusterodm-windows-x64.zip";

async.series([
cb => {
// Cleanup directories
console.log("Cleaning up folders");
for (let dir of ["data", "tmp"]){
for (let entry of fs.readdirSync(dir)){
if (entry !== ".gitignore"){
const e = path.join(dir, entry);
console.log(`Removing ${e}`);
if (fs.lstatSync(e).isDirectory()){
fs.rmdirSync(e, { recursive: true });
}else{
fs.unlinkSync(e);
}
}
}
}
cb();
},

cb => {
console.log("Building executable");
const code = spawnSync('nexe.cmd', ['index.js', '-t', 'windows-x64-12.16.3', '-o', 'clusterodm.exe', '-r', 'libs/**'], { stdio: "pipe"}).status;

if (code === 0) cb();
else cb(new Error(`nexe returned non-zero error code: ${code}`));
},
cb => {
// Zip
const outFile = path.join("dist", bundleName);
if (!fs.existsSync("dist")) fs.mkdirSync("dist");
if (fs.existsSync(outFile)) fs.unlinkSync(outFile);

let output = fs.createWriteStream(outFile);
let archive = archiver.create('zip', {
zlib: { level: 5 } // Sets the compression level (1 = best speed since most assets are already compressed)
});

archive.on('finish', () => {
console.log("Done!");
cb();
});

archive.on('error', err => {
console.error(`Could not archive .zip file: ${err.message}`);
cb(err);
});

const files = [
"data",
"docs",
"letsencrypt",
"public",
"tmp",
"config-default.json",
"LICENSE",
"package.json",
"clusterodm.exe"
];

archive.pipe(output);
files.forEach(file => {
console.log(`Adding ${file}`);
let stat = fs.lstatSync(file);
if (stat.isFile()){
archive.file(file, {name: path.basename(file)});
}else if (stat.isDirectory()){
archive.directory(file, path.basename(file));
}else{
logger.error(`Could not add ${file}`);
}
});

// Plus node-libcurl
console.log("Adding node_modules/node-libcurl")
archive.directory(path.join("node_modules", "node-libcurl"), path.join("node_modules", "node-libcurl"));

archive.finalize();
}
], (err) => {
if (err) console.log(`Bundle failed: ${err}`);
else console.log(`Bundle ==> dist/${bundleName}`);
});


0 comments on commit 75bda3d

Please sign in to comment.