修复mac和linux兼容性

This commit is contained in:
whyour
2022-06-26 18:59:39 +08:00
parent 28ea160004
commit e85742a293
5 changed files with 95 additions and 21 deletions
+13
View File
@@ -2,6 +2,7 @@ import * as fs from 'fs';
import * as path from 'path';
import got from 'got';
import iconv from 'iconv-lite';
import { exec } from 'child_process';
export function getFileContentByName(fileName: string) {
if (fs.existsSync(fileName)) {
@@ -332,3 +333,15 @@ export function readDir(
});
return result;
}
export function promiseExec(command: string): Promise<string> {
return new Promise((resolve, reject) => {
exec(
command,
{ maxBuffer: 200 * 1024 * 1024, encoding: 'utf8' },
(err, stdout, stderr) => {
resolve(stdout || stderr || JSON.stringify(err));
},
);
});
}
+26
View File
@@ -2,6 +2,7 @@ import path from 'path';
import fs from 'fs';
import chokidar from 'chokidar';
import config from '../config/index';
import { promiseExec } from '../config/util';
function linkToNodeModule(src: string, dst?: string) {
const target = path.join(config.rootPath, 'node_modules', dst || src);
@@ -16,7 +17,32 @@ function linkToNodeModule(src: string, dst?: string) {
});
}
async function linkCommand() {
const commandPath = await promiseExec('which node');
const commandDir = path.dirname(commandPath);
const linkShell = [
{
src: 'update.sh',
dest: 'ql',
},
{
src: 'task.sh',
dest: 'task',
},
];
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) => {});
}
}
export default async (src: string = 'deps') => {
await linkCommand();
linkToNodeModule(src);
const source = path.join(config.rootPath, src);