Skip to content

Commit 146d1ae

Browse files
committed
WIP: initial commit
0 parents  commit 146d1ae

19 files changed

+439
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
test/tmp
2+
node_modules
3+
package-lock.json

.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

CODE_OF_CONDUCT.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Code of Conduct
2+
3+
The Node.js Code of Conduct, which applies to this project, can be found at
4+
https://github.com/nodejs/admin/blob/master/CODE_OF_CONDUCT.md.

CONTRIBUTING.md

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Contributing
2+
3+
## Code of Conduct
4+
5+
The Node.js project has a
6+
[Code of Conduct](https://github.com/nodejs/admin/blob/master/CODE_OF_CONDUCT.md)
7+
to which all contributors must adhere.
8+
9+
See [details on our policy on Code of Conduct](https://github.com/nodejs/node/blob/master/doc/guides/contributing/code-of-conduct.md).
10+
11+
<a id="developers-certificate-of-origin"></a>
12+
## Developer's Certificate of Origin 1.1
13+
14+
By making a contribution to this project, I certify that:
15+
16+
* (a) The contribution was created in whole or in part by me and I
17+
have the right to submit it under the open source license
18+
indicated in the file; or
19+
20+
* (b) The contribution is based upon previous work that, to the best
21+
of my knowledge, is covered under an appropriate open source
22+
license and I have the right under that license to submit that
23+
work with modifications, whether created in whole or in part
24+
by me, under the same open source license (unless I am
25+
permitted to submit under a different license), as indicated
26+
in the file; or
27+
28+
* (c) The contribution was provided directly to me by some other
29+
person who certified (a), (b) or (c) and I have not modified
30+
it.
31+
32+
* (d) I understand and agree that this project and the contribution
33+
are public and that a record of the contribution (including all
34+
personal information I submit with it, including my sign-off) is
35+
maintained indefinitely and may be redistributed consistent with
36+
this project or the open source license(s) involved.

LICENSE

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Contributors https://github.com/pkgjs/create/graphs/contributors
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Scaffold a Package
2+
3+
[![NPM Version](https://img.shields.io/npm/v/create-pkg.svg)](https://npmjs.org/package/create-pkg)
4+
[![NPM Downloads](https://img.shields.io/npm/dm/create-pkg.svg)](https://npmjs.org/package/create-pkg)
5+
[![test](https://github.com/pkgjs/create/workflows/Test/badge.svg)](https://github.com/pkgjs/create/actions?query=workflow%3ATest)
6+
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](https://github.com/standard/standard)
7+
8+
## Usage
9+
10+
```
11+
$ npm init pkg
12+
13+
# or
14+
15+
$ npx create-pkg
16+
17+
# or
18+
19+
$ npm install -g create-pkg
20+
$ create-pkg
21+
```
22+
23+
### CLI Usage
24+
25+
```
26+
$ create-pkg --help
27+
create-git
28+
29+
initalize a package
30+
31+
Options:
32+
--help Show help [boolean]
33+
--version Show version number [boolean]
34+
--cwd, -d Directory to run in [default: process.cwd()]
35+
# TODO
36+
```
37+
38+
### Programmatic Usage
39+
40+
```javascript
41+
const createPkg = require('@pkgjs/create-pkg')
42+
43+
await createPkg({
44+
// TODO
45+
})
46+
```
47+
48+
#### Composition with other `create-*` packages
49+
50+
This generator is built on top of `opta`, a helper library for collecting
51+
user input from multiple interfaces: CLI via `yargs`, interactive prompts via `inquirer`
52+
and via a JS interface. To compose with other `opta` based input collection,
53+
you can use `.options` to access the cli/prompt/js configurations.
54+
55+
```javascript
56+
const createPkg = require('create-pkg')
57+
const opta = require('opta')
58+
59+
const opts = opta({
60+
commandDescription: 'Your description',
61+
options: {
62+
// Spread the options from createGPkg
63+
...createPkg.options,
64+
}
65+
})
66+
67+
// Our generator main
68+
module.exports = async function (input) {
69+
// Add our input as overrides on the opta instance
70+
options.overrides(input)
71+
72+
// Prompt the user,
73+
await options.prompt()
74+
75+
// Get the current values from the opta instance
76+
let opts = options.values()
77+
78+
// Call create git
79+
await createPkg(opts)
80+
}
81+
```
82+
83+
For more information check out the [docs for `opta`](https://www.npmjs.com/package/opta).

bin/create-package

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env node
2+
'use strict'
3+
require('../').cli()(process.argv.slice(2))

index.js

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
'use strict'
2+
const path = require('path')
3+
const opta = require('opta')
4+
const createPackageJson = require('create-package-json')
5+
const createGit = require('create-git')
6+
const cptmpl = require('cptmpl')
7+
const { Loggerr } = require('loggerr')
8+
9+
function initOpts () {
10+
return opta({
11+
commandDescription: 'Generate a package.json',
12+
options: {
13+
cwd: {
14+
description: 'Directory to run in',
15+
prompt: false,
16+
flag: {
17+
alias: 'd',
18+
defaultDescription: 'process.cwd()'
19+
}
20+
},
21+
22+
silent: {
23+
type: 'boolean',
24+
prompt: false,
25+
flag: {
26+
conflicts: ['verbose']
27+
}
28+
},
29+
verbose: {
30+
type: 'boolean',
31+
prompt: false,
32+
flag: {
33+
conflicts: ['silent']
34+
}
35+
},
36+
37+
// First ask the package questions
38+
...createPackageJson.options,
39+
40+
// Add our additional prompts
41+
githubOrg: {
42+
default: 'pkgjs',
43+
prompt: {
44+
message: 'GitHub User/Org:'
45+
}
46+
},
47+
githubRepo: {
48+
flag: {
49+
key: 'github-repo'
50+
},
51+
prompt: {
52+
message: 'GitHub repo:',
53+
default: (promptInput, allInput) => {
54+
// Remove the scope from the package name
55+
return allInput.name && allInput.name.replace(/^@[^/]+\//, '')
56+
}
57+
}
58+
},
59+
60+
...createGit.options,
61+
62+
// Override createGit.options.remoteOrigin
63+
remoteOrigin: {
64+
...createGit.options.remoteOrigin,
65+
prompt: {
66+
...createGit.options.remoteOrigin.prompt,
67+
default: (promptInput, allInput) => {
68+
return `[email protected]:${allInput.githubOrg}/${allInput.githubRepo}.git`
69+
}
70+
}
71+
}
72+
}
73+
})
74+
}
75+
76+
module.exports = main
77+
async function main (input, _opts = {}) {
78+
const options = initOpts()
79+
options.overrides({
80+
...input,
81+
cwd: input.cwd || process.cwd(),
82+
83+
// My opinionated overrides
84+
version: '0.0.0',
85+
devDependencies: ['standard', 'mocha'],
86+
additionalRules: ['package-lock.json']
87+
})
88+
89+
let opts = options.values()
90+
91+
const log = _opts.logger || new Loggerr({
92+
level: (opts.silent && 'silent') || (opts.verbose && 'debug') || 'info',
93+
formatter: 'cli'
94+
})
95+
96+
await options.prompt({
97+
promptor: _opts.promptor
98+
})()
99+
100+
opts = options.values()
101+
102+
// do stuff
103+
await cptmpl.recursive(tmplPath(), opts.cwd, opts)
104+
await createPackageJson(opts, {
105+
promptor: _opts.promptor,
106+
logger: log
107+
})
108+
await createGit(opts, {
109+
promptor: _opts.promptor,
110+
logger: log
111+
})
112+
}
113+
114+
function tmplPath (...args) {
115+
return path.join(__dirname, 'templates', ...args)
116+
}
117+
118+
module.exports.options = initOpts().options
119+
module.exports.cli = function () {
120+
return initOpts().cli((yargs) => {
121+
yargs.command('$0', 'Generate a package', () => {}, main)
122+
})
123+
}

package.json

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"name": "@pkgjs/create-pkg",
3+
"version": "0.0.0",
4+
"description": "Scaffold a package",
5+
"author": "Wes Todd <[email protected]>",
6+
"keywords": [
7+
"scaffold",
8+
"package",
9+
"git",
10+
"module",
11+
"package.json",
12+
"readme",
13+
"mocha",
14+
"standard"
15+
],
16+
"license": "ISC",
17+
"main": "index.js",
18+
"repository": {
19+
"type": "git",
20+
"url": "[email protected]:pkgjs/create.git"
21+
},
22+
"bin": {
23+
"create-package": "bin/create-package"
24+
},
25+
"scripts": {
26+
"test": "standard && mocha --timeout=60000",
27+
"test:debug": "mocha --inspect --inspect-brk --timeout=0",
28+
"release": "npm t && standard-version && npm publish",
29+
"postpublish": "git push origin && git push origin --tags"
30+
},
31+
"dependencies": {
32+
"cptmpl": "0.0.5",
33+
"create-git": "^1.0.0-2",
34+
"create-package-json": "^1.0.0-2",
35+
"loggerr": "^3.0.0-3",
36+
"opta": "0.0.6",
37+
"semver": "^7.3.2"
38+
},
39+
"devDependencies": {
40+
"fs-extra": "^8.0.1",
41+
"fs-test-fixtures": "^0.1.3",
42+
"mocha": "^6.2.2",
43+
"standard": "^14.3.1",
44+
"standard-version": "^9.0.0"
45+
}
46+
}

templates/.github/CODE_OF_CONDUCT.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Code of Conduct
2+
3+
This project as adopted the Contributor Covenant v1.4.1 as its Code of Conduct.
4+
See here for the details:
5+
6+
https://www.contributor-covenant.org/version/1/4/code-of-conduct
7+
8+
To report or discuss issues you can email <%- author %> or open a public issue on GitHub.

templates/.github/CONTRIBUTING.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Contributing
2+
3+
:+1::tada: Welcome, thanks for taking the time to contribute! :tada::+1:
4+
5+
[Code Of Conduct](./CODE_OF_CONDUCT.md)
6+
7+
All contributions are welcome; features, fixes, documentation or just helping
8+
others solve their issues. The best way to get started is to look through
9+
our Issues and Pull Requests. If you have questions feel free to open an Issue
10+
and tag it with `question` so others can find it and help out!
11+
12+
Happy Hacking!

templates/.github/SECURITY.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Security Policy
2+
3+
## Supported Versions
4+
5+
This project supports security and feature development on the two most recent
6+
major versions. It also supports all active and LTS Node.js release lines.
7+
8+
## Reporting a Vulnerability
9+
10+
To report a vulnerability email <%- author %> before opening public issues on the repo.

templates/.github/workflows/test.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Test
2+
on:
3+
pull_request:
4+
push:
5+
branches:
6+
- master
7+
jobs:
8+
test:
9+
runs-on: ubuntu-latest
10+
strategy:
11+
matrix:
12+
node-version: [10.x, 12.x, 13.x, 14.x]
13+
steps:
14+
- uses: actions/checkout@v1
15+
- name: Use Node.js ${{ matrix.node-version }}
16+
uses: actions/setup-node@v1
17+
with:
18+
node-version: ${{ matrix.node-version }}
19+
- name: npm install and test
20+
run: npm it

templates/.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

templates/LICENSE

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright (c) <%- (new Date()).getFullYear() %>, <%- author %>
2+
3+
Permission to use, copy, modify, and/or distribute this software for any
4+
purpose with or without fee is hereby granted, provided that the above
5+
copyright notice and this permission notice appear in all copies.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10+
SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12+
OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13+
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

templates/README.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# <%- name %>
2+
3+
[![NPM Version](https://img.shields.io/npm/v/<%- name %>.svg)](https://npmjs.org/package/<%- name %>)
4+
[![NPM Downloads](https://img.shields.io/npm/dm/<%- name %>.svg)](https://npmjs.org/package/<%- name %>)
5+
[![test](https://github.com/<%- githubOrg %>/<%- githubRepo %>/workflows/Test/badge.svg)](https://github.com/<%- githubOrg %>/<%- githubRepo %>/actions?query=workflow%3ATest)
6+
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](https://github.com/standard/standard)
7+
8+
<%- typeof description !== 'undefined' ? description : '' %>
9+
10+
```
11+
$ npm i <%- name %>
12+
```

0 commit comments

Comments
 (0)