-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexport_util.js
More file actions
35 lines (28 loc) · 886 Bytes
/
export_util.js
File metadata and controls
35 lines (28 loc) · 886 Bytes
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
import fs from 'fs'
import { dirname } from 'node:path'
export let totalBytesWritten = 0
// make a tiny DSL
export const
cleanDir = (dirName) => {
if(fs.existsSync(dirName)) {
fs.rmSync(dirName, { recursive: true, force: true })
}
fs.mkdirSync(dirName, { recursive: true, force: true })
console.log(`/${dirName}: clean`)
},
copyDir = (from, to) => {
fs.cpSync(from, to, { recursive: true })
console.log(`/${from}/* copied to /${to}/*`)
},
write = (filename, fileContents) => {
const
dirName = dirname(filename),
bytesToWrite = fileContents.length/1000
// ensure dir is present before writing
if(!fs.existsSync(dirName)) {
fs.mkdirSync(dirName, { recursive: true })
}
fs.writeFileSync(filename, fileContents)
console.log(`/${filename} (${bytesToWrite}k)`)
totalBytesWritten += bytesToWrite
}