addon-tools-raub
Advanced tools
Comparing version 5.0.0 to 5.1.0
37
cpbin.js
'use strict'; | ||
const fs = require('fs'); | ||
const { copy, exists, mkdir, rm } = require('./utils'); | ||
const { bin } = require('.'); | ||
const copy = (src, dest) => new Promise( | ||
(res, rej) => fs.copyFile(src, dest, err => (err ? rej(err) : res())) | ||
); | ||
const exists = name => new Promise( | ||
res => fs.access( | ||
name, | ||
fs.constants.F_OK, | ||
err => res(err ? false : true) | ||
) | ||
); | ||
const mkdir = async name => { | ||
if (await exists(name)) { | ||
return; | ||
} | ||
return new Promise( | ||
(res, rej) => fs.mkdir(name, err => (err ? rej(err) : res())) | ||
); | ||
}; | ||
const rm = async name => { | ||
if ( ! await exists(name) ) { | ||
return; | ||
} | ||
await new Promise( | ||
(res, rej) => fs.unlink(name, err => (err ? rej(err) : res())) | ||
); | ||
}; | ||
module.exports = async name => { | ||
@@ -43,0 +8,0 @@ |
@@ -6,6 +6,8 @@ 'use strict'; | ||
const http = require('http'); | ||
const fs = require('fs'); | ||
const unzipper = require('unzipper'); | ||
const AdmZip = require('adm-zip'); | ||
const { bin, platform } = require('.'); | ||
const { mkdir, rm } = require('./utils'); | ||
@@ -20,9 +22,16 @@ | ||
const zipPath = `${bin}/${bin}.zip`; | ||
const install = (url, count = 1) => { | ||
const proto = protocols[url.match(/^https?/)[0]]; | ||
const request = proto.get(url, response => { | ||
const install = async (url, count = 1) => { | ||
try { | ||
const proto = protocols[url.match(/^https?/)[0]]; | ||
const response = await new Promise((res, rej) => { | ||
const request = proto.get(url, response => res(response)); | ||
request.on('error', err => rej(err)); | ||
}); | ||
response.on('error', err => { throw err; }); | ||
// Handle redirects | ||
@@ -34,3 +43,3 @@ if ([301, 302, 303, 307].includes(response.statusCode)) { | ||
console.log(url); | ||
return onError('Error: Too many redirects.'); | ||
throw new Error('Error: Too many redirects.'); | ||
} | ||
@@ -41,16 +50,23 @@ | ||
console.log(url); | ||
return onError(`Response status was ${response.statusCode}`); | ||
throw new Error(`Response status was ${response.statusCode}`); | ||
} | ||
response.on('error', err => onError(err.message)); | ||
await mkdir(bin); | ||
const extractor = unzipper.Extract({ path: bin }); | ||
extractor.on('error', err => onError(err.message)); | ||
await new Promise((res, rej) => { | ||
const zipWriter = fs.createWriteStream(zipPath); | ||
zipWriter.on('error', err => rej(err)); | ||
zipWriter.on('finish', () => res()); | ||
response.pipe(zipWriter); | ||
}); | ||
response.pipe(extractor); | ||
const zip = new AdmZip(zipPath); | ||
zip.extractAllTo(bin, true); | ||
}); | ||
await rm(zipPath); | ||
} catch (ex) { | ||
onError(ex.message); | ||
} | ||
request.on('error', err => onError(err.message)); | ||
}; | ||
@@ -61,3 +77,3 @@ | ||
const url = `${folder}/${platform}.zip`; | ||
install(url); | ||
install(url).then(); | ||
}; |
{ | ||
"author": "Luis Blanco <luisblanco1337@gmail.com>", | ||
"name": "addon-tools-raub", | ||
"version": "5.0.0", | ||
"version": "5.1.0", | ||
"description": "Helpers for Node.js addons and dependency packages", | ||
@@ -26,2 +26,3 @@ "license": "MIT", | ||
"install.js", | ||
"utils.js", | ||
"writable-buffer.js", | ||
@@ -41,5 +42,5 @@ "LICENSE", | ||
"dependencies": { | ||
"node-addon-api": "1.7.1", | ||
"unzipper": "0.10.5" | ||
"adm-zip": "0.4.14", | ||
"node-addon-api": "2.0.0" | ||
} | ||
} |
@@ -120,1 +120,23 @@ # Addon Tools | ||
``` | ||
## utils.js | ||
* `read` - (async) Reads a whole file to string, NOT A Buffer. | ||
* `write` - (async) Write a file. | ||
* `copy` - (async) Copy a file. | ||
* `exists` - (async) Check if a file/folder exists. | ||
* `mkdir` - (async) Create an empty folder. | ||
* `stat` - (async) Get status on a file. | ||
* `isDir` - (async) Check if the path is a folder. | ||
* `isFile` - (async) Check if the path is a file. | ||
* `dirUp` - Cut the path one folder up. | ||
* `ensuredir` - (async) Like `mkdir -p`, makes sure a directory exists. | ||
* `copysafe` - (async) Copy a file, `dest` folder is created if needed. | ||
* `readdir` - (async) Get file/folder names of the 1st level. | ||
* `subdirs` - (async) Get folder paths (concatenated with input) of the 1st level. | ||
* `subfiles` - (async) Get file paths (concatenated with input) of the 1st level. | ||
* `traverse` - (async) Get all nested files recursively. | ||
* `copyall` - (async) Copy a folder with all the contained files. | ||
* `rmdir` - (async) Like `rm -rf`, removes everything recursively. | ||
* `rm` - (async) Remove a file. Must be a file, not a folder. Just `fs.unlink`. |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
44262
311
142
4
5
+ Addedadm-zip@0.4.14
+ Addedadm-zip@0.4.14(transitive)
+ Addednode-addon-api@2.0.0(transitive)
- Removedunzipper@0.10.5
- Removedbalanced-match@1.0.2(transitive)
- Removedbig-integer@1.6.52(transitive)
- Removedbinary@0.3.0(transitive)
- Removedbluebird@3.4.7(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedbuffer-indexof-polyfill@1.0.2(transitive)
- Removedbuffers@0.1.1(transitive)
- Removedchainsaw@0.1.0(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removedcore-util-is@1.0.3(transitive)
- Removedduplexer2@0.1.4(transitive)
- Removedfs.realpath@1.0.0(transitive)
- Removedfstream@1.0.12(transitive)
- Removedglob@7.2.3(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removedinflight@1.0.6(transitive)
- Removedinherits@2.0.4(transitive)
- Removedisarray@1.0.0(transitive)
- Removedlistenercount@1.0.1(transitive)
- Removedminimatch@3.1.2(transitive)
- Removedminimist@1.2.8(transitive)
- Removedmkdirp@0.5.6(transitive)
- Removednode-addon-api@1.7.1(transitive)
- Removedonce@1.4.0(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedprocess-nextick-args@2.0.1(transitive)
- Removedreadable-stream@2.3.8(transitive)
- Removedrimraf@2.7.1(transitive)
- Removedsafe-buffer@5.1.2(transitive)
- Removedsetimmediate@1.0.5(transitive)
- Removedstring_decoder@1.1.1(transitive)
- Removedtraverse@0.3.9(transitive)
- Removedunzipper@0.10.5(transitive)
- Removedutil-deprecate@1.0.2(transitive)
- Removedwrappy@1.0.2(transitive)
Updatednode-addon-api@2.0.0