Socket
Socket
Sign inDemoInstall

altv-pkg

Package Overview
Dependencies
21
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.2.0 to 2.0.0

113

bin/altv-pkg.js
#!/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": {

]
}
}

@@ -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.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc