Skip to content

Commit

Permalink
Merge commit '5690999' into demo
Browse files Browse the repository at this point in the history
  • Loading branch information
cueedee committed Oct 10, 2017
2 parents c209298 + 5690999 commit 5bf98b5
Show file tree
Hide file tree
Showing 45 changed files with 1,657 additions and 450 deletions.
82 changes: 46 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ yo bat:demo
**Note:** that the latter _will_ result in a few clashes with some of the files produced from the earlier `yo bat` run. These are however, caveat codor, harmless.


## Grunt tasks
### Grunt tasks

After you're all set up, you'll want to build your project; this is where [Grunt](http://gruntjs.com) comes in:

Expand All @@ -169,21 +169,22 @@ Grunt can do more than just that; here's a recap of common grunt idioms:

command | description
:-- |:--
`grunt [default]` | does a for-production, non-debugging, all-parts, tested, minified build plus artifacts;
`grunt [default]` | shortcut for `grunt dist` unless the `GRUNT_TASKS` environment variable specifies a space separated list of alternative tasks to run instead;
`grunt dist` | does a for-production, non-debugging, all-parts, tested, minified build plus artifacts;
`grunt debug` | does a for-testing, debugging, all-parts except documentation, tested, as-is build;
`grunt dev` | does a for-local, debugging, all-parts except documentation, as-is build; <br>_(**Note that this variant doesn't exit**. Instead it'll keep a close watch on filesystem changes, selectively re-triggering part builds as needed)_
`grunt dev` | does a for-local, debugging, all-parts except documentation, as-is build; <br> _**(Note that this variant doesn't exit**. Instead it'll keep a close watch on filesystem changes, selectively re-triggering part builds as needed)_
`grunt doc` | will build just the code documentation;
`grunt lint` | will just lint your code;
`grunt test` | will run your test suite;
`grunt test:dev` | will run your test suite and will keep monitoring it for changes, triggering re-runs;
`grunt --help` | will show you all of the above and the kitchen sink;


## Unit tests
### Unit tests

BAT comes with support for unit testing using [Karma](http://karma-runner.github.io/1.0/), [Jasmine](http://jasmine.github.io/2.4/introduction.html) and [PhantomJS](http://phantomjs.org/).

Unit testing is an integrated build step in both `default` and `debug` build runs, but can also be run independently as:
Unit testing is an integrated build step in both `dist` and `debug` build runs, but can also be run independently as:

```shell
grunt test
Expand Down Expand Up @@ -222,15 +223,19 @@ Clone this repository somewhere, switch to it, then:

```bash
$ git config commit.template ./.gitmessage
$ git checkout master
$ git checkout develop
$ git flow init -d
$ npm install
```

This will:
* Setup [a helpful reminder](.gitmessage) of how to make [a good commit message](#commit-message-format-discipline). If you adhere to this, then a detailed,
meaningful [CHANGELOG](CHANGELOG.md) can be constructed automatically.
* Setup the git flow [branching model](#branching-model) and checkout the `develop` branch.
* Install all required dependencies.

* Set up [a helpful reminder](.gitmessage) of how to make [a good commit message](#commit-message-format-discipline). If you adhere to this, then a
detailed, meaningful [CHANGELOG](CHANGELOG.md) can be constructed automatically;
* Ensure you have local `master` and `develop` branches tracking their respective remote counterparts;
* Set up the git flow [branching model](#branching-model) with default branch names;
* Install all required dependencies;


### Commit
Expand All @@ -256,40 +261,45 @@ $ git config commit.template ./.gitmessage

### Release

* Determine what your next [semver](https://docs.npmjs.com/getting-started/semantic-versioning#semver-for-publishers) `<version>` should be:
```bash
$ version="<version>"
```
* Determine what your next [semver](https://docs.npmjs.com/getting-started/semantic-versioning#semver-for-publishers) `<version>` should be:

```bash
$ version="<version>"
```

* Create and checkout a `release/v<version>` branch off of `develop`:

```bash
$ git flow release start "v${version}"
```

* Bump the package's `.version`, update the [CHANGELOG](./CHANGELOG.md), commit these, and tag the commit as `v<version>`:
```bash
$ npm run release
```
* Create and checkout a `release/v<version>` branch off of `develop`:
```bash
$ git flow release start "v${version}"
```
* If all is well this new `version` **should** be identical to your intended `<version>`:
* Bump the package's `.version`, update the [CHANGELOG](./CHANGELOG.md), commit these, and tag the commit as `v<version>`:
```bash
$ npm run release
```
```bash
$ jq ".version == \"${version}\"" package.json
```
* If all is well this new `version` **should** be identical to your intended `<version>`:
```bash
$ jq ".version == \"${version}\"" package.json
```
*If this is not the case*, then either your assumptions about what changed are wrong, or (at least) one of your commits did not adhere to the
[Commit Message Format Discipline](#commit-message-format-discipline); **Abort the release, and sort it out first.**
*If this is not the case*, then either your assumptions about what changed are wrong, or (at least) one of your commits did not adhere to the
[Commit Message Format Discipline](#commit-message-format-discipline); **Abort the release, and sort it out first.**
* Merge `release/v<version>` back into both `develop` and `master`, checkout `develop` and delete `release/v<version>`:
* Merge `release/v<version>` back into both `develop` and `master`, checkout `develop` and delete `release/v<version>`:
```bash
$ git flow release finish -n "v${version}"
```
```bash
$ git flow release finish -n "v${version}"
```
Note that contrary to vanilla `git flow`, the merge commit into `master` will *not* have been tagged (that's what the
[`-n`](https://github.com/nvie/gitflow/wiki/Command-Line-Arguments#git-flow-release-finish--fsumpkn-version) was for). This is done because `npm run release`
has already tagged its own commit.
Note that contrary to vanilla `git flow`, the merge commit into `master` will *not* have been tagged (that's what the
[`-n`](https://github.com/nvie/gitflow/wiki/Command-Line-Arguments#git-flow-release-finish--fsumpkn-version) was for). This is done because
`npm run release` has already tagged its own commit.

I believe that in practice, this won't make a difference for the use of `git flow`; and ensuring it's done the other way round instead would render the use
of `conventional-changelog` impossible.
I believe that in practice, this won't make a difference for the use of `git flow`; and ensuring it's done the other way round instead would render the use
of `conventional-changelog` impossible.


### Publish
Expand Down
177 changes: 177 additions & 0 deletions generators/api/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
'use strict';

//
// Yeoman bat:api sub-generator.
//

var generators = require( 'yeoman-generator' )
, yosay = require( 'yosay' )
, youtil = require( './../../lib/youtil.js' )
, chalk = require( 'chalk' )
, _ = require( 'lodash' )
;

var ApiGenerator = generators.Base.extend(
{
constructor: function ()
{
generators.Base.apply( this, arguments );

this.description = this._description( 'API-instance' );

this.argument(
'apiName'
, {
type: String
, required: false
, desc: 'The name of the API-instance to create.'
}
);

// Also add 'apiName' as a - hidden - option, defaulting to the positional argument's value.
// This way `_promptsPruneByOptions()` can filter away prompting for the API name too.
//
this.option(
'apiName'
, {
type: String
, desc: 'The name of the API-instance to create.'
, default: this.apiName
, hide: true
}
);

// Normal options.
//
this.option(
'description'
, {
type: String
, desc: 'The purpose of this API.'
}
);

this.option(
'url'
, {
type: String
, desc: 'The base URL for this API.'
}
);

}

, initializing: function ()
{
this._assertBatApp();

// Container for template expansion data.
//
this.templateData = {};
}

, prompting:
{
askSomeQuestions: function ()
{
// Ask only those question that have not yet been provided with answers via the command line.
//
var prompts = this._promptsPruneByOptions(
[
{
type: 'input'
, name: 'apiName'
, message: 'What is the name of this API-instance you so desire?'
, default: youtil.definedToString( this.options.apiName )
, validate: youtil.isIdentifier
, filter: function ( value )
{
return _.lowerFirst( _.trim( value ).replace( /api$/i, '' ));
}
}
, {
type: 'input'
, name: 'description'
, message: 'What is the purpose (description) of this API?'
, default: function ( answers )
{
return (
youtil.definedToString( this.options.description )
|| (
'A collection of services\' endpoints available on the '
+ ( answers.apiName || this.templateData.apiName )
+ ' API.'
)
);
}.bind( this )
, validate: youtil.isNonBlank
, filter: youtil.sentencify
}
, {
type: 'input'
, name: 'url'
, message: 'What is the base URL for this API? ' + chalk.gray( ' - please enter as code:' )
, default: youtil.definedToString( this.options.url )
, validate: youtil.isCoffeeScript
}
]
)
;

if ( prompts.length )
{
// Have Yeoman greet the user.
//
this.log( yosay( 'So you want a BAT API-instance?' ) );

return (
this
.prompt( prompts )
.then( function ( answers ) { _.extend( this.templateData, answers ); }.bind( this ) )
);
}
}
}

, configuring: function ()
{
var data = this.templateData
, apiName = data.apiName
;

_.extend(
data
, {
className: _.upperFirst( apiName ) + 'Api'
, fileBase: _.kebabCase( _.deburr( apiName ))

, userName: this.user.git.name()

}
);
}

, writing:
{
createApi: function ()
{
var data = this.templateData
, templates =
{
'api.coffee': [ 'src/apis/' + data.fileBase + '.coffee' ]
}
;

this._templatesProcess( templates );
}
}
}
);

_.extend(
ApiGenerator.prototype
, require( './../../lib/generator.js' )
, require( './../../lib/sub-generator.js' )
);

module.exports = ApiGenerator;
54 changes: 54 additions & 0 deletions generators/api/templates/api.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
( ( factory ) ->
if typeof exports is 'object'
module.exports = factory(

require( './../collections/api-services.coffee' )
)
else if typeof define is 'function' and define.amd
define( [

'./../collections/api-services.coffee'
], factory )
return
)((

ApiServicesCollection
) ->

###*
# @author <%- userName %>
# @module App
# @submodule Apis
###

'use strict'


###*<% if ( description ) { %>
# <%- description %>
#<% } %>
# @class <%- className %>
# @static
###

new ApiServicesCollection(

[
]

,
###*
# The `<%- className %>`'s base url.
#
# @property url
# @type String
# @final
#
# @default <%- url %>
###

url: <%- url %>

)

)
Loading

0 comments on commit 5bf98b5

Please sign in to comment.