UNPKG

@omnia/tooling-vue

Version:

Used to bundle and serve manifests web component that build on Vue framework.

105 lines (104 loc) 3.86 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createViteServer = void 0; const tslib_1 = require("tslib"); const path_1 = tslib_1.__importDefault(require("path")); const fs_1 = tslib_1.__importDefault(require("fs")); const vite_1 = require("vite"); const appdata_path_1 = tslib_1.__importDefault(require("appdata-path")); const del_1 = tslib_1.__importDefault(require("del")); const tooling_composers_1 = require("@omnia/tooling-composers"); const tooling_1 = require("@omnia/tooling"); const plugins_1 = require("./plugins"); async function createViteServer() { const hosting = (0, tooling_composers_1.getHosting)(); let plugins = [ (0, plugins_1.omniaPlugin)({ hosting: hosting }) ]; let https = hosting.https || await getCert(); let serverConfig = { configFile: false, esbuild: false, optimizeDeps: { entries: [], exclude: '**' // https://github.com/vitejs/vite/issues/1662 }, publicDir: "wwwroot", mode: 'development', server: { hmr: hosting.hmr, port: hosting.port, https: https, cors: false }, plugins: plugins }; if (hosting.userConfig) { serverConfig = Object.assign({}, serverConfig, hosting.userConfig); serverConfig.plugins = (serverConfig.plugins || []).concat(plugins); } const server = await (0, vite_1.createServer)(serverConfig); await server.listen(); tooling_1.utils.log(`Done hosting -> https://localhost:${hosting.port}`); return server; } exports.createViteServer = createViteServer; function getCert() { return new Promise((resolve, reject) => { let appPath = (0, appdata_path_1.default)(); let certFolderPath = path_1.default.join(appPath, "omnia", "https"); const certName = "devcert"; const certFilePath = path_1.default.join(certFolderPath, `${certName}.pem`); const keyFilePath = path_1.default.join(certFolderPath, `${certName}.key`); if (!fs_1.default.existsSync(certFilePath) || !fs_1.default.existsSync(keyFilePath)) { const spawn = require('child_process').spawn; spawn('dotnet', [ 'dev-certs', 'https', '--export-path', certFilePath, '--format', 'Pem', '--no-password', ], { stdio: 'inherit', }) .on('exit', (code) => { resolve({ cert: fs_1.default.readFileSync(certFilePath), key: fs_1.default.readFileSync(keyFilePath) }); //process.exit(code); }); } else { resolve({ cert: fs_1.default.readFileSync(certFilePath), key: fs_1.default.readFileSync(keyFilePath) }); } }); } tooling_1.core.registerCleanTask({ order: 2, task: function () { return new Promise(function (resolve, reject) { let appPath = (0, appdata_path_1.default)(); let certFolderPath = path_1.default.join(appPath, "omnia", "https"); const certName = "devcert"; const certFilePath = path_1.default.join(certFolderPath, `${certName}.pem`); const keyFilePath = path_1.default.join(certFolderPath, `${certName}.key`); if (fs_1.default.existsSync(certFilePath)) { del_1.default.sync(certFilePath, { force: true }); } if (fs_1.default.existsSync(keyFilePath)) { del_1.default.sync(keyFilePath, { force: true }); } resolve(); }); } });