datainout
Version:
Import and reports data
103 lines (99 loc) • 2.98 kB
JavaScript
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/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
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;`
);
}
};
// 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);
}));
});
}
};
export {
InitializeCommander
};