def install_npm(path=None, build_dir=None, source_dir=None, build_cmd='<STR_LIT>', force=False, npm=None):
class NPM(BaseCommand):<EOL><INDENT>description = '<STR_LIT>'<EOL>def run(self):<EOL><INDENT>if skip_npm:<EOL><INDENT>log.info('<STR_LIT>')<EOL>return<EOL><DEDENT>node_package = path or HERE<EOL>node_modules = pjoin(node_package, '<STR_LIT>')<EOL>is_yarn = os.path.exists(pjoin(node_package, '<STR_LIT>'))<EOL>npm_cmd = npm<EOL>if npm is None:<EOL><INDENT>if is_yarn:<EOL><INDENT>npm_cmd = ['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>npm_cmd = ['<STR_LIT>']<EOL><DEDENT><DEDENT>if not which(npm_cmd[<NUM_LIT:0>]):<EOL><INDENT>log.error("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>.format(npm_cmd[<NUM_LIT:0>]))<EOL>return<EOL><DEDENT>if force or is_stale(node_modules, pjoin(node_package, '<STR_LIT>')):<EOL><INDENT>log.info('<STR_LIT>'<EOL>'<STR_LIT>')<EOL>run(npm_cmd + ['<STR_LIT>'], cwd=node_package)<EOL><DEDENT>if build_dir and source_dir and not force:<EOL><INDENT>should_build = is_stale(build_dir, source_dir)<EOL><DEDENT>else:<EOL><INDENT>should_build = True<EOL><DEDENT>if should_build:<EOL><INDENT>run(npm_cmd + ['<STR_LIT>', build_cmd], cwd=node_package)<EOL><DEDENT><DEDENT><DEDENT>return NPM<EOL>
Return a Command for managing an npm installation.

    Note: The command is skipped if the `--skip-npm` flag is used.

    Parameters
    ----------
    path: str, optional
        The base path of the node package.  Defaults to the repo root.
    build_dir: str, optional
        The target build directory.  If this and source_dir are given,
        the JavaScript will only be build if necessary.
    source_dir: str, optional
        The source code directory.
    build_cmd: str, optional
        The npm command to build assets to the build_dir.
    npm: str or list, optional.
        The npm executable name, or a tuple of ['node', executable].