/
Dante
/
node-core
Обзор
Документация
Войти
/
Dante
/
node-core
Код
Запросы
0
Задачи
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
node_modules/lib-cmd/src/index.ts
32 строки
883 B
Александр Данилюк
add
24 сен 2024, 12:59
24 сен 2024, 12:59
9eaeea8
Код
Авторство
О чём код?
import EventEmitter from "node:events"; import { exec } from 'node:child_process'; const packageInfo = require('../package.json'); export class Module { private eventBus: EventEmitter; private cmd: string; async onInit(config: {cmd: string}, eventBus: EventEmitter): Promise<void> { this.eventBus = eventBus; this.cmd = config.cmd; } async run(): Promise<void> { this.eventBus.on('writeFileComplete', async (url: string) => { await this.execPromise(this.cmd); }); } async info(): Promise<{name: string, version: string}> { return Promise.resolve({name: packageInfo.name, version: packageInfo.version}); } async execPromise(cmd: string): Promise<string> { return new Promise((resolve, reject) => { exec(cmd, (err, stdout) => { if (err) return reject(err); resolve(stdout); }); }); } }