项目作者: quangnd

项目描述 :
The beauty of simplification
高级语言: JavaScript
项目地址: git://github.com/quangnd/vitamin-hair-backend.git
创建时间: 2017-10-09T18:48:39Z
项目社区:https://github.com/quangnd/vitamin-hair-backend

开源协议:

下载


Get started

  1. Clone the project. git clone https://github.com/quangnd/vitamin-hair-backend.git.
  2. Install packages. npm install
  3. Run app. npm run dev
    This will run the automated build process, start up a webserver, and open the application in your default browser. When doing development with this kit, this command will continue watching all your files. Every time you hit save the code is rebuilt, linting runs, and tests run automatically.

Technologies

This project offers a rich development experience using the following technologies:

Tech Description
NodeJS A JavaScript runtime built on Chrome’s V8 JavaScript engine.
Hapi A rich framework for building applications and services with NodeJS
MySQL A pure node.js JavaScript Client implementing the MySql protocol.
Knex SQL query builder for MySQL
Bookshelf.js JavaScript ORM for Node.js, built on the Knex SQL query builder
nsp node security platform command-line tool
ESLint Lint JS. Reports syntax and style issues.
Editor Config Enforce consistent editor settings (spaces vs tabs, etc). IDE Plugins

Git workflow


1. Some Git rules

There are a set of rules to keep in mind:

  • Perform work in a feature branch.

    Why:

    Because this way all work is done in isolation on a dedicated branch rather than the main branch. It allows you to submit multiple pull requests without confusion. You can iterate without polluting the master branch with potentially unstable, unfinished code. read more…

  • Branch out from develop

    Why:

    This way, you can make sure that code in master will almost always build without problems, and can be mostly used directly for releases (this might be overkill for some projects).

  • Never push into develop or master branch. Make a Pull Request.

    Why:

    It notifies team members that they have completed a feature. It also enables easy peer-review of the code and dedicates forum for discussing the proposed feature.

  • Update your local develop branch and do an interactive rebase before pushing your feature and making a Pull Request.

    Why:

    Rebasing will merge in the requested branch (master or develop) and apply the commits that you have made locally to the top of the history without creating a merge commit (assuming there were no conflicts). Resulting in a nice and clean history. read more …

  • Resolve potential conflicts while rebasing and before making a Pull Request.

  • Delete local and remote feature branches after merging.

    Why:

    It will clutter up your list of branches with dead branches.It insures you only ever merge the branch back into (master or develop) once. Feature branches should only exist while the work is still in progress.

  • Before making a Pull Request, make sure your feature branch builds successfully and passes all tests (including code style checks).

    Why:

    You are about to add your code to a stable branch. If your feature-branch tests fail, there is a high chance that your destination branch build will fail too. Additionally, you need to apply code style check before making a Pull Request. It aids readability and reduces the chance of formatting fixes being mingled in with actual changes.

  • Use this .gitignore file.

    Why:

    It already has a list of system files that should not be sent with your code into a remote repository. In addition, it excludes setting folders and files for most used editors, as well as most common dependency folders.

  • Protect your develop and master branch.

    Why:

    It protects your production-ready branches from receiving unexpected and irreversible changes. read more… Github and Bitbucket

2. Git workflow

Because of most of the reasons above, we use Feature-branch-workflow with Interactive Rebasing and some elements of Gitflow (naming and having a develop branch). The main steps are as follow:

  • For a new project, initialize a git repository in the project directory. For subsequent features/changes this step should be ignored.

    1. cd <project directory>
    2. git init
  • Checkout a new feature/bug-fix branch.

    1. git checkout -b <branchname>
  • Make Changes.

    1. git add
    2. git commit -a

    Why:

    git commit -a will start an editor which lets you separate the subject from the body. Read more about it in section 1.3.

  • Sync with remote to get changes you’ve missed.

    1. git checkout develop
    2. git pull

    Why:

    This will give you a chance to deal with conflicts on your machine while rebasing(later) rather than creating a Pull Request that contains conflicts.

  • Update your feature branch with latest changes from develop by interactive rebase.

    1. git checkout <branchname>
    2. git rebase -i --autosquash develop

    Why:

    You can use —autosquash to squash all your commits to a single commit. Nobody wants many commits for a single feature in develop branch. read more…

  • If you don’t have conflict skip this step. If you have conflicts, resolve them and continue rebase.

    1. git add <file1> <file2> ...
    2. git rebase --continue
  • Push your branch. Rebase will change history, so you’ll have to use -f to force changes into the remote branch. If someone else is working on your branch, use the less destructive --force-with-lease.

    1. git push -f

    Why:

    When you do a rebase, you are changing the history on your feature branch. As a result, Git will reject normal git push. Instead, you’ll need to use the -f or —force flag. read more…

  • Make a Pull Request.
  • Pull request will be accepted, merged and close by a reviewer.
  • Remove your local feature branch if you’re done.

    1. git branch -d <branchname>

    to remove all branches which are no longer on remote

    1. git fetch -p && for branch in `git branch -vv | grep ': gone]' | awk '{print $1}'`; do git branch -D $branch; done

3. Writing good commit messages

Having a good guideline for creating commits and sticking to it makes working with Git and collaborating with others a lot easier. Here are some rules of thumb (source):

  • Separate the subject from the body with a newline between the two.

    Why:

    Git is smart enough to distinguish the first line of your commit message as your summary. In fact, if you try git shortlog, instead of git log, you will see a long list of commit messages, consisting of the id of the commit, and the summary only.

  • Limit the subject line to 50 characters and Wrap the body at 72 characters.

    why

    Commits should be as fine-grained and focused as possible, it is not the place to be verbose. @preslavrachev/what-s-with-the-50-72-rule-8a906f61f09c">read more…

  • Capitalize the subject line.

  • Do not end the subject line with a period.
  • Use imperative mood in the subject line.

    Why:

    Rather than writing messages that say what a committer has done. It’s better to consider these messages as the instructions for what is going to be done after the commit is applied on the repository. read more…

Todo

  • Add production build.
  • Install editorconfig extension for visual studio code.
  • Add .env package.
  • Add eslint.
  • Add babel-watch.
  • Add knex.
  • Add node security.

Note

  • babel-watch could be crash when it was occurred Error: Cannot find module './chalkConfig'. You should kill the current command with Ctrt+C and re-run npm run dev.