UNPKG

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

600 lines (486 loc) โ€ข 27.6 kB
/* eslint-disable prettier/prettier */ /* eslint-disable no-undef */ /* eslint-disable no-useless-escape */ 'use strict'; function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } Object.defineProperty(exports, "__esModule", { value: true }); exports.mysql = mysql; var _fsExtra = _interopRequireDefault(require("fs-extra")); var _path = _interopRequireDefault(require("path")); var _inquirer = _interopRequireDefault(require("inquirer")); var _exec = _interopRequireDefault(require("../../../utils/exec")); var logger = _interopRequireWildcard(require("../../../utils/logger")); var _validate = require("../../../utils/validate"); function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; } 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); }); }; } var shell = require('shelljs'); function mysql() { return _mysql.apply(this, arguments); } function _mysql() { _mysql = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() { var _yield$inquirer$promp, template_backend, _yield$inquirer$promp2, templateServer, currPath, newPath, _yield$inquirer$promp3, host, _yield$inquirer$promp4, user, _yield$inquirer$promp5, pass, _yield$inquirer$promp6, db, _yield$inquirer$promp7, port, _yield$inquirer$promp8, APP_NAME, _yield$inquirer$promp9, PUSHER_APP_KEY, _yield$inquirer$promp10, PUSHER_APP_CLUSTER, _currPath, _newPath, _yield$inquirer$promp11, _host, _yield$inquirer$promp12, _user, _yield$inquirer$promp13, _pass, _yield$inquirer$promp14, _db, _yield$inquirer$promp15, _port, _yield$inquirer$promp16, _APP_NAME, _yield$inquirer$promp17, _PUSHER_APP_KEY, _yield$inquirer$promp18, _PUSHER_APP_CLUSTER, _yield$inquirer$promp19, _templateServer, _currPath2, _newPath2, _yield$inquirer$promp20, _host2, _yield$inquirer$promp21, _user2, _yield$inquirer$promp22, _pass2, _yield$inquirer$promp23, _db2, _currPath3, _newPath3, _yield$inquirer$promp24, _host3, _yield$inquirer$promp25, _user3, _yield$inquirer$promp26, _pass3, _yield$inquirer$promp27, _db3; return regeneratorRuntime.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: _context.next = 2; return (0, _validate.validateInstallation)('composer -V'); case 2: _context.next = 4; return (0, _validate.validateInstallation)('php -v'); case 4: _context.next = 6; return _inquirer["default"].prompt([{ name: 'template_backend', type: 'list', message: 'Please choose a BACKEND framework โœจ', choices: ['express', 'laravel'] }]); case 6: _yield$inquirer$promp = _context.sent; template_backend = _yield$inquirer$promp.template_backend; if (!(template_backend === 'laravel')) { _context.next = 134; break; } _context.next = 11; return _inquirer["default"].prompt([{ name: 'templateServer', type: 'list', message: 'Please choose a starter template for the CRUD API๐Ÿ’พ', choices: ['Rest API', 'GraphQL'] }]); case 11: _yield$inquirer$promp2 = _context.sent; templateServer = _yield$inquirer$promp2.templateServer; if (!(templateServer === 'Rest API')) { _context.next = 73; break; } logger.info('Creating the Rest API ๐Ÿ“ƒ'); _fsExtra["default"].copySync(_path["default"].resolve(__dirname, '../../../templates/server/laravel-mysql/RestAPI'), './RestAPI'); currPath = './RestAPI'; newPath = './server'; _fsExtra["default"].rename(currPath, newPath); _fsExtra["default"].copySync(_path["default"].resolve(__dirname, '../../../templates/config/venm.config.js'), './venm.config.js'); _context.next = 22; return _inquirer["default"].prompt([{ type: 'input', name: 'uri', message: 'Enter the HOST of the Mysql DB ๐Ÿ‘‰', "default": '127.0.0.1', validate: _validate.validateInputhost }]); case 22: _yield$inquirer$promp3 = _context.sent; host = _yield$inquirer$promp3.host; _context.next = 26; return _inquirer["default"].prompt([{ type: 'input', name: 'uri', message: 'Enter the USER of the Mysql DB ๐Ÿ‘‰', "default": 'root', validate: _validate.validateInputuser }]); case 26: _yield$inquirer$promp4 = _context.sent; user = _yield$inquirer$promp4.user; _context.next = 30; return _inquirer["default"].prompt([{ type: 'input', name: 'uri', message: 'Enter the PASSWORD of the Mysql DB ๐Ÿ‘‰', "default": 'root', validate: _validate.validateInputpass }]); case 30: _yield$inquirer$promp5 = _context.sent; pass = _yield$inquirer$promp5.pass; _context.next = 34; return _inquirer["default"].prompt([{ type: 'input', name: 'name', message: 'Enter the NAME of the new Database ๐Ÿ‘‰', "default": 'example', validate: _validate.validateInputdb }]); case 34: _yield$inquirer$promp6 = _context.sent; db = _yield$inquirer$promp6.db; _context.next = 38; return _inquirer["default"].prompt([{ type: 'input', name: 'port', message: 'Enter the PORT of the Mysql DB ๐Ÿ‘‰', "default": '27017', validate: _validate.validateInputuser }]); case 38: _yield$inquirer$promp7 = _context.sent; port = _yield$inquirer$promp7.port; _context.next = 42; return _inquirer["default"].prompt([{ type: 'input', name: 'mail', message: 'Enter the NAME MAIL of the app ๐Ÿ‘‰', "default": 'example', validate: _validate.validateInputdb }]); case 42: _yield$inquirer$promp8 = _context.sent; APP_NAME = _yield$inquirer$promp8.APP_NAME; _context.next = 46; return _inquirer["default"].prompt([{ type: 'input', name: 'PUSHER_APP_KEY', message: 'Enter the PUSHER_APP_KEY ๐Ÿ‘‰', "default": 'example', validate: _validate.validateInputdb }]); case 46: _yield$inquirer$promp9 = _context.sent; PUSHER_APP_KEY = _yield$inquirer$promp9.PUSHER_APP_KEY; _context.next = 50; return _inquirer["default"].prompt([{ type: 'input', name: 'name', message: 'Enter the PUSHER_APP_CLUSTER ๐Ÿ‘‰', "default": 'example', validate: _validate.validateInputdb }]); case 50: _yield$inquirer$promp10 = _context.sent; PUSHER_APP_CLUSTER = _yield$inquirer$promp10.PUSHER_APP_CLUSTER; _fsExtra["default"].writeFileSync('./server/.env', "APP_NAME=Laravel\n APP_ENV=local\n APP_KEY=base64:Q2JklRcMGT2RfbDcJprAZs4q8stBo0A79ltNzm6scAM=\n APP_DEBUG=true\n APP_URL=http://localhost\n\n LOG_CHANNEL=stack\n LOG_LEVEL=debug\n\n DB_CONNECTION=mysql\n DB_HOST=".concat(host, "\n DB_PORT=").concat(port, "\n DB_DATABASE=").concat(db, "\n DB_USERNAME=").concat(user, "\n DB_PASSWORD=").concat(pass, "\n\n BROADCAST_DRIVER=log\n CACHE_DRIVER=file\n FILESYSTEM_DRIVER=local\n QUEUE_CONNECTION=sync\n SESSION_DRIVER=file\n SESSION_LIFETIME=120\n\n MEMCACHED_HOST=127.0.0.1\n\n REDIS_HOST=127.0.0.1\n REDIS_PASSWORD=null\n REDIS_PORT=6379\n\n MAIL_MAILER=smtp\n MAIL_HOST=mailhog\n MAIL_PORT=1025\n MAIL_USERNAME=null\n MAIL_PASSWORD=null\n MAIL_ENCRYPTION=null\n MAIL_FROM_ADDRESS=null\n MAIL_FROM_NAME=\"").concat(APP_NAME, "\"\n\n AWS_ACCESS_KEY_ID=\n AWS_SECRET_ACCESS_KEY=\n AWS_DEFAULT_REGION=us-east-1\n AWS_BUCKET=\n AWS_USE_PATH_STYLE_ENDPOINT=false\n\n PUSHER_APP_ID=\n PUSHER_APP_KEY=\n PUSHER_APP_SECRET=\n PUSHER_APP_CLUSTER=mt1\n\n MIX_PUSHER_APP_KEY=\"").concat(PUSHER_APP_KEY, "\"\n MIX_PUSHER_APP_CLUSTER=\"").concat(PUSHER_APP_CLUSTER, "\"")); shell.cd("server"); _context.next = 56; return (0, _exec["default"])('composer install', 'Installing Composer'); case 56: _context.next = 58; return (0, _exec["default"])('php artisan key:generate', 'Artisan key generated'); case 58: _context.next = 60; return (0, _exec["default"])('php artisan migrate', 'Artisan migrated'); case 60: _context.next = 62; return (0, _exec["default"])('php artisan db:seed', 'Artisan db seed done'); case 62: _context.next = 64; return (0, _exec["default"])('php artisan passport:install', 'Installing Passport '); case 64: _context.next = 66; return (0, _exec["default"])('npm install', 'Installing Backend Dependencies'); case 66: _context.next = 68; return (0, _exec["default"])('npm i sequelize', 'Installing sequelize'); case 68: _context.next = 70; return (0, _exec["default"])('npm i mysql2', 'Installing mysql2'); case 70: module.exports.templateServer = 'RestAPI'; _context.next = 132; break; case 73: if (!(templateServer === 'GraphQL')) { _context.next = 132; break; } _fsExtra["default"].copySync(_path["default"].resolve(__dirname, '../../../templates/server/laravel-mysql/GraphQL'), './GraphQL'); _currPath = './GraphQL'; _newPath = './server'; _fsExtra["default"].rename(_currPath, _newPath); _fsExtra["default"].copySync(_path["default"].resolve(__dirname, '../../../templates/config/venm.config.js'), './venm.config.js'); _context.next = 81; return _inquirer["default"].prompt([{ type: 'input', name: 'uri', message: 'Enter the HOST of the Mysql DB ๐Ÿ‘‰', "default": '127.0.0.1', validate: _validate.validateInputhost }]); case 81: _yield$inquirer$promp11 = _context.sent; _host = _yield$inquirer$promp11.host; _context.next = 85; return _inquirer["default"].prompt([{ type: 'input', name: 'uri', message: 'Enter the USER of the Mysql DB ๐Ÿ‘‰', "default": 'root', validate: _validate.validateInputuser }]); case 85: _yield$inquirer$promp12 = _context.sent; _user = _yield$inquirer$promp12.user; _context.next = 89; return _inquirer["default"].prompt([{ type: 'input', name: 'uri', message: 'Enter the PASSWORD of the Mysql DB ๐Ÿ‘‰', "default": '', validate: _validate.validateInputpass }]); case 89: _yield$inquirer$promp13 = _context.sent; _pass = _yield$inquirer$promp13.pass; _context.next = 93; return _inquirer["default"].prompt([{ type: 'input', name: 'name', message: 'Enter the NAME of the new Mysql DB ๐Ÿ‘‰', "default": 'example', validate: _validate.validateInputdb }]); case 93: _yield$inquirer$promp14 = _context.sent; _db = _yield$inquirer$promp14.db; _context.next = 97; return _inquirer["default"].prompt([{ type: 'input', name: 'port', message: 'Enter the PORT of the Mysql DB ๐Ÿ‘‰', "default": '27017', validate: _validate.validateInputuser }]); case 97: _yield$inquirer$promp15 = _context.sent; _port = _yield$inquirer$promp15.port; _context.next = 101; return _inquirer["default"].prompt([{ type: 'input', name: 'mail', message: 'Enter the NAME MAIL of the app ๐Ÿ‘‰', "default": 'example', validate: _validate.validateInputdb }]); case 101: _yield$inquirer$promp16 = _context.sent; _APP_NAME = _yield$inquirer$promp16.APP_NAME; _context.next = 105; return _inquirer["default"].prompt([{ type: 'input', name: 'PUSHER_APP_KEY', message: 'Enter the PUSHER_APP_KEY ๐Ÿ‘‰', "default": 'example', validate: _validate.validateInputdb }]); case 105: _yield$inquirer$promp17 = _context.sent; _PUSHER_APP_KEY = _yield$inquirer$promp17.PUSHER_APP_KEY; _context.next = 109; return _inquirer["default"].prompt([{ type: 'input', name: 'name', message: 'Enter the PUSHER_APP_CLUSTER ๐Ÿ‘‰', "default": 'example', validate: _validate.validateInputdb }]); case 109: _yield$inquirer$promp18 = _context.sent; _PUSHER_APP_CLUSTER = _yield$inquirer$promp18.PUSHER_APP_CLUSTER; _fsExtra["default"].writeFileSync('./server/.env', "APP_NAME=Laravel\n APP_ENV=local\n APP_KEY=base64:Q2JklRcMGT2RfbDcJprAZs4q8stBo0A79ltNzm6scAM=\n APP_DEBUG=true\n APP_URL=http://localhost\n\n LOG_CHANNEL=stack\n LOG_LEVEL=debug\n\n DB_CONNECTION=mysql\n DB_HOST=".concat(_host, "\n DB_PORT=").concat(_port, "\n DB_DATABASE=").concat(_db, "\n DB_USERNAME=").concat(_user, "\n DB_PASSWORD=").concat(_pass, "\n\n BROADCAST_DRIVER=log\n CACHE_DRIVER=file\n FILESYSTEM_DRIVER=local\n QUEUE_CONNECTION=sync\n SESSION_DRIVER=file\n SESSION_LIFETIME=120\n\n MEMCACHED_HOST=127.0.0.1\n\n REDIS_HOST=127.0.0.1\n REDIS_PASSWORD=null\n REDIS_PORT=6379\n\n MAIL_MAILER=smtp\n MAIL_HOST=mailhog\n MAIL_PORT=1025\n MAIL_USERNAME=null\n MAIL_PASSWORD=null\n MAIL_ENCRYPTION=null\n MAIL_FROM_ADDRESS=null\n MAIL_FROM_NAME=\"").concat(_APP_NAME, "\"\n\n AWS_ACCESS_KEY_ID=\n AWS_SECRET_ACCESS_KEY=\n AWS_DEFAULT_REGION=us-east-1\n AWS_BUCKET=\n AWS_USE_PATH_STYLE_ENDPOINT=false\n\n PUSHER_APP_ID=\n PUSHER_APP_KEY=\n PUSHER_APP_SECRET=\n PUSHER_APP_CLUSTER=mt1\n\n MIX_PUSHER_APP_KEY=\"").concat(_PUSHER_APP_KEY, "\"\n MIX_PUSHER_APP_CLUSTER=\"").concat(_PUSHER_APP_CLUSTER, "\"")); shell.cd("server"); _context.next = 115; return (0, _exec["default"])('composer install', 'Installing Composer'); case 115: _context.next = 117; return (0, _exec["default"])('php artisan key:generate', 'Artisan key generated'); case 117: _context.next = 119; return (0, _exec["default"])('php artisan migrate', 'Artisan migrated'); case 119: _context.next = 121; return (0, _exec["default"])('php artisan db:seed', 'Artisan db seed done'); case 121: _context.next = 123; return (0, _exec["default"])('php artisan passport:install', 'Installing Passport '); case 123: _context.next = 125; return (0, _exec["default"])('npm install', 'Installing Backend Dependencies'); case 125: _context.next = 127; return (0, _exec["default"])('npm install graphql --save', 'Installing GraphQL'); case 127: _context.next = 129; return (0, _exec["default"])('npm i sequelize', 'Installing sequelize'); case 129: _context.next = 131; return (0, _exec["default"])('npm i mysql2', 'Installing mysql2'); case 131: module.exports.templateServer = 'GraphQL'; case 132: _context.next = 210; break; case 134: if (!(template_backend === 'express')) { _context.next = 210; break; } _context.next = 137; return _inquirer["default"].prompt([{ name: 'templateServer', type: 'list', message: 'Please choose a starter template for the CRUD API ๐Ÿ’พ', choices: ['Rest API', 'GraphQL'] }]); case 137: _yield$inquirer$promp19 = _context.sent; _templateServer = _yield$inquirer$promp19.templateServer; if (!(_templateServer === 'Rest API')) { _context.next = 175; break; } logger.info('Creating the Rest API ๐Ÿ“ƒ'); _fsExtra["default"].copySync(_path["default"].resolve(__dirname, '../../../templates/server/express-mysql/RestAPI'), './RestAPI'); _currPath2 = './RestAPI'; _newPath2 = './server'; _fsExtra["default"].rename(_currPath2, _newPath2); _fsExtra["default"].copySync(_path["default"].resolve(__dirname, '../../../templates/config/venm.config.js'), './venm.config.js'); _context.next = 148; return _inquirer["default"].prompt([{ type: 'input', name: 'uri', message: 'Enter the HOST of the mySQL db ๐Ÿ‘‰', "default": 'localhost', validate: _validate.validateInputhost }]); case 148: _yield$inquirer$promp20 = _context.sent; _host2 = _yield$inquirer$promp20.host; _context.next = 152; return _inquirer["default"].prompt([{ type: 'input', name: 'uri', message: 'Enter the USER of the mySQL db ๐Ÿ‘‰', "default": 'root', validate: _validate.validateInputuser }]); case 152: _yield$inquirer$promp21 = _context.sent; _user2 = _yield$inquirer$promp21.user; _context.next = 156; return _inquirer["default"].prompt([{ type: 'input', name: 'uri', message: 'Enter the PASSWORD of the mySQL db ๐Ÿ‘‰', "default": '', validate: _validate.validateInputpass }]); case 156: _yield$inquirer$promp22 = _context.sent; _pass2 = _yield$inquirer$promp22.pass; _context.next = 160; return _inquirer["default"].prompt([{ type: 'input', name: 'name', message: 'Enter the NAME of the new Database ๐Ÿ‘‰', "default": 'example', validate: _validate.validateInputdb }]); case 160: _yield$inquirer$promp23 = _context.sent; _db2 = _yield$inquirer$promp23.db; _fsExtra["default"].writeFileSync('./server/config/db.config.js', "con.connect(function (err) {\n if (err) throw err\n console.log('Connected!')\n con.query('CREATE DATABASE ".concat(_db2, "', function (err, result) {\n if (err) throw err\n console.log('Database created')\n })\n })\n \n module.exports = {\n HOST: '").concat(_host2, "',\n USER: '").concat(_user2, "',\n PASSWORD: '").concat(_pass2, "',\n DB: '").concat(_db2, "',\n }")); shell.cd("server"); _context.next = 166; return (0, _exec["default"])('npm install', 'Installing Backend Dependencies'); case 166: _context.next = 168; return (0, _exec["default"])('npm install express --save', 'Installing ExpressJS'); case 168: _context.next = 170; return (0, _exec["default"])('npm i sequelize', 'Installing sequelize'); case 170: _context.next = 172; return (0, _exec["default"])('npm i mysql2', 'Installing mysql2'); case 172: module.exports.templateServer = 'RestAPI'; _context.next = 210; break; case 175: if (!(_templateServer === 'GraphQL')) { _context.next = 210; break; } _fsExtra["default"].copySync(_path["default"].resolve(__dirname, '../../../templates/server/express-mysql/GraphQL'), './GraphQL'); _currPath3 = './GraphQL'; _newPath3 = './server'; _fsExtra["default"].rename(_currPath3, _newPath3); _fsExtra["default"].copySync(_path["default"].resolve(__dirname, '../../../templates/config/venm.config.js'), './venm.config.js'); _context.next = 183; return _inquirer["default"].prompt([{ type: 'input', name: 'uri', message: 'Enter the HOST of the mySQL db ๐Ÿ‘‰', "default": 'localhost', validate: _validate.validateInputhost }]); case 183: _yield$inquirer$promp24 = _context.sent; _host3 = _yield$inquirer$promp24.host; _context.next = 187; return _inquirer["default"].prompt([{ type: 'input', name: 'uri', message: 'Enter the USER of the mySQL db ๐Ÿ‘‰', "default": 'root', validate: _validate.validateInputuser }]); case 187: _yield$inquirer$promp25 = _context.sent; _user3 = _yield$inquirer$promp25.user; _context.next = 191; return _inquirer["default"].prompt([{ type: 'input', name: 'uri', message: 'Enter the PASSWORD of the mySQL db ๐Ÿ‘‰', "default": 'root', validate: _validate.validateInputpass }]); case 191: _yield$inquirer$promp26 = _context.sent; _pass3 = _yield$inquirer$promp26.pass; _context.next = 195; return _inquirer["default"].prompt([{ type: 'input', name: 'name', message: 'Enter the NAME of the new Database ๐Ÿ‘‰', "default": 'example', validate: _validate.validateInputdb }]); case 195: _yield$inquirer$promp27 = _context.sent; _db3 = _yield$inquirer$promp27.db; _fsExtra["default"].writeFileSync('./server/models/index.js', "import Sequelize from 'sequelize'\n\n const sequelize = new Sequelize('".concat(_db3, "', '").concat(_user3, "', '").concat(_pass3, "', {\n host: '").concat(_host3, "',\n dialect: 'mysql',\n operatorsAliases: false,\n })\n \n const db = {\n User: sequelize.import('./user.js'),\n }\n \n db.sequelize = sequelize\n db.Sequelize = Sequelize\n \n export default db")); shell.cd("server"); _context.next = 201; return (0, _exec["default"])('npm install', 'Installing Backend Dependencies'); case 201: _context.next = 203; return (0, _exec["default"])('npm install express --save', 'Installing ExpressJS'); case 203: _context.next = 205; return (0, _exec["default"])('npm install graphql --save', 'Installing GraphQL'); case 205: _context.next = 207; return (0, _exec["default"])('npm i sequelize', 'Installing sequelize'); case 207: _context.next = 209; return (0, _exec["default"])('npm i mysql2', 'Installing mysql2'); case 209: module.exports.templateServer = 'GraphQL'; case 210: case "end": return _context.stop(); } } }, _callee); })); return _mysql.apply(this, arguments); }