altv-pkg
Advanced tools
Comparing version 1.2.0 to 2.0.0
#!/usr/bin/env node | ||
const program = require('commander'); | ||
const { handleInstall } = require('./options/install'); | ||
const { handleRemove } = require('./options/remove'); | ||
const { handleDownload } = require('./options/download'); | ||
const yargs = require('yargs/yargs')(); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const axios = require('axios'); | ||
const chalk = require('chalk'); | ||
// Properties | ||
program.version('1.0.2'); | ||
program.name('altv-pkg'); | ||
program.usage('<command> [options]'); | ||
const platform = process.platform == 'win32' ? 'x64_win32' : 'x64_linux'; | ||
const rootPath = process.cwd(); | ||
// Options | ||
program | ||
.command('install <author/repo>') | ||
.alias('i') | ||
.description('Install an alt:V resource from GitHub.') | ||
.action(handleInstall); | ||
let branch = 'release' | ||
program | ||
.command('remove <author/repo>') | ||
.alias('r') | ||
.description('Remove an alt:V resource from local installation.') | ||
.action(handleRemove); | ||
yargs.usage(`Usage: altv-pkg [release/rc/dev]`) | ||
program | ||
.command(`download <branch>`) | ||
.alias('d') | ||
.description('Install alt:V server framework from CDN.') | ||
.action(handleDownload); | ||
yargs.command('release', 'Download altest release files', { alias: 'd' }, () => { | ||
branch = 'release'; | ||
}); | ||
// Parse Args. | ||
program.parse(process.argv); | ||
yargs.command('rc', 'Download altest rc files', { alias: 'rc' }, () => { | ||
branch = 'rc'; | ||
}); | ||
yargs.command('dev', 'Download altest dev files', { alias: 'dev' }, () => { | ||
branch = 'dev'; | ||
}); | ||
async function start() { | ||
console.log(chalk.greenBright('===== altv-pkg =====')); | ||
console.log(chalk.whiteBright(`System: `), chalk.yellowBright(platform)); | ||
console.log(chalk.whiteBright(`Branch: `), chalk.yellowBright(branch)); | ||
const binaryDownload = platform === 'x64_linux' ? `https://cdn.altv.mp/server/${branch}/x64_linux/altv-server` : `https://cdn.altv.mp/server/${branch}/x64_win32/altv-server.exe`; | ||
const altvFiles = { | ||
// alt:V data files | ||
'data/vehmodels.bin': `https://cdn.altv.mp/data/${branch}/data/vehmodels.bin`, | ||
'data/vehmods.bin': `https://cdn.altv.mp/data/${branch}/data/vehmods.bin`, | ||
'data/clothes.bin': `https://cdn.altv.mp/data/${branch}/data/clothes.bin`, | ||
// alt:V modules | ||
'modules/js-module.dll': `https://cdn.altv.mp/js-module/${branch}/${platform}/modules/js-module/js-module.dll`, | ||
'libnode.dll': `https://cdn.altv.mp/js-module/${branch}/${platform}/modules/js-module/libnode.dll`, | ||
}; | ||
if (!fs.existsSync(path.join(rootPath, 'data'))) { | ||
fs.mkdirSync(path.join(rootPath, 'data')); | ||
} | ||
if (!fs.existsSync(path.join(rootPath, 'modules'))) { | ||
fs.mkdirSync(path.join(rootPath, 'modules')); | ||
} | ||
let promises = []; | ||
console.log(chalk.greenBright('===== Download =====')); | ||
for (const [file, url] of Object.entries(altvFiles)) { | ||
console.log(chalk.whiteBright(`${file}`)) | ||
const promise = new Promise((resolve) => { | ||
axios.get(url, { responseType: 'arraybuffer' }).then(response => { | ||
fs.writeFileSync(path.join(rootPath, file), response.data); | ||
resolve(); | ||
}).catch(error => { | ||
console.error(`Failed to download ${file}: ${error}`); | ||
resolve(); | ||
}); | ||
}); | ||
promises.push(promise); | ||
} | ||
const binaryPathing = binaryDownload.split('/'); | ||
const binaryFileName = binaryPathing[binaryPathing.length - 1]; | ||
const promise = new Promise((resolve) => { | ||
axios.get(binaryDownload, { responseType: 'arraybuffer' }).then(response => { | ||
console.log(chalk.whiteBright(`${binaryFileName}`)) | ||
fs.writeFileSync(path.join(rootPath, binaryFileName), response.data); | ||
resolve(); | ||
}).catch(error => { | ||
console.error(`Failed to download ${binaryFileName}: ${error}`); | ||
resolve(); | ||
}) | ||
}); | ||
promises.push(promise); | ||
await Promise.all(promises); | ||
console.log(chalk.greenBright('===== Complete =====')); | ||
} | ||
start(); | ||
{ | ||
"name": "altv-pkg", | ||
"version": "1.2.0", | ||
"description": "A CLI tool for installing open source resourced and their dependencies.", | ||
"version": "2.0.0", | ||
"description": "Install alt:V Binaries Quickly", | ||
"main": "bin/index.js", | ||
@@ -12,9 +12,5 @@ "author": "stuyk", | ||
"dependencies": { | ||
"async-execute": "^1.2.0", | ||
"axios": "latest", | ||
"axios": "^0.26.1", | ||
"chalk": "^4.1.0", | ||
"commander": "^6.0.0", | ||
"download": "^6.2.5", | ||
"node-fetch": "^2.6.0", | ||
"rimraf": "^3.0.2" | ||
"yargs": "^17.4.1" | ||
}, | ||
@@ -37,2 +33,2 @@ "prettier": { | ||
] | ||
} | ||
} |
162
README.md
@@ -1,163 +0,23 @@ | ||
# alt:V PKG | ||
# altv-pkg | ||
<p align="center"> | ||
<img width="500px" src="https://thumbs.gfycat.com/MildSecondhandIndigobunting-size_restricted.gif" /> | ||
</p> | ||
Download server binaries quickly and easily for [alt:V Servers](https://altv.mp). | ||
#### An easy to use resource installer for alt:V | ||
| Usage | Description | | ||
| ------------------ | -------------------------------- | | ||
| `altv-pkg release` | Download latest release binaries | | ||
| `altv-pkg rc` | Download latest rc binaries | | ||
| `altv-pkg dev` | Download latest dev binaries | | ||
--- | ||
## How to install? | ||
A community resource that allows users to easily install resources and ask questions during the installation process, install dependencies, clone the repository, and then handle the responses in their post install script. | ||
This was created to easily install resources from your server's `base` directory. | ||
[Find resources on alt:V Hub](https://hub.altv.mp) | ||
[Visit the official alt:V GTA:V Client Website](https://altv.mp) | ||
[❤️ Become a Sponsor of my Open Source Work](https://github.com/sponsors/Stuyk/) | ||
[⌨️ Learn how to script for alt:V](https://altv.stuyk.com/) | ||
⭐ This repository if you found it useful! | ||
# How to Use | ||
## Install with Command Line | ||
Make sure to get `NodeJS` Version `13+`. | ||
If you get module not found errors. You don't have `13+`. | ||
```sh | ||
npm install -g altv-pkg | ||
``` | ||
**Powershell Users** | ||
If you have issues running the altv-pkg command. | ||
Simply run the following to unblock powershell from running scripts. | ||
Ensure you use powershell with **administrative** permission. | ||
npm i --save-dev altv-pkg | ||
``` | ||
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted -Force; | ||
``` | ||
## Download Server Files with Command Line | ||
## How to run? | ||
You should be running this in a directory with existing server files or where you want to download the alt:V Server Framework for JavaScript. | ||
```sh | ||
altv-pkg d <branch_name> | ||
``` | ||
ie. `altv-pkg d release` | ||
## Install with Command Line | ||
You should be running this in your base server directory where `package.json` is. | ||
If you don't have a package.json do `npm init`. | ||
Also make sure to create a folder called `resources`. | ||
```sh | ||
altv-pkg i <author>/<reponame> | ||
npx altv-pkg release | ||
``` | ||
ie. `altv-pkg i stuyk/altv-discord-auth` | ||
If the repo is `NOT` supported it will tell you. | ||
## Remove with Command Line | ||
You should be running this in your base server directory where `package.json` is. | ||
```sh | ||
altv-pkg r <author>/<reponame> | ||
``` | ||
<br /> | ||
# Resource Creators | ||
If you wish to add support to your resource for this file. Please add `.altv` file to your repository with installation instructions. You can also specify `[]` inside of your `.altv` file to skip all instructions. | ||
## Use This Badge | ||
Only all the cool devs do it. 😎 | ||
[![Generic badge](https://img.shields.io/badge/.altv_pkg_support-Yes!-4E753E.svg)](https://shields.io/) | ||
``` | ||
[![Generic badge](https://img.shields.io/badge/.altv_pkg_support-Yes!-4E753E.svg)](https://shields.io/) | ||
``` | ||
## Instruction Types | ||
### package | ||
Installs an npm package automatically. | ||
### question | ||
Ask a question for the user to respond to in the comnand line. | ||
Responses are recorded to `resources/<your_repo>/responses.json` | ||
### postinstall | ||
Specify a script for node to run at the end of the script. | ||
This file should be located in your repository. | ||
<br /> | ||
# Instructions Example | ||
Here is a baseline example of your `.altv` file could look. | ||
Yes, you can have multiple instructions of the same type. | ||
```json | ||
[ | ||
{ | ||
"type": "package", | ||
"name": "sjcl", | ||
"version": "latest" | ||
}, | ||
{ | ||
"type": "question", | ||
"question": "What is your favorite color?" | ||
}, | ||
{ | ||
"type": "postinstall", | ||
"file": "post.js" | ||
} | ||
] | ||
``` | ||
### Explanation | ||
1. Add `sjcl` to `package.json` dependencies. | ||
2. Ask the user a question and store the response in `responses.json` | ||
3. Run a `postinstall` script called `post.js` with NodeJS. | ||
<br /> | ||
# Author | ||
Created by Stuyk (Trevor Wessel) | ||
https://github.com/sponsors/Stuyk/ | ||
https://patreon.com/stuyk | ||
<br /> | ||
# alt:V Installer Supported Resources | ||
- Make a pull request to append your files to the bottom of this list. |
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
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
3
1
1
40317
4
71
24
+ Addedyargs@^17.4.1
+ Addedansi-regex@5.0.1(transitive)
+ Addedaxios@0.26.1(transitive)
+ Addedcliui@8.0.1(transitive)
+ Addedemoji-regex@8.0.0(transitive)
+ Addedescalade@3.1.2(transitive)
+ Addedget-caller-file@2.0.5(transitive)
+ Addedis-fullwidth-code-point@3.0.0(transitive)
+ Addedrequire-directory@2.1.1(transitive)
+ Addedstring-width@4.2.3(transitive)
+ Addedstrip-ansi@6.0.1(transitive)
+ Addedwrap-ansi@7.0.0(transitive)
+ Addedy18n@5.0.8(transitive)
+ Addedyargs@17.7.2(transitive)
+ Addedyargs-parser@21.1.1(transitive)
- Removedasync-execute@^1.2.0
- Removedcommander@^6.0.0
- Removeddownload@^6.2.5
- Removednode-fetch@^2.6.0
- Removedrimraf@^3.0.2
- Removedasync-execute@1.2.0(transitive)
- Removedasynckit@0.4.0(transitive)
- Removedaxios@1.7.2(transitive)
- Removedbalanced-match@1.0.2(transitive)
- Removedbase64-js@1.5.1(transitive)
- Removedbl@1.2.3(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedbuffer@5.7.1(transitive)
- Removedbuffer-alloc@1.2.0(transitive)
- Removedbuffer-alloc-unsafe@1.1.0(transitive)
- Removedbuffer-crc32@0.2.13(transitive)
- Removedbuffer-fill@1.0.0(transitive)
- Removedcaw@2.0.1(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removedcommander@2.20.36.2.1(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removedconfig-chain@1.1.13(transitive)
- Removedcontent-disposition@0.5.4(transitive)
- Removedcore-util-is@1.0.3(transitive)
- Removeddecompress@4.2.1(transitive)
- Removeddecompress-response@3.3.0(transitive)
- Removeddecompress-tar@4.1.1(transitive)
- Removeddecompress-tarbz2@4.1.1(transitive)
- Removeddecompress-targz@4.1.1(transitive)
- Removeddecompress-unzip@4.0.1(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removeddownload@6.2.5(transitive)
- Removedduplexer3@0.1.5(transitive)
- Removedend-of-stream@1.4.4(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedext-list@2.2.2(transitive)
- Removedext-name@5.0.0(transitive)
- Removedfd-slicer@1.1.0(transitive)
- Removedfile-type@3.9.05.2.06.2.0(transitive)
- Removedfilename-reserved-regex@2.0.0(transitive)
- Removedfilenamify@2.1.0(transitive)
- Removedform-data@4.0.0(transitive)
- Removedfs-constants@1.0.0(transitive)
- Removedfs.realpath@1.0.0(transitive)
- Removedget-proxy@2.1.0(transitive)
- Removedget-stream@2.3.13.0.0(transitive)
- Removedglob@7.2.3(transitive)
- Removedgot@7.1.0(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removedhas-symbol-support-x@1.4.2(transitive)
- Removedhas-to-string-tag-x@1.4.1(transitive)
- Removedieee754@1.2.1(transitive)
- Removedinflight@1.0.6(transitive)
- Removedinherits@2.0.4(transitive)
- Removedini@1.3.8(transitive)
- Removedis-natural-number@4.0.1(transitive)
- Removedis-object@1.0.2(transitive)
- Removedis-plain-obj@1.1.0(transitive)
- Removedis-retry-allowed@1.2.0(transitive)
- Removedis-stream@1.1.0(transitive)
- Removedisarray@1.0.0(transitive)
- Removedisurl@1.0.0(transitive)
- Removedlowercase-keys@1.0.1(transitive)
- Removedmake-dir@1.3.0(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedmimic-response@1.0.1(transitive)
- Removedminimatch@3.1.2(transitive)
- Removednode-fetch@2.7.0(transitive)
- Removednpm-conf@1.1.3(transitive)
- Removedobject-assign@4.1.1(transitive)
- Removedonce@1.4.0(transitive)
- Removedp-cancelable@0.3.0(transitive)
- Removedp-event@1.3.0(transitive)
- Removedp-finally@1.0.0(transitive)
- Removedp-timeout@1.2.1(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedpend@1.2.0(transitive)
- Removedpify@2.3.03.0.0(transitive)
- Removedpinkie@2.0.4(transitive)
- Removedpinkie-promise@2.0.1(transitive)
- Removedprepend-http@1.0.4(transitive)
- Removedprocess-nextick-args@2.0.1(transitive)
- Removedproto-list@1.2.4(transitive)
- Removedproxy-from-env@1.1.0(transitive)
- Removedreadable-stream@2.3.8(transitive)
- Removedrimraf@3.0.2(transitive)
- Removedsafe-buffer@5.1.25.2.1(transitive)
- Removedseek-bzip@1.0.6(transitive)
- Removedsort-keys@1.1.2(transitive)
- Removedsort-keys-length@1.0.1(transitive)
- Removedstring_decoder@1.1.1(transitive)
- Removedstrip-dirs@2.1.0(transitive)
- Removedstrip-outer@1.0.1(transitive)
- Removedtar-stream@1.6.2(transitive)
- Removedthrough@2.3.8(transitive)
- Removedtimed-out@4.0.1(transitive)
- Removedto-buffer@1.1.1(transitive)
- Removedtr46@0.0.3(transitive)
- Removedtrim-repeated@1.0.0(transitive)
- Removedtunnel-agent@0.6.0(transitive)
- Removedunbzip2-stream@1.4.3(transitive)
- Removedurl-parse-lax@1.0.0(transitive)
- Removedurl-to-options@1.0.1(transitive)
- Removedutil-deprecate@1.0.2(transitive)
- Removedwebidl-conversions@3.0.1(transitive)
- Removedwhatwg-url@5.0.0(transitive)
- Removedwrappy@1.0.2(transitive)
- Removedxtend@4.0.2(transitive)
- Removedyauzl@2.10.0(transitive)
Updatedaxios@^0.26.1