Refactor metamigo-common
This commit is contained in:
parent
cae0071851
commit
b3d8c3918e
32 changed files with 5 additions and 14 deletions
41
packages/metamigo-common/src/config/print.ts
Normal file
41
packages/metamigo-common/src/config/print.ts
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
import chalk from "chalk";
|
||||
import convict from "convict";
|
||||
|
||||
const visitLeaf = (path: any, key: any, leaf: any) => {
|
||||
if (leaf.skipGenerate) {
|
||||
return;
|
||||
}
|
||||
|
||||
let name = `${path}.${key}`;
|
||||
if (path.length === 0) name = key;
|
||||
console.log(chalk.green(name));
|
||||
console.log(leaf.doc);
|
||||
if (leaf.default === undefined) {
|
||||
console.log(chalk.red("\t required"));
|
||||
} else {
|
||||
console.log(`\tdefault: ${JSON.stringify(leaf.default)}`);
|
||||
}
|
||||
|
||||
console.log(`\tformat: ${leaf.format}`);
|
||||
console.log(`\tenv: ${leaf.env}`);
|
||||
};
|
||||
|
||||
const visitNode = (path: any, node: any, key = "") => {
|
||||
if (node._cvtProperties) {
|
||||
const keys = Object.keys(node._cvtProperties);
|
||||
const subpath = key === "" ? path : `${key}`;
|
||||
|
||||
keys.forEach((key) => {
|
||||
visitNode(subpath, node._cvtProperties[key], key);
|
||||
});
|
||||
console.log();
|
||||
} else {
|
||||
visitLeaf(path, key, node);
|
||||
}
|
||||
};
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
export const printConfigOptions = (conf: convict.Config<any>): void => {
|
||||
const schema = conf.getSchema();
|
||||
visitNode("", schema);
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue