diff --git a/ConfigFileClass.js b/ConfigFileClass.js index 954594b..871c7c4 100644 --- a/ConfigFileClass.js +++ b/ConfigFileClass.js @@ -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){ diff --git a/file-tools.js b/file-tools.js index 22e707c..cddd91f 100644 --- a/file-tools.js +++ b/file-tools.js @@ -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); } }; diff --git a/fvm b/fvm old mode 100644 new mode 100755 index 548e26c..1b53ce7 --- a/fvm +++ b/fvm @@ -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); @@ -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:"); @@ -30,7 +30,7 @@ latestVersion('fvm-installer').then(function(lastversion) { } - var arguments = process.argv; + const arguments = process.argv; var save = false; var specifiedfolder = ""; @@ -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 = []; @@ -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)); @@ -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)); @@ -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); @@ -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 ")); - }).catch(function(data) { + }).catch((data) => { process.exit(0); }); } @@ -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.")); @@ -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; } diff --git a/package-lock.json b/package-lock.json index fff3823..d302fce 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "fvm-installer", - "version": "1.1.4", + "version": "1.1.6", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -22,10 +22,25 @@ "resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz", "integrity": "sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ==" }, + "@types/node": { + "version": "14.0.1", + "resolved": "https://registry.npmjs.org/@types/node/-/node-14.0.1.tgz", + "integrity": "sha512-FAYBGwC+W6F9+huFIDtn43cpy7+SzG+atzRiTfdp3inUKL2hXnd4rG8hylJLIh4+hqrQy1P17kvJByE/z825hA==", + "optional": true + }, + "@types/yauzl": { + "version": "2.9.1", + "resolved": "https://registry.npmjs.org/@types/yauzl/-/yauzl-2.9.1.tgz", + "integrity": "sha512-A1b8SU4D10uoPjwb0lnHmmu8wZhR9d+9o2PKBQT2jU5YPTKsxac6M2qGAdY7VcL+dHHhARVUDmeg0rOrcd9EjA==", + "optional": true, + "requires": { + "@types/node": "*" + } + }, "adm-zip": { - "version": "0.4.13", - "resolved": "https://registry.npmjs.org/adm-zip/-/adm-zip-0.4.13.tgz", - "integrity": "sha512-fERNJX8sOXfel6qCBCMPvZLzENBEhZTzKqg6vrOW5pvoEaQuJhRU4ndTAh6lHOxn1I6jnz2NHra56ZODM751uw==" + "version": "0.4.14", + "resolved": "https://registry.npmjs.org/adm-zip/-/adm-zip-0.4.14.tgz", + "integrity": "sha512-/9aQCnQHF+0IiCl0qhXoK7qs//SwYE7zX8lsr/DNk1BRAHYxeLZPL4pguwK29gUEqasYQjqPtEpDRSWEkdHn9g==" }, "ansi-styles": { "version": "4.2.1", @@ -55,10 +70,10 @@ "concat-map": "0.0.1" } }, - "buffer-from": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz", - "integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==" + "buffer-crc32": { + "version": "0.2.13", + "resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.13.tgz", + "integrity": "sha1-DTM+PwDqxQqhRUq9MO+MKl2ackI=" }, "cacheable-request": { "version": "6.1.0", @@ -90,9 +105,9 @@ } }, "chalk": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz", - "integrity": "sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.0.0.tgz", + "integrity": "sha512-N9oWFcegS0sFr9oh1oz2d7Npos6vNoWW9HvtCg5N1KRFpUhaAhvTv5Y58g880fZaEYSNm3qDz8SU1UrGvp+n7A==", "requires": { "ansi-styles": "^4.1.0", "supports-color": "^7.1.0" @@ -150,33 +165,17 @@ "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" }, - "concat-stream": { - "version": "1.6.2", - "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz", - "integrity": "sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==", - "requires": { - "buffer-from": "^1.0.0", - "inherits": "^2.0.3", - "readable-stream": "^2.2.2", - "typedarray": "^0.0.6" - } - }, "cookiejar": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/cookiejar/-/cookiejar-2.1.2.tgz", "integrity": "sha512-Mw+adcfzPxcPeI+0WlvRrr/3lGVO0bD75SxX6811cxSh1Wbxx7xZBGK1eVtDf6si8rg2lhnUjsVLMFMfbRIuwA==" }, - "core-util-is": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", - "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" - }, "debug": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", - "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", + "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", "requires": { - "ms": "2.0.0" + "ms": "^2.1.1" } }, "decompress-response": { @@ -216,14 +215,24 @@ } }, "extract-zip": { - "version": "1.6.7", - "resolved": "https://registry.npmjs.org/extract-zip/-/extract-zip-1.6.7.tgz", - "integrity": "sha1-qEC0uK9kAyZMjbV/Txp0Mz74H+k=", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/extract-zip/-/extract-zip-2.0.0.tgz", + "integrity": "sha512-i42GQ498yibjdvIhivUsRslx608whtGoFIhF26Z7O4MYncBxp8CwalOs1lnHy21A9sIohWO2+uiE4SRtC9JXDg==", "requires": { - "concat-stream": "1.6.2", - "debug": "2.6.9", - "mkdirp": "0.5.1", - "yauzl": "2.4.1" + "@types/yauzl": "^2.9.1", + "debug": "^4.1.1", + "get-stream": "^5.1.0", + "yauzl": "^2.10.0" + }, + "dependencies": { + "get-stream": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.1.0.tgz", + "integrity": "sha512-EXr1FOzrzTfGeL0gQdeFEvOMm2mzMOglyiOXSTpPC+iAjAKftbr3jpCMWynogwYnM+eSj9sHGc6wjIcDvYiygw==", + "requires": { + "pump": "^3.0.0" + } + } } }, "fast-safe-stringify": { @@ -232,9 +241,9 @@ "integrity": "sha512-Utm6CdzT+6xsDk2m8S6uL8VHxNwI6Jub+e9NYTcAms28T84pTa25GJQV9j0CY0N1rM8hK4x6grpF2BQf+2qwVA==" }, "fd-slicer": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/fd-slicer/-/fd-slicer-1.0.1.tgz", - "integrity": "sha1-i1vL2ewyfFBBv5qwI/1nUPEXfmU=", + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/fd-slicer/-/fd-slicer-1.1.0.tgz", + "integrity": "sha1-JcfInLH5B3+IkbvmHY85Dq4lbx4=", "requires": { "pend": "~1.2.0" } @@ -250,9 +259,9 @@ } }, "formidable": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/formidable/-/formidable-1.2.1.tgz", - "integrity": "sha512-Fs9VRguL0gqGHkXS5GQiMCr1VhZBxz0JnJs4JmMp/2jL18Fmbzvv7vOFRU+U8TBkHEE/CX1qDXzJplVULgsLeg==" + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/formidable/-/formidable-1.2.2.tgz", + "integrity": "sha512-V8gLm+41I/8kguQ4/o1D3RIHRmhYFG4pnNyonvua+40rqcEmT4+V71yaZ3B457xbbgCsCfjSPi65u/W6vK1U5Q==" }, "fs.realpath": { "version": "1.0.0", @@ -327,11 +336,6 @@ "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.5.tgz", "integrity": "sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw==" }, - "isarray": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", - "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=" - }, "json-buffer": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.0.tgz", @@ -369,21 +373,21 @@ "integrity": "sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4=" }, "mime": { - "version": "2.4.4", - "resolved": "https://registry.npmjs.org/mime/-/mime-2.4.4.tgz", - "integrity": "sha512-LRxmNwziLPT828z+4YkNzloCFC2YM4wrB99k+AV5ZbEyfGNWfG8SO1FUXLmLDBSo89NrJZ4DIWeLjy1CHGhMGA==" + "version": "2.4.5", + "resolved": "https://registry.npmjs.org/mime/-/mime-2.4.5.tgz", + "integrity": "sha512-3hQhEUF027BuxZjQA3s7rIv/7VCQPa27hN9u9g87sEkWaKwQPuXOkVKtOeiyUrnWqTDiOs8Ed2rwg733mB0R5w==" }, "mime-db": { - "version": "1.43.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.43.0.tgz", - "integrity": "sha512-+5dsGEEovYbT8UY9yD7eE4XTc4UwJ1jBYlgaQQF38ENsKR3wj/8q8RFZrF9WIZpB2V1ArTVFUva8sAul1NzRzQ==" + "version": "1.44.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.44.0.tgz", + "integrity": "sha512-/NOTfLrsPBVeH7YtFPgsVWveuL+4SjjYxaQ1xtM1KMFj7HdxlBlxeyNLzhyJVx7r4rZGJAZ/6lkKCitSc/Nmpg==" }, "mime-types": { - "version": "2.1.26", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.26.tgz", - "integrity": "sha512-01paPWYgLrkqAyrlDorC1uDwl2p3qZT7yl806vW7DvDoxwXi46jsjFbg+WdwotBIk6/MbEhO/dh5aZ5sNj/dWQ==", + "version": "2.1.27", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.27.tgz", + "integrity": "sha512-JIhqnCasI9yD+SsmkquHBxTSEuZdQX5BuQnS2Vc7puQQQ+8yiP5AY5uWhpdv4YL4VM5c6iliiYWPgJ/nJQLp7w==", "requires": { - "mime-db": "1.43.0" + "mime-db": "1.44.0" } }, "mimic-response": { @@ -400,22 +404,14 @@ } }, "minimist": { - "version": "0.0.8", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", - "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=" - }, - "mkdirp": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", - "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", - "requires": { - "minimist": "0.0.8" - } + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", + "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==" }, "ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" }, "normalize-url": { "version": "4.5.0", @@ -461,11 +457,6 @@ "resolved": "https://registry.npmjs.org/prepend-http/-/prepend-http-2.0.0.tgz", "integrity": "sha1-6SQ0v6XqjBn0HN/UAddBo8gZ2Jc=" }, - "process-nextick-args": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", - "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==" - }, "pump": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz", @@ -476,9 +467,9 @@ } }, "qs": { - "version": "6.9.1", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.9.1.tgz", - "integrity": "sha512-Cxm7/SS/y/Z3MHWSxXb8lIFqgqBowP5JMlTUFyJN88y0SGQhVmZnqFK/PeuMX9LzUyWsqqhNxIyg0jlzq946yA==" + "version": "6.9.4", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.9.4.tgz", + "integrity": "sha512-A1kFqHekCTM7cz0udomYUoYNWjBebHm/5wzU/XqrBRBNWectVH0QIiN+NEcZ0Dte5hvzHwbr8+XQmguPhJ6WdQ==" }, "rc": { "version": "1.2.8", @@ -489,27 +480,16 @@ "ini": "~1.3.0", "minimist": "^1.2.0", "strip-json-comments": "~2.0.1" - }, - "dependencies": { - "minimist": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", - "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=" - } } }, "readable-stream": { - "version": "2.3.7", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", - "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", + "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", "requires": { - "core-util-is": "~1.0.0", - "inherits": "~2.0.3", - "isarray": "~1.0.0", - "process-nextick-args": "~2.0.0", - "safe-buffer": "~5.1.1", - "string_decoder": "~1.1.1", - "util-deprecate": "~1.0.1" + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" } }, "registry-auth-token": { @@ -538,9 +518,9 @@ } }, "rimraf": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.0.tgz", - "integrity": "sha512-NDGVxTsjqfunkds7CqsOiEnxln4Bo7Nddl3XhS4pXg5OzwkLqJ971ZVAAnB+DDLnF76N+VnDEiBHaVV8I06SUg==", + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", + "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", "requires": { "glob": "^7.1.3" } @@ -556,11 +536,18 @@ "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==" }, "string_decoder": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", - "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", + "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", "requires": { - "safe-buffer": "~5.1.0" + "safe-buffer": "~5.2.0" + }, + "dependencies": { + "safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==" + } } }, "strip-json-comments": { @@ -569,9 +556,9 @@ "integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=" }, "superagent": { - "version": "5.2.1", - "resolved": "https://registry.npmjs.org/superagent/-/superagent-5.2.1.tgz", - "integrity": "sha512-46b4Lkwnlz7Ebdv2FBbfuqb3kVkG1jV/SK3EW6NnwL9a3T4h5hHtegNEQfbXvTFbDoUZXId4W3dMgap2f6ic1g==", + "version": "5.2.2", + "resolved": "https://registry.npmjs.org/superagent/-/superagent-5.2.2.tgz", + "integrity": "sha512-pMWBUnIllK4ZTw7p/UaobiQPwAO5w/1NRRTDpV0FTVNmECztsxKspj3ZWEordVEaqpZtmOQJJna4yTLyC/q7PQ==", "requires": { "component-emitter": "^1.3.0", "cookiejar": "^2.1.2", @@ -584,31 +571,6 @@ "qs": "^6.9.1", "readable-stream": "^3.4.0", "semver": "^6.3.0" - }, - "dependencies": { - "debug": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", - "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", - "requires": { - "ms": "^2.1.1" - } - }, - "ms": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" - }, - "readable-stream": { - "version": "3.4.0", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.4.0.tgz", - "integrity": "sha512-jItXPLmrSR8jmTRmRWJXCnGJsfy85mB3Wd/uINMXA65yrnFo0cPClFIUWzo2najVNSl+mx7/4W8ttlLWJe99pQ==", - "requires": { - "inherits": "^2.0.3", - "string_decoder": "^1.1.1", - "util-deprecate": "^1.0.1" - } - } } }, "superagent-binary-parser": { @@ -629,11 +591,6 @@ "resolved": "https://registry.npmjs.org/to-readable-stream/-/to-readable-stream-1.0.0.tgz", "integrity": "sha512-Iq25XBt6zD5npPhlLVXGFN3/gyR2/qODcKNNyTMd4vbm39HUaOiAM4PMq0eMVC/Tkxz+Zjdsc55g9yyz+Yq00Q==" }, - "typedarray": { - "version": "0.0.6", - "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", - "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=" - }, "url-parse-lax": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/url-parse-lax/-/url-parse-lax-3.0.0.tgz", @@ -653,11 +610,12 @@ "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" }, "yauzl": { - "version": "2.4.1", - "resolved": "https://registry.npmjs.org/yauzl/-/yauzl-2.4.1.tgz", - "integrity": "sha1-lSj0QtqxsihOWLQ3m7GU4i4MQAU=", + "version": "2.10.0", + "resolved": "https://registry.npmjs.org/yauzl/-/yauzl-2.10.0.tgz", + "integrity": "sha1-x+sXyT4RLLEIb6bY5R+wZnt5pfk=", "requires": { - "fd-slicer": "~1.0.1" + "buffer-crc32": "~0.2.3", + "fd-slicer": "~1.1.0" } } } diff --git a/package.json b/package.json index d54e1e0..170e434 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fvm-installer", - "version": "1.1.6", + "version": "1.1.7", "description": "Resource Installer for FiveM", "main": "./fvm", "repository": { @@ -28,14 +28,14 @@ "node": ">=0.12" }, "dependencies": { - "adm-zip": "^0.4.13", - "chalk": "^3.0.0", + "adm-zip": "^0.4.14", + "chalk": "^4.0.0", "co": "^4.6.0", "co-prompt": "^1.0.0", - "extract-zip": "^1.6.7", + "extract-zip": "^2.0.0", "latest-version": "^5.1.0", - "rimraf": "^3.0.0", - "superagent": "^5.2.1", + "rimraf": "^3.0.2", + "superagent": "^5.2.2", "superagent-binary-parser": "^1.0.1" } } diff --git a/tools.js b/tools.js index 7be04e9..6ee7da9 100644 --- a/tools.js +++ b/tools.js @@ -1,136 +1,113 @@ -var binaryParser = require('superagent-binary-parser'); -var request = require('superagent'); -var chalk = require('chalk'); -var fs = require('fs'); -var extract = require('extract-zip'); -var rimraf = require('rimraf'); -var path = require('path'); +const binaryParser = require('superagent-binary-parser'); +const request = require('superagent'); +const chalk = require('chalk'); +const fs = require('fs'); +const extract = require('extract-zip'); +const rimraf = require('rimraf'); +const path = require('path'); module.exports = { - download_resource: function(resource, dataConfigFile, save, specifiedfolder) { - var arraytosplit = resource.split("/"); - var resource_user = arraytosplit[0]; - var resource_name = arraytosplit[1].split("@")[0] || arraytosplit[1]; + download_resource: (resource, dataConfigFile, save, specifiedfolder) => { + const arraytosplit = resource.split("/"); + const resource_user = arraytosplit[0]; + const resource_name = arraytosplit[1].split("@")[0] || arraytosplit[1]; + const versionarray = arraytosplit[1].split("@"); + var resource_version; - var versionarray = arraytosplit[1].split("@"); - - if(versionarray.length > 0){ - resource_version = versionarray[1] || ""; - } - - return new Promise(function(resolve, reject) { - request.get('https://api.github.com/repos/' + resource_user + "/" + resource_name + "/tags").set('Accept', 'application/json').set('User-Agent', 'fvm-installer').end(function(err, res) { - if (err) { - console.log(chalk.red("Error: Resource "+ resource_user + "/" + resource_name + " Not Found or not possible to download !")); - console.log("\n"); - reject("Error: Resource "+ resource_user + "/" + resource_name + " Not Found or not possible to download !"); - return; - } else { + + if (versionarray.length > 0) resource_version = versionarray[1] || ""; + + return new Promise(async (resolve, reject) => { + await request.get('https://api.github.com/repos/' + resource_user + "/" + resource_name + "/tags").set('Accept', 'application/json').set('User-Agent', 'fvm-installer') + .then(async res => { var data; - if(resource_version == ""){ + if(resource_version == "") { data = res.body[0]; resource_version = data.name; - }else{ - data = res.body.find(function(element){ - if(element.name == resource_version){ - return true; - }else{ - return false; - } + } else { + data = res.body.find((element) => { + return (element.name == resource_version) ? true : false }); - - if (!(data)){ + + if (!(data)) { console.log(chalk.red("Error: Version for "+ resource_user + "/" + resource_name + " not found !")); console.log("\n"); reject("Error: Resource "+ resource_user + "/" + resource_name + " Not Found for this version !"); return; - } + } } - - - console.log(chalk.green("Installing " + resource_name + " - " + resource_version)); - var zip_url = data.zipball_url; + console.log(chalk.green('Installing ' + resource_name + ' - ' + resource_version)); + const zip_url = data.zipball_url; console.log(zip_url); - request.get(zip_url).set('User-Agent', 'fvm-installer').parse(binaryParser).buffer().end(function(err, resp) { - if(err){ - console.log(chalk.red("Please Try Again in 60 Minutes - Exceed Github Rate Limite or Github Down")); - process.exit(0); - } - if(!res.body){ - console.log(chalk.red("Please Try Again - Network Bug")); - process.exit(0); - } - fs.writeFileSync("resourcedownloadedfvm.zip", resp.body); - var zipfolder = ""; - - extract("resourcedownloadedfvm.zip", { - dir: path.join(process.cwd(), "resources"), - onEntry: function(fileunzipped, zip) { - if (zipfolder == "") { - zipfolder = fileunzipped.fileName; - } + await request + .get(zip_url) + .set('User-Agent', 'fvm-installer') + .parse(binaryParser) + .buffer() + .then(async resp => { + if (!resp.body) { + console.log(chalk.red('Please Try Again - Network Bug')); + process.exit(0); } - }, function(err) { - fs.unlinkSync(path.join(process.cwd(), "resourcedownloadedfvm.zip")); - //Remove and put resource in folder - var pathtoinstall = path.join(process.cwd(), "resources", resource_name); - - if(specifiedfolder != ""){ - pathtoinstall = path.join(process.cwd(), "resources", "[" + specifiedfolder + "]", resource_name, "/"); - if (!fs.existsSync(path.join(process.cwd(), "resources", "[" + specifiedfolder + "]"))){ - fs.mkdirSync(path.join(process.cwd(), "resources", "[" + specifiedfolder + "]")); - } - } - rimraf(pathtoinstall, function() { - - fs.rename(path.join(process.cwd(), "resources", zipfolder), pathtoinstall, function(err) { - console.log("\n"); - if(save){ - dataConfigFile.addResource(resource_user+"/"+resource_name, resource_version, specifiedfolder); + fs.writeFileSync('resourcedownloadedfvm.zip', resp.body); + var zipfolder = ''; + try { + await extract('resourcedownloadedfvm.zip', { + dir: path.join(process.cwd(), 'resources'), + onEntry: (fileunzipped, zip) => { if (zipfolder == '') zipfolder = fileunzipped.fileName; }, + }) + fs.unlinkSync(path.join(process.cwd(), 'resourcedownloadedfvm.zip')); + //Remove and put resource in folder + var pathtoinstall = path.join(process.cwd(), 'resources', resource_name); + + if (specifiedfolder != '') { + pathtoinstall = path.join(process.cwd(), 'resources', '[' + specifiedfolder + ']', resource_name, '/'); + if (!fs.existsSync(path.join(process.cwd(), 'resources', '[' + specifiedfolder + ']'))) fs.mkdirSync(path.join(process.cwd(), 'resources', '[' + specifiedfolder + ']')); } - resolve("Install Successful of "+resource_user+"/"+resource_name); - }); - }); - }); - - }); - } + rimraf(pathtoinstall, _ => { + fs.rename(path.join(process.cwd(), 'resources', zipfolder), pathtoinstall, (err) => { + console.log('\n'); + if (save) dataConfigFile.addResource(resource_user + '/' + resource_name, resource_version, specifiedfolder); + resolve('Install Successful of ' + resource_user + '/' + resource_name); + }); + }); + } catch (err) { console.log (err) } + }) + .catch(err => { + console.log(chalk.red('Please Try Again in 60 Minutes - Exceed Github Rate Limite or Github Down')); + process.exit(0); + }) + }); + }) + .catch(err => { + console.log(chalk.red("Error: Resource "+ resource_user + "/" + resource_name + " Not Found or not possible to download !")); + console.log("\n"); + reject("Error: Resource "+ resource_user + "/" + resource_name + " Not Found or not possible to download !"); + return; }); - }); }, - update_resource: function(resource, previous_version, dataConfigFile, save) { - var arraytosplit = resource.split("/"); - var resource_user = arraytosplit[0]; - var resource_name = arraytosplit[1].split("@")[0] || arraytosplit[1]; + update_resource: (resource, previous_version, dataConfigFile, save) => { + const arraytosplit = resource.split("/"); + const resource_user = arraytosplit[0]; + const resource_name = arraytosplit[1].split("@")[0] || arraytosplit[1]; var resource_version; - var versionarray = arraytosplit[1].split("@"); - - if(versionarray.length > 0){ - resource_version = versionarray[1] || ""; - } - - return new Promise(function(resolve, reject) { - request.get('https://api.github.com/repos/' + resource_user + "/" + resource_name + "/tags").set('Accept', 'application/json').end(function(err, res) { - if (err) { - console.log(chalk.red("Error: Resource "+ resource_user + "/" + resource_name + " Not Found or not possible to update !")); - console.log("\n"); - reject("Error: Resource "+ resource_user + "/" + resource_name + " Not Found or not possible to update !"); - return; - } else { + const versionarray = arraytosplit[1].split("@"); + + if(versionarray.length > 0) resource_version = versionarray[1] || ""; + + return new Promise(async (resolve, reject) => { + await request.get('https://api.github.com/repos/' + resource_user + "/" + resource_name + "/tags").set('Accept', 'application/json') + .then(async res => { var data; - if(resource_version == ""){ + if(resource_version == "") { data = res.body[0]; resource_version = data.name; - }else{ - data = res.body.find(function(element){ - if(element.name == resource_version){ - return true; - }else{ - return false; - } + } else { + data = res.body.find((element) => { + return (element.name == resource_version) ? true : false; }); if (!(data)){ @@ -140,111 +117,99 @@ module.exports = { return; } } - - console.log(chalk.green("Updating " + resource_name + " - " + chalk.red(previous_version) + " -> " + resource_version)); var zip_url = data.zipball_url; console.log(zip_url); - request.get(zip_url).parse(binaryParser).buffer().end(function(err, resp) { - if(err){ - console.log(chalk.red("Please Try Again in 60 Minutes - Exceed Github Rate Limite or Github Down ")); - process.exit(0); - } + await request.get(zip_url).parse(binaryParser).buffer() + .then(async res => { if(!res.body){ console.log(chalk.red("Please Try Again - Network Bug")); process.exit(0); } - fs.writeFileSync("resourcedownloadedfvm.zip", resp.body); + fs.writeFileSync("resourcedownloadedfvm.zip", res.body); var zipfolder = ""; - - extract("resourcedownloadedfvm.zip", { - dir: path.join(process.cwd(), "resources"), - onEntry: function(fileunzipped, zip) { - if (zipfolder == "") { - zipfolder = fileunzipped.fileName; - } - } - }, function(err) { + try { + await extract('resourcedownloadedfvm.zip', { + dir: path.join(process.cwd(), 'resources'), onEntry: (fileunzipped, zip) => { + if (zipfolder == '') zipfolder = fileunzipped.fileName; + }, + }); // fs.unlinkSync(path.join(process.cwd(), "resourcedownloadedfvm.zip")); //Remove and put resource in folder - var pathtoupdate = path.join(process.cwd(), "resources", resource_name); - - if(dataConfigFile.folder[resource_user+"/"+resource_name]){ - pathtoupdate = path.join(process.cwd(), "resources", "[" + dataConfigFile.folder[resource_user+"/"+resource_name] + "]", resource_name); - - if (!fs.existsSync(path.join(process.cwd(), "resources", "[" + dataConfigFile.folder[resource_user+"/"+resource_name] + "]"))){ - fs.mkdirSync(path.join(process.cwd(), "resources", "[" + dataConfigFile.folder[resource_user+"/"+resource_name] + "]")); - } + var pathtoupdate = path.join(process.cwd(), 'resources', resource_name); + if (dataConfigFile.folder[resource_user + '/' + resource_name]) { + pathtoupdate = path.join(process.cwd(), 'resources', '[' + dataConfigFile.folder[resource_user + '/' + resource_name] + ']', resource_name); + if (!fs.existsSync(path.join(process.cwd(), 'resources', '[' + dataConfigFile.folder[resource_user + '/' + resource_name] + ']'))) fs.mkdirSync(path.join(process.cwd(), 'resources', '[' + dataConfigFile.folder[resource_user + '/' + resource_name] + ']')); } - rimraf(pathtoupdate, function() { - - fs.rename(path.join(process.cwd(), "resources", zipfolder), pathtoupdate, function(err) { - console.log("\n"); - if(save){ - if(dataConfigFile.folder[resource_user+"/"+resource_name]){ - dataConfigFile.addResource(resource_user+"/"+resource_name, resource_version, dataConfigFile.folder[resource_user+"/"+resource_name]); - }else{ - dataConfigFile.addResource(resource_user+"/"+resource_name, resource_version, ""); - } + rimraf(pathtoupdate, _ => { + fs.rename(path.join(process.cwd(), 'resources', zipfolder), pathtoupdate, (err) => { + console.log('\n'); + if (save) { + (dataConfigFile.folder[resource_user + '/' + resource_name]) + ? dataConfigFile.addResource(resource_user + '/' + resource_name, resource_version, dataConfigFile.folder[resource_user + '/' + resource_name]) + : dataConfigFile.addResource(resource_user + '/' + resource_name, resource_version, ''); } - resolve("Update Successful of "+resource_user+"/"+resource_name); + resolve('Update Successful of ' + resource_user + '/' + resource_name); }); }); - }); - - }); - } + } catch (err) { console.log (err) } + }) + .catch(err => { + console.log(chalk.red("Please Try Again in 60 Minutes - Exceed Github Rate Limite or Github Down ")); + process.exit(0); + }) + }) + .catch(err => { + console.log(chalk.red("Error: Resource "+ resource_user + "/" + resource_name + " Not Found or not possible to update !")); + console.log("\n"); + reject("Error: Resource "+ resource_user + "/" + resource_name + " Not Found or not possible to update !"); + return; }); }); }, - deleteresource: function(resource, save, dataConfigFile){ - return new Promise(function(resolve, reject) { - var arraytosplit = resource.split("/"); - var resource_user = arraytosplit[0]; - var resource_name = arraytosplit[1].split("@")[0] || arraytosplit[1]; + deleteresource: (resource, save, dataConfigFile) => { + return new Promise((resolve, reject) => { + const arraytosplit = resource.split("/"); + const resource_user = arraytosplit[0]; + const resource_name = arraytosplit[1].split("@")[0] || arraytosplit[1]; var pathtodelete = path.join(process.cwd(), "resources", resource_name); - if(dataConfigFile.folder[resource]){ - pathtodelete = path.join(process.cwd(), "resources", "[" + dataConfigFile.folder[resource] + "]", resource_name) - } + if(dataConfigFile.folder[resource]) pathtodelete = path.join(process.cwd(), "resources", "[" + dataConfigFile.folder[resource] + "]", resource_name); + + rimraf(pathtodelete, _ => { + if (save) dataConfigFile.removeResource(resource); - rimraf(pathtodelete, function() { - if (save){ - dataConfigFile.removeResource(resource); - } console.log("Delete Successful of "+resource_user+"/"+resource_name); resolve("Delete Successful of "+resource_user+"/"+resource_name); }); }); }, - check_update_resource: function(resource, resource_version){ - var arraytosplit = resource.split("/"); - var resource_user = arraytosplit[0]; - var resource_name = arraytosplit[1].split("@")[0] || arraytosplit[1]; - - return new Promise(function(resolve, reject) { - request.get('https://api.github.com/repos/' + resource_user + "/" + resource_name + "/tags").set('Accept', 'application/json').end(function(err, res) { - if (err) { - console.log(chalk.red("Error: Resource "+ resource_user + "/" + resource_name + " Not Found or not possible to update !")); - console.log("\n"); - reject("Error: Resource "+ resource_user + "/" + resource_name + " Not Found or not possible to update !"); - return; - } else { - var version = res.body[0].name; - - if(resource_version != version){ - console.log(resource + "\t"+ "Installed: " + resource_version+"\t" +chalk.green(" New Version:"+version)+"\n"); - }else{ - console.log(resource + "\t"+ "Installed: " + resource_version+"\n"); - } - resolve(); - } + check_update_resource: (resource, resource_version) => { + const arraytosplit = resource.split("/"); + const resource_user = arraytosplit[0]; + const resource_name = arraytosplit[1].split("@")[0] || arraytosplit[1]; + + return new Promise(async (resolve, reject) => { + await request.get('https://api.github.com/repos/' + resource_user + "/" + resource_name + "/tags").set('Accept', 'application/json') + .then(res => { + const version = res.body[0].name; + + (resource_version != version) + ? console.log(resource + "\t"+ "Installed: " + resource_version+"\t" +chalk.green(" New Version:"+version)+"\n") + : console.log(resource + "\t"+ "Installed: " + resource_version+"\n"); + resolve(); + }) + .catch(err => { + console.log(chalk.red("Error: Resource "+ resource_user + "/" + resource_name + " Not Found or not possible to update !")); + console.log("\n"); + reject("Error: Resource "+ resource_user + "/" + resource_name + " Not Found or not possible to update !"); + return; }); }); }, - check_resource_format: function (resource_name){ + check_resource_format: (resource_name) => { return /(^([^/]+)\/([^/]+)@\S+$)|(^([^/]+)\/([^/]+)$)/g.test(resource_name); } -}; +}; \ No newline at end of file