(obj: any = twCtx.use().config, path: string[] = [], level = 1)
| 16 | ) => objPath.reduce((prev, curr) => prev?.[curr], twConfig as Record<string, any>) |
| 17 | |
| 18 | const populateMap = (obj: any = twCtx.use().config, path: string[] = [], level = 1) => { |
| 19 | Object.entries(obj).forEach(([key, value = {} as any]) => { |
| 20 | const subpathComponents = path.concat(key) |
| 21 | const subpath = subpathComponents.join('/') |
| 22 | |
| 23 | if ( |
| 24 | level >= config.level // if recursive call is more than desired |
| 25 | || !isJSObject(value) // if its not an object, no more recursion required |
| 26 | || Object.keys(value).find(k => !k.match(NON_ALPHANUMERIC_RE)) // object has non-alphanumeric property (unsafe var name) |
| 27 | ) { |
| 28 | templates.push(addTemplate({ |
| 29 | filename: `tailwind/expose/${subpath}.mjs`, |
| 30 | getContents: () => { |
| 31 | const _value = getTWConfig(subpathComponents) |
| 32 | |
| 33 | if (isJSObject(_value)) { |
| 34 | const [validKeys, invalidKeys]: [string[], string[]] = [[], []] |
| 35 | Object.keys(_value).forEach(i => (NON_ALPHANUMERIC_RE.test(i) ? validKeys : invalidKeys).push(i)) |
| 36 | |
| 37 | return [ |
| 38 | `${validKeys.map(i => `const _${i} = ${JSON.stringify(_value[i])}`).join('\n')}`, |
| 39 | `const config = { ${validKeys.map(i => `"${i}": _${i}, `).join('')}${invalidKeys.map(i => `"${i}": ${JSON.stringify(_value[i])}, `).join('')} }`, |
| 40 | `export { config as default${validKeys.length > 0 ? ', _' : ''}${validKeys.join(', _')} }`, |
| 41 | ].join('\n') |
| 42 | } |
| 43 | return `export default ${JSON.stringify(_value, null, 2)}` |
| 44 | }, |
| 45 | write: config.write, |
| 46 | })) |
| 47 | } |
| 48 | else { |
| 49 | // recurse through nested objects |
| 50 | populateMap(value, path.concat(key), level + 1) |
| 51 | |
| 52 | templates.push(addTemplate({ |
| 53 | filename: `tailwind/expose/${subpath}.mjs`, |
| 54 | getContents: () => { |
| 55 | const _value = getTWConfig(subpathComponents) |
| 56 | const values = Object.keys(_value) |
| 57 | |
| 58 | return [ |
| 59 | `${values.map(v => `import _${v} from "./${key}/${v}.mjs"`).join('\n')}`, |
| 60 | `const config = { ${values.map(k => `"${k}": _${k}`).join(', ')} }`, |
| 61 | `export { config as default${values.length > 0 ? ', _' : ''}${values.join(', _')} }`, |
| 62 | ].join('\n') |
| 63 | }, |
| 64 | write: config.write, |
| 65 | })) |
| 66 | } |
| 67 | }) |
| 68 | } |
| 69 | |
| 70 | populateMap() |
| 71 |
no test coverage detected