UNPKG

datainout

Version:

Import and reports data

57 lines (55 loc) 1.57 kB
var __async = (__this, __arguments, generator) => { return new Promise((resolve, reject) => { var fulfilled = (value) => { try { step(generator.next(value)); } catch (e) { reject(e); } }; var rejected = (value) => { try { step(generator.throw(value)); } catch (e) { reject(e); } }; var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected); step((generator = generator.apply(__this, __arguments)).next()); }); }; // src/commanders/command-actions/InitializeAction.ts import * as path from "path"; import * as fs from "fs/promises"; var InitializeAction = class { handleAction(data) { return __async(this, null, function* () { if ((data == null ? void 0 : data.type) === "js") this.genJsFile(); else if ((data == null ? void 0 : data.type) === "ts") this.genTsFile(); else throw new Error(`File extension ${data == null ? void 0 : data.type} is not supports.`); }); } genJsFile() { const _path = path.join(process.cwd(), "datainout.config.js"); fs.writeFile( _path, `/** @type {import("datainout").DataInoutConfigOptions} */ module.exports = { templateExtension: ".js", };` ); } genTsFile() { const _path = path.join(process.cwd(), "datainout.config.ts"); fs.writeFile( _path, `import { DataInoutConfigOptions } from 'datainout/types' export default { templateExtension: ".ts", } as DataInoutConfigOptions;` ); } }; export { InitializeAction };