-
Notifications
You must be signed in to change notification settings - Fork 1
/
todos.txt
277 lines (201 loc) · 8.38 KB
/
todos.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
# Add a repl serverlike console to it
# https://nodejs.org/api/repl.html
# complete the checklist and update process
# https://ericdouglas.github.io/2015/09/27/checklist-for-your-new-open-source-javascript-project/
Checklist
Prefer to write a micro-library. Benefits:
easier to reason about
easier to test
easier to reuse
Create a repository for your library:
Go to your git repository hosting service (here we’ll use GitHub)
Create a new repository
Create a README file
Clone your repository to your local machine
git clone [email protected]:YOUR_USER_NAME/YOUR_REPOSITORY_NAME
Ensure that you have Node.js installed.
Set NPM properties:
npm set init-author-name 'Your name'
npm set init-author-email 'Your email'
npm set init-author-url 'http://yourdomain.com'
npm set init-license 'MIT'
Save modules with an exact version:
npm set save-exact true
Login with your NPM account on terminal:
npm adduser
Username: YOUR_USER_NAME
Password: YOUR_PASSWORD
Email: [email protected]
Create a package.json:
npm init
Create the main file:
Create the src/index.js file that will expose all the module’s functionalities.
module.exports = {
funcOne: funcOne,
funcTwo: funcTwo
};
PROTIPs:
Install and save dependencies: npm i -S module-name is equal to npm install --save module-name
Install and save development dependencies: npm i -D module-name is equal to npm install --save-dev module-name
Add a .gitignore file
Push your changes to GitHub
Publish to NPM: npm publish
Releasing a version to GitHub
git tag 1.0.0
git push --tags
Go to releases on GitHub
Draft a new release
Releasing a new version to NPM:
Based on the type of change that you did in your code, you should bump the version of your module.
Use Semantic Versioning to bump the version correctly
Commit the code git add & git commit
Add a new tag git tag 1.1.0
Push to GH (GitHub) git push
Push the tags git push --tags
Republish to NPM npm publish
See if all is okay npm info <your-module-name>
Publishing a beta version:
Do some stuff in your code
Bump the version with the sufix -beta.0. Ex: 1.3.1-beta.3
Commit the code git add & git commit
Add a new tag git tag 1.1.0
Push to GH (GitHub) git push
Push the tags git push --tags
Publish to NPM with –tag beta . Ex: npm publish --tag beta
See if all is okay. npm info <your-module-name>
How to install a beta version: npm install <module-name>@beta (latest beta) or npm install <module-name>@1.3.1-beta.3 (specific version)
Setting up Unit Testing with Mocha and Chai:
Install mocha and chai npm i -D mocha chai
Create your test file src/index.test.js or src/index.spec.js
Update package.json "test": "mocha src/index.test.js -w"
Run npm test
Automating Releases with semantic-release:
Install semantic-release npm i -g semantic-release-cli
Setup semantic-release semantic-release-cli setup
Setup your CI configuration file to run the tests before run semantic-release.
Ex: .travis.yml
# some stuff here
before_script:
- npm prune
script:
- npm run test
after_success:
- npm run semantic-release
Writing conventional commits with commitizen:
Angular git commit guidelines
npm i -D commitizen cz-conventional-changelog
commitizen: allows to write commit messages
cz-conventional-changelog: Ask questions to generate the commit
Add commitizen in npm scripts:
"script": {
"commit": "git-cz"
}
Configure commitizen to use cz-conventional-changelog. In package.json, add the following property:
"czConfig": {
"path": "node_modules/cz-conventional-changelog"
}
ps: I got a problem with the version 1.1.1 and 1.1.0 of the cz-conventional-changelog, and other people too. To fix it, I installed the version 1.0.1, and worked properly.
npm install [email protected] -D
ps2: Commitizen (and cz-conventional-changelog) updated! :)
Using commitizen:
Add your changes git add
npm run commit
Choose the type of changes that you did. Ex: chore
Choose the scope of the change. Ex: releasing
Add a description. Ex: Add travis config, conventional commit and semantic-release
Add a longer description
List break changes or issues closed by this change. Ex: closes #1
See if everything is ok git log
Committing a new feature with commitizen:
Create an issue on GitHub to be closed with that feature/commit
Add a new feature and its test
git add
npm run commit
Type of change: feat
Scope: random
Short description: Add ability to get an array of starwars names
Longer description: If you pass a number to the random function, you will receive an array with that number of random items
List any break changes/issues closed: closes #2
Verify if everything is ok git log
Automatically running tests before commits with ghooks:
Install ghooks npm i -D ghooks
Configure ghooks in package.json:
"config": {
"ghooks": {
"pre-commit": "npm run test:single"
}
}
ps: ghooks will prevent us to commit bad code
Adding code coverage recording with Istanbul:
npm i -D istanbul
Set npm script to run Istanbul:
"scripts": {
"test:single": "istanbul cover -x *.test.js _mocha -- -R spec src/index.test.js"
}
Add the coverage folder in the .gitignore file
Run npm run test:single
Adding code coverage checking:
Check coverage with ghook:
"config": {
"ghooks": {
"pre-commit": "npm run test:single && npm run check-coverage"
}
}
Add check-coverage in npm scripts:
"scripts": {
"check-coverage": "istanbul check-coverage --statements 100 --branches 100 --functions 100 --lines 100"
}
Add check-coverage in your CI config file:
.travis.yml
script:
- npm run test:single
- npm run check-coverage
Add code coverage reporting:
Create an account at codecov.io
npm i -D codecov.io
Add report-coverage into npm scripts:
"scripts": {
"report-coverage": "cat ./coverage/lcov.info | codecov"
}
Add report-coverage in your CI config file:
.travis.yml
after_success:
- npm run report-coverage
- npm run semantic-release
Adding badges to your README:
Go to shields.io
Choose your badges! :)
Markdown structure to add badges:
[![image description](shields.io link)](link the badge to the respective place)
Adding ES6 Support:
npm i -D babel
Add a build task in npm scripts:
"scripts": {
"build": "babel src/index.js -o dist/index.js"
}
Change the “main” file in your package.json to dist/index.js
Add a prebuild task into npm scripts:
"scripts": {
"prebuild": "rm -rf dist && mkdir dist"
}
Add build in your CI config file:
.travis.yml
script:
- npm run test:single
- npm run check-coverage
- npm run build
Add a postbuild task in npm scripts:
"scripts": {
"postbuild": "cp src/starwars-names.json dist/starwars-names.json"
}
Adding ES6 Support in Tests using Mocha and Babel:
Update your test and test:single tasks on npm script:
"scripts": {
"test": "mocha src/index.test.js -w --compilers js:babel/register",
"test:single": "istanbul cover -x *.test.js _mocha -- -R spec src/index.test.js --compilers js:babel/register"
}
Limit Built Branches on Travis:
Add the following code in your .travis.yml:
branches:
only:
- master