UNPKG

@agatee/cli

Version:

CLI for Agatee App

66 lines (65 loc) 3.07 kB
"use strict"; var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.addGraphql = void 0; var fs_1 = require("fs"); var path_1 = __importDefault(require("path")); var prettier_1 = require("prettier"); var process_1 = require("process"); var generales_1 = require("../../../generales"); var console_1 = require("../../../utils/console"); var file_1 = require("../../../utils/file"); var workers_1 = require("../../../utils/workers"); var gaphql_module_starter_1 = require("./starter-code/gaphql-module.starter"); var additionnalPackages = [ 'apollo-server-express', 'graphql', '@agatee/graphql', '@graphql-tools/schema', 'graphql-middleware', 'graphql-shield' ]; var addGraphql = function (params) { checkGraphqlError(params); var workingDirectory = (0, process_1.cwd)(); console.log('Installing graphql, apollo-server-express, @agatee/graphql'); console.log(">npm install --save " + additionnalPackages.join(' ')); (0, workers_1.runSpawnWorker)("npm", __spreadArray(__spreadArray(['install', '--save'], additionnalPackages, true), ['--prefix', workingDirectory, workingDirectory], false), { onExit: function () { var agateeConfig = JSON.parse((0, file_1.getFileContent)(generales_1.agateeConfigPath)); var graphqlModuleContent = (0, gaphql_module_starter_1.graphqlModuleStarterCode)().trim(); (0, console_1.logSuccess)("[\u2714] Installation done ..."); console.log('Setting up Graphql ...'); (0, fs_1.mkdirSync)('./app/graphql', { recursive: true }); (0, fs_1.writeFileSync)('./app/graphql/index.ts', graphqlModuleContent); if (agateeConfig.apiStyle != 'graphql') { agateeConfig.apiStyle = 'graphql'; (0, fs_1.writeFileSync)(generales_1.agateeConfigPath, (0, prettier_1.format)(JSON.stringify(agateeConfig), { parser: 'json' })); } console.log('[✔] Graphql setup done !\n⚠️ Don\'t forget to import the GatGraphqlModule to the @GatModule imports array in app.ts file.'); }, onDataErr: function (err) { if (!err.toLowerCase().includes('npm warn')) { console.error(err); } } }); }; exports.addGraphql = addGraphql; var checkGraphqlError = function (params) { var workingDirectory = (0, process_1.cwd)(); if ((0, fs_1.existsSync)(path_1.default.resolve(workingDirectory + '/app/graphql'))) { throw new Error('Graphql already added in app/graphql!'); } };