Skip to content

Commit

Permalink
[Optimize] 优化 remove 任务
Browse files Browse the repository at this point in the history
  • Loading branch information
VisualSJ committed Nov 29, 2023
1 parent 72b9950 commit ea68a0e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@itharbors/workflow",
"version": "0.2.4",
"version": "0.2.5",
"description": "",
"main": "./dist/index.js",
"scripts": {
Expand All @@ -26,11 +26,9 @@
"@itharbors/structures": "^1.0.2",
"@types/download": "^8.0.5",
"@types/fs-extra": "^11.0.4",
"@types/graceful-fs": "^4.1.9",
"chalk": "^4.1.2",
"download": "^8.0.0",
"fs-extra": "^11.1.1",
"graceful-fs": "^4.2.11",
"v-unzip": "^1.1.0",
"workflow-extra": "^0.2.7"
}
Expand Down
15 changes: 10 additions & 5 deletions source/internal/less.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from 'fs';
import { cpus } from 'os';

import { green, italic } from 'chalk';
import { green, italic, yellow } from 'chalk';

import { registerTask, Task, TaskState } from '../task';
import { bash } from '../utils';
Expand Down Expand Up @@ -45,10 +45,10 @@ export class LessTask extends Task {
let changed = false;

// 获取编译的文件列表
const fileArray: string[] = [
path,
];
try {
const fileArray: string[] = [
path,
];
const out = './.less.cache.json';
await bash('npx', ['lessc', '--depends', config.source, out], {
cwd: workspace,
Expand All @@ -64,7 +64,6 @@ export class LessTask extends Task {
}
});
});
this.print(`${italic(config.source)} Compile files: ${green(fileArray.length)}`);

fileArray.forEach((file) => {
const stat = statSync(file);
Expand All @@ -80,10 +79,16 @@ export class LessTask extends Task {
hasError = true;
}

if (!existsSync(config.dist)) {
changed = true;
}

// 没有变化
if (changed === false) {
this.print(`${italic(config.source)} Cache files: ${yellow(fileArray.length)}`);
continue;
}
this.print(`${italic(config.source)} Compile files: ${green(fileArray.length)}`);

// 实际编译
try {
Expand Down
11 changes: 3 additions & 8 deletions source/internal/remove.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import {
join,
isAbsolute,
relative,
} from 'path';
import {
existsSync,
statSync,
Stats,
copyFileSync,
} from 'fs';
import { rmSync } from 'graceful-fs';
remove,
} from 'fs-extra';

import { italic } from 'chalk';

Expand Down Expand Up @@ -38,7 +33,7 @@ export class RemoveTask extends Task {
this.print(italic(`Remove files in ${source}`));

try {
rmSync(source, { recursive: true, force: true });
await remove(source);
} catch (error) {
const err = error as Error;
this.print(err.message);
Expand Down

0 comments on commit ea68a0e

Please sign in to comment.