Project Creation
Before you start, you will need
- A Git hosting service (Github, Gitlab, Bitbucket)
- A CI/CD (Github Actions, Gitlab, Travis, CircleCI)
- An npm account / org
- Git installed on your machine.
- Node installed on your machine.
- Node Version Manager installed.
What a nice project would have
- Documentation
- Consistent Code Style
- 100% Test Coverage
- Stable Releases
What we want to do:
- Set up any kind on javascript project (node, react, angular, …)
- Set up testing.
- Save code changes to a repo.
- Automate Publishing.
Possible order of actions
- Init Code -> Create Repo -> Automate -> Deploy
- Create Repo -> Init Code -> Automate -> Deploy
- Create Repo -> Setup Automation -> Init Code -> Deploy
- Create Repo -> Init Code -> Deploy -> Setup Automation
Steps for POAs
Possible order of actions
1. Init Code -> Create Repo -> Automate
- Init Code eg:
mkdir my-app && cd $_ && npm init && git initnpx create-react-app my-app --template typescriptng new my-app
-
Create repo:
- More details here
- If your project init didn’t do it:
git init - Create a new repo
- Copy the repo url (not the browser one, the ‘clone’ one. Usually: ssh://)
git remote add origin remote repository URL- Once you write some code you can:
git add .git commit -m "Init Commit"git pushorgit push origin master
- Establish a Branching Strategy
- Automate
- Set up a CI/CD
- Prettier
- Lint Staged
- Commit Lint
- Commitizen
- Semantic Release
Setting up a project
- Create a repo, init npm, and set node version.
- Create a .gitignore file, Editor Config and Linting
- Install Typescript and Jest
Setup Automation
Setting up a project
Create a repo, init npm, and set node version.
# Create a git repo and check it out
git clone ssh:_repo_name_ && cd _repo_name_
# Add npm
npm init
# Set node version
node -v > .nvmrc
Create a .gitignore file, Editor Config and Linting
# install eslint
# follow the prompts and create an .eslintrc.js
npx eslint --init
# Add typescript support
npm install --save-dev @typescript-eslint/parser @typescript-eslint/eslint-plugin
Install Typescript and Jest
npm install --save-dev typescript ts-node @types/node
-
Install jest, and typescript files for jest
npm install --save-dev @types/jest jest ts-jest
-
Create a Directory and index file for the source code
mkdir ./src && cat > ./src/index.ts <<EOL
export {};
EOL
- Add npm run scripts to Package.json
//...
"scripts": {
"start": "ts-node ./index.ts",
"ts:defs": "tsc --declaration --outDir ./dist --emitDeclarationOnly",
"build": "rm -rf ./dist && tsc && npm run ts:defs",
"test": "jest",
"semantic-release": "semantic-release"
},
//...
Setup Automation
Prettier
# install prettier
npm install --save-dev --save-exact prettier
npm install eslint-config-prettier --save-dev
# Create prettierrc
echo {}> .prettierrc.json
Prettier Git Hooks
# lint-staged (via mrm which syncs up configs) This will also install husky.
npx mrm lint-staged
- lint-staged, and husky configs can now be removed from package.json
Commit Lint
npm install --save-dev @commitlint/{config-conventional,cli}
Add Commit Lint to husky config
Commitizen
npm install commitizen -g
commitizen init cz-conventional-changelog --save-dev --save-exact
Add commitizen to the husky config
semantic-release
npm install semantic-release --save-dev
In order to update auto-update the the changelog:
npm install @semantic-release/changelog --save-dev
npm install @semantic-release/release-notes-generator --save-dev
npm install semantic-release-contributors --save-dev