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CAAC,cAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC;IAC7C,MAAM,kBAAE,CAAC,SAAS,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;AAC5C,CAAC;AAJD,kDAIC;AAED,SAAgB,YAAY,CAAC,SAAoB,EAAE,qBAA+B;IAChF,IAAI,qBAAqB,CAAC,SAAS,CAAC,KAAK,EAAE;QACzC,IAAI,eAAe,GAAG,qBAAqB,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,CAChE,CAAC,CAAU,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CACvD,CAAC,CAAC,CAAC,CAAC;QACL,IAAI,eAAe,EAAE;YACnB,eAAe,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;SAC1C;aAAM;YACL,qBAAqB,CAAC,SAAS,CAAC,KAAK,GAAG,qBAAqB,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,CAClF,SAAS,CACV,CAAC;SACH;KACF;SAAM;QACL,IAAI,OAAO,qBAAqB,CAAC,SAAS,KAAK,QAAQ,EAAE;YACvD,+CAA+C;YAC/C,qBAAqB,CAAC,SAAS,GAAG,EAAE,CAAC;SACtC;QACD,qBAAqB,CAAC,SAAS,CAAC,KAAK,GAAG,SAAS,CAAC;KACnD;IACD,OAAO,qBAAqB,CAAC;AAC/B,CAAC;AApBD,oCAoBC","sourcesContent":["import path from 'path';\nimport fs from 'fs-extra';\nimport { Builder, Parser } from 'xml2js';\nimport { Document } from './Manifest';\nimport { XMLItem } from './Styles';\n\nconst BASE_STYLES_XML = `<?xml version=\"1.0\" encoding=\"utf-8\"?><resources></resources>`;\n\nexport async function getProjectColorsXMLPathAsync(projectDir: string): Promise<string | null> {\n try {\n const shellPath = path.join(projectDir, 'android');\n if ((await fs.stat(shellPath)).isDirectory()) {\n const colorsPath = path.join(shellPath, 'app/src/main/res/values/colors.xml');\n await fs.ensureFile(colorsPath);\n return colorsPath;\n }\n } catch (error) {\n throw new Error('No android directory found in your project.');\n }\n\n return null;\n}\n\nexport async function readColorsXMLAsync(colorsPath: string): Promise<Document> {\n const contents = await fs.readFile(colorsPath, { encoding: 'utf8', flag: 'r' });\n const parser = new Parser();\n const manifest = parser.parseStringPromise(contents || BASE_STYLES_XML);\n return manifest;\n}\n\nexport async function writeColorsXMLAsync(colorsPath: string, colorsContent: any): Promise<void> {\n const colorsXml = new Builder().buildObject(colorsContent);\n await fs.ensureDir(path.dirname(colorsPath));\n await fs.writeFile(colorsPath, colorsXml);\n}\n\nexport function setColorItem(itemToAdd: XMLItem[], colorFileContentsJSON: Document) {\n if (colorFileContentsJSON.resources.color) {\n let colorNameExists = colorFileContentsJSON.resources.color.filter(\n (e: XMLItem) => e['$'].name === itemToAdd[0]['$'].name\n )[0];\n if (colorNameExists) {\n colorNameExists['_'] = itemToAdd[0]['_'];\n } else {\n colorFileContentsJSON.resources.color = colorFileContentsJSON.resources.color.concat(\n itemToAdd\n );\n }\n } else {\n if (typeof colorFileContentsJSON.resources === 'string') {\n //file was empty and JSON is `{resources : ''}`\n colorFileContentsJSON.resources = {};\n }\n colorFileContentsJSON.resources.color = itemToAdd;\n }\n return colorFileContentsJSON;\n}\n"]}
\No newline at end of file