From e8c19df8c953b4e43b2052fece03b38b6a04fadf Mon Sep 17 00:00:00 2001 From: Tim Perry Date: Wed, 13 Dec 2017 15:08:36 +0100 Subject: [PATCH] Set up a script to automate builds, and support native extensions --- automation/build-bin.ts | 34 ++++++++++++++++++++++++++++++++++ package.json | 6 +++++- 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 automation/build-bin.ts diff --git a/automation/build-bin.ts b/automation/build-bin.ts new file mode 100644 index 00000000..0db0b1a8 --- /dev/null +++ b/automation/build-bin.ts @@ -0,0 +1,34 @@ +import * as path from 'path'; +import * as fs from 'fs-extra'; +import * as FileHound from 'filehound'; +import { exec as execPkg } from 'pkg'; + +const ROOT = path.join(__dirname, '..'); + +console.log('Building package...\n'); + +execPkg([ + '--target', 'host', + '--output', 'build-bin/resin', + 'package.json' +]).then(() => fs.copy( + path.join(ROOT, 'node_modules', 'opn', 'xdg-open'), + path.join(ROOT, 'build-bin', 'xdg-open') +)).then(() => { + return FileHound.create() + .paths(path.join(ROOT, 'node_modules')) + .ext(['node', 'dll']) + .find(); +}).then((nativeExtensions: string[]) => { + console.log(`\nCopying to build-bin:\n${nativeExtensions.join('\n')}`); + + return nativeExtensions.map((extPath) => { + return fs.copy( + extPath, + extPath.replace( + path.join(ROOT, 'node_modules'), + path.join(ROOT, 'build-bin') + ) + ); + }); +}); diff --git a/package.json b/package.json index a20212b2..8001c631 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "prebuild": "rimraf build/ build-bin/", "build": "npm run build:src && npm run build:bin", "build:src": "gulp build && tsc && npm run doc", - "build:bin": "pkg . -t host -o build-bin/resin && cp node_modules/opn/xdg-open build-bin/", + "build:bin": "ts-node automation/build-bin.ts", "pretest": "npm run build", "test": "gulp test", "ci": "npm run test && catch-uncommitted", @@ -51,8 +51,11 @@ "node": ">=6.0" }, "devDependencies": { + "@types/fs-extra": "^5.0.0", "catch-uncommitted": "^1.0.0", "ent": "^2.2.0", + "filehound": "^1.16.2", + "fs-extra": "^5.0.0", "gulp": "^3.9.0", "gulp-coffee": "^2.2.0", "gulp-coffeelint": "^0.6.0", @@ -62,6 +65,7 @@ "mochainon": "^2.0.0", "pkg": "^4.3.0-beta.1", "require-npm4-to-publish": "^1.0.0", + "ts-node": "^4.0.1", "typescript": "^2.6.1" }, "dependencies": {