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 d94a56e commit 858251bCopy full SHA for 858251b
src/writeFile.ts
@@ -0,0 +1,18 @@
1
+import fs from 'fs'
2
+import { isStr } from './isStr'
3
+
4
+export function writeFile(paths: string[] | string, callback: (content: string, index: number) => string) {
5
+ if (!callback)
6
+ throw new Error('callback is required')
7
+ if (isStr(paths))
8
+ paths = [paths as string];
9
+ (paths as string[]).forEach(async (relativepath, i) => {
10
+ const result = callback(await fs.readFileSync('./dist/index.js', 'utf-8'), i)
11
+ if (!result)
12
+ throw new Error('callback needs to return string content')
13
+ fs.writeFile(relativepath, result, (err) => {
14
+ if (err)
15
+ throw err
16
+ })
17
18
+}
0 commit comments