UNPKG

@foal/cli

Version:

CLI tool for FoalTS

52 lines (51 loc) 2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ConnectVueCommandService = void 0; const path_1 = require("path"); const safe_1 = require("colors/safe"); /** * Service for connecting a Vue frontend to a FoalTS application. */ class ConnectVueCommandService { generator; constructor(generator) { this.generator = generator; } /** * Configure a Vue project to interact with a FoalTS application. * * @param {string} path - The path to the Vue project directory * @returns {void} */ run(path) { if (!this.generator.exists(path)) { if (process.env.P1Z7kEbSUUPMxF8GqPwD8Gx_FOAL_CLI_TEST !== 'true') { console.log((0, safe_1.red)(` The directory ${path} does not exist.`)); } return; } if (!this.generator.exists((0, path_1.join)(path, 'package.json'))) { if (process.env.P1Z7kEbSUUPMxF8GqPwD8Gx_FOAL_CLI_TEST !== 'true') { console.log((0, safe_1.red)(` The directory ${path} is not a Vue project (missing package.json).`)); } return; } this.generator .cd(path) .modify('package.json', content => { const pkg = JSON.parse(content); pkg.vue = pkg.vue || {}; // Proxy configuration pkg.vue.devServer = pkg.vue.devServer || {}; pkg.vue.devServer.proxy = pkg.vue.devServer.proxy || {}; pkg.vue.devServer.proxy['^/api'] = { target: 'http://localhost:3001' }; // Output build directory const outputPath = (0, path_1.join)((0, path_1.relative)(path, process.cwd()), 'public') // Make projects generated on Windows build on Unix. .replace(/\\/g, '/'); pkg.vue.outputDir = outputPath; return JSON.stringify(pkg, null, 2); }); } } exports.ConnectVueCommandService = ConnectVueCommandService;