2024-06-27 09:58:24 -07:00
|
|
|
// @ts-check
|
|
|
|
|
const path = require('path');
|
|
|
|
|
|
|
|
|
|
const { samples, lspSamples } = require('./samples');
|
|
|
|
|
const fs = require('fs');
|
|
|
|
|
|
|
|
|
|
const root = path.join(__dirname, '..');
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
throw new Error(`Sample '${fileName}' is not listed in samples.js`);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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();
|