1.0.2 • Published 6 years ago

add-project-script v1.0.2

Weekly downloads
83
License
MIT
Repository
github
Last release
6 years ago

Add Project Script

Description

This is a small package that will allow you to programatically add scripts to your package.json file. It was inspired by this package, but this one allows you to specify path to your package.json file as well. Note that you will (almost) never need to specify the path, as most of the time you will want to manipulate the package.json file in your current project (which the script will automatically assume if you don't specify path parameter). There are however few edge cases that can happen, mainly when dealing with git submodules and since I needed something like this, but wasn't able to find it, I just decided to build it myself and share it, because why not.

Installation

If you're using npm you can write this to your terminal

npm install -save-dev add-project-script

Alternatively, you can also use yarn

yarn add --dev add-project-script

You can also install it globally in order to gain a nice command line tool in case you need it.

npm install -g add-project-script

Usage

CLI

Usage is fairly simple.

add-project-script -n "prestart" -v "node scripts/setup-hooks.js"

API

Calling this from the node is equally simple. Simply pass an object of options.

import addScript from 'add-project-script';

addScript({ name: 'prestart', value: 'node scripts/setup-hooks.js' });

Available commands

Here is a list of all available commands.

ShortLongAPIDescriptionType
-n--namenamename of the scriptString
-v--valuevaluevalue of the scriptString
-p--pathpathspecify the path to package.jsonString
-f--forceforceif script with same name exists, overwrite itBoolean (default: false)
--no-throwsthrowsthrow an error in case package.json does not existsBoolean (default: true)
1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago