2022-11-23 07:20:28 -08:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
2024-12-10 05:48:39 -08:00
|
|
|
const { LoggerProxy } = require('n8n-workflow');
|
2022-11-23 07:20:28 -08:00
|
|
|
const { PackageDirectoryLoader } = require('../dist/DirectoryLoader');
|
|
|
|
const { packageDir, writeJSON } = require('./common');
|
|
|
|
|
2023-10-20 09:26:33 -07:00
|
|
|
LoggerProxy.init(console);
|
2022-11-23 07:20:28 -08:00
|
|
|
|
2023-04-12 06:46:11 -07:00
|
|
|
function findReferencedMethods(obj, refs = {}, latestName = '') {
|
|
|
|
for (const key in obj) {
|
|
|
|
if (key === 'name' && 'group' in obj) {
|
|
|
|
latestName = obj[key];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof obj[key] === 'object') {
|
|
|
|
findReferencedMethods(obj[key], refs, latestName);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (key === 'loadOptionsMethod') {
|
|
|
|
refs[latestName] = refs[latestName]
|
|
|
|
? [...new Set([...refs[latestName], obj[key]])]
|
|
|
|
: [obj[key]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return refs;
|
|
|
|
}
|
|
|
|
|
2022-11-23 07:20:28 -08:00
|
|
|
(async () => {
|
|
|
|
const loader = new PackageDirectoryLoader(packageDir);
|
2023-04-20 07:21:07 -07:00
|
|
|
await loader.loadAll();
|
2022-11-23 07:20:28 -08:00
|
|
|
|
2023-04-12 06:46:11 -07:00
|
|
|
const loaderNodeTypes = Object.values(loader.nodeTypes);
|
|
|
|
|
|
|
|
const definedMethods = loaderNodeTypes.reduce((acc, cur) => {
|
2024-12-10 05:48:39 -08:00
|
|
|
loader.getVersionedNodeTypeAll(cur.type).forEach((type) => {
|
2023-04-12 06:46:11 -07:00
|
|
|
const methods = type.description?.__loadOptionsMethods;
|
|
|
|
|
|
|
|
if (!methods) return;
|
|
|
|
|
|
|
|
const { name } = type.description;
|
|
|
|
|
2023-04-20 07:21:07 -07:00
|
|
|
if (acc[name]) {
|
|
|
|
acc[name] = [...new Set([...acc[name], ...methods])];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
acc[name] = methods;
|
2023-04-12 06:46:11 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
return acc;
|
|
|
|
}, {});
|
|
|
|
|
|
|
|
const nodeTypes = loaderNodeTypes
|
2024-12-10 05:48:39 -08:00
|
|
|
.map(({ type }) => type)
|
2023-11-13 03:11:16 -08:00
|
|
|
.flatMap((nodeType) =>
|
2024-12-10 05:48:39 -08:00
|
|
|
loader.getVersionedNodeTypeAll(nodeType).map((item) => {
|
2023-04-12 06:46:11 -07:00
|
|
|
const { __loadOptionsMethods, ...rest } = item.description;
|
|
|
|
return rest;
|
2023-11-13 03:11:16 -08:00
|
|
|
}),
|
|
|
|
);
|
2022-11-23 07:20:28 -08:00
|
|
|
|
2024-09-27 03:04:00 -07:00
|
|
|
const knownCredentials = loader.known.credentials;
|
2024-12-10 05:48:39 -08:00
|
|
|
const credentialTypes = Object.values(loader.credentialTypes).map(({ type }) => type);
|
2023-04-12 06:46:11 -07:00
|
|
|
const referencedMethods = findReferencedMethods(nodeTypes);
|
|
|
|
|
2022-11-23 07:20:28 -08:00
|
|
|
await Promise.all([
|
2024-12-10 05:48:39 -08:00
|
|
|
writeJSON('known/nodes.json', loader.known.nodes),
|
|
|
|
writeJSON('known/credentials.json', loader.known.credentials),
|
2022-11-23 07:20:28 -08:00
|
|
|
writeJSON('types/credentials.json', credentialTypes),
|
|
|
|
writeJSON('types/nodes.json', nodeTypes),
|
2023-04-12 06:46:11 -07:00
|
|
|
writeJSON('methods/defined.json', definedMethods),
|
|
|
|
writeJSON('methods/referenced.json', referencedMethods),
|
2022-11-23 07:20:28 -08:00
|
|
|
]);
|
|
|
|
})();
|