Skip to content
This repository was archived by the owner on Aug 12, 2020. It is now read-only.

Commit ad5ec05

Browse files
authored
Merge pull request #26 from NLeSC/development-setup-documentation
Development setup documentation
2 parents 0352497 + c0ebc14 commit ad5ec05

File tree

1 file changed

+162
-0
lines changed

1 file changed

+162
-0
lines changed

development-setup.md

+162
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
# Development setup
2+
3+
(for https://github.com/NLeSC/create-react-app)
4+
5+
6+
## long story short
7+
8+
```
9+
npm install -g create-react-app
10+
npm install -g verdaccio
11+
verdaccio
12+
npm set registry http://localhost:4873
13+
git clone https://github.com/NLeSC/create-react-app.git
14+
cd create-react-app/packages/react-scripts
15+
<make changes>
16+
npm version <major|minor|patch|...>
17+
npm adduser --registry http://localhost:4873/
18+
npm publish
19+
cd <somewhere else>
20+
create-react-app my-app --scripts-version @nlesc/react-scripts
21+
22+
```
23+
24+
25+
26+
## long story long
27+
28+
A user who just wants to automatically generate an initial setup for a React app
29+
could do so by installing the ``create-react-app`` generator as follows:
30+
```
31+
npm install -g create-react-app
32+
```
33+
34+
Afterwards, you will have a command available that will allow you to run the
35+
line below and create a new React app:
36+
```
37+
create-react-app <your-app-name>
38+
```
39+
40+
This will create a directory ``your-app-name`` that contains a complete setup for
41+
developing the newly created React app, including testing, code coverage generation,
42+
bundling, minification, incremental buidling, linting, etc.
43+
44+
Note that the above uses the ``npm`` registry at ``https://registry.npmjs.org/``.
45+
Now let's say you'd want to make changes to the template used to generate new
46+
apps, for example because you want new apps to be in TypeScript instead of the
47+
default JavaScript. For this, it is useful to run your own, local ``npm`` registry
48+
using [verdaccio](https://github.com/verdaccio/verdaccio). Verdaccio sits between
49+
you and https://registry.npmjs.com. It lets you publish development versions of
50+
your npm package to the local, private repo, while still being able to retrieve
51+
any other packages from the 'normal' registry at npmjs.
52+
53+
Install verdaccio with:
54+
55+
```
56+
npm install -g verdaccio
57+
```
58+
59+
Check to see if it works:
60+
61+
```
62+
verdaccio
63+
```
64+
65+
``verdaccio`` should tell you where its registry lives. Mine is at
66+
``http://localhost:4873/``. We will now tell ``npm`` to use the local
67+
``verdaccio`` registry instead of ``http://registry.npmjs.com``, as follows:
68+
```
69+
npm set registry http://localhost:4873
70+
```
71+
If you want to return to the normal setup at a later point in time, you can do
72+
so with:
73+
```
74+
npm set registry https://registry.npmjs.com
75+
```
76+
77+
Let's say you now want to make some changes to the ``create-react-app``
78+
generator application. First get the source code of ``create-react-app`` using
79+
nlesc's fork. I'm checking out the source code into ``~/github/nlesc/``:
80+
```
81+
cd ~/github/nlesc/
82+
git clone https://github.com/NLeSC/create-react-app.git
83+
```
84+
85+
Any changes you make will likely be in one of ``create-react-app``'s constituent
86+
packages, which are located at ``create-react-app/packages``. Each of its
87+
subdirectories is a separate ``npm`` package. Let's say you want to make changes
88+
to the App template from ``create-react-app/packages/react-scripts/template/src``.
89+
90+
```
91+
cd create-react-app/packages/react-scripts/template/src
92+
<make changes>
93+
```
94+
95+
Before publishing your changes, you need to:
96+
97+
1. increment the semantic versioning of the package
98+
1. add yourself as a user to verdaccio's npm registry server
99+
100+
Let's first check what the current semantic version number is, as follows. Walk
101+
up the directory tree until you find a ``package.json``. You should find one in
102+
``create-react-app/packages/react-scripts/``. Look up the value for ``version``.
103+
Now go back to the terminal and use ``npm version patch`` to increment the patch
104+
part of the semantic version number. The 'patch' part of the
105+
version value in package.json should have been incremented (reload your editor
106+
if necessary).
107+
108+
Now let's add a user to verdaccio, as follows:
109+
```
110+
npm adduser --registry http://localhost:4873/
111+
```
112+
This will ask you to enter a user name, password, and e-mail address, which will
113+
be stored in verdaccio. It doesn't really matter what you enter on any of the
114+
three questions.
115+
116+
117+
Now look up the value for ``name`` in package.json. This will be the name the
118+
package is published under. For me, it's ``@nlesc/react-scripts``.
119+
120+
Verify that verdaccio is the active npm registry with ``npm get registry``, and
121+
that verdaccio is in fact up and running, then publish the package to verdaccio
122+
with:
123+
124+
```
125+
npm publish
126+
```
127+
128+
You can point your browser to http://localhost:4873/ to get an overview of
129+
packages that are present in verdaccio's registry.
130+
131+
Now when we want to test if the new version of ``@nlesc/react-scripts`` does
132+
what we want it to do, we can ``cd`` to some other place, let's say ``~/tmp``:
133+
134+
```
135+
cd ~/tmp
136+
```
137+
``npm install`` ``@nlesc/react-scripts`` locally (still using verdaccio's repo):
138+
```
139+
npm install @nlesc/react-scripts
140+
```
141+
142+
You can now inspect the package at ``~/tmp/node_modules/@nlesc/react-scripts/``.
143+
144+
The local install (``npm install`` without the ``-g`` flag) makes it a little
145+
easier to remove the ``node_modules`` directory when additional changes have
146+
been made to the package, and those changes have been ``npm publish``'ed to the
147+
verdaccio registry.
148+
149+
150+
Now create a new app using the updated generator as follows:
151+
```
152+
cd ~/tmp # or wherever you want the new app to be
153+
create-react-app the-new-app --scripts-version @nlesc/react-scripts
154+
```
155+
This uses the globally installed ``create-react-app``, but with the custom
156+
version of ``react-scripts``, namely ``@nlesc/react-scripts`` from verdaccio.
157+
158+
159+
160+
161+
162+

0 commit comments

Comments
 (0)