UNPKG

@atao60/fse-cli

Version:
76 lines (70 loc) 1.63 kB
import sourceMapSupport from "source-map-support"; sourceMapSupport.install(); import chalk from 'chalk'; const { red } = chalk; import fse from 'fs-extra'; const { ensureFile } = fse; import { env } from 'process'; import * as logger from '../logger.js'; const quietDefault = env.FSE_CLI_QUIET && env.FSE_CLI_QUIET === 'true'; const ensureFileDef = { name: 'ensureFile', spec: { '--quiet': Boolean, '-q': '--quiet' }, 'default': { quiet: quietDefault }, options: args => ({ quiet: args['--quiet'] || ensureFileDef.default.quiet, file: args._[0] }), questions: options => { const questions = []; if (!options.file) { questions.push({ type: 'input', name: 'file', message: "Please fill in the file to create", validate: input => input && input.trim() ? true : "A file path is required" }); } return questions; } }; export const def = ensureFileDef; /** * Wrapper for node-fs-extra ensureFile function. * https://github.com/jprichardson/node-fs-extra/blob/master/docs/ensureFile.md */ export function job({ file, quiet }) { function info(message, ...params) { logger.info(message, { quiet, params }); } function error(message, ...params) { logger.error(message, { quiet, params }); } info(`Checking if existing and, if not, creating file ${file} ...`); ensureFile(file, err => { if (err) { error(`${red.bold('ERROR')} thrown while creating file: `, err); return; } info(`File ${file} exists`); }); } //# sourceMappingURL=ensureFile.js.map