Home Reference Source

src/private/Paths.js

import {join, parse} from 'path'

/** Holds path information relevant to the transformation of a single file. */
export default class Paths {
	constructor(transformers, inDir, outDir, relInPath) {
		this.relInPath = relInPath
		this.fullInPath = join(inDir, relInPath)

		const {dir: relInDir, name, ext} = parse(relInPath)
		this.inExtension = ext

		const outExt = transformers.getOutExtension(this.inExtension)

		const outName = outExt ? `${name}.${outExt}` : name
		this.relOutPath = manglePath(join(relInDir, outName))
		this.fullOutPath = join(outDir, this.relOutPath)
	}
}

/** Transform paths that can't be directly served over html. */
const manglePath = path =>
	path.replace(/!/g, 'bang')
	.replace(/@/g, 'at')
	.replace(/\?/g, 'q')
	.replace(/\$/g, 'cash')