Skip to content

Commit 074f495

Browse files
authored
feat(create): Add create command (#79)
## Problem Needed to support the `create` command so that a new library with all the infra could be created. Also needed the ability to be able to update an existing library with the infra, either an existing library that had never used `@benmvp/cli` or one that just needs updated infra. ## Solution Build out the command to: 1. Initialize the repo with git and npm 1. Set up `LICENSE`, `.gitignore`, and `CODE_OF_CONDUCT.md` 1. Set up the `package.json` correctly 1. Copy over the necessary local configuration files The integration tests are what really validate that a new lib can be created (or updated), but there are unit tests for updating the `package.json`. The output directory specified in the `create` command gets passed along to the `build` script stored in the repo's `package.json` so we could no longer default it to `lib/`. In order to copy over the local config files, I had to add a step to the repo's `build` script that copies over the files. This is **not** part of the CLI, but just a build step for the repo. Then the `create` command copies them over locally and replaces some text to reference the new repo's name. Fixed `spawnAsync` so that the sub-process writes to the standard output just as if it was the parent process (via `{stdio: 'inherit'}`).
1 parent a582e29 commit 074f495

File tree

24 files changed

+1443
-321
lines changed

24 files changed

+1443
-321
lines changed

.gitignore

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ logs
44
npm-debug.log*
55
yarn-debug.log*
66
yarn-error.log*
7+
lerna-debug.log*
8+
9+
# Diagnostic reports (https://nodejs.org/api/report.html)
10+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
711

812
# Runtime data
913
pids
@@ -16,11 +20,12 @@ lib-cov
1620

1721
# Coverage directory used by tools like istanbul
1822
coverage
23+
*.lcov
1924

2025
# nyc test coverage
2126
.nyc_output
2227

23-
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
28+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
2429
.grunt
2530

2631
# Bower dependency directory (https://bower.io/)
@@ -39,12 +44,21 @@ jspm_packages/
3944
# TypeScript v1 declaration files
4045
typings/
4146

47+
# TypeScript cache
48+
*.tsbuildinfo
49+
4250
# Optional npm cache directory
4351
.npm
4452

4553
# Optional eslint cache
4654
.eslintcache
4755

56+
# Microbundle cache
57+
.rpt2_cache/
58+
.rts2_cache_cjs/
59+
.rts2_cache_es/
60+
.rts2_cache_umd/
61+
4862
# Optional REPL history
4963
.node_repl_history
5064

@@ -56,9 +70,42 @@ typings/
5670

5771
# dotenv environment variables file
5872
.env
73+
.env.test
74+
75+
# parcel-bundler cache (https://parceljs.org/)
76+
.cache
5977

60-
# next.js build output
78+
# Next.js build output
6179
.next
6280

63-
# built directory
64-
lib/
81+
# Nuxt.js build / generate output
82+
.nuxt
83+
dist
84+
85+
# Gatsby files
86+
.cache/
87+
# Comment in the public line in if your project uses Gatsby and not Next.js
88+
# https://nextjs.org/blog/next-9-1#public-directory-support
89+
# public
90+
91+
# vuepress build output
92+
.vuepress/dist
93+
94+
# Serverless directories
95+
.serverless/
96+
97+
# FuseBox cache
98+
.fusebox/
99+
100+
# DynamoDB Local files
101+
.dynamodb/
102+
103+
# TernJS port file
104+
.tern-port
105+
106+
# Stores VSCode versions used for testing VSCode extensions
107+
.vscode-test
108+
109+
# built lib directory
110+
lib
111+

CODE_OF_CONDUCT.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as
6+
contributors and maintainers pledge to make participation in our project and
7+
our community a harassment-free experience for everyone, regardless of age, body
8+
size, disability, ethnicity, sex characteristics, gender identity and expression,
9+
level of experience, education, socio-economic status, nationality, personal
10+
appearance, race, religion, or sexual identity and orientation.
11+
12+
## Our Standards
13+
14+
Examples of behavior that contributes to creating a positive environment
15+
include:
16+
17+
- Using welcoming and inclusive language
18+
- Being respectful of differing viewpoints and experiences
19+
- Gracefully accepting constructive criticism
20+
- Focusing on what is best for the community
21+
- Showing empathy towards other community members
22+
23+
Examples of unacceptable behavior by participants include:
24+
25+
- The use of sexualized language or imagery and unwelcome sexual attention or
26+
advances
27+
- Trolling, insulting/derogatory comments, and personal or political attacks
28+
- Public or private harassment
29+
- Publishing others' private information, such as a physical or electronic
30+
address, without explicit permission
31+
- Other conduct which could reasonably be considered inappropriate in a
32+
professional setting
33+
34+
## Our Responsibilities
35+
36+
Project maintainers are responsible for clarifying the standards of acceptable
37+
behavior and are expected to take appropriate and fair corrective action in
38+
response to any instances of unacceptable behavior.
39+
40+
Project maintainers have the right and responsibility to remove, edit, or
41+
reject comments, commits, code, wiki edits, issues, and other contributions
42+
that are not aligned to this Code of Conduct, or to ban temporarily or
43+
permanently any contributor for other behaviors that they deem inappropriate,
44+
threatening, offensive, or harmful.
45+
46+
## Scope
47+
48+
This Code of Conduct applies within all project spaces, and it also applies when
49+
an individual is representing the project or its community in public spaces.
50+
Examples of representing a project or community include using an official
51+
project e-mail address, posting via an official social media account, or acting
52+
as an appointed representative at an online or offline event. Representation of
53+
a project may be further defined and clarified by project maintainers.
54+
55+
## Enforcement
56+
57+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
58+
reported by contacting the project team at ben@benmvp.com. All
59+
complaints will be reviewed and investigated and will result in a response that
60+
is deemed necessary and appropriate to the circumstances. The project team is
61+
obligated to maintain confidentiality with regard to the reporter of an incident.
62+
Further details of specific enforcement policies may be posted separately.
63+
64+
Project maintainers who do not follow or enforce the Code of Conduct in good
65+
faith may face temporary or permanent repercussions as determined by other
66+
members of the project's leadership.
67+
68+
## Attribution
69+
70+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71+
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72+
73+
[homepage]: https://www.contributor-covenant.org
74+
75+
For answers to common questions about this code of conduct, see
76+
https://www.contributor-covenant.org/faq

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Contributing
22

3-
Thank you for your interest in contributing to my CLI!
3+
Thank you for your interest in contributing to the library!
44

55
## Table of Contents
66

@@ -25,7 +25,7 @@ To work on changes, create a new branch on your local repository. `git checkout
2525

2626
## Keeping your local repository up to date
2727

28-
To ensure your branch never gets out of sync with benmvp's `master`, ensure that you have your upstream set properly (see the [Setup](#setup) step)
28+
To ensure your branch never gets out of sync with [https://github.com/benmvp/benmvp-cli](benmvp)'s `master`, ensure that you have your upstream set properly (see the [Setup](#setup) step)
2929

3030
1. `git checkout master` (you may have to [stash](https://git-scm.com/book/en/v1/Git-Tools-Stashing) or commit your local changes)
3131
1. `git pull upstream master`
@@ -60,5 +60,5 @@ Please try to conform to the coding style of the code base.
6060
1. Please ensure that your changes are fully covered by one or more unit tests.
6161
1. Check to make sure that your changes are documented properly (inline comments for interesting lines, READMEs, etc.)
6262
1. Run `npm test` to ensure that all tests pass, the linter is satisfied and your changes are typescript compliant.
63-
1. PR titles must be prefixed by the type of changes the PR contains followed by the scope of what the PR touches. We are following the [angular commit guidelines](https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#-git-commit-guidelines). Please use one of `feat, fix, docs, style, refactor, perf, test, chore` as the prefix. The " is the the direct product your changes affect. Example: `chore(build): Add encrypted ssh key for semantic-release` because its a chore and it touches the build. For multiple scope items, you can comma separate 2 or 3 but if there are more than that please use a `*` instead.
63+
1. PR titles must be prefixed by the type of changes the PR contains followed by the scope of what the PR touches. We are following the [angular commit guidelines](https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#-git-commit-guidelines). Please use one of `feat, fix, docs, style, refactor, perf, test, chore` as the prefix. The "()" is the the direct product your changes affect. Example: `chore(build): Add encrypted ssh key for semantic-release` because its a `chore` and it touches the `build`. For multiple scope items, you can comma separate 2 or 3 but if there are more than that please use a `*` instead.
6464
1. Please use a [closing issue keyword](https://help.github.com/articles/closing-issues-using-keywords/) to indicate the issue that your fix addresses in the description section of the pull request template. Example: `fixes #32` to close issue #32

docs/api/create.md

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
11
# `create()` Documentation
22

3-
> NOTE: `create()` is still under development
4-
5-
Creates a new library with the specified name set up with infrastructure using `@benmvp/cli`, returning a `Promise` indicating whether the creation succeeded or failed.
3+
Creates a new library or updates an existing library, to be set up with infrastructure using the latest version of `@benmvp/cli`, returning a `Promise` indicating whether the creation succeeded or failed.
64

75
It will:
86

7+
- Set up git (i.e. `git init`) in the directory
98
- Add `"test"`, `"start"`, `"build"` and `"integrate"` scripts in the `package.json` to call [`benmvp test`](test.md), [`benmvp start`](start.md), [`benmvp build`](build.md), and [`benmvp integrate`](integrate.md), respectively
10-
- After the `package.json` is created (or updated), it will install `@benmvp/cli` as a dev dependency, using [Yarn](https://yarnpkg.com/) if available. If Yarn is unavailable, it will fallback to [npm](https://docs.npmjs.com/)
11-
- Add (or overwrite) `.prettierrc.json`, `.prettierignore` & `.vscode/settings.json` files to format all code
12-
- Add (or overwrite) a `.github/workflows/ci.yml` [Github workflow](https://help.github.com/en/actions) for testing your code when a branch is pushed to or a PR is updated.
13-
- Add (or overwrite) a `.github/workflows/format.yml` [Github workflow](https://help.github.com/en/actions) for formatting your files when a non-`master` branch is pushed to. Formatted code will be pushed as a new commit to the branch.
14-
- Add (or overwrite) a `.github/workflows/release.yml` [Github workflow](https://help.github.com/en/actions) for release a new version of your package with new commits to `master`.
15-
- Add (or overwrite) `.github/pull_request_template.md` & `.github/ISSUE_TEMPLATE/*` for more organized [pull request](https://help.github.com/en/github/building-a-strong-community/creating-a-pull-request-template-for-your-repository) and [issue](https://help.github.com/en/github/building-a-strong-community/configuring-issue-templates-for-your-repository) creation.
16-
17-
> NOTE: `create()` can be called multiple times on a repo. It's a good idea to call `create()` every time you bump the version of `@benmvp/cli` so you can get the latest configuration for `package.json`, prettier, Github workflows, and Github PR/Issue templates.
9+
- After the `package.json` is created (or updated), it will install `@benmvp/cli` as a dev dependency, using [npm](https://docs.npmjs.com/)
10+
- Add a dummy `src/index.ts` file which is the entry-point to the lib and from where all top-level API functions will be exported
11+
- Add (or overwrite) [`.prettierrc.json`](https://github.com/benmvp/benmvp-cli/blob/master/.prettierrc.json), [`.prettierignore`](https://github.com/benmvp/benmvp-cli/blob/master/.prettierignore) & [`.vscode/settings.json`](https://github.com/benmvp/benmvp-cli/blob/master/.vscode/settings.json) files to format all code
12+
- Add (or overwrite) [Github workflows](https://help.github.com/en/actions):
13+
- [`.github/workflows/ci.yml`](https://github.com/benmvp/benmvp-cli/blob/master/.github/workflows/ci.yml) for testing your code when a branch is pushed to or a PR is updated.
14+
- [`.github/workflows/format.yml`](https://github.com/benmvp/benmvp-cli/blob/master/.github/workflows/format.yml) for formatting your files when a non-`master` branch is pushed to. Formatted code will be pushed as a new commit to the branch.
15+
- [`.github/workflows/validate-pr.yml`](https://github.com/benmvp/benmvp-cli/blob/master/.github/workflows/validate-pr.yml) for validating that each PR title follows the [Conventional Commits specification](https://www.conventionalcommits.org/).
16+
- [`.github/workflows/release.yml`](https://github.com/benmvp/benmvp-cli/blob/master/.github/workflows/release.yml) for releasing a new version of your package upon new commits to `master`.
17+
- Add (or overwrite) [`.github/pull_request_template.md`](https://github.com/benmvp/benmvp-cli/blob/master/.github/pull_request_template.md) & [`.github/ISSUE_TEMPLATE`](https://github.com/benmvp/benmvp-cli/tree/master/.github/ISSUE_TEMPLATE) for more organized [pull request](https://help.github.com/en/github/building-a-strong-community/creating-a-pull-request-template-for-your-repository) and [issue](https://help.github.com/en/github/building-a-strong-community/configuring-issue-templates-for-your-repository) creation.
18+
- Add (or overwrite) other miscellaneous config files:
19+
- [`.gitignore`](https://github.com/benmvp/benmvp-cli/blob/master/.gitignore)
20+
- [`.nvmrc`](https://github.com/benmvp/benmvp-cli/blob/master/.nvmrc)
21+
- [`CHANGELOG.md`](https://github.com/benmvp/benmvp-cli/blob/master/CHANGELOG.md)
22+
- [`CONTRIBUTING.md`](https://github.com/benmvp/benmvp-cli/blob/master/CONTRIBUTING.md)
23+
- [`CODE_OF_CONDUCT.md`](https://github.com/benmvp/benmvp-cli/blob/master/CODE_OF_CONDUCT.md)
24+
- [`LICENSE`](https://github.com/benmvp/benmvp-cli/blob/master/LICENSE)
25+
26+
> NOTE: `create()` can be called multiple times on a repo. It's a good idea to call `create()` every time you bump the version of `@benmvp/cli` so you can get the latest configuration for `package.json`, prettier, Github workflows, Github PR/Issue templates, and other miscellaneous config files.
1827
1928
Looking for CLI docs? View companion [`benmvp create` documentation](../cli/create.md).
2029

@@ -75,14 +84,14 @@ The optional `Options` object supports the following properties:
7584

7685
### `name`
7786

78-
The name of the library to create or update.
87+
(Optional) The name of the library to create or update.
7988

80-
When `name` is unspecified:
89+
When `name` is unspecified, it assumes the current working directory is the root of the library. Also:
8190

8291
- If a `package.json` does not already exist, it creates a new `package.json` with the name matching the directory it's within.
8392
- If a `package.json` does exist, it does nothing to the existing `package.json`.
8493

85-
When `name` is specified:
94+
When `name` is specified, it will create a directory of `name` within the current working directory. Also:
8695

8796
- If a `package.json` does not already exist, it creates a new `package.json` with the specified name.
8897
- If a `package.json` does exist, it updates the `"name"` property of the `package.json` with specified name.

docs/cli/create.md

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
11
# `benmvp create` Documentation
22

3-
> NOTE: `benmvp create` is still under development
4-
5-
Creates a new library set up with infrastructure using `@benmvp/cli`.
3+
Creates a new library or updates an existing library, to be set up with infrastructure using the latest version of `@benmvp/cli`.
64

75
It will:
86

7+
- Set up git (i.e. `git init`) in the directory
98
- Add `"test"`, `"start"`, `"build"` and `"integrate"` scripts in the `package.json` to call [`benmvp test`](test.md), [`benmvp start`](start.md), [`benmvp build`](build.md), and [`benmvp integrate`](integrate.md), respectively
10-
- After the `package.json` is created (or updated), it will install `@benmvp/cli` as a dev dependency, using [Yarn](https://yarnpkg.com/) if available. If Yarn is unavailable, it will fallback to [npm](https://docs.npmjs.com/)
11-
- Add (or overwrite) `.prettierrc.json`, `.prettierignore` & `.vscode/settings.json` files to format all code
12-
- Add (or overwrite) a `.github/workflows/ci.yml` [Github workflow](https://help.github.com/en/actions) for testing your code when a branch is pushed to or a PR is updated.
13-
- Add (or overwrite) a `.github/workflows/format.yml` [Github workflow](https://help.github.com/en/actions) for formatting your files when a non-`master` branch is pushed to. Formatted code will be pushed as a new commit to the branch.
14-
- Add (or overwrite) a `.github/workflows/release.yml` [Github workflow](https://help.github.com/en/actions) for release a new version of your package with new commits to `master`.
15-
- Add (or overwrite) `.github/pull_request_template.md` & `.github/ISSUE_TEMPLATE/*` for more organized [pull request](https://help.github.com/en/github/building-a-strong-community/creating-a-pull-request-template-for-your-repository) and [issue](https://help.github.com/en/github/building-a-strong-community/configuring-issue-templates-for-your-repository) creation.
16-
17-
> NOTE: `benmvp create` can be called multiple times on a repo. It's a good idea to call `create()` every time you bump the version of `@benmvp/cli` so you can get the latest configuration for `package.json`, prettier, Github workflows, and Github PR/Issue templates.
9+
- After the `package.json` is created (or updated), it will install `@benmvp/cli` as a dev dependency, using [npm](https://docs.npmjs.com/)
10+
- Add a dummy `src/index.ts` file which is the entry-point to the lib and from where all top-level API functions will be exported
11+
- Add (or overwrite) [`.prettierrc.json`](https://github.com/benmvp/benmvp-cli/blob/master/.prettierrc.json), [`.prettierignore`](https://github.com/benmvp/benmvp-cli/blob/master/.prettierignore) & [`.vscode/settings.json`](https://github.com/benmvp/benmvp-cli/blob/master/.vscode/settings.json) files to format all code
12+
- Add (or overwrite) [Github workflows](https://help.github.com/en/actions):
13+
- [`.github/workflows/ci.yml`](https://github.com/benmvp/benmvp-cli/blob/master/.github/workflows/ci.yml) for testing your code when a branch is pushed to or a PR is updated.
14+
- [`.github/workflows/format.yml`](https://github.com/benmvp/benmvp-cli/blob/master/.github/workflows/format.yml) for formatting your files when a non-`master` branch is pushed to. Formatted code will be pushed as a new commit to the branch.
15+
- [`.github/workflows/validate-pr.yml`](https://github.com/benmvp/benmvp-cli/blob/master/.github/workflows/validate-pr.yml) for validating that each PR title follows the [Conventional Commits specification](https://www.conventionalcommits.org/).
16+
- [`.github/workflows/release.yml`](https://github.com/benmvp/benmvp-cli/blob/master/.github/workflows/release.yml) for releasing a new version of your package upon new commits to `master`.
17+
- Add (or overwrite) [`.github/pull_request_template.md`](https://github.com/benmvp/benmvp-cli/blob/master/.github/pull_request_template.md) & [`.github/ISSUE_TEMPLATE`](https://github.com/benmvp/benmvp-cli/tree/master/.github/ISSUE_TEMPLATE) for more organized [pull request](https://help.github.com/en/github/building-a-strong-community/creating-a-pull-request-template-for-your-repository) and [issue](https://help.github.com/en/github/building-a-strong-community/configuring-issue-templates-for-your-repository) creation.
18+
- Add (or overwrite) other miscellaneous config files:
19+
- [`.gitignore`](https://github.com/benmvp/benmvp-cli/blob/master/.gitignore)
20+
- [`.nvmrc`](https://github.com/benmvp/benmvp-cli/blob/master/.nvmrc)
21+
- [`CHANGELOG.md`](https://github.com/benmvp/benmvp-cli/blob/master/CHANGELOG.md)
22+
- [`CONTRIBUTING.md`](https://github.com/benmvp/benmvp-cli/blob/master/CONTRIBUTING.md)
23+
- [`CODE_OF_CONDUCT.md`](https://github.com/benmvp/benmvp-cli/blob/master/CODE_OF_CONDUCT.md)
24+
- [`LICENSE`](https://github.com/benmvp/benmvp-cli/blob/master/LICENSE)
25+
26+
> NOTE: `benmvp create` can be called multiple times on a repo. It's a good idea to call `benmvp create` every time you bump the version of `@benmvp/cli` so you can get the latest configuration for `package.json`, prettier, Github workflows, Github PR/Issue templates, and other miscellaneous config files.
1827
1928
Looking for Node API docs? View companion [`create()` documentation](../api/create.md).
2029

@@ -52,12 +61,12 @@ npx @benmvp/cli create --modes type spec --out ./built --formats esm cjs
5261

5362
(Optional) The name of the library to create or update.
5463

55-
When `name` is unspecified:
64+
When `name` is unspecified, it assumes the current working directory is the root of the library. Also:
5665

5766
- If a `package.json` does not already exist, it creates a new `package.json` with the name matching the directory it's within.
5867
- If a `package.json` does exist, it does nothing to the existing `package.json`.
5968

60-
When `name` is specified:
69+
When `name` is specified, it will create a directory of `name` within the current working directory. Also:
6170

6271
- If a `package.json` does not already exist, it creates a new `package.json` with the specified name.
6372
- If a `package.json` does exist, it updates the `"name"` property of the `package.json` with specified name.

0 commit comments

Comments
 (0)