Files
vscode-extension-samples/.scripts/run-command.ts
Matt Bierner 1a3ac0c722 Switch internal scripts to ts
Also adds a formatting script and runs it against all TS files in the samples
2024-10-28 16:41:49 -07:00

34 lines
950 B
TypeScript

// @ts-check
/**
* Try running install for all the samples
*/
import * as child_process from 'child_process';
import * as fs from 'fs';
import * as path from 'path';
import { lspSamples, Sample, samples } from './samples';
async function tryRunCommand(command: string, sample: Sample) {
const packageJsonPath = path.join(sample.path, 'package.json');
if (fs.existsSync(packageJsonPath)) {
try {
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath).toString());
if (packageJson['devDependencies'] || packageJson['dependencies']) {
console.log(`=== Running ${command} on ${path.basename(sample.path)} ===`);
child_process.execSync(command, {
cwd: sample.path,
stdio: 'inherit'
});
}
} catch (e) {
console.error(e);
}
}
}
if (require.main === module) {
const command = process.argv.slice(2).join(' ');
for (const sample of [...samples, ...lspSamples]) {
tryRunCommand(command, sample);
}
}