forked from abdedarghal111/js-discord-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathesbuild.config.mjs
More file actions
107 lines (100 loc) · 2.89 KB
/
Copy pathesbuild.config.mjs
File metadata and controls
107 lines (100 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import { existsSync, readdir, readdirSync, rmSync } from 'fs'
import esbuild from 'esbuild'
import { replace } from 'esbuild-plugin-replace'
import { copy } from 'esbuild-plugin-copy'
import path from 'path'
import { fileURLToPath } from 'url'
import c from 'colors'
/*
Parámetros disponibles:
--developing => compilar para desarrollo
--production => compilar para producción (lo empaqueta)
--no-clean => no realiza la limpieza
--clean => realiza limpieza de directorios (por defecto)
*/
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const __dist = path.join(__dirname, 'dist')
let checkParam = par => process.argv.find(val => val === par)
// limpieza
if (existsSync(__dist) && !checkParam('--no-clean')) {
let files = readdirSync(__dist)
let emptyDist = files.length === 0 || (files.length === 1 && files[0] === 'data')
if(!emptyDist){console.log('\n==> Limpiando carpeta de compilación...'.yellow)}
for (const file of files) {
if (file !== 'data') {
const filePath = path.join(__dist, file)
rmSync(filePath, { recursive: true, force: true })
console.log(` -> ${file} borrado`.cyan)
}
}
console.log('\n==> Carpeta de compilación limpia'.green)
}
if (checkParam('--developing')) {
// configuración para produccion
await esbuild.build({
logLevel: 'info',
entryPoints: ['src/**/*.mts'],
sourceRoot: 'src',
outdir: './dist',
bundle: false,
sourcemap: false,
target: 'es2022',
platform: 'node',
format: 'esm',
outExtension: {
'.js': '.mjs'
},
resolveExtensions: ['.mts'],
//external: ['discord.js', 'dotenv', '@google'],
tsconfig: './tsconfig.json',
plugins: [
replace({
'.mts': '.mjs'
}),
copy({
assets: [
{
from: ['./src/**/{*.txt,*.img}'],
to: ['.'],
},
],
})
]
}).catch(() => process.exit(1))
} else if (checkParam('--production')) {
// configuración para desarrollo
await esbuild.build({
logLevel: 'info',
entryPoints: ['src/app.mts'],
sourceRoot: 'src',
outdir: './dist',
bundle: true,
minify: true,
sourcemap: true,
target: 'es2022',
platform: 'node',
format: 'esm',
outExtension: {
'.js': '.mjs'
},
external: ['discord.js', 'dotenv', '@google', 'colors', 'path', 'url', 'fs'],
tsconfig: './tsconfig.json',
plugins: [
copy({
assets: [
{
from: ['./src/**/{*.txt,*.img}'],
to: ['.'],
},
],
})
],
}).catch(() => process.exit(1))
}else{
if(!checkParam('--clean')){
console.log(c.yellow('\n==> Aviso: No se ha especificado ')+c.red('--production')+c.yellow(' o ')+c.red('--developing')+c.yellow(' como parámetro'))
console.log('==> Cancelando...'.yellow)
}
}
console.log('\n==> Cadena de compilación finalizada\n'.green)