Git Product home page Git Product logo

yarn-or-npm's Introduction

yarn-or-npm

Execute scripts with Yarn or npm

npm i --save-dev yarn-or-npm

Module

import yarnOrNpm, { spawn, hasYarn, hasNpm } from 'yarn-or-npm';

// String of `yarn` or `npm` returned
console.log(yarnOrNpm());

// Boolean values for hasYarn, hasNpm
console.log(hasYarn());

// Spawn yarn or npm command
spawn(['init']);

// Spawn sync option
spawn.sync(['init'], { stdio: 'inherit' });

Under the covers, there is a cached value being used for efficiency. This can be manually cleared:

import yarnOrNpm from 'yarn-or-npm';
import { spawnSync } from 'child_process';

console.log(yarnOrNpm.hasYarn()); // false

spawnSync('npm', ['i', '-g', 'yarn'], { stdio: 'inherit' });

console.log(yarnOrNpm.hasYarn()); // false (cached)

yarnOrNpm.clearCache();
console.log(yarnOrNpm.hasYarn()); // true

CLI

yarn-or-npm <command>
# Can also use `yon` shorthand
yon <command>

Package

Modules with bin files can be called directly in package.json scripts:

{
  "devDependencies": {
    ...
    "yarn-or-npm": "^1.0.0"
  },
  "scripts": {
    "compile": "babel src --out-dir dist",
    "lint": "eslint .",
    "prepublish": "yarn-or-npm run lint && yarn-or-npm run compile"
  }
}

yarn-or-npm's People

Contributors

elektronik2k5 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.