mirror of
https://github.com/withastro/astro.git
synced 2024-12-23 21:53:55 -05:00
7b4f284020
* feat(toolbar): Add a `astro:toolbar` module * fix: use entrypoint * feat: add new shape for defining toolbar apps * fix: types * feat(toolbar): Add helpers features (#10667) * feat(toolbar): Add helpers features * fix: consistent payloads and naming * chore: changeset * nit: rename eventTarget to app * feat: add server-side helpers * test: update test to use new APIs * fix: types * nit: erikaaaaa * feat: add new event * Update .changeset/khaki-pianos-burn.md * test: use data to create text * Apply suggestions from code review Co-authored-by: Florian Lefebvre <contact@florian-lefebvre.dev> * nit: use diff * nit: documentation effort * test: fix --------- Co-authored-by: Florian Lefebvre <contact@florian-lefebvre.dev> * nit: small changes to helpers * nit: update changeset * fix: move to astro/toolbar for building purposes * feat(toolbar): Add a toolbar example (#10793) * feat: add a toolbar starter * test: skip examples that are not Astro projects * nit: small changes * feat: setup for build step * fix: add to devdep * docs: add commands to README * fix: reorder classes to make more sense * fix: add improvements from recipe * Apply suggestions from code review Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> --------- Co-authored-by: Florian Lefebvre <contact@florian-lefebvre.dev> Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
105 lines
3 KiB
JavaScript
105 lines
3 KiB
JavaScript
// @ts-check
|
|
|
|
import { spawn } from 'node:child_process';
|
|
import { existsSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
import * as path from 'node:path';
|
|
import pLimit from 'p-limit';
|
|
import { tsconfigResolverSync } from 'tsconfig-resolver';
|
|
|
|
const skippedExamples = ['toolbar-app', 'component']
|
|
|
|
function checkExamples() {
|
|
let examples = readdirSync('./examples', { withFileTypes: true });
|
|
examples = examples.filter((dirent) => dirent.isDirectory()).filter((dirent) => !skippedExamples.includes(dirent.name));
|
|
|
|
console.log(`Running astro check on ${examples.length} examples...`);
|
|
|
|
// Run astro check in parallel with 5 at most
|
|
const checkPromises = [];
|
|
const limit = pLimit(5);
|
|
|
|
for (const example of examples) {
|
|
checkPromises.push(
|
|
limit(
|
|
() =>
|
|
new Promise((resolve) => {
|
|
// Sometimes some examples may get deleted, but after a `git pull` the directory still exists.
|
|
// This can stall the process time as it'll typecheck the entire monorepo, so do a quick exist
|
|
// check here before typechecking this directory.
|
|
if (!existsSync(path.join('./examples/', example.name, 'package.json'))) {
|
|
resolve(0);
|
|
return;
|
|
}
|
|
|
|
const originalConfig = prepareExample(example.name);
|
|
let data = '';
|
|
const child = spawn('node', ['../../packages/astro/astro.js', 'check'], {
|
|
cwd: path.join('./examples', example.name),
|
|
env: { ...process.env, FORCE_COLOR: 'true' },
|
|
});
|
|
|
|
child.stdout.on('data', function (buffer) {
|
|
data += buffer.toString();
|
|
});
|
|
|
|
child.on('exit', (code) => {
|
|
if (code !== 0) {
|
|
console.error(data);
|
|
}
|
|
if (originalConfig) {
|
|
resetExample(example.name, originalConfig);
|
|
}
|
|
resolve(code);
|
|
});
|
|
})
|
|
)
|
|
);
|
|
}
|
|
|
|
Promise.all(checkPromises).then((codes) => {
|
|
if (codes.some((code) => code !== 0)) {
|
|
process.exit(1);
|
|
}
|
|
|
|
console.log('No errors found!');
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @param {string} examplePath
|
|
*/
|
|
function prepareExample(examplePath) {
|
|
const tsconfigPath = path.join('./examples/', examplePath, 'tsconfig.json');
|
|
const tsconfig = tsconfigResolverSync({ filePath: tsconfigPath, cache: false });
|
|
let originalConfig = undefined;
|
|
|
|
if (tsconfig.exists) {
|
|
tsconfig.config.extends = 'astro/tsconfigs/strictest';
|
|
originalConfig = readFileSync(tsconfigPath).toString();
|
|
|
|
if (!tsconfig.config.compilerOptions) {
|
|
tsconfig.config.compilerOptions = {};
|
|
}
|
|
|
|
tsconfig.config.compilerOptions = Object.assign(tsconfig.config.compilerOptions, {
|
|
types: tsconfig.config.compilerOptions.types ?? [], // Speeds up tests
|
|
});
|
|
}
|
|
|
|
if (tsconfig.config) {
|
|
writeFileSync(tsconfigPath, JSON.stringify(tsconfig.config));
|
|
}
|
|
|
|
return originalConfig;
|
|
}
|
|
|
|
/**
|
|
* @param {string} examplePath
|
|
* @param {string} originalConfig
|
|
*/
|
|
function resetExample(examplePath, originalConfig) {
|
|
const tsconfigPath = path.join('./examples/', examplePath, 'tsconfig.json');
|
|
writeFileSync(tsconfigPath, originalConfig);
|
|
}
|
|
|
|
checkExamples();
|