app-downloader
Advanced tools
Comparing version 0.0.1 to 1.0.0
@@ -1,53 +0,169 @@ | ||
(function (root, factory) { | ||
// https://github.com/umdjs/umd/blob/master/templates/returnExports.js | ||
if (typeof define === 'function' && define.amd) { | ||
// AMD. Register as an anonymous module. | ||
define([], factory); | ||
} else if (typeof module === 'object' && module.exports) { | ||
// Node. Does not work with strict CommonJS, but | ||
// only CommonJS-like environments that support module.exports, | ||
// like Node. | ||
module.exports = factory(); | ||
} else { | ||
// Browser globals (root is window) | ||
root.returnExports = factory(); | ||
// Modules | ||
const os = require('os'); | ||
const jetpack = require('fs-jetpack'); | ||
const path = require('path'); | ||
const fetch = require('wonderful-fetch'); | ||
const downloads = require('downloads-folder'); | ||
const powertools = require('node-powertools'); | ||
// Main | ||
module.exports = async function () { | ||
const interval = setInterval(() => { | ||
log('Still downloading, please be patient! :)'); | ||
}, 3000); | ||
try { | ||
// Clear | ||
clear(); | ||
// Download | ||
await download(); | ||
// Launch | ||
launch() | ||
.then(() => { | ||
install(); | ||
}); | ||
return | ||
} catch (e) { | ||
error('Failed to download:', e); | ||
error('Ensure you are using the right Node.js version'); | ||
error('Alternatively, download the app manually from:', getURL()); | ||
} finally { | ||
clearInterval(interval); | ||
} | ||
}(typeof self !== 'undefined' ? self : this, function () { | ||
}; | ||
var environment = (Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]') ? 'node' : 'browser'; | ||
if (require.main === module) { | ||
module.exports(); | ||
} | ||
var SOURCE = 'library'; | ||
var VERSION = '0.0.1'; | ||
function clear() { | ||
const location = getDownloadPath(); | ||
function __module_title(options) { | ||
var self = this; | ||
log(`Clearing ${location}`) | ||
self.options = options || {}; | ||
jetpack.remove(location); | ||
} | ||
return self | ||
}; | ||
function download(location) { | ||
return new Promise(async function(resolve, reject) { | ||
const location = getDownloadPath(); | ||
const url = getURL(); | ||
__module_title.prototype.method = function (options) { | ||
var self = this; | ||
log(`Downloading app to ${location} from ${url}`); | ||
options = options || {}; | ||
// Process | ||
const res = await fetch(url); | ||
const fileStream = jetpack.createWriteStream(location); | ||
return new Promise(function(resolve, reject) { | ||
await new Promise((resolve, reject) => { | ||
res.body.pipe(fileStream); | ||
res.body.on('error', reject); | ||
}); | ||
fileStream.on('finish', resolve); | ||
}) | ||
.then((r) => { | ||
log('Download finished!'); | ||
}) | ||
.catch((e) => { | ||
error('Download failed!', e); | ||
}) | ||
return resolve(); | ||
}); | ||
} | ||
function getDownloadPath() { | ||
const url = getURL(); | ||
const packageJSON = jetpack.read(path.join(process.cwd(), 'package.json'), 'json'); | ||
return path.join(downloads(), url.split('/').slice(-1)[0]); | ||
} | ||
function getURL() { | ||
const name = os.type(); | ||
if (name === 'Darwin') { | ||
return 'https://github.com/somiibo/download-server/releases/download/installer/Somiibo.dmg' | ||
} else if (name === 'Windows_NT') { | ||
return 'https://github.com/somiibo/download-server/releases/download/installer/Somiibo-Setup.exe' | ||
} else { | ||
return 'https://github.com/somiibo/download-server/releases/download/installer/Somiibo_amd64.deb' | ||
} | ||
} | ||
// Register | ||
if (environment === 'browser') { | ||
try { | ||
window.__module_title = __module_title; | ||
} catch (e) { | ||
async function launch() { | ||
const location = getDownloadPath(); | ||
const name = os.type(); | ||
log(`Launching app at ${location}`) | ||
try { | ||
if (name === 'Darwin') { | ||
powertools.execute(`open "${location}"`) | ||
.then(() => { | ||
log('Drag the app to your Applications folder to install it'); | ||
}) | ||
} else if (name === 'Windows_NT') { | ||
powertools.execute(`"${location}"`) | ||
.then(() => {}) | ||
} else { | ||
powertools.execute(`sudo apt install "${location}"`) | ||
.then(() => { | ||
powertools.execute(`restart-manager`).catch(e => {console.error(e)}) | ||
}) | ||
} | ||
} catch (e) { | ||
error('Application failed to execute:', e); | ||
console.log('\n\n\n') | ||
log(`Please launch the app manually: ${location}`); | ||
} | ||
} | ||
// Just return a value to define the module export. | ||
// This example returns an object, but the module | ||
// can return a function as the exported value. | ||
return __module_title; // Enable if using UMD | ||
async function install() { | ||
const location = getDownloadPath(); | ||
const name = os.type(); | ||
const parsedPath = path.parse(location); | ||
const filename = parsedPath.name; | ||
})); | ||
try { | ||
if (name === 'Darwin') { | ||
log(`Attempting to install ${location}...`); | ||
const volumes = jetpack.list('/Volumes').sort().reverse(); | ||
const found = volumes.find(v => v.includes(filename)); | ||
const applicationPath = `/Applications/${filename}.app`; | ||
// Check if the app is mounted | ||
if (!found) { | ||
return setTimeout(() => { | ||
install(); | ||
}, 1000); | ||
} | ||
// Remove the app if it already exists | ||
if (jetpack.exists(applicationPath)) { | ||
jetpack.remove(applicationPath); | ||
} | ||
// Copy the app to the Applications folder | ||
jetpack.copy(path.join('/Volumes', found, `${filename}.app`), applicationPath) | ||
await powertools.execute(`open "${applicationPath}"`); | ||
} | ||
} catch (e) { | ||
error('Application failed to install:', e); | ||
console.log('\n\n\n') | ||
log(`Please install the app manually: ${location}`); | ||
} | ||
} | ||
function log() { | ||
console.log(`[${new Date().toLocaleTimeString()}]`, ...arguments) | ||
} | ||
function error() { | ||
console.error(`[${new Date().toLocaleTimeString()}]`, ...arguments) | ||
} |
{ | ||
"TODO": "__module_domain, __module_name, __asset_file_name, __module_owner, __module_title, __module_class_name, __module_description, __module_feature", | ||
"name": "app-downloader", | ||
"version": "0.0.1", | ||
"description": "__module_description", | ||
"version": "1.0.0", | ||
"description": "Helper module to install package.json downloads", | ||
"main": "./dist/index.js", | ||
"scripts": { | ||
"start": "node ./dist/index.js", | ||
"test": "npm run prepare && ./node_modules/mocha/bin/mocha test/ --recursive --timeout=10000", | ||
"prepare": "node -e 'require(`prepare-package`)()'", | ||
"prepare": "node -e \"require('prepare-package')()\"", | ||
"prepare:watch": "nodemon -w ./src -e '*' --exec 'npm run prepare'" | ||
@@ -18,3 +18,3 @@ }, | ||
"engines": { | ||
"node": ">=6.0.0" | ||
"node": ">=18" | ||
}, | ||
@@ -32,6 +32,6 @@ "os": [ | ||
"type": "git", | ||
"url": "git+https://github.com/__module_owner/__module_name" | ||
"url": "git+https://github.com/itw-creative-works/app-downloader" | ||
}, | ||
"keywords": [ | ||
"__module_name" | ||
"app-downloader" | ||
], | ||
@@ -41,12 +41,16 @@ "author": "ITW Creative Works", | ||
"bugs": { | ||
"url": "https://github.com/__module_owner/__module_name/issues" | ||
"url": "https://github.com/itw-creative-works/app-downloader/issues" | ||
}, | ||
"homepage": "https://__module_domain", | ||
"homepage": "https://itwcreativeworks.com", | ||
"dependencies": { | ||
"itwcw-package-analytics": "^1.0.1" | ||
"downloads-folder": "^3.0.3", | ||
"fs-jetpack": "^5.1.0", | ||
"itwcw-package-analytics": "^1.0.6", | ||
"node-powertools": "^1.5.9", | ||
"wonderful-fetch": "^1.1.12" | ||
}, | ||
"devDependencies": { | ||
"mocha": "^8.4.0", | ||
"prepare-package": "^1.1.5" | ||
"prepare-package": "^1.1.13" | ||
} | ||
} | ||
} |
<p align="center"> | ||
<a href="https://__module_domain"> | ||
<img src="https://cdn.itwcreativeworks.com/assets/__asset_file_name/images/logo/__asset_file_name-brandmark-black-x.svg" width="100px"> | ||
<a href="https://itwcreativeworks.com"> | ||
<img src="https://cdn.itwcreativeworks.com/assets/itw-creative-works/images/logo/itw-creative-works-brandmark-black-x.svg" width="100px"> | ||
</a> | ||
@@ -8,82 +8,46 @@ </p> | ||
<p align="center"> | ||
<img src="https://img.shields.io/github/package-json/v/__module_owner/__module_name.svg"> | ||
<img src="https://img.shields.io/github/package-json/v/itw-creative-works/app-downloader.svg"> | ||
<br> | ||
<img src="https://img.shields.io/librariesio/release/npm/__module_name.svg"> | ||
<img src="https://img.shields.io/bundlephobia/min/__module_name.svg"> | ||
<img src="https://img.shields.io/codeclimate/maintainability-percentage/__module_owner/__module_name.svg"> | ||
<img src="https://img.shields.io/npm/dm/__module_name.svg"> | ||
<img src="https://img.shields.io/node/v/__module_name.svg"> | ||
<img src="https://img.shields.io/website/https/__module_domain.svg"> | ||
<img src="https://img.shields.io/github/license/__module_owner/__module_name.svg"> | ||
<img src="https://img.shields.io/github/contributors/__module_owner/__module_name.svg"> | ||
<img src="https://img.shields.io/github/last-commit/__module_owner/__module_name.svg"> | ||
<img src="https://img.shields.io/librariesio/release/npm/app-downloader.svg"> | ||
<img src="https://img.shields.io/bundlephobia/min/app-downloader.svg"> | ||
<img src="https://img.shields.io/codeclimate/maintainability-percentage/itw-creative-works/app-downloader.svg"> | ||
<img src="https://img.shields.io/npm/dm/app-downloader.svg"> | ||
<img src="https://img.shields.io/node/v/app-downloader.svg"> | ||
<img src="https://img.shields.io/website/https/itwcreativeworks.com.svg"> | ||
<img src="https://img.shields.io/github/license/itw-creative-works/app-downloader.svg"> | ||
<img src="https://img.shields.io/github/contributors/itw-creative-works/app-downloader.svg"> | ||
<img src="https://img.shields.io/github/last-commit/itw-creative-works/app-downloader.svg"> | ||
<br> | ||
<br> | ||
<a href="https://__module_domain">Site</a> | <a href="https://www.npmjs.com/package/__module_name">NPM Module</a> | <a href="https://github.com/__module_owner/__module_name">GitHub Repo</a> | ||
<a href="https://itwcreativeworks.com">Site</a> | <a href="https://www.npmjs.com/package/app-downloader">NPM Module</a> | <a href="https://github.com/itw-creative-works/app-downloader">GitHub Repo</a> | ||
<br> | ||
<br> | ||
<strong>__module_name</strong> is the official npm module of <a href="https://__module_domain">__module_title</a>, a free app for __module_feature. | ||
<strong>app-downloader</strong> is the official npm module of <a href="https://itwcreativeworks.com">App Downloader</a>, a free app for Helper module to install package.json downloads. | ||
</p> | ||
## 🌐 __module_title Works in Node AND browser environments | ||
## 🌐 App Downloader Works in Node AND browser environments | ||
Yes, this module works in both Node and browser environments, including compatibility with [Webpack](https://www.npmjs.com/package/webpack) and [Browserify](https://www.npmjs.com/package/browserify)! | ||
## 🦄 Features | ||
* __module_feature | ||
* Helper module to install package.json downloads | ||
## 🔑 Getting an API key | ||
You can use so much of `__module_name` for free, but if you want to do some advanced stuff, you'll need an API key. You can get one by [signing up for a __module_title account](https://__module_domain/signup). | ||
## 📦 Install __module_title | ||
## 📦 Install App Downloader | ||
### Option 1: Install via npm | ||
Install with npm if you plan to use `__module_name` in a Node project or in the browser. | ||
Install with npm if you plan to use `app-downloader` in a Node project or in the browser. | ||
```shell | ||
npm install __module_name | ||
npm install app-downloader | ||
``` | ||
If you plan to use `__module_name` in a browser environment, you will probably need to use [Webpack](https://www.npmjs.com/package/webpack), [Browserify](https://www.npmjs.com/package/browserify), or a similar service to compile it. | ||
If you plan to use `app-downloader` in a browser environment, you will probably need to use [Webpack](https://www.npmjs.com/ | ||
```js | ||
const __module_name = new (require('__module_name'))({ | ||
// Not required, but having one removes limits (get your key at https://__module_domain). | ||
apiKey: 'api_test_key' | ||
}); | ||
``` | ||
## 📘 Using App Downloader | ||
After you have followed the install step, you can start using `app-downloader` to enhance your project. | ||
### Option 2: Install via CDN | ||
Install with CDN if you plan to use __module_title only in a browser environment. | ||
```html | ||
<script src="https://cdn.jsdelivr.net/npm/__module_name@latest/dist/index.min.js"></script> | ||
<script type="text/javascript"> | ||
var __module_name = new __module_class_name({ | ||
// Not required, but having one removes limits (get your key at https://__module_domain). | ||
apiKey: 'api_test_Key' | ||
}); | ||
</script> | ||
``` | ||
For a more in-depth documentation of this library and the App Downloader service, please visit the official App Downloader website. | ||
### Option 3: Use without installation | ||
You can use `__module_name` in a variety of ways that require no installation, such as `curl` in terminal/shell. | ||
## 📝 What Can App Downloader do? | ||
Helper module to install package.json downloads | ||
```shell | ||
# Standard | ||
curl -X POST https://api.__module_domain | ||
``` | ||
## ⚡️ Usage | ||
### __module_name.run(options) | ||
```js | ||
__module_name.run(options); | ||
``` | ||
## 📘 Using __module_title | ||
After you have followed the install step, you can start using `__module_name` to enhance your project. | ||
For a more in-depth documentation of this library and the __module_title service, please visit the official __module_title website. | ||
## 📝 What Can __module_title do? | ||
__module_description | ||
## 🗨️ Final Words | ||
If you are still having difficulty, we would love for you to post | ||
a question to [the __module_title issues page](https://github.com/__module_owner/__module_name/issues). It is much easier to answer questions that include your code and relevant files! So if you can provide them, we'd be extremely grateful (and more likely to help you find the answer!) | ||
a question to [the App Downloader issues page](https://github.com/itw-creative-works/app-downloader/issues). It is much easier to answer questions that include your code and relevant files! So if you can provide them, we'd be extremely grateful (and more likely to help you find the answer!) | ||
@@ -90,0 +54,0 @@ ## 📚 Projects Using this Library |
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
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
10429
6
138
0
0
5
64
1
1
+ Addeddownloads-folder@^3.0.3
+ Addedfs-jetpack@^5.1.0
+ Addednode-powertools@^1.5.9
+ Addedwonderful-fetch@^1.1.12
+ Addedansi-regex@2.1.1(transitive)
+ Addedaproba@1.2.0(transitive)
+ Addedare-we-there-yet@1.1.7(transitive)
+ Addedbase64-js@1.5.1(transitive)
+ Addedbl@4.1.0(transitive)
+ Addedbrace-expansion@2.0.1(transitive)
+ Addedbuffer@5.7.1(transitive)
+ Addedchownr@1.1.4(transitive)
+ Addedcode-point-at@1.1.0(transitive)
+ Addedconsole-control-strings@1.1.0(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addeddecompress-response@4.2.1(transitive)
+ Addeddeep-extend@0.6.0(transitive)
+ Addeddelegates@1.0.0(transitive)
+ Addeddetect-libc@1.0.3(transitive)
+ Addeddownloads-folder@3.0.3(transitive)
+ Addedend-of-stream@1.4.4(transitive)
+ Addedexpand-template@2.0.3(transitive)
+ Addedfs-constants@1.0.0(transitive)
+ Addedfs-jetpack@5.1.0(transitive)
+ Addedgauge@2.7.4(transitive)
+ Addedgithub-from-package@0.0.0(transitive)
+ Addedhas-unicode@2.0.1(transitive)
+ Addedieee754@1.2.1(transitive)
+ Addedini@1.3.8(transitive)
+ Addedis-fullwidth-code-point@1.0.0(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedmimic-response@2.1.0(transitive)
+ Addedminimatch@5.1.6(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedmkdirp-classic@0.5.3(transitive)
+ Addednapi-build-utils@1.0.2(transitive)
+ Addednode-abi@2.30.1(transitive)
+ Addednode-addon-api@3.2.1(transitive)
+ Addednode-powertools@1.7.0(transitive)
+ Addednoop-logger@0.1.1(transitive)
+ Addednpmlog@4.1.2(transitive)
+ Addednumber-is-nan@1.0.1(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedprebuild-install@5.3.6(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedpump@3.0.2(transitive)
+ Addedrc@1.2.8(transitive)
+ Addedreadable-stream@2.3.83.6.2(transitive)
+ Addedregistry-js@1.16.0(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedsemver@5.7.2(transitive)
+ Addedset-blocking@2.0.0(transitive)
+ Addedsignal-exit@3.0.7(transitive)
+ Addedsimple-concat@1.0.1(transitive)
+ Addedsimple-get@3.1.1(transitive)
+ Addedstring-width@1.0.2(transitive)
+ Addedstring_decoder@1.1.1(transitive)
+ Addedstrip-ansi@3.0.1(transitive)
+ Addedstrip-json-comments@2.0.1(transitive)
+ Addedtar-fs@2.1.1(transitive)
+ Addedtar-stream@2.2.0(transitive)
+ Addedtunnel-agent@0.6.0(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedwhich-pm-runs@1.1.0(transitive)
+ Addedwide-align@1.1.5(transitive)