Skip to content

Commit

Permalink
feat(generators/app/templates): include setting up two git hooks that…
Browse files Browse the repository at this point in the history
… will help keeping `node_modules` in sync with `package-lock.json`

Include guidance for this in the generated `README.md`
  • Loading branch information
cueedee committed Oct 11, 2017
1 parent 9f2e96c commit e633778
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 6 deletions.
15 changes: 15 additions & 0 deletions generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,11 @@ class AppGenerator extends Generator
// Third-party, external libraries:

, 'vendor'

// Version-controlled git hooks

, '.git/hooks'
, '.git-hooks'
]
;

Expand Down Expand Up @@ -589,6 +594,9 @@ class AppGenerator extends Generator
, 'test/unit/spec/models/settings-environment.spec.coffee'
, 'test/unit/spec/trivial.spec.coffee'

// Version controlled git hook scripts.

, '@.git-hooks/git-hook-on-npm-lockfile-change.sh'
]
;

Expand Down Expand Up @@ -639,6 +647,13 @@ class AppGenerator extends Generator

this._symLink( 'settings/testing.json', 'test/unit/asset/settings.json' );

//
// Symlink git hooks:
//

this._symLink( '.git-hooks/git-hook-on-npm-lockfile-change.sh', '.git/hooks/post-checkout' );
this._symLink( '.git-hooks/git-hook-on-npm-lockfile-change.sh', '.git/hooks/post-merge' );

}
)();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

## Do not `post-checkout` when checking out a single file
##
if [[ "$( basename "${0}" )" == "post-checkout" && "${3}" == "0" ]] ; then
exit
fi

changed_files="$(git diff-tree -r --name-only --no-commit-id HEAD@{1} HEAD)"

function changed
{
echo "${changed_files}" | grep --quiet "${1}"
}

changed package-lock.json && npm run refresh
17 changes: 11 additions & 6 deletions generators/app/templates/@README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ Clone this repository somewhere, switch to it, then:
$ git config commit.template ./.gitmessage
# ... Set up any local tracking branches in addition to the default one. Depends on the branching model used, if any;
# ... Initialize your branching model tools, if need be ... ex: `git flow init -d`;
$ npm install
$ ( cd ./.git/hooks && ln -s ../../.git-hooks/git-hook-on-npm-lockfile-change.sh post-checkout )
$ ( cd ./.git/hooks && ln -s ../../.git-hooks/git-hook-on-npm-lockfile-change.sh post-merge )
$ npm run refresh
```

This will:
Expand All @@ -40,7 +42,10 @@ This will:
detailed, meaningful [CHANGELOG](./CHANGELOG.md) can be constructed automatically;
* _\[... Ensure you have local ... and ... branches tracking their respective remote counterparts;\]_
* _\[... Set up the ... [branching model](#branching-model);\]_
* Install all required dependencies;
* Set up two [git hooks](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks) to ensure that your `node_modules` will be synced with the
[`package-lock.json`](https://docs.npmjs.com/files/package-lock.json) dependency tree definition whenever a `git merge` or -`checkout` causes it to
change.
* Install all required dependencies, pruned and deduplicated;


### Build
Expand Down Expand Up @@ -110,8 +115,8 @@ This project uses [`conventional-changelog/standard-version`](https://github.com
[CHANGELOG](./CHANGELOG.md) management.
To make this work, *please* ensure that your commit messages adhere to the
[Commit Message Format](https://github.com/bcoe/conventional-changelog-standard/blob/master/convention.md#commit-message-format). Setting your `git config` to
have the `commit.template` as referenced below will help you with [a detailed reminder](.gitmessage) of how to do this on every `git commit`.
[Commit Message Format](https://github.com/bcoe/conventional-changelog-standard/blob/master/convention.md#commit-message-format). Setting your `git config`
to have the `commit.template` as referenced below will help you with [a detailed reminder](.gitmessage) of how to do this on every `git commit`.
```bash
$ git config commit.template ./.gitmessage
Expand All @@ -120,8 +125,8 @@ $ git config commit.template ./.gitmessage
### Release
_\[Here, you might want to say something about your release- and versioning strategy. Likely, this is related to what you chose for a branching model. At the
very least it should include:\]_
_\[Here, you might want to say something about your release- and versioning strategy. Likely, this is related to what you chose for a branching model. At
the very least it should include:\]_
* Determine what your next [semver](https://docs.npmjs.com/getting-started/semantic-versioning#semver-for-publishers) `<version>` should be:
Expand Down
1 change: 1 addition & 0 deletions generators/app/templates/@package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"prebuild": "rm -rf \"${npm_package_config_dist}\"",
"predist": "npm run build",
"prepublishOnly": "npm run dist",
"refresh": "set -x; npm prune && npm install && npm dedupe",
"release": "standard-version",
"test": "command -v grunt > /dev/null || { echo >&2 'It appears that \"grunt\" is not installed. Consider running \"[sudo ]npm install -g grunt-cli\" first.'; exit ; } && grunt test"
},
Expand Down

0 comments on commit e633778

Please sign in to comment.