From 7789d15e0a8f67e3fc2604800fb52757d4cd0cc0 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Fri, 31 May 2019 11:49:59 -0700 Subject: [PATCH] Add install all script --- .scripts/run-install.js | 26 ++++++++++++++++++++++++++ .scripts/run-script.js | 5 +++-- package.json | 1 + 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 .scripts/run-install.js diff --git a/.scripts/run-install.js b/.scripts/run-install.js new file mode 100644 index 00000000..7369bdd6 --- /dev/null +++ b/.scripts/run-install.js @@ -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); +} \ No newline at end of file diff --git a/.scripts/run-script.js b/.scripts/run-script.js index 895581e9..c216e874 100644 --- a/.scripts/run-script.js +++ b/.scripts/run-script.js @@ -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); } \ No newline at end of file diff --git a/package.json b/package.json index cba72493..cd5f44b2 100644 --- a/package.json +++ b/package.json @@ -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" }