/// import * as fs from 'node:fs' import * as path from 'node:path' import { dirname } from 'node:path' import { fileURLToPath } from 'node:url' const __filename = fileURLToPath(import.meta.url) const __dirname = dirname(__filename) const targetDir = path.join(__dirname, '../') const moduleTargetDir = path.join(targetDir, 'generated-modules') function addImportStatement(filePath: string, importStatement: string) { const fileContent = fs.readFileSync(filePath, 'utf8') const lines = fileContent.split('\n') const lastImportLine = lines.findIndex((line) => line.startsWith('@import')) lines.splice(lastImportLine + 1, 0, importStatement) fs.writeFileSync(filePath, lines.join('\n'), 'utf8') } function main() { const files = ['animation', 'color', 'font', 'layout', 'elevation', 'combined'] const COLOR_FILE = 'color' const ELEVATION_FILE = 'elevation' files.forEach((namePart) => { const filesToAddImports = path.join(targetDir, `_${namePart}.scss`) const moduleFilesToAddImports = path.join(moduleTargetDir, `_${namePart}.module.scss`) let importStatement = `@forward './deprecated/${namePart}';\n` let moduleImportStatement = `@forward '../deprecated/${namePart}';\n` if (namePart === COLOR_FILE) { importStatement = `@use 'sass:color' as Color;\n@use './palette';\n${importStatement}` moduleImportStatement = `@use 'sass:color' as Color;\n@use '../palette';\n${moduleImportStatement}` } if (namePart === ELEVATION_FILE) { importStatement = `@use './palette';\n@use './space';\n` moduleImportStatement = `@use '../palette';\n@use '../space';\n` } if (namePart === 'combined') { importStatement = `@use './palette';\n@use './color';\n@use './elevation';\n@use './font';\n@use './fontsize';\n@use './lineheight';\n@use './weight';\n@use './layout';\n@use './animation';\n@use './space';\n` moduleImportStatement = `@use '../palette';\n@use '../color';\n@use '../elevation';\n@use '../font';\n@use '../fontsize';\n@use '../lineheight';\n@use '../weight';\n@use '../layout';\n@use '../animation';\n@use '../space';\n` } addImportStatement(filesToAddImports, importStatement) addImportStatement(moduleFilesToAddImports, moduleImportStatement) }) console.log('\x1b[32m', `Updated imports in ${files.length} SCSS partials and module files`, '\x1b[0m') } main()