UNPKG

@salesforce-ux/sds-metadata

Version:

This package simplifies the management, distribution, and usage of Salesforce Design System metadata, ensuring that developers and designers can easily access and integrate design system metadata into their workflows.

78 lines (63 loc) 1.97 kB
import path from 'path'; import { fileURLToPath } from 'url'; import { globbySync } from 'globby'; import fs from 'fs'; import camelCase from 'lodash.camelcase'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); ["next", "current"].forEach(async (releaseType) => { const generatedDir = path.join(__dirname, `../${releaseType}`); const rootDir = path.join(__dirname, '../'); // Get all JSON files from the generated directory const jsonFiles = globbySync(path.join(generatedDir, '*.json')); // Create a map of camelCase keys to file paths const fileMap = jsonFiles.reduce((acc, file) => { const key = camelCase(path.basename(file, '.json')); const relativePath = './'+path.relative(rootDir, file); acc[key] = relativePath; return acc; }, {}); // Create a lightweight ESM index file const esmContent = ` // This file is auto-generated. Do not edit directly. import { fileURLToPath } from 'url'; import path from 'path'; import fs from 'fs'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); const metadata = { ${Object.entries(fileMap) .map(([key, filePath]) => ` get ${key}() { return JSON.parse(fs.readFileSync(path.join(__dirname, '${filePath}'), 'utf8')); }, `).join('')} }; export default metadata; `; // Write ESM index file directly await fs.promises.writeFile( path.join(rootDir, `./${releaseType}.metadata.mjs`), esmContent, 'utf8' ); // Create a lightweight CJS index file const cjsContent = ` // This file is auto-generated. Do not edit directly. const metadata = { ${Object.entries(fileMap) .map(([key, filePath]) => ` get ${key}() { return require('${filePath}'); }, `).join('')} }; module.exports = metadata; `; // Write CJS index file directly await fs.promises.writeFile( path.join(rootDir, `./${releaseType}.metadata.cjs`), cjsContent, 'utf8' ); });