UNPKG

datainout

Version:

Import and reports data

139 lines (134 loc) 4.71 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); 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/InitializeCommander.ts var InitializeCommander_exports = {}; __export(InitializeCommander_exports, { InitializeCommander: () => InitializeCommander }); module.exports = __toCommonJS(InitializeCommander_exports); // src/commanders/AbstractCommander.ts var AbstractCommander = class { constructor(name, action) { this.sleepTime = 3e3; this.logs = { Trigger: "", Run: "", Complated: "" }; this.name = name; this.action = action; this.logs = { Complated: `Action ${this.name} is completed !!`, Run: `Action ${this.name} is running !!`, Trigger: `Action ${this.name} is waitting ${this.sleepTime}ms. To cancel action, please press Ctrl + C...` }; } sleep() { return new Promise((resolve) => setTimeout(resolve, this.sleepTime)); } wrapAction(...data) { return __async(this, null, function* () { console.log(this.logs.Trigger); yield this.sleep(); console.log(this.logs.Run); yield this.action.handleAction(...data); console.log(this.logs.Complated); }); } }; // src/commanders/command-actions/InitializeAction.ts var path = __toESM(require("path"), 1); var fs = __toESM(require("fs/promises"), 1); 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;` ); } }; // src/commanders/InitializeCommander.ts var InitializeCommander = class extends AbstractCommander { constructor() { super("init", new InitializeAction()); } run(program) { return __async(this, null, function* () { program.command("init").alias("i").option("-t, --type [type]", "Config file extension", "js").description("Initialize the configuration file datainout").allowExcessArguments().action((...args) => __async(this, null, function* () { return yield this.wrapAction(...args); })); }); } }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { InitializeCommander });