venmjs
Version:
This is a tool 🔧 that can be installed in your terminal at any time ⛏️ it was made for beginners and even for experts, for his utilities, and for a simple creation process 🧨. Every web developer knows how frustrating is to deal with the creation of a ne
519 lines (409 loc) • 15.5 kB
JavaScript
/* eslint-disable no-unused-vars */
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.validateInstallation = exports.validateInputpass = exports.validateInputuser = exports.validateInputdb = exports.validateInputhost = exports.validateInputname = exports.validateInput = void 0;
var _chalk = _interopRequireDefault(require("chalk"));
var _execa = _interopRequireDefault(require("execa"));
var _inquirer = _interopRequireDefault(require("inquirer"));
var _exec = _interopRequireDefault(require("./exec"));
var _ora = _interopRequireDefault(require("ora"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
var isWin = process.platform === 'win32';
var isLinux = process.platform === 'linux';
var isMac = process.platform === 'darwin';
var Spinner = /*#__PURE__*/function () {
function Spinner(text) {
_classCallCheck(this, Spinner);
this.text = text;
}
_createClass(Spinner, [{
key: "start",
value: function start() {
this.spinner = (0, _ora["default"])(this.text).start();
}
}, {
key: "info",
value: function info(text) {
this.spinner.info(text);
}
}, {
key: "succeed",
value: function succeed(text) {
this.spinner.succeed(text);
}
}, {
key: "fail",
value: function fail(text) {
this.spinner.fail(text);
}
}, {
key: "stop",
value: function stop() {
this.spinner.stop();
}
}]);
return Spinner;
}();
var spinner = new Spinner();
/**
* Shows installation information
* @param {String} depCandidate - The repective package to be installed
* @param {String} url - Official downloads page url
* @returns {Void}
* -------------------------------------------------------------------------
* Helper method to validate installation
* @param {String} dependency
* @returns {Promise<boolean>}
* -------------------------------------------------------------------------
* Install Git for supported platforms, else show installation instructions
* @returns {Promise<void>}
* -------------------------------------------------------------------------
* Install Docker for Linux platform, else show installation instructions
* @returns {Promise<void>}
* -------------------------------------------------------------------------
* Validates user input for input prompts
* @param {String} userInput
* @returns {Boolean}
* -------------------------------------------------------------------------
* Checks if a necessary dependency is installed
* @param {String} dependency
* @returns {Promise<Void>}
*/
//#region region VALIDATE INPUT
var validateInput = function validateInput(userInput) {
if (!userInput) {
return "Can't be empty!";
}
return true;
};
exports.validateInput = validateInput;
var validateInputname = function validateInputname(userInput) {
if (!userInput) {
return "Can't be empty!";
}
return true;
};
exports.validateInputname = validateInputname;
var validateInputhost = function validateInputhost(userInput) {
if (!userInput) {
return "Can't be empty!";
}
return true;
};
exports.validateInputhost = validateInputhost;
var validateInputdb = function validateInputdb(userInput) {
if (!userInput) {
return "Can't be empty!";
}
return true;
};
exports.validateInputdb = validateInputdb;
var validateInputuser = function validateInputuser(userInput) {
if (!userInput) {
return "Can't be empty!";
}
return true;
};
exports.validateInputuser = validateInputuser;
var validateInputpass = function validateInputpass(userInput) {
if (!userInput) {
return "Can't be empty!";
}
return true;
}; //#endregion
exports.validateInputpass = validateInputpass;
var showInstallationInfo = function showInstallationInfo(depCandidate, url) {
var msg = " You need to download ".concat(depCandidate, " from the official downloads page: ").concat(url);
console.log(_chalk["default"].cyan.bold(msg));
process.exit(0);
};
var checkInstallationStatus = /*#__PURE__*/function () {
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(dependency) {
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.prev = 0;
_context.next = 3;
return _execa["default"].command(dependency);
case 3:
return _context.abrupt("return", true);
case 6:
_context.prev = 6;
_context.t0 = _context["catch"](0);
return _context.abrupt("return", false);
case 9:
case "end":
return _context.stop();
}
}
}, _callee, null, [[0, 6]]);
}));
return function checkInstallationStatus(_x) {
return _ref.apply(this, arguments);
};
}(); //#region INSTALL PACKAGES
var installGit = function installGit() {
var url = 'https://git-scm.com/download/win';
if (isWin) {
return showInstallationInfo('git', url);
} else if (isLinux) {
return (0, _exec["default"])("apt install -g git");
} else if (isMac) {
return (0, _exec["default"])("brew install git");
}
};
var installDocker = function installDocker() {
var urlMap = {
win32: 'https://hub.docker.com/editions/community/docker-ce-desktop-windows',
darwin: 'https://docs.docker.com/docker-for-mac/install/'
};
if (!isLinux) {
return showInstallationInfo('docker', urlMap[process.platform]);
}
return (0, _exec["default"])('apt install docker.io');
};
var installYarn = function installYarn() {
if (isMac || isLinux) {
return (0, _exec["default"])("sudo npm install --global yarn --unsafe-perm");
} else if (isWin) {
return (0, _exec["default"])("npm install --global yarn");
}
};
var installwt = function installwt() {
var urlMap = {
win32: 'https://www.microsoft.com/store/productId/9N0DX20HK701'
};
if (isWin) {
return showInstallationInfo('wt', urlMap[process.platform]);
}
};
var installfirebase = function installfirebase() {
if (isMac || isLinux) {
return (0, _exec["default"])("sudo npm i -g firebase-tools --unsafe-perm");
} else if (isWin) {
return (0, _exec["default"])("npm i -g firebase-tools");
}
};
var installnetlify = function installnetlify() {
if (isMac || isLinux) {
return (0, _exec["default"])("sudo npm i netlify-cli -g --unsafe-perm");
} else if (isWin) {
return (0, _exec["default"])("npm i netlify-cli -g");
}
};
var installgridsome = function installgridsome() {
if (isMac || isLinux) {
return (0, _exec["default"])("sudo npm i --global @gridsome/cli --unsafe-perm");
} else if (isWin) {
return (0, _exec["default"])("npm i --global @gridsome/cli");
}
};
var installnuxt = function installnuxt() {
if (isMac || isLinux) {
return (0, _exec["default"])("sudo npm i -g @nuxt/cli --unsafe-perm");
} else if (isWin) {
return (0, _exec["default"])("npm i -g @nuxt/cli");
}
};
var installquasar = function installquasar() {
if (isMac || isLinux) {
return (0, _exec["default"])("sudo npm i -g @quasar/cli --unsafe-perm");
} else if (isWin) {
return (0, _exec["default"])("npm i -g @quasar/cli");
}
};
var installvue = function installvue() {
if (isMac || isLinux) {
return (0, _exec["default"])("sudo npm i -g @vue/cli --unsafe-perm");
} else if (isWin) {
return (0, _exec["default"])("npm i -g @vue/cli");
}
};
var installelectron = function installelectron() {
if (isMac || isLinux) {
return (0, _exec["default"])("sudo npm i -g electron@latest --unsafe-perm");
} else if (isWin) {
return (0, _exec["default"])("npm i -g electron@latest");
}
};
var installexpocli = function installexpocli() {
if (isMac || isLinux) {
return (0, _exec["default"])("sudo npm i --global expo-cli --unsafe-perm");
} else if (isWin) {
return (0, _exec["default"])("npm i --global expo-cli");
}
};
var installvuenative = function installvuenative() {
if (isMac || isLinux) {
return (0, _exec["default"])("sudo npm i --global vue-native-cli --unsafe-perm");
} else if (isWin) {
return (0, _exec["default"])("npm i --global vue-native-cli");
}
};
var installionic = function installionic() {
if (isMac || isLinux) {
return (0, _exec["default"])("sudo npm i -g electron@latest --unsafe-perm");
} else if (isWin) {
return (0, _exec["default"])("npm i -g electron@latest");
}
};
var installcomposer = function installcomposer() {
var urlMap = 'https://www.microsoft.com/store/productId/9N0DX20HK701';
return showInstallationInfo('composer', urlMap[process.platform]);
};
var installxampp = function installxampp() {
var urlMap = 'https://www.apachefriends.org/download.html';
return showInstallationInfo('xampp', urlMap[process.platform]);
}; //#endregion
var validateInstallation = /*#__PURE__*/function () {
var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(dependency) {
var isDepInstalled, sep, _yield$inquirer$promp, shouldInstallDep;
return regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
_context2.next = 2;
return checkInstallationStatus(dependency);
case 2:
isDepInstalled = _context2.sent;
if (dependency.includes(' ')) {
sep = dependency.includes('-') ? '-' : '';
dependency = dependency.split(sep)[0];
}
if (isDepInstalled) {
_context2.next = 46;
break;
}
_context2.next = 7;
return _inquirer["default"].prompt([{
type: 'confirm',
name: 'shouldInstallDep',
message: "Sorry, ".concat(dependency, " is not installed on your system, Do you want to install it?")
}]);
case 7:
_yield$inquirer$promp = _context2.sent;
shouldInstallDep = _yield$inquirer$promp.shouldInstallDep;
if (!shouldInstallDep) {
console.warn(_chalk["default"].yellow.bold(" Warning:- ".concat(_chalk["default"].cyan.bold("".concat(dependency, " is required to be installed")))));
process.exit(1);
}
spinner.text = "The installation of ".concat(dependency, " is starting");
spinner.start();
if (!(dependency === 'yarn -v')) {
_context2.next = 14;
break;
}
return _context2.abrupt("return", installYarn());
case 14:
if (!(dependency === 'git help -g')) {
_context2.next = 16;
break;
}
return _context2.abrupt("return", installGit());
case 16:
if (!(dependency === 'docker')) {
_context2.next = 18;
break;
}
return _context2.abrupt("return", installDocker());
case 18:
if (!(dependency === 'wt')) {
_context2.next = 20;
break;
}
return _context2.abrupt("return", installwt());
case 20:
if (!(dependency === 'nuxt -v')) {
_context2.next = 22;
break;
}
return _context2.abrupt("return", installnuxt());
case 22:
if (!(dependency === 'firebase')) {
_context2.next = 24;
break;
}
return _context2.abrupt("return", installfirebase());
case 24:
if (!(dependency === 'netlify')) {
_context2.next = 26;
break;
}
return _context2.abrupt("return", installnetlify());
case 26:
if (!(dependency === 'gridsome -v')) {
_context2.next = 28;
break;
}
return _context2.abrupt("return", installgridsome());
case 28:
if (!(dependency === 'quasar -v')) {
_context2.next = 30;
break;
}
return _context2.abrupt("return", installquasar());
case 30:
if (!(dependency === 'vue -V')) {
_context2.next = 32;
break;
}
return _context2.abrupt("return", installvue());
case 32:
if (!(dependency === 'electron -v')) {
_context2.next = 34;
break;
}
return _context2.abrupt("return", installelectron());
case 34:
if (!(dependency === 'vue-native -v')) {
_context2.next = 36;
break;
}
return _context2.abrupt("return", installvuenative());
case 36:
if (!(dependency === 'expo-cli -V')) {
_context2.next = 38;
break;
}
return _context2.abrupt("return", installexpocli());
case 38:
if (!(dependency === 'ionic -v')) {
_context2.next = 40;
break;
}
return _context2.abrupt("return", installionic());
case 40:
if (!(dependency === 'composer -V')) {
_context2.next = 42;
break;
}
return _context2.abrupt("return", installcomposer());
case 42:
if (!(dependency === 'php -v')) {
_context2.next = 44;
break;
}
return _context2.abrupt("return", installxampp());
case 44:
_context2.next = 46;
return (0, _exec["default"])("npm install -g ".concat(dependency));
case 46:
case "end":
return _context2.stop();
}
}
}, _callee2);
}));
return function validateInstallation(_x2) {
return _ref2.apply(this, arguments);
};
}();
exports.validateInstallation = validateInstallation;