Skip to content

Commit 0d1b5b5

Browse files
committed
Add terse script
1 parent 883e99f commit 0d1b5b5

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

scripts/terse.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { readFile, writeFile, readdir, stat } from 'fs/promises'
2+
import { extname } from 'path'
3+
import { minify } from 'terser'
4+
5+
const terseDir = async (dir: string) => {
6+
const subPaths = await readdir(dir)
7+
8+
for (const subPath of subPaths) await terse(`${dir}/${subPath}`)
9+
}
10+
11+
const terseFile = async (file: string) => {
12+
if (extname(file) === '.js') {
13+
const { code: tersed } = minify( await readFile( file, 'utf-8' ) )
14+
await writeFile( file, tersed )
15+
}
16+
}
17+
18+
const terse = async (path: string) => {
19+
const curr = await stat(path)
20+
21+
if (curr.isFile()) await terseFile(path)
22+
else await terseDir(path)
23+
}
24+
25+
26+
// CLI
27+
const [,,path] = process.argv
28+
terse(path)

0 commit comments

Comments
 (0)