1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-06-27 01:19:00 +02:00
unleash.unleash/.husky/update-openapi-spec-list.js
Gastón Fournier abe160eb7d
feat: Unleash v7 ESM migration (#9877)
We're migrating to ESM, which will allow us to import the latest
versions of our dependencies.

Co-Authored-By: Christopher Kolstad <chriswk@getunleash.io>
2025-05-14 09:47:12 +02:00

35 lines
1.3 KiB
JavaScript

import { readdir, writeFileSync } from 'node:fs';
import { join, basename, dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const directoryPath = join(`${__dirname}/..`, 'src/lib/openapi/spec');
const indexPath = join(directoryPath, 'index.ts');
// Read files from the directory
readdir(directoryPath, (err, files) => {
if (err) {
console.error('Could not list the directory.', err);
process.exit(1);
}
const exports = files
.filter((file) => file.includes('schema.ts')) // Filter files by 'schema.ts'
.map((file) => `export * from './${file.replace('.ts', '.js')}';`) // Create export statements
.join('\n');
// Append export statements to index.ts
const script = basename(__filename);
const message = `/**
* Auto-generated file by ${script}. Do not edit.
* To run it manually execute \`yarn schema:update\` or \`node ${basename(__dirname)}/${script}\`
*/\n`;
writeFileSync(indexPath, `${message}${exports}\n${message}`, (err) => {
if (err) {
console.error('Could not append to file.', err);
process.exit(1);
}
console.log('Export statements added to index.ts successfully.');
});
});