2024-10-28 16:41:49 -07:00
|
|
|
import * as fs from 'fs';
|
|
|
|
|
import * as path from 'path';
|
|
|
|
|
import { lspSamples, samples } from './samples';
|
2024-06-27 09:58:24 -07:00
|
|
|
|
|
|
|
|
const root = path.join(__dirname, '..');
|
2024-10-28 16:41:49 -07:00
|
|
|
console.log(root);
|
2024-06-27 09:58:24 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Validates that all samples are correctly listed in `.scripts/samples.js`.
|
|
|
|
|
*/
|
|
|
|
|
function validateSamplesAreListed() {
|
|
|
|
|
const allSamples = samples.concat(lspSamples);
|
|
|
|
|
|
|
|
|
|
const samplesByPath = new Map();
|
|
|
|
|
for (const sample of allSamples) {
|
|
|
|
|
samplesByPath.set(sample.path, sample);
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-24 15:56:19 -07:00
|
|
|
|
|
|
|
|
const errors: Error[] = [];
|
|
|
|
|
|
2024-06-27 09:58:24 -07:00
|
|
|
for (const fileName of fs.readdirSync(root)) {
|
2024-10-26 17:44:03 -07:00
|
|
|
if (fileName === 'node_modules'
|
|
|
|
|
|| fileName.startsWith('.')
|
|
|
|
|
|| !fs.lstatSync(path.join(root, fileName)).isDirectory()
|
|
|
|
|
) {
|
2024-06-27 09:58:24 -07:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const sampleEntry = samplesByPath.get(fileName);
|
|
|
|
|
if (!sampleEntry) {
|
2025-07-24 15:56:19 -07:00
|
|
|
errors.push(new Error(`Sample '${fileName}' is not listed in samples.js`));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (errors.length > 0) {
|
|
|
|
|
if (errors.length === 1) {
|
|
|
|
|
throw errors[0];
|
|
|
|
|
} else {
|
|
|
|
|
throw new AggregateError(errors, 'Multiple samples are not listed in samples.js');
|
2024-06-27 09:58:24 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Validates that all samples are correctly listed in `.scripts/samples.js`.
|
|
|
|
|
*/
|
|
|
|
|
function validateReadmeUpdated() {
|
|
|
|
|
const { updateReadme } = require('./update-readme');
|
|
|
|
|
if (updateReadme(true)) {
|
|
|
|
|
throw new Error(`Readme not updated. Run 'node .scripts/update-readme.js' to update the readme.`);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
validateSamplesAreListed();
|
|
|
|
|
validateReadmeUpdated();
|