|
1 | | -import { writeFileSync } from 'fs'; |
2 | | -import * as path from 'path'; |
| 1 | +import { existsSync, writeFileSync } from 'fs'; |
| 2 | +import { join, dirname } from 'path'; |
3 | 3 |
|
4 | | -const styleFilePath = path.join(__dirname, '../../src/core/styles/style.module.css'); |
5 | | -const globalFilePath = path.join(__dirname, '../../src/core/styles/global.css'); |
| 4 | +function findNextJsProjectRoot(startPath: string, count: number): string | null { |
| 5 | + let currentPath = startPath; |
| 6 | + for (let i = 1; i <= count; i++) { |
| 7 | + if ( |
| 8 | + existsSync(join(currentPath, 'package.json')) && |
| 9 | + (existsSync(join(currentPath, 'next.config.js')) || existsSync(join(currentPath, 'next.config.mjs'))) |
| 10 | + ) { |
| 11 | + return currentPath; |
| 12 | + } |
| 13 | + currentPath = dirname(currentPath); |
| 14 | + } |
| 15 | + return null; |
| 16 | +} |
6 | 17 |
|
7 | 18 | export const cleanUp = async () => { |
| 19 | + const currentDir = __dirname; |
| 20 | + const projectRoot = findNextJsProjectRoot(currentDir, 5); |
| 21 | + |
| 22 | + if (!projectRoot) { |
| 23 | + console.error('Next.js project root not found'); |
| 24 | + return; |
| 25 | + } |
| 26 | + |
| 27 | + const srcDir = join(projectRoot, 'src'); |
| 28 | + let stylesDir: string; |
| 29 | + |
| 30 | + if (existsSync(srcDir)) { |
| 31 | + stylesDir = join(srcDir, 'styles'); |
| 32 | + } else { |
| 33 | + stylesDir = join(projectRoot, 'styles'); |
| 34 | + } |
| 35 | + |
| 36 | + const styleFilePath = join(__dirname, '../../src/core/styles/style.module.css'); |
| 37 | + const globalFilePath = join(stylesDir, 'typedcssx-global.css'); |
| 38 | + |
8 | 39 | try { |
9 | 40 | writeFileSync(styleFilePath, '/*------------------------------*/', 'utf-8'); |
10 | 41 | console.log('...💫(reseted module css)'); |
|
0 commit comments