| 344 | description = 'install package.json dependencies using npm' |
| 345 | |
| 346 | def run(self): |
| 347 | if skip_npm: |
| 348 | log.info('Skipping npm-installation') |
| 349 | return |
| 350 | node_package = path or HERE |
| 351 | node_modules = pjoin(node_package, 'node_modules') |
| 352 | is_yarn = os.path.exists(pjoin(node_package, 'yarn.lock')) |
| 353 | |
| 354 | npm_cmd = npm |
| 355 | |
| 356 | if npm is None: |
| 357 | if is_yarn: |
| 358 | npm_cmd = ['yarn'] |
| 359 | else: |
| 360 | npm_cmd = ['npm'] |
| 361 | |
| 362 | if not which(npm_cmd[0]): |
| 363 | log.error("`{0}` unavailable. If you're running this command " |
| 364 | "using sudo, make sure `{0}` is available to sudo" |
| 365 | .format(npm_cmd[0])) |
| 366 | return |
| 367 | |
| 368 | if force or is_stale(node_modules, pjoin(node_package, 'package.json')): |
| 369 | log.info('Installing build dependencies with npm. This may ' |
| 370 | 'take a while...') |
| 371 | run(npm_cmd + ['install'], cwd=node_package) |
| 372 | if build_dir and source_dir and not force: |
| 373 | should_build = is_stale(build_dir, source_dir) |
| 374 | else: |
| 375 | should_build = True |
| 376 | if should_build: |
| 377 | run(npm_cmd + ['run', build_cmd], cwd=node_package) |
| 378 | |
| 379 | return NPM |
| 380 | |