-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
67 lines (53 loc) · 1.51 KB
/
build.js
File metadata and controls
67 lines (53 loc) · 1.51 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
import path from 'node:path'
// Utilities from @tangible/roller
import fs from 'fs-extra'
import esbuild from 'esbuild'
import glob from 'fast-glob'
async function buildForNpm() {
const sourceFolder = `assets/src`
const targetFolder = `publish/npm`
console.log('Prepare target folder', targetFolder)
if (await fs.exists(targetFolder)) {
await fs.remove(targetFolder)
}
await fs.ensureDir(targetFolder)
console.log('Build files from', sourceFolder)
let i = 0
for (const file of await glob(`**/*.{js,jsx,ts,tsx,scss}`, {
cwd: sourceFolder,
})) {
i++
console.log(file)
const extension = file.split('.').pop()
const sourceFile = path.join(sourceFolder, file)
if (extension === 'scss') {
// Copy as is
const targetFile = path.join(targetFolder, file)
await fs.copy(sourceFile, targetFile)
continue
}
// Compile
const targetFile = path.join(targetFolder, file.replace(extension, 'js'))
await esbuild.build({
entryPoints: [sourceFile],
bundle: false,
outfile: targetFile,
})
}
console.log('Built', i, 'files')
for (const file of ['package.json', 'readme.md']) {
await fs.copy(file, path.join(targetFolder, file))
console.log('Copied', file)
}
}
async function help() {
console.log(`Usage: node build.js [command] [...options]
Available commands:
npm - Build NPM package`)
}
const [command, ...args] = process.argv.slice(2)
const run =
{
npm: buildForNpm,
}[command] || help
run().catch(console.error)