UNPKG

zaincode_terminal

Version:

A Git-like Node.js terminal tool that provides an interactive CLI experience with support for custom commands, colors, and automation. Built with chalk, axios, and node-pty for developers who want a modern, lightweight, and powerful command-line utility.

34 lines (27 loc) 866 B
import cmdEvents from '../cmdEventEmitter.js' import { dirname, join } from 'path' import fs from 'fs/promises' import { fileURLToPath } from 'url' const __filename = fileURLToPath(import.meta.url) const __dirname = dirname(__filename) cmdEvents.on('checkType', async (name, resolve, reject) => { const fullPath = join(__dirname, '../', name) try { const state = await fs.stat(fullPath) if (state.isDirectory()) { resolve('dir') } else if (state.isFile()) { resolve('file') } else { reject(new Error(`${name} is neither file nor directory`)) } } catch (error) { reject(new Error(`Error: ${name} does not exist`)) } }) const CheckType = name => { return new Promise((resolve, reject) => { cmdEvents.emit('checkType', name, resolve, reject) }) } export default CheckType