mirror of
https://github.com/EvolutionAPI/evolution-manager.git
synced 2025-07-13 15:14:49 -06:00
Fix file paths and error handling in server.js and
build.js
This commit is contained in:
parent
b6f447bb0a
commit
b44edc8631
@ -11,20 +11,28 @@ const functions = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports = async (argv) => {
|
module.exports = async (argv) => {
|
||||||
if (argv._.length === 1) throw new Error('No operation specified')
|
try{
|
||||||
|
|
||||||
const operation = argv._[1]
|
if (argv._.length === 1) throw new Error('No operation specified')
|
||||||
if (!functions[operation]) throw new Error(`Unknown operation: ${operation}`)
|
|
||||||
|
const operation = argv._[1]
|
||||||
await functions[operation](argv)
|
if (!functions[operation]) throw new Error(`Unknown operation: ${operation}`)
|
||||||
|
|
||||||
|
await functions[operation](argv)
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e.message || e)
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
function startServer(argv) {
|
function startServer(argv) {
|
||||||
const { port = 9615 } = argv || {}
|
const { port = 9615 } = argv || {}
|
||||||
|
|
||||||
const index = fs.readFileSync(process.cwd() + '/dist/index.html');
|
const index = fs.readFileSync(path.join(__dirname, '..', 'dist', 'index.html'));
|
||||||
|
|
||||||
http.createServer(function (req, res) {
|
http.createServer(function (req, res) {
|
||||||
try {
|
try {
|
||||||
@ -32,7 +40,7 @@ function startServer(argv) {
|
|||||||
|
|
||||||
// verify if url is a file in dist folder
|
// verify if url is a file in dist folder
|
||||||
if (parsedUrl.pathname === '/') throw {}
|
if (parsedUrl.pathname === '/') throw {}
|
||||||
let filePath = process.cwd() + '/dist' + parsedUrl.pathname;
|
let filePath = path.join(__dirname, '..', 'dist', parsedUrl.pathname);
|
||||||
|
|
||||||
if (fs.existsSync(filePath)) {
|
if (fs.existsSync(filePath)) {
|
||||||
const contentType = mime.lookup(filePath) || 'text/plain';
|
const contentType = mime.lookup(filePath) || 'text/plain';
|
||||||
|
@ -1,17 +1,19 @@
|
|||||||
const { exec } = require('child_process')
|
const { exec } = require('child_process')
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
|
const path = require('path')
|
||||||
|
|
||||||
module.exports = () => {
|
module.exports = () => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
console.log('📦 Build start')
|
console.log('📦 Build start')
|
||||||
console.time('📦 Build complete')
|
console.time('📦 Build complete')
|
||||||
const distFolder = process.cwd() + '/dist'
|
const distFolder = path.join(__dirname, '..', '..', 'dist')
|
||||||
if (fs.existsSync(distFolder)) {
|
if (fs.existsSync(distFolder)) {
|
||||||
console.time('📦 Remove dist folder')
|
console.time('📦 Remove dist folder')
|
||||||
fs.rmSync(distFolder, { recursive: true, force: true })
|
fs.rmSync(distFolder, { recursive: true, force: true })
|
||||||
console.timeEnd('📦 Remove dist folder')
|
console.timeEnd('📦 Remove dist folder')
|
||||||
}
|
}
|
||||||
exec('npm run build', (err, stdout) => {
|
|
||||||
|
exec('npm run build', { cwd: path.join(__dirname, '..', '..') }, (err, stdout) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
reject(err)
|
reject(err)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "evolution-manager",
|
"name": "evolution-manager",
|
||||||
"version": "0.2.0",
|
"version": "0.2.1",
|
||||||
"main": "dist",
|
"main": "dist",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
|
Loading…
Reference in New Issue
Block a user