UNPKG

@atao60/fse-cli

Version:
56 lines (51 loc) 1.63 kB
import sourceMapSupport from "source-map-support"; sourceMapSupport.install(); import chalk from 'chalk'; import fse from 'fs-extra'; const { existsSync, readFileSync } = fse; import { dirname, join } from 'path'; import terminalLink from 'terminal-link'; import { fileURLToPath } from 'url'; import { job as version } from './version.js'; import { info } from '../logger.js'; const __dirname = dirname(fileURLToPath(import.meta.url)); const versionDef = { name: 'help', spec: {}, 'default': {}, options: _ => ({}), questions: _ => [] }; export const def = versionDef; export function job() { version(); info(''); showHelp(); } function showHelp() { const manualPath = join(__dirname, '../../USAGE'); if (!existsSync(manualPath)) { throw new Error(`Unable to find the usage file: ${manualPath}`); } const content = readFileSync(manualPath, { encoding: 'utf8' }); const usage = content.replace(/^(.*)$/m, m => { return chalk.bold(m); }).replace(/(?<!`)`([^`]+)`(?!`)/gm, '%%%yellow:$1%%%').replace(/(?<!\*)\*{3}([^*]+)\*{3}(?!\*)/gm, '%%%bold.italic:$1%%%').replace(/%%%([A-Za-z.]*):(.*?)%%%/gm, (_match, property, value, _offset, _source) => { // styles provided with first parameter are taken in account as it const styles = property.split('.'); const styling = styles.reduce((o, i) => { return o[i]; }, chalk); return styling(value); }).replace(/(?<!\[)\[(.*?)\]\((.*?)\)/gm, (_match, title, url, _offset, _source) => { const link = terminalLink(title, url); return chalk.blue(link); }); info(usage); } //# sourceMappingURL=help.js.map