fix to not import multiple times

This commit is contained in:
zongor 2024-05-27 19:13:13 -04:00
parent af15775e5e
commit ad00791462
1 changed files with 12 additions and 6 deletions

View File

@ -51,12 +51,12 @@ const { values } = parseArgs({
short: "S", short: "S",
}, },
jsout: { jsout: {
type: "string", type: "string",
short: "j" short: "j",
}, },
cout: { cout: {
type: "string", type: "string",
short: "c" short: "c",
}, },
}, },
strict: true, strict: true,
@ -146,7 +146,10 @@ for (const type of Object.keys(schema)) {
set ${prop}(v) { set ${prop}(v) {
this._data.set(v.bytes(), ${offset}); this._data.set(v.bytes(), ${offset});
}`; }`;
importStatements += `import ${propType} from "./${propType}"\n\n`; const importS = `import ${propType} from "./${propType}"\n\n`;
if (!importStatements.includes(importS)) {
importStatements += importS;
}
cData += `\n\t\t${types[propType].c} ${prop};`; cData += `\n\t\t${types[propType].c} ${prop};`;
break; break;
@ -179,6 +182,9 @@ export default ${type}`;
`; `;
await Bun.write(Bun.file(values.jsout + type + ".js"), (importStatements + jsData)); await Bun.write(
Bun.file(values.jsout + type + ".js"),
importStatements + jsData
);
} }
await Bun.write(Bun.file(values.cout + "types.h"), cData); await Bun.write(Bun.file(values.cout + "types.h"), cData);