fs 文件操作替换为 fs.promise

This commit is contained in:
whyour
2023-11-01 16:44:34 +08:00
parent 66a2769e7c
commit 20f615eadf
17 changed files with 284 additions and 260 deletions
+10 -15
View File
@@ -1,20 +1,17 @@
import path from 'path';
import fs from 'fs';
import fs from 'fs/promises';
import chokidar from 'chokidar';
import config from '../config/index';
import { promiseExec } from '../config/util';
import { fileExist, promiseExec, rmPath } from '../config/util';
function linkToNodeModule(src: string, dst?: string) {
async function linkToNodeModule(src: string, dst?: string) {
const target = path.join(config.rootPath, 'node_modules', dst || src);
const source = path.join(config.rootPath, src);
fs.lstat(target, (err, stat) => {
if (!stat) {
fs.symlink(source, target, 'dir', (err) => {
if (err) throw err;
});
}
});
const _exist = await fileExist(target);
if (!_exist) {
await fs.symlink(source, target, 'dir');
}
}
async function linkCommand() {
@@ -34,16 +31,14 @@ async function linkCommand() {
for (const link of linkShell) {
const source = path.join(config.rootPath, 'shell', link.src);
const target = path.join(commandDir, link.dest);
if (fs.existsSync(target)) {
fs.unlinkSync(target);
}
fs.symlink(source, target, (err) => { });
await rmPath(target);
await fs.symlink(source, target);
}
}
export default async (src: string = 'deps') => {
await linkCommand();
linkToNodeModule(src);
await linkToNodeModule(src);
const source = path.join(config.rootPath, src);
const watcher = chokidar.watch(source, {