diff --git a/.github/workflows/publish-windows.yml b/.github/workflows/publish-windows.yml new file mode 100644 index 0000000..a76d453 --- /dev/null +++ b/.github/workflows/publish-windows.yml @@ -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 + diff --git a/config-default.json b/config-default.json index 189248e..6a211d3 100644 --- a/config-default.json +++ b/config-default.json @@ -16,5 +16,5 @@ "stale-uploads-timeout": 0, "ssl-key": "", "ssl-cert": "", - "asr": "", + "asr": "" } diff --git a/package.json b/package.json index 37e7f8b..62aaac2 100644 --- a/package.json +++ b/package.json @@ -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", @@ -28,5 +29,8 @@ "tree-kill": "^1.2.1", "uuid": "^3.3.2", "winston": "^3.3.3" + }, + "devDependencies": { + "archiver": "^3.0.0" } } diff --git a/winbundle.js b/winbundle.js new file mode 100644 index 0000000..af33026 --- /dev/null +++ b/winbundle.js @@ -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}`); +}); + +