Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit 790a0a6

Browse files
committed
feat(clean-up.ts): update
1 parent 2e5df62 commit 790a0a6

File tree

1 file changed

+35
-4
lines changed

1 file changed

+35
-4
lines changed

compiler/src/clean-up.ts

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,41 @@
1-
import { writeFileSync } from 'fs';
2-
import * as path from 'path';
1+
import { existsSync, writeFileSync } from 'fs';
2+
import { join, dirname } from 'path';
33

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+
}
617

718
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+
839
try {
940
writeFileSync(styleFilePath, '/*------------------------------*/', 'utf-8');
1041
console.log('...💫(reseted module css)');

0 commit comments

Comments
 (0)