UNPKG

@qigy/run

Version:

A collection of tools capable of executing complex commands through their abbreviation.

76 lines (73 loc) 2.22 kB
const { path, Table, chalk, figlet } = require('./libs'); class Item { alias = ''; command = ''; remark = ''; constructor(alias = '', command = '', remark = '') { this.alias = alias; this.command = command; this.remark = remark; } } class Result { success = true; code = 200; data = null; msg = ''; constructor(success = true, data = null, msg = '', code = 200) { this.data = data; this.success = success; this.code = code; this.msg = msg; } } const red = (str) => chalk.red(str); const green = (str) => chalk.green(str); const outputTable = (raw = []) => { if (!raw.length) return console.error(red('No The current keyword has no matching data!')); const table = new Table({ style: { padding: '16px' }, head: ['Alias', 'Command', 'Remark'] }); table.push(...raw.map((it) => [it.alias, it.command, it.remark])); console.log(table.toString()); }; module.exports = { Item, Result, isUnix: () => ['darwin', 'linux'].includes(process.platform), includesPro: (raw = '', keyword = '') => String(raw).toLowerCase().includes(String(keyword).toLowerCase()), ulid: () => Math.random().toString(36).substring(2, 9), configPath: path.join(__dirname, '/config.json'), batPath: path.join(__dirname, '/tmp.bat'), uiPath: path.join(__dirname, '../'), multipartConfig: { limits: { fieldNameSize: 100, fieldSize: 100, fields: 10, fileSize: 1000000, files: 1, headerPairs: 2000 } }, staticConfig: { root: path.join(__dirname, '../public'), etag: false, lastModified: false, maxAge: 0, cacheControl: true, setHeaders: (res) => { res.setHeader('Cache-Control', 'no-store, no-cache, max-age=0, must-revalidate'); } }, corsConfig: { origin: '*', methods: ['GET', 'POST'] }, rateLimitConfig: { max: 100, timeWindow: '1 minute' }, port: 7000, red, green, yellow: (str) => chalk.yellow(str), helper: async (result, isGet = false) => { const { success, data, msg } = await result; if (!success) return console.error(red(msg)); isGet ? outputTable(data) : console.log(green(msg)); }, welcome: () => figlet.textSync('run', { font: 'ANSI Regular' }) };