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

365 lines (287 loc) โ€ข 16.5 kB
/* eslint-disable prettier/prettier */ /* eslint-disable no-unused-vars */ /* 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.mongo = mongo; 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 mongo() { return _mongo.apply(this, arguments); } function _mongo() { _mongo = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() { var _yield$inquirer$promp, template_backend, _yield$inquirer$promp2, host, _yield$inquirer$promp3, user, _yield$inquirer$promp4, port, _yield$inquirer$promp5, pass, _yield$inquirer$promp6, db, _yield$inquirer$promp7, APP_NAME, _yield$inquirer$promp8, PUSHER_APP_KEY, _yield$inquirer$promp9, PUSHER_APP_CLUSTER, _yield$inquirer$promp10, templateServer, currPath, newPath, _yield$inquirer$promp11, uri, _yield$inquirer$promp12, name, _currPath, _newPath, _yield$inquirer$promp13, _uri, _yield$inquirer$promp14, _name; return regeneratorRuntime.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: _context.next = 2; return _inquirer["default"].prompt([{ name: 'template_backend', type: 'list', message: 'Please choose a BACKEND framework โœจ', choices: ['express', 'laravel'] }]); case 2: _yield$inquirer$promp = _context.sent; template_backend = _yield$inquirer$promp.template_backend; if (!(template_backend === 'laravel')) { _context.next = 64; break; } logger.info('Creating the Rest API ๐Ÿ“ƒ'); _context.next = 8; return (0, _validate.validateInstallation)('composer -V'); case 8: _context.next = 10; return (0, _validate.validateInstallation)('php -v'); case 10: _fsExtra["default"].copySync(_path["default"].resolve(__dirname, '../../../templates/server/laravel-mongodb/server'), './server'); _fsExtra["default"].copySync(_path["default"].resolve(__dirname, '../../../templates/config/venm.config.js'), './venm.config.js'); _context.next = 14; return _inquirer["default"].prompt([{ type: 'input', name: 'uri', message: 'Enter the HOST of the Mongodb ๐Ÿ‘‰', "default": 'localhost', validate: _validate.validateInputhost }]); case 14: _yield$inquirer$promp2 = _context.sent; host = _yield$inquirer$promp2.host; _context.next = 18; return _inquirer["default"].prompt([{ type: 'input', name: 'user', message: 'Enter the USER of the Mongodb ๐Ÿ‘‰', "default": 'root', validate: _validate.validateInputuser }]); case 18: _yield$inquirer$promp3 = _context.sent; user = _yield$inquirer$promp3.user; _context.next = 22; return _inquirer["default"].prompt([{ type: 'input', name: 'port', message: 'Enter the PORT of the Mongodb ๐Ÿ‘‰', "default": '27017', validate: _validate.validateInputuser }]); case 22: _yield$inquirer$promp4 = _context.sent; port = _yield$inquirer$promp4.port; _context.next = 26; return _inquirer["default"].prompt([{ type: 'input', name: 'pass', message: 'Enter the PASSWORD of the Mongodb ๐Ÿ‘‰', "default": '', validate: _validate.validateInputpass }]); case 26: _yield$inquirer$promp5 = _context.sent; pass = _yield$inquirer$promp5.pass; _context.next = 30; return _inquirer["default"].prompt([{ type: 'input', name: 'name', message: 'Enter the NAME of the new Database ๐Ÿ‘‰', "default": 'example', validate: _validate.validateInputdb }]); case 30: _yield$inquirer$promp6 = _context.sent; db = _yield$inquirer$promp6.db; _context.next = 34; return _inquirer["default"].prompt([{ type: 'input', name: 'mail', message: 'Enter the NAME MAIL of the app ๐Ÿ‘‰', "default": 'example', validate: _validate.validateInputdb }]); case 34: _yield$inquirer$promp7 = _context.sent; APP_NAME = _yield$inquirer$promp7.APP_NAME; _context.next = 38; return _inquirer["default"].prompt([{ type: 'input', name: 'PUSHER_APP_KEY', message: 'Enter the PUSHER_APP_KEY ๐Ÿ‘‰', "default": 'example', validate: _validate.validateInputdb }]); case 38: _yield$inquirer$promp8 = _context.sent; PUSHER_APP_KEY = _yield$inquirer$promp8.PUSHER_APP_KEY; _context.next = 42; return _inquirer["default"].prompt([{ type: 'input', name: 'name', message: 'Enter the PUSHER_APP_CLUSTER ๐Ÿ‘‰', "default": 'example', validate: _validate.validateInputdb }]); case 42: _yield$inquirer$promp9 = _context.sent; PUSHER_APP_CLUSTER = _yield$inquirer$promp9.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 MONGO_DB_HOST=".concat(host, "\n MONGO_DB_PORT=").concat(port, "\n MONGO_DB_DATABASE=").concat(db, "\n MONGO_DB_USERNAME=").concat(user, "\n MONGO_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/app'); _fsExtra["default"].writeFileSync('Users.php', "<?php\n\n namespace AppModels;\n \n use IlluminateDatabaseEloquentModel;\n use JenssegersMongodbEloquentModel as Eloquent;\n \n class Users extends Eloquent\n {\n protected $connection = 'prova';\n protected $collection = 'users';\n \n protected $fillable = [\n 'name', 'age', 'description'\n ];\n }"); _context.next = 49; return (0, _exec["default"])('composer install', 'Installing Composer'); case 49: _context.next = 51; return (0, _exec["default"])('php artisan key:generate', 'Artisan key generated'); case 51: _context.next = 53; return (0, _exec["default"])('php artisan migrate', 'Artisan migrated'); case 53: _context.next = 55; return (0, _exec["default"])('php artisan db:seed', 'Artisan db seed done'); case 55: _context.next = 57; return (0, _exec["default"])('php artisan passport:install', 'Installing Passport '); case 57: _context.next = 59; return (0, _exec["default"])('npm install', 'Installing Backend Dependencies'); case 59: _context.next = 61; return (0, _exec["default"])('npm i mongoose', 'Installing Mongoose'); case 61: module.exports.templateServer = 'RestAPI'; _context.next = 120; break; case 64: if (!(template_backend === 'express')) { _context.next = 120; break; } _context.next = 67; return _inquirer["default"].prompt([{ name: 'templateServer', type: 'list', message: 'Please choose a starter template for the CRUD API ๐Ÿ’พ', choices: ['Rest API', 'GraphQL'] }]); case 67: _yield$inquirer$promp10 = _context.sent; templateServer = _yield$inquirer$promp10.templateServer; if (!(templateServer === 'Rest API')) { _context.next = 95; break; } logger.info('Creating the Rest API ๐Ÿ“ƒ'); _fsExtra["default"].copySync(_path["default"].resolve(__dirname, '../../../templates/server/express-mongodb/RestAPI'), './RestAPI'); currPath = './RestAPI'; newPath = './server'; _fsExtra["default"].copySync(_path["default"].resolve(__dirname, '../../../templates/config/venm.config.js'), './venm.config.js'); _fsExtra["default"].rename(currPath, newPath); _context.next = 78; return _inquirer["default"].prompt([{ type: 'input', name: 'uri', message: 'Enter the URL of the MongoDB ๐Ÿ‘‰', "default": 'mongodb://localhost:27017', validate: _validate.validateInput }]); case 78: _yield$inquirer$promp11 = _context.sent; uri = _yield$inquirer$promp11.uri; _context.next = 82; return _inquirer["default"].prompt([{ type: 'input', name: 'name', message: 'Enter the NAME of the new Database ๐Ÿ‘‰', "default": 'example', validate: _validate.validateInputname }]); case 82: _yield$inquirer$promp12 = _context.sent; name = _yield$inquirer$promp12.name; _fsExtra["default"].writeFileSync('./server/.env', "DB_URL=".concat(uri, "/").concat(name)); shell.cd("server"); _context.next = 88; return (0, _exec["default"])('npm install', 'Installing Backend Dependencies'); case 88: _context.next = 90; return (0, _exec["default"])('npm install express --save', 'Installing ExpressJS'); case 90: _context.next = 92; return (0, _exec["default"])('npm i mongoose', 'Installing Mongoose'); case 92: module.exports.templateServer = 'RestAPI'; _context.next = 120; break; case 95: if (!(templateServer === 'GraphQL')) { _context.next = 120; break; } _fsExtra["default"].copySync(_path["default"].resolve(__dirname, '../../../templates/server/express-mongodb/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 = 103; return _inquirer["default"].prompt([{ type: 'input', name: 'uri', message: 'Enter the URL of the MongoDB ๐Ÿ‘‰', "default": 'mongodb://localhost:27017', validate: _validate.validateInput }]); case 103: _yield$inquirer$promp13 = _context.sent; _uri = _yield$inquirer$promp13.uri; _context.next = 107; return _inquirer["default"].prompt([{ type: 'input', name: 'name', message: 'Enter the NAME of the new Database ๐Ÿ‘‰', "default": 'example', validate: _validate.validateInputname }]); case 107: _yield$inquirer$promp14 = _context.sent; _name = _yield$inquirer$promp14.name; _fsExtra["default"].writeFileSync('./server/.env', "DB_URL=".concat(_uri, "/").concat(_name)); shell.cd("server"); _context.next = 113; return (0, _exec["default"])('npm install', 'Installing Backend Dependencies'); case 113: _context.next = 115; return (0, _exec["default"])('npm install express --save', 'Installing ExpressJS'); case 115: _context.next = 117; return (0, _exec["default"])('npm install graphql --save', 'Installing GraphQL'); case 117: _context.next = 119; return (0, _exec["default"])('npm i mongoose', 'Installing Mongoose'); case 119: module.exports.templateServer = 'GraphQL'; case 120: case "end": return _context.stop(); } } }, _callee); })); return _mongo.apply(this, arguments); }