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CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAA;;gDAA/B,IAAI,GAAG,SAAwB;gDACrC,IAAI,IAAI,CAAC,WAAW,EAAE;oDAAE,sBAAO,QAAQ,CAAC,SAAS,EAAC;gDAClD,0BAA0B;gDAC1B,IAAI,IAAI,CAAC,MAAM,EAAE;oDAAE,sBAAO,QAAQ,CAAC,IAAI,EAAC;gDACxC,0BAA0B;gDAC1B,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;;;gDAE7C,sBAAO,QAAQ,CAAC,OAAO,EAAC;;;;qCAE3B,CAAC,EAAE,EAAA;;4BAXE,IAAI,GAAG,SAWT;4BACJ,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;4BACtB,sBAAO,IAAI,EAAC;;;iBACb,CAAC,EAAE,CAAC;QACP,CAAC;;;OAAA;IACD,sBAAI,wBAAM;aAAV;YAAA,iBAIC;YAHC,OAAO,CAAC;;;gCACE,qBAAM,IAAI,CAAC,IAAI,EAAA;gCAAvB,sBAAO,CAAC,SAAe,CAAC,KAAK,QAAQ,CAAC,OAAO,EAAC;;;iBAC/C,CAAC,EAAE,CAAC;QACP,CAAC;;;OAAA;IACD,yBAAU,GAAV,UAAW,GAAW;QACpB,IAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC;QAChC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,UAAU,GAAG,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;QACtE,OAAO,IAAI,CAAC;IACd,CAAC;IACH,WAAC;AAAD,CAAC,AAnFD,IAmFC;AAnFY,oBAAI","sourcesContent":["import * as fs from 'fs-extra';\nimport * as nodePath from 'path';\n\nexport enum PathType {\n file = 'file',\n directory = 'directory',\n missing = 'missing',\n}\n\nexport class Path {\n constructor(\n public props?: {\n basename?: string;\n cwd?: string;\n path?: string;\n }\n ) {}\n cacheBasename?: string;\n cachePath?: string;\n cacheCwd?: string;\n cacheDirname?: string;\n cacheExtname?: string;\n cacheType?: PathType;\n cacheCoreBasename?: string;\n get path() {\n if (this.cachePath) return this.cachePath;\n this.cachePath = (() => {\n if (this.props?.path) return this.props.path;\n if (this.props?.basename) {\n return nodePath.join(this.cwd, this.props.basename);\n }\n return this.cwd;\n })();\n return this.cachePath;\n }\n get cwd(): string {\n if (this.cacheCwd) return this.cacheCwd;\n this.cacheCwd = this.props?.cwd ?? process.cwd();\n return this.cacheCwd;\n }\n get basename(): string {\n if (this.cacheBasename) return this.cacheBasename;\n this.cacheBasename = nodePath.basename(this.path);\n return this.cacheBasename;\n }\n get coreBasename(): string {\n if (this.cacheCoreBasename) return this.cacheCoreBasename;\n this.cacheCoreBasename = nodePath.basename(this.path, this.extname);\n return this.cacheCoreBasename;\n }\n get relativePath() {\n return this.path.replace(new RegExp('^' + this.cwd), '.');\n }\n get dirname(): string {\n if (this.cacheDirname) return this.cacheDirname;\n this.cacheDirname = nodePath.dirname(this.path);\n return this.cacheDirname;\n }\n get extname(): string {\n if (this.cacheExtname) return this.cacheExtname;\n this.cacheExtname = nodePath.extname(this.path);\n return this.cacheExtname;\n }\n get type(): Promise {\n return (async () => {\n if (this.cacheType) return this.cacheType;\n const type = await (async () => {\n try {\n const stat = await fs.stat(this.path);\n if (stat.isDirectory()) return PathType.directory;\n /* istanbul ignore next */\n if (stat.isFile()) return PathType.file;\n /* istanbul ignore next */\n throw new Error('File type not recognized.');\n } catch (e) {\n return PathType.missing;\n }\n })();\n this.cacheType = type;\n return type;\n })();\n }\n get exists(): Promise {\n return (async () => {\n return (await this.type) !== PathType.missing;\n })();\n }\n replaceExt(ext: string) {\n const currentExt = this.extname;\n this.cachePath = this.path.replace(new RegExp(currentExt + '$'), ext);\n return this;\n }\n}\n"]}