Export handwritten integrations consistently
This commit is contained in:
@@ -29,6 +29,15 @@ const isGeneratedFolder = async (folderUrl) => {
|
||||
}
|
||||
};
|
||||
|
||||
const fileExists = async (fileUrl) => {
|
||||
try {
|
||||
await stat(fileUrl);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
const json = (value) => JSON.stringify(value, null, 2);
|
||||
|
||||
await mkdir(integrationsRoot, { recursive: true });
|
||||
@@ -116,4 +125,28 @@ await writeFile(
|
||||
`// Generated by scripts/generate-homeassistant-ports.mjs. Do not edit manually.\n\nimport type { BaseIntegration } from '../../core/classes.baseintegration.js';\n${imports}\n\nexport const generatedHomeAssistantPortIntegrations: BaseIntegration[] = [];\n${constructorPushes}\n\nexport const generatedHomeAssistantPortCount = ${ports.filter((port) => !port.handwritten).length};\nexport const handwrittenHomeAssistantPortDomains = ${json(ports.filter((port) => port.handwritten).map((port) => port.domain))};\n`
|
||||
);
|
||||
|
||||
const handwrittenFolders = [];
|
||||
for (const entry of await readdir(integrationsRoot, { withFileTypes: true })) {
|
||||
if (!entry.isDirectory()) continue;
|
||||
if (entry.name === 'generated') continue;
|
||||
|
||||
const folderUrl = new URL(`./${entry.name}/`, integrationsRoot);
|
||||
if (await isGeneratedFolder(folderUrl)) continue;
|
||||
if (!(await fileExists(new URL('index.ts', folderUrl)))) continue;
|
||||
|
||||
handwrittenFolders.push(entry.name);
|
||||
}
|
||||
|
||||
handwrittenFolders.sort((a, b) => a.localeCompare(b));
|
||||
|
||||
await writeFile(
|
||||
new URL('index.ts', integrationsRoot),
|
||||
[
|
||||
'// Generated by scripts/generate-homeassistant-ports.mjs. Do not edit manually.',
|
||||
"export * from './generated/index.js';",
|
||||
...handwrittenFolders.map((folderName) => `export * from './${folderName}/index.js';`),
|
||||
'',
|
||||
].join('\n')
|
||||
);
|
||||
|
||||
console.log(`Generated ${ports.filter((port) => !port.handwritten).length} native TypeScript port skeletons. Preserved ${ports.filter((port) => port.handwritten).length} handwritten folders.`);
|
||||
|
||||
Reference in New Issue
Block a user