Setting the file. One moment. Domain Knowledge · Rp Target Wix · wix/skills · Skills Docsscripts/domain-knowledge.js
scripts/domain-knowledge.js
JavaScript·100 lines·3 KB
,
13} = require('../lib/domain-knowledge.js');
14
15function usage() {
16 return [
17 'Usage:',
18 ' node scripts/domain-knowledge.js list-domains',
19 ' node scripts/domain-knowledge.js list-entities --domain stores',
20 ' node scripts/domain-knowledge.js read-entity --ref stores/product',
21 ' node scripts/domain-knowledge.js resolve-source --source-system woocommerce --source-entity product',
22 ' node scripts/domain-knowledge.js resolve-source --route /wc/v3/products',
23 ' node scripts/domain-knowledge.js list-flagged --flag IMPORT_UNRELIABLE',
24 ' node scripts/domain-knowledge.js summarize-entities --refs stores/product,ecom/order [--include-evidence]',
25 ].join('\n');
26}
27
28function parseArgs(argv) {
29 const args = { _: [] };
30 for (let i = 0; i < argv.length; i += 1) {
31 const arg = argv[i];
32 if (arg.startsWith('--')) {
33 const key = arg.slice(2).replace(/-([a-z])/g, (_, char) => char.toUpperCase());
34 const next = argv[i + 1];
35 if (!next || next.startsWith('--')) {
36 args[key] = true;
37 } else {
38 args[key] = next;
39 i += 1;
40 }
41 } else {
42 args._.push(arg);
43 }
44 }
45 return args;
46}
47
48function print(value, pretty) {
49 process.stdout.write(`${JSON.stringify(value, null, pretty ? 2 : 0)}\n`);
50}
51
52function main() {
53 const args = parseArgs(process.argv.slice(2));
54 const command = args._[0];
55 const domainsDir = knowledgeRoot(path.resolve(__dirname, '..'));
56
57 if (!command || args.help) {
58 process.stderr.write(`${usage()}\n`);
59 process.exit(command ? 0 : 1);
60 }
61
62 let output;
63 if (command === 'list-domains') {
64 output = { domains: listDomains(domainsDir) };
65 } else if (command === 'list-entities') {
66 if (!args.domain) throw new Error('--domain is required');
67 output = { domain: args.domain, entities: listEntities(domainsDir, args.domain) };
68 } else if (command === 'read-entity') {
69 if (!args.ref) throw new Error('--ref is required');
70 output = readEntityByRef(domainsDir, args.ref);
71 } else if (command === 'resolve-source') {
72 output = {
73 matches: resolveSource(domainsDir, {
74 sourceSystem: args.sourceSystem,
75 sourceEntity: args.sourceEntity,
76 route: args.route,
77 }),
78 };
79 } else if (command === 'list-flagged') {
80 if (!args.flag) throw new Error('--flag is required');
81 output = { flag: args.flag, entities: listFlagged(domainsDir, args.flag) };
82 } else if (command === 'summarize-entities') {
83 if (!args.refs) throw new Error('--refs is required');
84 output = {
85 entities: summarizeEntities(domainsDir, args.refs.split(',').filter(Boolean), {
86 includeEvidence: Boolean(args.includeEvidence),
87 }),
88 };
89 } else {
90 throw new Error(`Unknown command: ${command}\n${usage()}`);
91 }
92 print(output, Boolean(args.pretty));
93}
94
95try {
96 main();
97} catch (error) {
98 process.stderr.write(`${error.message}\n`);
99 process.exit(1);
100}