-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
53 lines (49 loc) · 1.46 KB
/
build.js
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
// build.js
import esbuild from 'esbuild';
import fs from 'fs';
import path from 'path';
// Function to clean the dist directory
const cleanDist = () => {
const distPath = path.resolve('dist');
if (fs.existsSync(distPath)) {
fs.rmSync(distPath, { recursive: true, force: true });
console.log('Cleaned dist directory.');
}
};
// Function to copy necessary files to the dist directory
const copyFiles = () => {
const filesToCopy = ['package.json', 'README.md', 'LICENSE'];
filesToCopy.forEach((file) => {
const srcPath = path.resolve(file);
const destPath = path.resolve('dist', file);
if (fs.existsSync(srcPath)) {
fs.copyFileSync(srcPath, destPath);
console.log(`Copied ${file} to dist directory.`);
} else {
console.warn(`Warning: ${file} not found.`);
}
});
};
// Clean dist directory
cleanDist();
// Run the esbuild bundling process
esbuild
.build({
entryPoints: ['src/main.js'],
bundle: true,
platform: 'node',
format: 'esm', // Output as an ES module
outfile: 'dist/local-pack.js',
minify: true,
external: ['chalk'], // Exclude chalk from bundling
banner: { js: '#!/usr/bin/env node' },
})
.then(() => {
fs.chmodSync('dist/local-pack.js', '755');
console.log('Build successful and executable permissions set!');
copyFiles(); // Copy additional files to dist after build is complete
})
.catch((error) => {
console.error('Build failed:', error);
process.exit(1);
});