Add install all script

This commit is contained in:
Matt Bierner
2019-05-31 11:49:59 -07:00
parent d835433d33
commit 7789d15e0a
3 changed files with 30 additions and 2 deletions

26
.scripts/run-install.js Normal file
View File

@ -0,0 +1,26 @@
// @ts-check
/**
* Try running install for all the samples
*/
const fs = require('fs');
const path = require('path');
const child_process = require('child_process');
const { samples, lspSamples } = require('./samples')
async function tryRunInstall(
/** @type {import('./samples').Sample} */ sample
) {
const packageJsonPath = path.join(sample.path, 'package.json');
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath).toString());
if (packageJson['devDependencies'] || packageJson['dependencies']) {
console.log(`=== Running install on ${path.basename(sample.path)} ===`)
child_process.execSync(`npm install`, {
cwd: sample.path,
stdio: 'inherit'
});
}
}
for (const sample of [...samples, ...lspSamples]) {
tryRunInstall(sample);
}

View File

@ -1,3 +1,4 @@
// @ts-check
/**
* Try running an npm script for each of the samples.
*/
@ -6,7 +7,7 @@ const path = require('path');
const child_process = require('child_process');
const { samples, lspSamples } = require('./samples')
async function tryLint(
async function tryRun(
/** @type {string} */ scriptName,
/** @type {import('./samples').Sample} */ sample
) {
@ -23,5 +24,5 @@ async function tryLint(
const scriptName = process.argv[2];
for (const sample of [...samples, ...lspSamples]) {
tryLint(scriptName, sample);
tryRun(scriptName, sample);
}

View File

@ -4,6 +4,7 @@
"version": "0.0.1",
"scripts": {
"compile": "node .scripts/run-script.js compile",
"install": "node .scripts/run-install.js",
"lint": "node .scripts/run-script.js lint",
"update-readme": "node .scripts/update-readme.js"
}