-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathesbuild.config.js
More file actions
93 lines (86 loc) · 2.3 KB
/
esbuild.config.js
File metadata and controls
93 lines (86 loc) · 2.3 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
const {build: esbuild} = require('esbuild')
const {createRequire} = require('module')
const fs = require('fs')
const path = require('path')
const commitlintRequire = createRequire(require.resolve('@commitlint/load'))
function copyTemplates() {
const templatesDir = 'dist/templates'
if (!fs.existsSync(templatesDir)) {
fs.mkdirSync(templatesDir, {recursive: true})
}
try {
const angularDir = path.dirname(
commitlintRequire.resolve('conventional-changelog-angular')
)
const templateSrc = path.join(angularDir, 'templates')
if (fs.existsSync(templateSrc)) {
for (const file of fs.readdirSync(templateSrc)) {
if (file.endsWith('.hbs')) {
fs.copyFileSync(
path.join(templateSrc, file),
path.join(templatesDir, file)
)
}
}
}
} catch (e) {
console.warn('Warning: Could not copy template files:', e.message)
}
}
function copySchema() {
try {
const schemaFile = commitlintRequire.resolve(
'@commitlint/config-validator/lib/commitlint.schema.json'
)
fs.copyFileSync(schemaFile, path.join('dist', 'commitlint.schema.json'))
} catch (e) {
console.warn('Warning: Could not copy schema file:', e.message)
}
}
const config = {
entryPoints: ['lib/main.js'],
bundle: true,
outfile: 'dist/index.js',
platform: 'node',
target: 'node20',
format: 'cjs',
minify: true,
sourcemap: false,
external: [],
mainFields: ['module', 'main'],
conditions: ['node', 'import', 'require'],
banner: {
js: 'const import_meta_url = require("url").pathToFileURL(__filename).href;'
},
plugins: [
{
name: 'import-meta-url',
setup(build) {
build.onLoad({filter: /\.js$/}, async args => {
const contents = await fs.promises.readFile(args.path, 'utf8')
const transformedContents = contents.replace(
/import\.meta\.url/g,
'import_meta_url'
)
return {
contents: transformedContents,
loader: 'js'
}
})
}
},
{
name: 'copy-assets',
setup(build) {
build.onEnd(() => {
copyTemplates()
copySchema()
})
}
}
]
}
module.exports = config
if (require.main === module) {
esbuild(config).catch(() => process.exit(1))
}