({projectRoot, log = console.log, exec = execFileAsync})
| 527 | * @returns {Promise<'already-installed'|'installed'>} Action taken. |
| 528 | */ |
| 529 | export async function installDependencies({projectRoot, log = console.log, exec = execFileAsync}) { |
| 530 | const nodeModulesPath = path.join(projectRoot, 'node_modules'); |
| 531 | let action; |
| 532 | |
| 533 | if (await exists(nodeModulesPath)) { |
| 534 | log(`install skip (exists): node_modules`); |
| 535 | action = 'already-installed'; |
| 536 | } else { |
| 537 | log(`installing dependencies (npm install)...`); |
| 538 | const start = Date.now(); |
| 539 | await exec('npm', ['install'], {cwd: projectRoot}); |
| 540 | log(`installed dependencies in ${Math.round((Date.now() - start) / 1000)}s`); |
| 541 | action = 'installed'; |
| 542 | } |
| 543 | |
| 544 | log(`bundling parse5 (test-runner prerequisite)...`); |
| 545 | const bundleStart = Date.now(); |
| 546 | await exec('npm', ['run', 'bundle-parse5'], {cwd: projectRoot}); |
| 547 | log(`bundled parse5 in ${Math.round((Date.now() - bundleStart) / 1000)}s`); |
| 548 | |
| 549 | return action; |
| 550 | } |
| 551 | |
| 552 | /** |
| 553 | * @summary Runs the full `npm run build-all` after ensuring dependencies are installed. |
no test coverage detected