1
1
2
2
import path from 'path' ;
3
3
import fs from 'fs-extra' ;
4
+ import readPkgUp from 'read-pkg-up' ;
4
5
import { getLessFiles } from './getLessFiles' ;
5
6
import { executeLess , IOutputFile } from './executeLess' ;
6
7
@@ -15,6 +16,8 @@ export default async function compile(dir: string, option: ICompileOtion) {
15
16
const { excludeCss, rmGlobal, combine, out, ...otherOpts } = option || { } ;
16
17
const inputDir = path . join ( process . cwd ( ) , dir ) ;
17
18
try {
19
+ const pkg = await readPkgUp ( ) ;
20
+ const projectName = pkg ? pkg ?. packageJson . name : '' ;
18
21
const files : Array < string > = await getLessFiles ( inputDir , excludeCss ? / \. ( l e s s ) $ / : undefined ) ;
19
22
const lessSource = await Promise . all ( files . map ( async ( lessPath : string ) => {
20
23
return executeLess ( lessPath , { rmGlobal, ...otherOpts } ) ;
@@ -25,9 +28,9 @@ export default async function compile(dir: string, option: ICompileOtion) {
25
28
const cssStr : Array < string > = lessSource . map ( ( item : IOutputFile ) => item . css ) ;
26
29
if ( ! ! cssStr . join ( '' ) . trim ( ) ) {
27
30
await fs . outputFile ( outputCssFile , cssStr . join ( '' ) ) ;
28
- console . log ( '♻️ \x1b[32m =>\x1b[0m:' , 'Output one file: ->' , outputCssFile ) ;
31
+ await log ( outputCssFile ) ;
29
32
} else {
30
- console . log ( ' 🚧\x1b[33m No content is output.\x1b[0m' ) ;
33
+ console . log ( ` 🚧\x1b[33m ${ projectName } No content is output.\x1b[0m` ) ;
31
34
}
32
35
} else {
33
36
const outputDir = path . join ( process . cwd ( ) , out ) ;
@@ -45,12 +48,22 @@ export async function outputFile(data: IOutputFile, inputDir: string, outputDir:
45
48
const logPathIn = data . path . replace ( process . cwd ( ) , '' ) ;
46
49
data . path = data . path . replace ( inputDir , outputDir ) . replace ( / .l e s s $ / , '.css' ) ;
47
50
const logPathOut = data . path . replace ( process . cwd ( ) , '' ) ;
48
- console . log ( '♻️ \x1b[32m =>\x1b[0m:' , logPathIn , '->' , logPathOut ) ;
51
+ await log ( logPathOut , logPathIn ) ;
49
52
await fs . outputFile ( data . path , data . css ) ;
50
53
if ( data . imports && data . imports . length > 0 ) {
51
54
// console.log('\x1b[35m imports-> \x1b[0m:', data.imports);
52
55
}
53
56
} catch ( error ) {
54
57
throw error ;
55
58
}
59
+ }
60
+
61
+ async function log ( output : string , input ?: string ) {
62
+ const pkg = await readPkgUp ( ) ;
63
+ const projectName = pkg ? pkg ?. packageJson . name : '' ;
64
+ if ( input ) {
65
+ console . log ( `♻️ \x1b[32m ${ projectName } =>\x1b[0m:` , input , '->' , output ) ;
66
+ } else {
67
+ console . log ( `♻️ \x1b[32m ${ projectName } =>\x1b[0m:` , 'Output one file: ->' , output ) ;
68
+ }
56
69
}
0 commit comments