Skip to content
This repository has been archived by the owner on Aug 16, 2023. It is now read-only.

Commit

Permalink
Updated to work with node version 10.20.1 LTS (#5)
Browse files Browse the repository at this point in the history
* Changed to ES6 initial refactor

* fixed const/var declarations

* Refactored tools.js added async functions

* fixed async functions on tools.js

* fixed async/await functions on tools.js

* fixed error catching on tools.js

* fixed directory naming on tools.js

Co-authored-by: root <root@jitsi.alvin.tech>
  • Loading branch information
alvinveroy and root authored May 13, 2020
1 parent c99b28b commit b055c47
Show file tree
Hide file tree
Showing 6 changed files with 299 additions and 376 deletions.
4 changes: 2 additions & 2 deletions ConfigFileClass.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var fileTools = require('./file-tools');
var chalk = require('chalk');
const fileTools = require('./file-tools');
const chalk = require('chalk');

function ConfigFile(existingFile) {
if (existingFile == true){
Expand Down
12 changes: 6 additions & 6 deletions file-tools.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
var fs = require('fs');
var path = require('path');
const fs = require('fs');
const path = require('path');

module.exports = {
check_existing_config_file: function(){
check_existing_config_file: _ => {
return fs.existsSync(path.join(process.cwd(), "scripts.json"));
},
check_existing_resource_folder: function(){
check_existing_resource_folder: _ => {
return fs.existsSync(path.join(process.cwd(), "resources"));
},
get_config_file: function(){
get_config_file: _ => {
return require(path.join(process.cwd(), "scripts.json"));
},
set_config_file: function(data){
set_config_file: (data) => {
fs.writeFileSync(path.join(process.cwd(), "scripts.json"), data);
}
};
70 changes: 35 additions & 35 deletions fvm
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/usr/bin/env node

var request = require('superagent');
var chalk = require('chalk');
var fs = require('fs');
var tools = require('./tools');
var ConfigFile = require('./ConfigFileClass');
var co = require('co');
var prompt = require('co-prompt');
const request = require('superagent');
const chalk = require('chalk');
const fs = require('fs');
const tools = require('./tools');
const ConfigFile = require('./ConfigFileClass');
const co = require('co');
const prompt = require('co-prompt');


var pjson = require('./package.json');
const pjson = require('./package.json');
console.log("\n");
console.log("===========================");
console.log("FiveM Installer v"+pjson.version);
Expand All @@ -19,9 +19,9 @@ console.log("===========================");
console.log("\n");


var latestVersion = require('latest-version');
const latestVersion = require('latest-version');

latestVersion('fvm-installer').then(function(lastversion) {
latestVersion('fvm-installer').then((lastversion) => {
if (lastversion != pjson.version){
console.log("New Version "+chalk.red("v"+pjson.version)+ " -> "+chalk.green("v"+lastversion));
console.log("Please run:");
Expand All @@ -30,7 +30,7 @@ latestVersion('fvm-installer').then(function(lastversion) {
}


var arguments = process.argv;
const arguments = process.argv;
var save = false;
var specifiedfolder = "";

Expand All @@ -56,7 +56,7 @@ latestVersion('fvm-installer').then(function(lastversion) {
var dataConfigFile = new ConfigFile(true);


var resourcestoinstall = arguments;
const resourcestoinstall = arguments;
resourcestoinstall.splice(0, 3);

promiseArray = [];
Expand All @@ -72,7 +72,7 @@ latestVersion('fvm-installer').then(function(lastversion) {
});

//Can give multiple resources to install
resourcestoinstall.forEach(function(resource){
resourcestoinstall.forEach((resource) => {
if(resource != "--save" && resource.substring(0, 9) != "--folder="){
if(tools.check_resource_format(resource)){
promiseArray.push(tools.download_resource(resource, dataConfigFile, save, specifiedfolder));
Expand All @@ -84,56 +84,56 @@ latestVersion('fvm-installer').then(function(lastversion) {
}
});

Promise.all(promiseArray).then(function(values) {
Promise.all(promiseArray).then((values) => {
console.log("\n");

console.log(chalk.green("Installation successful"));
}).catch(function(data) {
}).catch((data) => {
process.exit(0);
});

}else{
//Check if existing file and if exist install packages
var dataConfigFile = new ConfigFile(true);
dataConfigFile = new ConfigFile(true);

promiseArray = [];

Object.keys(dataConfigFile.resources).forEach(function(key) {
var resource = key + "@" +dataConfigFile.resources[key];
Object.keys(dataConfigFile.resources).forEach((key) => {
const resource = key + "@" +dataConfigFile.resources[key];
if(tools.check_resource_format(resource)){
promiseArray.push(tools.download_resource(resource, dataConfigFile, save, dataConfigFile.folder[key]));
}
}
);

Promise.all(promiseArray).then(function(values) {
Promise.all(promiseArray).then((values) => {
console.log("\n");

console.log(chalk.green("Installation successful!"));
}).catch(function(data) {
}).catch((data) => {
process.exit(0);
});
}
break;

case "update":
var dataConfigFile = new ConfigFile(true);
dataConfigFile = new ConfigFile(true);

if(arguments[3]){

var resourcestoupdate = arguments;
const resourcestoupdate = arguments;
resourcestoupdate.splice(0, 3);

promiseArray = [];

resourcestoupdate.forEach(function(resource){
resourcestoupdate.forEach((resource) => {
if(resource == "--save"){
save = true;
}
});

//Can give multiple resources to install
resourcestoupdate.forEach(function(resource){
resourcestoupdate.forEach((resource) => {
if(resource != "--save"){
if(tools.check_resource_format(resource)){
promiseArray.push(tools.update_resource(resource, dataConfigFile.resources[resource], dataConfigFile, save));
Expand All @@ -145,7 +145,7 @@ latestVersion('fvm-installer').then(function(lastversion) {
}
});

Promise.all(promiseArray).then(function(values) {
Promise.all(promiseArray).then((values) => {
console.log(chalk.green("Update successful!"));
}).catch(function(data) {
process.exit(0);
Expand All @@ -155,13 +155,13 @@ latestVersion('fvm-installer').then(function(lastversion) {

promiseArray = [];

Object.keys(dataConfigFile.resources).forEach(function(key) {
Object.keys(dataConfigFile.resources).forEach((key) => {
promiseArray.push(tools.check_update_resource(key, dataConfigFile.resources[key]));
});

Promise.all(promiseArray).then(function(values) {
Promise.all(promiseArray).then((values) => {
console.log("To upgrade packages, do " + chalk.green("fvm update <package_name>"));
}).catch(function(data) {
}).catch((data) => {
process.exit(0);
});
}
Expand All @@ -171,12 +171,12 @@ latestVersion('fvm-installer').then(function(lastversion) {
case "init":
console.log("Initialisation of FiveM Installer directory")
console.log("\n");
var dataConfigFile = new ConfigFile(false);
dataConfigFile = new ConfigFile(false);

co(function *() {
var nameConfig = yield prompt('Name: ');
var authorConfig = yield prompt('Author: ');
var websiteConfig = yield prompt('Website: ');
const nameConfig = yield prompt('Name: ');
const authorConfig = yield prompt('Author: ');
const websiteConfig = yield prompt('Website: ');
dataConfigFile.initConfigFile(nameConfig, authorConfig, websiteConfig);
console.log("\n");
console.log(chalk.green("Initialisation of FiveM Installer directory finish ! You can now use fvm installer."));
Expand All @@ -186,13 +186,13 @@ latestVersion('fvm-installer').then(function(lastversion) {

case "remove":
if(arguments[3]){
var dataConfigFile = new ConfigFile(true);
var resourcestodelete = arguments;
dataConfigFile = new ConfigFile(true);
const resourcestodelete = arguments;
resourcestodelete.splice(0, 3);

promiseArray = [];

resourcestodelete.forEach(function(resource){
resourcestodelete.forEach((resource) => {
if(resource == "--save"){
save = true;
}
Expand Down
Loading

0 comments on commit b055c47

Please sign in to comment.