11import * as path from 'path' ;
22import * as fs from 'fs' ;
3+ import * as ts from 'typescript' ;
34import { cleanUp } from './clean-up' ;
45import { createBuildIn } from '../../src/core/method/create-build-in-helper' ;
56import { setBuildIn } from '../../src/core/method/set-build-in-helper' ;
67import { globalBuildIn } from '../../src/core/method/global-build-in-helper' ;
78import { rootBuildIn } from '../../src/core/method/root-build-in-helper' ;
8- // eslint-disable-next-line @typescript-eslint/no-var-requires
9- const fg = require ( 'fast-glob' ) ;
9+
10+ function isStyleClass ( filePath : string ) : boolean {
11+ const content = fs . readFileSync ( filePath , 'utf8' ) ;
12+ const sourceFile = ts . createSourceFile ( filePath , content , ts . ScriptTarget . Latest , true ) ;
13+
14+ let isUsed = false ;
15+
16+ function checkNode ( node : ts . Node ) {
17+ if ( ts . isPropertyAccessExpression ( node ) && ts . isIdentifier ( node . name ) ) {
18+ const expressionText = node . expression . getText ( sourceFile ) ;
19+ const methodName = node . name . getText ( sourceFile ) ;
20+ const methods = [ 'create' , 'set' , 'root' , 'global' ] ;
21+ if ( expressionText === 'cssx' && methods . includes ( methodName ) ) {
22+ isUsed = true ;
23+ }
24+ }
25+
26+ ts . forEachChild ( node , checkNode ) ;
27+ }
28+
29+ checkNode ( sourceFile ) ;
30+
31+ return isUsed ;
32+ }
1033
1134( async ( ) => {
1235 await cleanUp ( ) ;
@@ -19,10 +42,13 @@ const fg = require('fast-glob');
1942 } else {
2043 appRoot = path . join ( process . cwd ( ) , '../../' ) ;
2144 }
22- const csstsPattern = [ path . join ( appRoot , '**/*.css.ts' ) , path . join ( appRoot , '**/*.css.tsx' ) ] ;
23- const files = await fg ( csstsPattern ) ;
45+ const csstsPattern = [ path . join ( appRoot , '**/*.ts' ) , path . join ( appRoot , '**/*.tsx' ) ] ;
46+ const files = fs . globSync ( csstsPattern ) ;
47+ const styleFiles = files . filter ( file => {
48+ return isStyleClass ( file ) ;
49+ } ) ;
2450 console . log ( '\n💬 The following CSS caches were accepted:\n' ) ;
25- for ( const file of files ) {
51+ for ( const file of styleFiles ) {
2652 const filePath = path . resolve ( file ) ;
2753 await import ( filePath ) ;
2854 createBuildIn ( ) ;
0 commit comments