|
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' |
3 | 3 | import { minify } from 'terser' |
4 | 4 |
|
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) |
7 | 7 |
|
8 | | - for (const subPath of subPaths) await terse(`${dir}/${subPath}`) |
| 8 | + for (const subPath of subPaths) await terse(`${dirPath}/${subPath}`) |
9 | 9 | } |
10 | 10 |
|
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) |
15 | 15 | } |
16 | 16 | } |
17 | 17 |
|
18 | 18 | const terse = async (path: string) => { |
19 | | - const curr = await stat(path) |
| 19 | + const curr = await fs.stat(path) |
20 | 20 |
|
21 | 21 | if (curr.isFile()) await terseFile(path) |
22 | 22 | else await terseDir(path) |
|
0 commit comments