Skip to content

Commit bc4b13e

Browse files
committed
expanded docs and fixed scripts
1 parent b655080 commit bc4b13e

2 files changed

Lines changed: 61 additions & 1 deletion

File tree

README.md

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ This is a fully featured `package.json` scaffolding tool. It goes above and bey
44
by supporting (almost) all of the keys you can set in a `package.json`. It can be used as a simple cli
55
tool, or inside your other package scaffolding tools.
66

7+
*NOTE:* This is a work in progress, more to come on docs and there are some missing options at the moment.
8+
[See here](https://github.com/wesleytodd/create-package-json/blob/master/index.js#L14-L27) for missing fields.
9+
710
## Usage
811

912
```
@@ -18,4 +21,55 @@ $ npm install -g create-package-json
1821
$ create-package-json
1922
```
2023

21-
*NOTE:* This is a work in progress, more to come on docs and there are some missing options at the moment.
24+
### CLI Usage
25+
26+
```
27+
$ create-package-json --help
28+
29+
Usage: create-package-json [options] <directory>
30+
31+
Options:
32+
33+
-V, --version output the version number
34+
--ignore-existing Ignore existing package.json
35+
--no-prompt Skip prompts and just use input options
36+
--spacer [json spacer] Format character for package json (default: 2)
37+
--name [name] The package name
38+
--scope [scope] The package scope
39+
--ver [version] The package version
40+
--description [description] The package description
41+
--author [author] The package author
42+
--repository [repository] The package repository
43+
--keywords [keywords] The package keywords
44+
--license [license] The package license
45+
--main [main] The package main entry point
46+
--private This is a private package
47+
--dependencies [dependencies] Package dependencies
48+
--dev-dependencies [dependencies] Package dev dependencies
49+
--scripts [scripts] Package scripts
50+
-h, --help output usage information
51+
```
52+
53+
Dependencies should be a comma separated list like `--dependencies="express,react"`, and it can also
54+
include versions, `--dependencies="express@5"`.
55+
56+
Scripts should be defined as a json string, `--scripts='{"test":"exit 0"}'`.
57+
58+
### Programmatic Usage
59+
60+
```javascript
61+
const createPackageJson = require('create-package-json')
62+
63+
;(async () => {
64+
const pkg = await createPackageJson({
65+
name: '@myscope/my-package',
66+
description: 'A useless new package',
67+
dependencies: ['express'],
68+
devDependencies: ['mocha'],
69+
author: 'Me <me@me.com>',
70+
version: '1.0.0'
71+
})
72+
73+
console.log(pkg) // The json after writing and installing
74+
})()
75+
```

bin/create-package-json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ program
3030
.option('--scripts [scripts]', 'Package scripts')
3131
.parse(process.argv)
3232

33+
// Process scripts as json
34+
if (program.scripts) {
35+
program.scripts = JSON.parse(program.scripts)
36+
}
37+
3338
// Run the process
3439
createPackageJson({
3540
directory: directory,
@@ -47,6 +52,7 @@ createPackageJson({
4752
license: program.license,
4853
main: program.main,
4954
private: program.private,
55+
scripts: program.scripts,
5056
dependencies: arrayFromList(program.dependencies),
5157
devDependencies: arrayFromList(program.devDependencies)
5258
})

0 commit comments

Comments
 (0)