UNPKG

@daiyu-5577/quickbuild

Version:

front-end build service

55 lines (54 loc) 1.96 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import { exec, spawn } from 'child_process'; import { promisify } from 'util'; import { constants } from 'node:fs'; import fs from 'node:fs/promises'; export const execPms = promisify(exec); export function spawnPms(command, args, options) { return new Promise((resolve, reject) => { const { onMessage } = options; const child = spawn(command, args, options); child.stdout.on('data', (data) => { const msg = data.toString(); if (!!onMessage) { onMessage(msg); return; } console.log(msg); }); child.stderr.on('data', (data) => { const msg = data.toString(); if (!!onMessage) { onMessage(msg); return; } console.log(msg); }); child.on('close', (code) => { if (code === 0) { resolve(code); } else { reject(code); } }); }); } export const checkMakeDir = (dir) => __awaiter(void 0, void 0, void 0, function* () { try { yield fs.access(dir, constants.F_OK); } catch (error) { yield fs.mkdir(dir, { recursive: true }); } });