Skip to content

Commit 246caef

Browse files
committedAug 31, 2021
chore: Modify the output log.
1 parent 1c1d1dd commit 246caef

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed
 

‎package.json

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"chokidar": "3.5.2",
4747
"directory-tree": "2.3.1",
4848
"fs-extra": "10.0.0",
49+
"read-pkg-up": "7.0.1",
4950
"less": "4.1.1",
5051
"less-plugin-autoprefix": "2.0.0",
5152
"minimist": "1.2.5"

‎src/compile.ts

+16-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
import path from 'path';
33
import fs from 'fs-extra';
4+
import readPkgUp from 'read-pkg-up';
45
import { getLessFiles } from './getLessFiles';
56
import { executeLess, IOutputFile } from './executeLess';
67

@@ -15,6 +16,8 @@ export default async function compile(dir: string, option: ICompileOtion) {
1516
const { excludeCss, rmGlobal, combine, out, ...otherOpts } = option || {};
1617
const inputDir = path.join(process.cwd(), dir);
1718
try {
19+
const pkg = await readPkgUp();
20+
const projectName = pkg ? pkg?.packageJson.name : '';
1821
const files: Array<string> = await getLessFiles(inputDir, excludeCss ? /\.(less)$/ : undefined);
1922
const lessSource = await Promise.all(files.map(async (lessPath: string) => {
2023
return executeLess(lessPath, { rmGlobal, ...otherOpts });
@@ -25,9 +28,9 @@ export default async function compile(dir: string, option: ICompileOtion) {
2528
const cssStr: Array<string> = lessSource.map((item: IOutputFile) => item.css);
2629
if (!!cssStr.join('').trim()) {
2730
await fs.outputFile(outputCssFile, cssStr.join(''));
28-
console.log('♻️ \x1b[32m =>\x1b[0m:', 'Output one file: ->', outputCssFile);
31+
await log(outputCssFile);
2932
} else {
30-
console.log('🚧\x1b[33m No content is output.\x1b[0m');
33+
console.log(`🚧\x1b[33m ${projectName} No content is output.\x1b[0m`);
3134
}
3235
} else {
3336
const outputDir = path.join(process.cwd(), out);
@@ -45,12 +48,22 @@ export async function outputFile(data: IOutputFile, inputDir: string, outputDir:
4548
const logPathIn = data.path.replace(process.cwd(), '');
4649
data.path = data.path.replace(inputDir, outputDir).replace(/.less$/, '.css');
4750
const logPathOut = data.path.replace(process.cwd(), '');
48-
console.log('♻️ \x1b[32m =>\x1b[0m:', logPathIn, '->', logPathOut);
51+
await log(logPathOut, logPathIn);
4952
await fs.outputFile(data.path, data.css);
5053
if (data.imports && data.imports.length > 0) {
5154
// console.log('\x1b[35m imports-> \x1b[0m:', data.imports);
5255
}
5356
} catch (error) {
5457
throw error;
5558
}
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+
}
5669
}

‎tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"compilerOptions": {
33
"baseUrl": ".",
4-
"target": "es5",
4+
"target": "ES5",
55
"lib": [
66
"es2015",
77
"es6",

0 commit comments

Comments
 (0)
Please sign in to comment.