{"version":3,"sources":["../../../packages/tools/wac-cli/src/common.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,oBAAY,YAAY;IACpB,QAAQ,aAAa;IACrB,UAAU,eAAe;CAC5B;AAED,qBAAa,MAAM;IACf,gBAAuB,WAAW,SAAgD;IAClF,gBAAuB,kBAAkB,SAAuE;IAEhH,OAAO,CAAC,MAAM,CAAC,SAAS,CAAS;IAEjC;;;OAGG;IACH,WAAkB,QAAQ,WAEzB;IAED;;;OAGG;IACH,WAAkB,QAAQ,CAAC,IAAI,QAAA,EAE9B;IAED;;;;OAIG;WACW,YAAY,CAAC,QAAQ,KAAA;IAYnC;;;;OAIG;WACW,aAAa,CAAC,QAAQ,KAAA,EAAE,UAAU,KAAA,GAAG,OAAO;IAc1D;;;;OAIG;WACiB,SAAS,CAAC,QAAQ,KAAA,EAAE,UAAU,KAAA,GAAG,OAAO,CAAC,IAAI,CAAC;IASlE;;;;OAIG;WACW,YAAY,CAAC,QAAQ,KAAA;IAYnC;;;;;;OAMG;WACW,eAAe,CAAC,cAAc,KAAA,EAAE,cAAc,KAAA,EAAE,SAAS,KAAA;CAG1E","file":"common.d.ts","sourcesContent":["const fs = require('fs');\r\nconst fse = require('fs-extra');\r\n\r\n/**\r\n * Error resolution states\r\n */\r\nexport enum ResolveState {\r\n    Resolved = 'RESOLVED',\r\n    Unresolved = 'UNRESOLVED'\r\n}\r\n\r\nexport class Common {\r\n    public static readonly cliRootPath = __dirname.substring(0, __dirname.length - 3);\r\n    public static readonly moduleTemplatePath = __dirname.substring(0, __dirname.length - 11) + 'module-template\\\\';\r\n\r\n    private static _rootPath: string;\r\n\r\n    /**\r\n     * Gets the root path for the current repository\r\n     * @returns {string} Root path for the current repository\r\n     */\r\n    public static get rootPath() {\r\n        return Common._rootPath;\r\n    }\r\n\r\n    /**\r\n     * Sets the root path for the current repository\r\n     * @param {string} path Root path for the current repository\r\n     */\r\n    public static set rootPath(path) {\r\n        Common._rootPath = path;\r\n    }\r\n\r\n    /**\r\n     * Retrieves content of given file\r\n     * @param {string} filePath Target file path\r\n     * @returns {string | null} String representation of file content or null if file was not found\r\n     */\r\n    public static readFileData(filePath) {\r\n        if (!fs.statSync(filePath).isDirectory()) {\r\n            if (!fse.existsSync(filePath)) {\r\n                return null;\r\n            }\r\n\r\n            return fse.readFileSync(filePath, 'utf8');\r\n        }\r\n\r\n        return null;\r\n    }\r\n\r\n    /**\r\n     * Writes to the content of given file\r\n     * @param {string} filePath Target file path\r\n     * @returns {boolean} indicates whether the file was written successfully.\r\n     */\r\n    public static writeFileData(filePath, newContent): boolean {\r\n        if (!fs.statSync(filePath).isDirectory()) {\r\n            if (!fse.existsSync(filePath)) {\r\n                return false;\r\n            }\r\n\r\n            fse.writeFileSync(filePath, newContent, 'utf8');\r\n\r\n            return true;\r\n        }\r\n\r\n        return false;\r\n    }\r\n\r\n    /**\r\n     * Creates the file with content.\r\n     * @param {string} filePath Target file path\r\n     * @param {string} newContent Content to write to the file\r\n     */\r\n    public static async writeFile(filePath, newContent): Promise<void> {\r\n        await fs.writeFile(filePath, newContent, (err) => {\r\n            if (err) {\r\n                console.error('Error creating file:', err);\r\n                return;\r\n            }\r\n        });\r\n    }\r\n\r\n    /**\r\n     * Retrieves content of given JSON file and parses into an object\r\n     * @param {string} filePath Target file path\r\n     * @returns {any | null} Parsed JSON object or null if file was not found\r\n     */\r\n    public static readFileJSON(filePath) {\r\n        if (!fs.statSync(filePath).isDirectory()) {\r\n            if (!fse.existsSync(filePath)) {\r\n                return null;\r\n            }\r\n\r\n            return fse.readJSONSync(filePath);\r\n        }\r\n\r\n        return null;\r\n    }\r\n\r\n    /**\r\n     * Replaces part of target string with a new string using given regex\r\n     * @param {string} originalString Target string\r\n     * @param {RegExp} regexToReplace Regex to apply to target string\r\n     * @param {string} newString String that will replace regex matches\r\n     * @returns {string} New string created from replacing regex matches or original string if no matches were found\r\n     */\r\n    public static replaceInString(originalString, regexToReplace, newString) {\r\n        return originalString.replace(regexToReplace, newString);\r\n    }\r\n}\r\n"]}