import fs from 'fs' ; import getPublicUrlOrPath from './public-url' ; import { PUBLIC_URL } from '../config/constants' ; const appDirectory = fs . realpathSync ( process . cwd ( ) ) ; const resolveApp = ( relativePath ) : string => path . resolve ( appDirectory , relativePath ) ; class File { get publicUrlOrPath ( ) : string { return getPublicUrlOrPath ( require ( resolveApp ( 'package.json' ) ) . homepage , process . env . PUBLIC_URL ) ; } get stylePaths ( ) : string [ ] { return [ path . resolve ( BalmJS . config . workspace , '.' ) , path . resolve ( BalmJS . config . workspace , 'node_modules' ) , ... BalmJS . config . styles . atImportPaths ] ; } get assetsSuffixPath ( ) : string { return ! BalmJS . config . inFrontend && BalmJS . config . env . isProd && BalmJS . config . assets . cache ? path . join ( BalmJS . config . assets . subDir , BalmJS . config . assets . buildDir ) : BalmJS . config . assets . subDir ; } get defaultEntry ( ) : string { return path . join ( BalmJS . config . src . js , 'index.js' ) ; } get templateBasePath ( ) : string { return BalmJS . config . scripts . injectHtml ? BalmJS . config . src . base : BalmJS . config . src . html ; } absPath ( _path ) { return path . resolve ( BalmJS . config . workspace , _path ) ; } absPaths ( _paths ) { let paths ; if ( BalmJS . utils . isArray ( _paths ) ) { paths = [ ] ; for ( const _path of _paths ) { const result = /^!(.+)$/ . exec ( _path ) as RegExpExecArray ; if ( result ) { paths . push ( '!' + this . absPath ( result [ 1 ] ) ) ; } else { paths . push ( this . absPath ( _path ) ) ; } } } else { paths = this . absPath ( _paths as string ) ; } return paths ; } matchAllFiles ( _path , _file ? ) { return path . join ( _path , '**' , _file || '*' ) ; } assetsPath ( _path ) { return BalmJS . config . env . isProd || ! BalmJS . config . inFrontend ? path . posix . join ( BalmJS . config . assets . virtualDir , this . assetsSuffixPath , _path ) : _path ; } setPublicPath ( ) { const publicPathSrc = `${ PUBLIC_URL }/` ; const publicPathDest = BalmJS . config . inDesktopApp ? `.${ this . publicUrlOrPath }` : this . publicUrlOrPath ; BalmJS . logger . debug ( `set public path` , { regex : publicPathSrc , replacement : publicPathDest } , { pre : true } ) ; return BalmJS . plugins . replace ( publicPathSrc , publicPathDest ) ; } } export default new File ( ) ;