2021-10-20 09:42:32 +08:00
|
|
|
import through2 from 'through2'
|
|
|
|
import { pathRewriter } from './pkg'
|
2021-09-28 20:28:47 +08:00
|
|
|
import type { TaskFunction } from 'gulp'
|
2021-10-20 09:42:32 +08:00
|
|
|
import type { Module } from '../info'
|
2021-09-28 20:28:47 +08:00
|
|
|
|
|
|
|
export const withTaskName = <T extends TaskFunction>(name: string, fn: T) =>
|
|
|
|
Object.assign(fn, { displayName: name })
|
2021-10-20 09:42:32 +08:00
|
|
|
|
|
|
|
export const gulpPathRewriter = (module: Module) => {
|
|
|
|
const rewriter = pathRewriter(module, true)
|
|
|
|
|
|
|
|
return through2.obj((file, _, cb) => {
|
|
|
|
const contents: string = file.contents.toString()
|
|
|
|
file.contents = Buffer.from(rewriter(contents))
|
|
|
|
cb(null, file)
|
|
|
|
})
|
|
|
|
}
|