Skip to content

Commit bba9b9d

Browse files
committed
Refactor terse script
1 parent 305f33b commit bba9b9d

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

scripts/terse.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
import { readFile, writeFile, readdir, stat } from 'fs/promises'
2-
import { extname } from 'path'
1+
import * as fs from 'node:fs/promises'
2+
import { extname } from 'node:path'
33
import { minify } from 'terser'
44

5-
const terseDir = async (dir: string) => {
6-
const subPaths = await readdir(dir)
5+
const terseDir = async (dirPath: string) => {
6+
const subPaths = await fs.readdir(dirPath)
77

8-
for (const subPath of subPaths) await terse(`${dir}/${subPath}`)
8+
for (const subPath of subPaths) await terse(`${dirPath}/${subPath}`)
99
}
1010

11-
const terseFile = async (file: string) => {
12-
if (extname(file) === '.js') {
13-
const { code } = await minify( await readFile( file, 'utf-8' ) )
14-
if (code) await writeFile( file, code )
11+
const terseFile = async (filePath: string) => {
12+
if (extname(filePath) === '.js') {
13+
const output = await minify(await fs.readFile(filePath, 'utf-8'))
14+
if (output.code) await fs.writeFile(filePath, output.code)
1515
}
1616
}
1717

1818
const terse = async (path: string) => {
19-
const curr = await stat(path)
19+
const curr = await fs.stat(path)
2020

2121
if (curr.isFile()) await terseFile(path)
2222
else await terseDir(path)

0 commit comments

Comments
 (0)