cheetah-framework
Version:
Cheetah Framework JS used in all our applications
54 lines (46 loc) • 1.21 kB
JavaScript
/* global path */
const _ = require('lodash')
class Paths {
constructor (rootPath, cheetah) {
this.cheetah = cheetah
this.setRootPath(rootPath)
this.appRelativePath = cheetah.config.appPath
this.appPath = this.rootPath + '/' + cheetah.config.appPath
this.symlinkFolder = this.root(this.appRelativePath + '/js/cheetahModules')
this.rootPathReplaceRegExp = new RegExp(`^${this.rootPath}`)
}
/**
* Set the root path to resolve webpack.mix.js.
*
* @param {string} rootPath
*/
setRootPath (rootPath) {
this.rootPath = rootPath
return this
}
/**
* Determine the path to the user's webpack.mix.js file.
*/
mix () {
return this.root(
this.cheetah.argv.env && this.cheetah.argv.env.mixfile ? this.cheetah.argv.env.mixfile : 'webpack.mix'
)
}
/**
* Determine the project root.
*
* @param {string|null} append
*/
root (append = '') {
return path.resolve(this.rootPath, append)
}
/**
* Return path relative to rootPath
*
* @param {string|null} absolutePath
*/
relative (absolutePath) {
return _.trimStart(absolutePath.replace(this.rootPathReplaceRegExp, ''), '/')
}
}
module.exports = Paths