Skip to content

Commit

Permalink
fix: 修复在windows系统下命令的错误
Browse files Browse the repository at this point in the history
  • Loading branch information
duan602728596 committed Dec 2, 2024
1 parent 87cb48f commit e62b407
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
10 changes: 8 additions & 2 deletions scripts/installPlugins.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import os from 'node:os';
import { spawn } from 'node:child_process';
import { cwd, npm } from './utils.mjs';

const isWindows = os.platform() === 'win32';

/* 修复window下bash的错误 */
if (os.platform() === 'win32') {
if (isWindows) {
$.quote = function(arg) {
if (/^[a-z\d/_.-]+$/i.test(arg) || arg === '') {
return arg;
Expand All @@ -24,7 +26,11 @@ if (os.platform() === 'win32') {
/* 执行命令 */
function $cmd(cmd, args) {
return new Promise((resolve, reject) => {
const child = spawn(cmd, args);
const spawnOptions = {};

if (isWindows) spawnOptions.shell = true;

const child = spawn(cmd, args, spawnOptions);

child.stdout.on('data', (data) => console.log(data.toString()));
child.stderr.on('data', (data) => console.log(data.toString()));
Expand Down
8 changes: 6 additions & 2 deletions scripts/utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,14 @@ export const isArm64 = process.arch === 'arm64';
*/
export function command(cmd, args, cwdPath) {
return new Promise((resolve, reject) => {
const child = spawn(cmd, args, {
const spawnOptions = {
stdio: 'inherit',
cwd: cwdPath
});
};

if (isWindows) spawnOptions.shell = true;

const child = spawn(cmd, args, spawnOptions);

child.on('close', function(code) {
resolve();
Expand Down

0 comments on commit e62b407

Please sign in to comment.