UNPKG

firescript

Version:
29 lines (24 loc) 869 B
const fs = require('fs') const path = require('path') const Firescript = require('../src/app') module.exports = (fireio) => { return fireio .cmd('mkastfile <slug> [outfile]') .description('Creates an AST file from <input>') .option('-c, --allow-comments', 'Allow comments') .action((ctx, slug, outfile) => { let inFile = 'index.js' if (/\.js/.test(slug)) { inFile = path.basename(slug) slug = path.dirname(slug) } const srcPath = path.join(__dirname, '../', slug, inFile) const astPath = path.join(__dirname, '../', slug, outfile || 'ast.json') const jsSource = fs.readFileSync(srcPath, { encoding: 'utf8' }) const ast = Firescript.parse(jsSource, { type: 'js', comments: ctx.allowComments }) fs.writeFileSync(astPath, JSON.stringify(ast, null, ' ')) }) }