We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 883e99f commit 0d1b5b5Copy full SHA for 0d1b5b5
scripts/terse.ts
@@ -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