From ecc820c3aac7f546ea3cc78652474caf9abc1cf1 Mon Sep 17 00:00:00 2001 From: Aaron Chambers Date: Thu, 27 Aug 2015 19:54:26 +0100 Subject: [PATCH 1/4] Rename repo to ember-cli-deploy-revision-data --- CHANGELOG.md | 20 ++++++++++---------- README.md | 6 +++--- RELEASE.md | 2 +- bin/changelog | 2 +- bin/prepare-release | 2 +- bower.json | 2 +- index.js | 2 +- package.json | 4 ++-- tests/unit/index-nodetest.js | 20 ++++++++++---------- 9 files changed, 30 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b7c4504..c9665b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,15 +13,15 @@ Thank you to all who took the time to contribute! #### Community Contributions -- [#1](https://github.com/zapnito/ember-cli-deploy-revision-key/pull/1) Create a tag form the hash of the index.html [@achambers](https://github.com/achambers) -- [#3](https://github.com/zapnito/ember-cli-deploy-revision-key/pull/3) Updated to be in line with how ember-cli-deploy handles context data [@achambers](https://github.com/achambers) -- [#4](https://github.com/zapnito/ember-cli-deploy-revision-key/pull/4) Remove dependency on index path [@achambers](https://github.com/achambers) -- [#5](https://github.com/zapnito/ember-cli-deploy-revision-key/pull/5) Now filePattern is relative to the dist dir stored in `context.distDir` [@achambers](https://github.com/achambers) -- [#6](https://github.com/zapnito/ember-cli-deploy-revision-key/pull/6) Rename index-hash to file-hash [@lukemelia](https://github.com/lukemelia) -- [#7](https://github.com/zapnito/ember-cli-deploy-revision-key/pull/7) Change to use `configure` hook instead of `willDeploy` [@achambers](https://github.com/achambers) -- [#8](https://github.com/zapnito/ember-cli-deploy-revision-key/pull/8) Renamed project and all references to `tags` [@achambers](https://github.com/achambers) -- [#9](https://github.com/zapnito/ember-cli-deploy-revision-key/pull/9) `configure` primes the config with data from the deployment context [@achambers](https://github.com/achambers) -- [#10](https://github.com/zapnito/ember-cli-deploy-revision-key/pull/10) Restructure to use ember-cli-deploy-plugin, and complete rename to em… [@lukemelia](https://github.com/lukemelia) -- [#12](https://github.com/zapnito/ember-cli-deploy-revision-key/pull/12) Update README for v0.5.0 [@achambers](https://github.com/achambers) +- [#1](https://github.com/zapnito/ember-cli-deploy-revision-data/pull/1) Create a tag form the hash of the index.html [@achambers](https://github.com/achambers) +- [#3](https://github.com/zapnito/ember-cli-deploy-revision-data/pull/3) Updated to be in line with how ember-cli-deploy handles context data [@achambers](https://github.com/achambers) +- [#4](https://github.com/zapnito/ember-cli-deploy-revision-data/pull/4) Remove dependency on index path [@achambers](https://github.com/achambers) +- [#5](https://github.com/zapnito/ember-cli-deploy-revision-data/pull/5) Now filePattern is relative to the dist dir stored in `context.distDir` [@achambers](https://github.com/achambers) +- [#6](https://github.com/zapnito/ember-cli-deploy-revision-data/pull/6) Rename index-hash to file-hash [@lukemelia](https://github.com/lukemelia) +- [#7](https://github.com/zapnito/ember-cli-deploy-revision-data/pull/7) Change to use `configure` hook instead of `willDeploy` [@achambers](https://github.com/achambers) +- [#8](https://github.com/zapnito/ember-cli-deploy-revision-data/pull/8) Renamed project and all references to `tags` [@achambers](https://github.com/achambers) +- [#9](https://github.com/zapnito/ember-cli-deploy-revision-data/pull/9) `configure` primes the config with data from the deployment context [@achambers](https://github.com/achambers) +- [#10](https://github.com/zapnito/ember-cli-deploy-revision-data/pull/10) Restructure to use ember-cli-deploy-plugin, and complete rename to em… [@lukemelia](https://github.com/lukemelia) +- [#12](https://github.com/zapnito/ember-cli-deploy-revision-data/pull/12) Update README for v0.5.0 [@achambers](https://github.com/achambers) Thank you to all who took the time to contribute! diff --git a/README.md b/README.md index 9e469a9..9c19b26 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# ember-cli-deploy-revision-key +# ember-cli-deploy-revision-data > An ember-cli-deploy plugin to generate a unique revision key based on the current build @@ -22,7 +22,7 @@ To get up and running quickly, do the following: - Install this plugin ```bash -$ ember install ember-cli-deploy-revision-key +$ ember install ember-cli-deploy-revision-data ``` - Run the pipeline @@ -35,7 +35,7 @@ $ ember deploy Run the following command in your terminal: ```bash -ember install ember-cli-deploy-revision-key +ember install ember-cli-deploy-revision-data ``` ## ember-cli-deploy Hooks Implemented diff --git a/RELEASE.md b/RELEASE.md index f7d2d21..a9a4610 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -16,7 +16,7 @@ The following steps should navigate you through the release process to ensure as 8. `git push upstream master` 9. `git tag "vx.y.z"` 10. `git push upstream vx.y.z` -11. `npm publish ./ember-cli-deploy-revision-key-.tgz` +11. `npm publish ./ember-cli-deploy-revision-data-.tgz` ### Create a github release diff --git a/bin/changelog b/bin/changelog index 85e08ff..b180d4b 100755 --- a/bin/changelog +++ b/bin/changelog @@ -21,7 +21,7 @@ var compareCommits = Promise.denodeify(github.repos.compareCommits); var currentVersion = 'v' + require('../package').version; var user = 'zapnito'; -var repo = 'ember-cli-deploy-revision-key'; +var repo = 'ember-cli-deploy-revision-data'; compareCommits({ user: user, diff --git a/bin/prepare-release b/bin/prepare-release index d06a2a1..cac7d9a 100755 --- a/bin/prepare-release +++ b/bin/prepare-release @@ -1,7 +1,7 @@ #!/bin/sh rm -rf node_modules && \ -rm -rf ./ember-cli-deploy-revision-key*.tgz && \ +rm -rf ./ember-cli-deploy-revision-data*.tgz && \ npm cache clear && \ npm i --no-optional && \ npm link --no-optional && \ diff --git a/bower.json b/bower.json index 41aa884..a3354f6 100644 --- a/bower.json +++ b/bower.json @@ -1,5 +1,5 @@ { - "name": "ember-cli-deploy-revision-key", + "name": "ember-cli-deploy-revision-data", "dependencies": { "ember": "1.11.1", "ember-cli-shims": "ember-cli/ember-cli-shims#0.0.3", diff --git a/index.js b/index.js index 5aa30a8..5a101b2 100644 --- a/index.js +++ b/index.js @@ -6,7 +6,7 @@ var Promise = require('ember-cli/lib/ext/promise'); var DeployPluginBase = require('ember-cli-deploy-plugin'); module.exports = { - name: 'ember-cli-deploy-revision-key', + name: 'ember-cli-deploy-revision-data', createDeployPlugin: function(options) { var DeployPlugin = DeployPluginBase.extend({ diff --git a/package.json b/package.json index e38ecfe..c392948 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "ember-cli-deploy-revision-key", + "name": "ember-cli-deploy-revision-data", "version": "0.1.0-beta.2", "description": "An ember-cli-plugin to create a unique revision key for the build", "directories": { @@ -11,7 +11,7 @@ "build": "ember build", "test": "node tests/runner.js" }, - "repository": "https://github.com/zapnito/ember-cli-deploy-revision-key", + "repository": "https://github.com/zapnito/ember-cli-deploy-revision-data", "engines": { "node": ">= 0.10.0" }, diff --git a/tests/unit/index-nodetest.js b/tests/unit/index-nodetest.js index 3f0221f..d7a2675 100644 --- a/tests/unit/index-nodetest.js +++ b/tests/unit/index-nodetest.js @@ -36,13 +36,13 @@ describe('the index', function() { describe('configure hook', function() { it('resolves if config is ok', function() { var plugin = subject.createDeployPlugin({ - name: 'revision-key' + name: 'revision-data' }); var context = { ui: mockUi, config: { - "revision-key": { + "revision-data": { type: 'file-hash', filePattern: 'eeee' } @@ -55,13 +55,13 @@ describe('the index', function() { }); it('warns about missing optional config', function() { var plugin = subject.createDeployPlugin({ - name: 'revision-key' + name: 'revision-data' }); var context = { ui: mockUi, config: { - "revision-key": { + "revision-data": { } } }; @@ -82,13 +82,13 @@ describe('the index', function() { it('adds default config to the config object', function() { var plugin = subject.createDeployPlugin({ - name: 'revision-key' + name: 'revision-data' }); var context = { ui: mockUi, config: { - "revision-key": { + "revision-data": { } } }; @@ -96,15 +96,15 @@ describe('the index', function() { plugin.beforeHook(context); plugin.configure(context); - assert.isDefined(context.config['revision-key'].type); - assert.isDefined(context.config['revision-key'].filePattern); + assert.isDefined(context.config['revision-data'].type); + assert.isDefined(context.config['revision-data'].filePattern); }); }); describe('didBuild hook', function() { it('returns the revisionKey', function() { var plugin = subject.createDeployPlugin({ - name: 'revision-key' + name: 'revision-data' }); var context = { @@ -112,7 +112,7 @@ describe('the index', function() { distFiles: ['index.html'], ui: mockUi, config: { - "revision-key": { + "revision-data": { type: 'file-hash', filePattern: 'index.html', distDir: function(context) { From 915ffc7d8bca0db2b4463883e44a6c76c27360c7 Mon Sep 17 00:00:00 2001 From: Aaron Chambers Date: Fri, 28 Aug 2015 08:25:49 +0100 Subject: [PATCH 2/4] Renamed KeyGenerators to DataGenerators --- README.md | 53 +++++++++++++++---- index.js | 10 ++-- .../file-hash.js | 8 --- .../git-tag-commit.js | 0 .../index.js | 0 .../version-commit.js | 0 package.json | 2 +- .../file-hash-nodetest.js | 12 ++--- .../git-tag-commit-nodetest.js | 12 ++--- .../version-commit-nodetest.js | 14 ++--- 10 files changed, 68 insertions(+), 43 deletions(-) rename lib/{key-generators => data-generators}/file-hash.js (87%) rename lib/{key-generators => data-generators}/git-tag-commit.js (100%) rename lib/{key-generators => data-generators}/index.js (100%) rename lib/{key-generators => data-generators}/version-commit.js (100%) rename tests/unit/lib/{key-generators => data-generators}/file-hash-nodetest.js (85%) rename tests/unit/lib/{key-generators => data-generators}/git-tag-commit-nodetest.js (81%) rename tests/unit/lib/{key-generators => data-generators}/version-commit-nodetest.js (87%) diff --git a/README.md b/README.md index 9c19b26..d0ef9d5 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,13 @@ # ember-cli-deploy-revision-data -> An ember-cli-deploy plugin to generate a unique revision key based on the current build +> An ember-cli-deploy plugin to generate data about this deploy revision including a unique revision key based on the current build
**WARNING: This plugin is only compatible with ember-cli-deploy versions >= 0.5.0**
-This plugin will generate a unique revision key for the current build. The revision key can be used to uniquely identify the particular version of the application. +This plugin will generate revison data for the current build. This data can be used by other plugins to understand more about the current revision being deployed. +The revision key included in the revison data can be used to uniquely identify the particular version of the application. ## What is an ember-cli-deploy plugin? @@ -51,18 +52,28 @@ For detailed information on how configuration of plugins works, please refer to ### type -The type of [Key Generator](#key-generators) to be used. +The type of [Data Generator](#data-generators) to be used. *Default:* `'file-hash'` *Alternatives:* `'git-tag-commit'`, `'version-commit'` -## Key Generators +## Data Generators -Key generators are the strategies used to generate the unique revision key. Currently there is only one Key Generator implementation but we will add more as needed. Some examples of other potential key generators are `GitHash` or `DateTime` generators. +Data generators are the strategies used to generate information about the revision being deployed. A data generator must return an object which contains a property called `revisionKey` which uniquely identifies the current revision. A generator can add any other data that it deems relevant to the data object that it returns. ### File Hash generator -This key generator will fingerprint the `index.html` and return an MD5 hash. The generation of the revision key, using this generator, is guaranteed to be idempotent. That is, the same revision key will be generated for the same set of project files. If the project files change in any way, this will be reflected by a change in the revision key. +This generator contructs a revisionKey from the fingerprint of the `index.html` file. + +#### Data fields returned + +##### revisionKey + +The unique identifier of this build based on the MD5 fingerprint of the `index.html` file. This key is guaranteed to be idempotent. That is, the same revision key will be generated for the same set of project files. If the project files change in any way, this will be reflected by a change in the revision key. + +##### timestamp + +The timestamp of the current deploy #### Configuration Options @@ -86,19 +97,41 @@ The list of built project files. This option should be relative to `distDir` and ### Git Tag Commit generator -Creates a key based on the most recent git tag and the currently checked-out commit. The tag is the tag identifier, followed by a `+` symbol, followed by the first 8 characters of the commit hash. +Constructs a revision key based on the most recent git tag and the currently checked-out commit. + +#### Data fields returned + +##### revisionKey + +The unique identifier of this build based on the git tag, followed by a `+` symbol, followed by the first 8 characters of the current commit hash. For example, if your most recent git tag is `v2.0.3`, and the current commit is `0993043d49f9e0[...]`, this generator will return a revision of `v2.0.3+0993043d`. +##### timestamp + +The timestamp of the current deploy + ### Version Commit generator -Similar to the Git Tag Commit generator, but uses the `package.json` version string instead of the git tag. The JSON file containing the version string can be configured with the `versionFile` option. +Similar to the Git Tag Commit generator but uses the `package.json` version string to construct the revision key instead of the git tag. + +#### Data fields returned + +##### revisionKey + +The unique identifier of this build based on the version in the `package.json`, followed by a `+` symbol, followed by the first 8 characters of the current commit hash. + +For example, if your package.json version is `v2.0.3`, and the current commit is `0993043d49f9e0[...]`, this generator will return a revision of `v2.0.3+0993043d`. + +##### timestamp + +The timestamp of the current deploy #### Configuration Options ##### versionFile -The file containing your project's version number. Must be a JSON file with a top-level `version` key. Only used by the `version-commit` key generator. +The file containing your project's version number. Must be a JSON file with a top-level `version` key. *Default:* `package.json` @@ -119,4 +152,4 @@ The following properties are expected to be present on the deployment `context` [1]: http://ember-cli.github.io/ember-cli-deploy/plugins "Plugin Documentation" [2]: https://github.com/zapnito/ember-cli-deploy-build "ember-cli-deploy-build" -[3]: https://github.com/ember-cli/ember-cli-deploy "ember-cli-deploy" +[3]: https://github.com/ember-cli/ember-cli-deploy "ember-cli-deploy" \ No newline at end of file diff --git a/index.js b/index.js index 5a101b2..2163f4e 100644 --- a/index.js +++ b/index.js @@ -25,15 +25,15 @@ module.exports = { didBuild: function(context) { var self = this; var type = this.readConfig('type'); - var KeyGenerator = require('./lib/key-generators')[type]; - var keyGenerator = new KeyGenerator({ + var DataGenerator = require('./lib/data-generators')[type]; + var dataGenerator = new DataGenerator({ plugin: this }); - this.log('creating revision key using `' + type + '`'); - return keyGenerator.generate() + this.log('creating revision data using `' + type + '`'); + return dataGenerator.generate() .then(function(revisionKey) { - self.log('generated revision key: `' + revisionKey + '`'); + self.log('generated revision ata for revision: `' + revisionKey + '`'); return revisionKey; }) .then(function(revisionKey) { diff --git a/lib/key-generators/file-hash.js b/lib/data-generators/file-hash.js similarity index 87% rename from lib/key-generators/file-hash.js rename to lib/data-generators/file-hash.js index f37e991..26b260b 100644 --- a/lib/key-generators/file-hash.js +++ b/lib/data-generators/file-hash.js @@ -31,14 +31,6 @@ module.exports = CoreObject.extend({ .then(function(contents) { return md5Hash(contents.toString()); }) - }, - - _resolveConfigValue: function(key, config, context) { - if(typeof config[key] === 'function') { - return config[key](context); - } - - return config[key]; } }); diff --git a/lib/key-generators/git-tag-commit.js b/lib/data-generators/git-tag-commit.js similarity index 100% rename from lib/key-generators/git-tag-commit.js rename to lib/data-generators/git-tag-commit.js diff --git a/lib/key-generators/index.js b/lib/data-generators/index.js similarity index 100% rename from lib/key-generators/index.js rename to lib/data-generators/index.js diff --git a/lib/key-generators/version-commit.js b/lib/data-generators/version-commit.js similarity index 100% rename from lib/key-generators/version-commit.js rename to lib/data-generators/version-commit.js diff --git a/package.json b/package.json index c392948..f66864c 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "ember-cli-deploy-revision-data", "version": "0.1.0-beta.2", - "description": "An ember-cli-plugin to create a unique revision key for the build", + "description": "An ember-cli-deploy plugin to generate data about this deploy revision including a unique revision key based on the current build", "directories": { "doc": "doc", "test": "tests" diff --git a/tests/unit/lib/key-generators/file-hash-nodetest.js b/tests/unit/lib/data-generators/file-hash-nodetest.js similarity index 85% rename from tests/unit/lib/key-generators/file-hash-nodetest.js rename to tests/unit/lib/data-generators/file-hash-nodetest.js index 4aeb756..6831b7c 100644 --- a/tests/unit/lib/key-generators/file-hash-nodetest.js +++ b/tests/unit/lib/data-generators/file-hash-nodetest.js @@ -2,11 +2,11 @@ var assert = require('ember-cli/tests/helpers/assert'); -describe('the file-hash key generator', function() { - var KeyGenerator; +describe('the file-hash data generator', function() { + var DataGenerator; before(function() { - KeyGenerator = require('../../../../lib/key-generators/file-hash'); + DataGenerator = require('../../../../lib/data-generators/file-hash'); }); describe('#generate', function() { @@ -20,7 +20,7 @@ describe('the file-hash key generator', function() { readConfig: function(key) { return this.stubConfig[key]; } }; - var subject = new KeyGenerator({ + var subject = new DataGenerator({ plugin: plugin }); @@ -40,7 +40,7 @@ describe('the file-hash key generator', function() { readConfig: function(key) { return this.stubConfig[key]; } }; - var subject = new KeyGenerator({ + var subject = new DataGenerator({ plugin: plugin }); @@ -60,7 +60,7 @@ describe('the file-hash key generator', function() { readConfig: function(key) { return this.stubConfig[key]; } }; - var subject = new KeyGenerator({ + var subject = new DataGenerator({ plugin: plugin }); diff --git a/tests/unit/lib/key-generators/git-tag-commit-nodetest.js b/tests/unit/lib/data-generators/git-tag-commit-nodetest.js similarity index 81% rename from tests/unit/lib/key-generators/git-tag-commit-nodetest.js rename to tests/unit/lib/data-generators/git-tag-commit-nodetest.js index 1434e09..df054e0 100644 --- a/tests/unit/lib/key-generators/git-tag-commit-nodetest.js +++ b/tests/unit/lib/data-generators/git-tag-commit-nodetest.js @@ -3,12 +3,12 @@ var assert = require('ember-cli/tests/helpers/assert'); var gitRepoInfo = require('git-repo-info'); -describe('the git-tag-commit key generator', function() { - var KeyGenerator; +describe('the git-tag-commit data generator', function() { + var DataGenerator; var cwd; before(function() { - KeyGenerator = require('../../../../lib/key-generators/git-tag-commit'); + DataGenerator = require('../../../../lib/data-generators/git-tag-commit'); gitRepoInfo._changeGitDir('dotgit'); }); @@ -24,7 +24,7 @@ describe('the git-tag-commit key generator', function() { it('concatenates the git tag and the git commit hash', function() { process.chdir('tests/fixtures/repo'); - var subject = new KeyGenerator(); + var subject = new DataGenerator(); return assert.isFulfilled(subject.generate()) .then(function(revision) { @@ -35,7 +35,7 @@ describe('the git-tag-commit key generator', function() { it('rejects if no repository found', function() { process.chdir('tests/fixtures/not-a-repo'); - var subject = new KeyGenerator(); + var subject = new DataGenerator(); return assert.isRejected(subject.generate()) .then(function(error) { @@ -46,7 +46,7 @@ describe('the git-tag-commit key generator', function() { it('rejects if no git tag found', function() { process.chdir('tests/fixtures/tagless-repo'); - var subject = new KeyGenerator(); + var subject = new DataGenerator(); return assert.isRejected(subject.generate()) .then(function(error) { diff --git a/tests/unit/lib/key-generators/version-commit-nodetest.js b/tests/unit/lib/data-generators/version-commit-nodetest.js similarity index 87% rename from tests/unit/lib/key-generators/version-commit-nodetest.js rename to tests/unit/lib/data-generators/version-commit-nodetest.js index 296f118..cd642a3 100644 --- a/tests/unit/lib/key-generators/version-commit-nodetest.js +++ b/tests/unit/lib/data-generators/version-commit-nodetest.js @@ -3,12 +3,12 @@ var assert = require('ember-cli/tests/helpers/assert'); var gitRepoInfo = require('git-repo-info'); -describe('the version-commit key generator', function() { - var KeyGenerator; +describe('the version-commit data generator', function() { + var DataGenerator; var cwd; before(function() { - KeyGenerator = require('../../../../lib/key-generators/version-commit'); + DataGenerator = require('../../../../lib/data-generators/version-commit'); gitRepoInfo._changeGitDir('dotgit'); }); @@ -31,7 +31,7 @@ describe('the version-commit key generator', function() { readConfig: function(key) { return this.stubConfig[key]; } }; - var subject = new KeyGenerator({ + var subject = new DataGenerator({ plugin: plugin }); @@ -51,7 +51,7 @@ describe('the version-commit key generator', function() { readConfig: function(key) { return this.stubConfig[key]; } }; - var subject = new KeyGenerator({ + var subject = new DataGenerator({ plugin: plugin }); @@ -71,7 +71,7 @@ describe('the version-commit key generator', function() { readConfig: function(key) { return this.stubConfig[key]; } }; - var subject = new KeyGenerator({ + var subject = new DataGenerator({ plugin: plugin }); @@ -91,7 +91,7 @@ describe('the version-commit key generator', function() { readConfig: function(key) { return this.stubConfig[key]; } }; - var subject = new KeyGenerator({ + var subject = new DataGenerator({ plugin: plugin }); From 280bf35bc4bc59515be7a5541b3f3a18dc9a1187 Mon Sep 17 00:00:00 2001 From: Aaron Chambers Date: Mon, 31 Aug 2015 19:41:32 +0100 Subject: [PATCH 3/4] Return revisionData object from generators --- index.js | 10 ++--- lib/data-generators/file-hash.js | 5 ++- lib/data-generators/git-tag-commit.js | 5 ++- lib/data-generators/version-commit.js | 5 ++- tests/unit/index-nodetest.js | 5 ++- .../lib/data-generators/file-hash-nodetest.js | 43 +++++++++++------- .../git-tag-commit-nodetest.js | 15 ++++++- .../version-commit-nodetest.js | 44 ++++++++++++++----- 8 files changed, 93 insertions(+), 39 deletions(-) diff --git a/index.js b/index.js index 2163f4e..d6d6ec8 100644 --- a/index.js +++ b/index.js @@ -32,12 +32,12 @@ module.exports = { this.log('creating revision data using `' + type + '`'); return dataGenerator.generate() - .then(function(revisionKey) { - self.log('generated revision ata for revision: `' + revisionKey + '`'); - return revisionKey; + .then(function(data) { + self.log('generated revision data for revision: `' + data.revisionKey + '`'); + return data; }) - .then(function(revisionKey) { - return { revisionKey: revisionKey }; + .then(function(data) { + return { revisionData: data }; }) .catch(this._errorMessage.bind(this)); }, diff --git a/lib/data-generators/file-hash.js b/lib/data-generators/file-hash.js index 26b260b..861f528 100644 --- a/lib/data-generators/file-hash.js +++ b/lib/data-generators/file-hash.js @@ -29,7 +29,10 @@ module.exports = CoreObject.extend({ return readFile(filePath) .then(function(contents) { - return md5Hash(contents.toString()); + return { + revisionKey: md5Hash(contents.toString()), + timestamp: new Date().toISOString() + }; }) } }); diff --git a/lib/data-generators/git-tag-commit.js b/lib/data-generators/git-tag-commit.js index b1741ea..f633450 100644 --- a/lib/data-generators/git-tag-commit.js +++ b/lib/data-generators/git-tag-commit.js @@ -18,6 +18,9 @@ module.exports = CoreObject.extend({ return Promise.reject('Could not build revision with tag `' + tag + '` and commit hash `' + sha + '`'); } - return Promise.resolve(info.tag + '+' + sha); + return Promise.resolve({ + revisionKey: info.tag + '+' + sha, + timestamp: new Date().toISOString() + }); } }); diff --git a/lib/data-generators/version-commit.js b/lib/data-generators/version-commit.js index 75a1af0..a5af9ac 100644 --- a/lib/data-generators/version-commit.js +++ b/lib/data-generators/version-commit.js @@ -31,7 +31,10 @@ module.exports = CoreObject.extend({ return Promise.reject('Could not build revision with version `' + json.version + '` and commit hash `' + sha + '`'); } - return json.version + '+' + sha; + return { + revisionKey: json.version + '+' + sha, + timestamp: new Date().toISOString() + }; }); } }); diff --git a/tests/unit/index-nodetest.js b/tests/unit/index-nodetest.js index d7a2675..d514d74 100644 --- a/tests/unit/index-nodetest.js +++ b/tests/unit/index-nodetest.js @@ -102,7 +102,7 @@ describe('the index', function() { }); describe('didBuild hook', function() { - it('returns the revisionKey', function() { + it('returns the revisionData', function() { var plugin = subject.createDeployPlugin({ name: 'revision-data' }); @@ -128,7 +128,8 @@ describe('the index', function() { return assert.isFulfilled(plugin.didBuild(context)) .then(function(result) { - assert.equal(result.revisionKey, 'ae1569f72495012cd5e8588e0f2f5d49'); + assert.equal(result.revisionData.revisionKey, 'ae1569f72495012cd5e8588e0f2f5d49'); + assert.isNotNull(result.revisionData.timestamp); }); }); }); diff --git a/tests/unit/lib/data-generators/file-hash-nodetest.js b/tests/unit/lib/data-generators/file-hash-nodetest.js index 6831b7c..0f6895d 100644 --- a/tests/unit/lib/data-generators/file-hash-nodetest.js +++ b/tests/unit/lib/data-generators/file-hash-nodetest.js @@ -10,24 +10,37 @@ describe('the file-hash data generator', function() { }); describe('#generate', function() { - it('generates a hash of the supplied index file', function() { - var plugin = { - stubConfig: { - distDir: 'tests/fixtures', - distFiles: ['index.html'], - filePattern: 'index.html' - }, - readConfig: function(key) { return this.stubConfig[key]; } - }; + describe('revisionData', function() { + var subject; - var subject = new DataGenerator({ - plugin: plugin - }); + before(function() { + var plugin = { + stubConfig: { + distDir: 'tests/fixtures', + distFiles: ['index.html'], + filePattern: 'index.html' + }, + readConfig: function(key) { return this.stubConfig[key]; } + }; - return assert.isFulfilled(subject.generate()) - .then(function(hash) { - assert.equal(hash, 'ae1569f72495012cd5e8588e0f2f5d49'); + subject = new DataGenerator({ + plugin: plugin }); + }); + + it('includes the revisonKey', function() { + return assert.isFulfilled(subject.generate()) + .then(function(revisionData) { + assert.equal(revisionData.revisionKey, 'ae1569f72495012cd5e8588e0f2f5d49'); + }); + }); + + it('includes a timestamp', function() { + return assert.isFulfilled(subject.generate()) + .then(function(revisionData) { + assert.isNotNull(revisionData.timestamp); + }); + }); }); it('rejects when the filePattern doesn\'t exist in distFiles', function() { diff --git a/tests/unit/lib/data-generators/git-tag-commit-nodetest.js b/tests/unit/lib/data-generators/git-tag-commit-nodetest.js index df054e0..de79b64 100644 --- a/tests/unit/lib/data-generators/git-tag-commit-nodetest.js +++ b/tests/unit/lib/data-generators/git-tag-commit-nodetest.js @@ -27,8 +27,19 @@ describe('the git-tag-commit data generator', function() { var subject = new DataGenerator(); return assert.isFulfilled(subject.generate()) - .then(function(revision) { - assert.equal(revision, '2.3.4+41d41f08'); + .then(function(data) { + assert.equal(data.revisionKey, '2.3.4+41d41f08'); + }); + }); + + it('returns a timestamp', function() { + process.chdir('tests/fixtures/repo'); + + var subject = new DataGenerator(); + + return assert.isFulfilled(subject.generate()) + .then(function(data) { + assert.isNotNull(data.timestamp); }); }); diff --git a/tests/unit/lib/data-generators/version-commit-nodetest.js b/tests/unit/lib/data-generators/version-commit-nodetest.js index cd642a3..83e76d9 100644 --- a/tests/unit/lib/data-generators/version-commit-nodetest.js +++ b/tests/unit/lib/data-generators/version-commit-nodetest.js @@ -36,17 +36,17 @@ describe('the version-commit data generator', function() { }); return assert.isFulfilled(subject.generate()) - .then(function(revision) { - assert.equal(revision, '3.2.1+41d41f08'); + .then(function(data) { + assert.equal(data.revisionKey, '3.2.1+41d41f08'); }); }); - it('rejects if no repository found', function() { - process.chdir('tests/fixtures/not-a-repo'); + it('has version source file option', function() { + process.chdir('tests/fixtures/repo'); var plugin = { stubConfig: { - versionFile: 'package.json' + versionFile: 'version.json' }, readConfig: function(key) { return this.stubConfig[key]; } }; @@ -55,18 +55,18 @@ describe('the version-commit data generator', function() { plugin: plugin }); - return assert.isRejected(subject.generate()) - .then(function(error) { - assert.equal(error, 'Could not find git repository'); + return assert.isFulfilled(subject.generate()) + .then(function(data) { + assert.equal(data.revisionKey, '1.2.3+41d41f08'); }); }); - it('has version source file option', function() { + it('returns a timestamp', function() { process.chdir('tests/fixtures/repo'); var plugin = { stubConfig: { - versionFile: 'version.json' + versionFile: 'package.json' }, readConfig: function(key) { return this.stubConfig[key]; } }; @@ -76,8 +76,28 @@ describe('the version-commit data generator', function() { }); return assert.isFulfilled(subject.generate()) - .then(function(revision) { - assert.equal(revision, '1.2.3+41d41f08'); + .then(function(data) { + assert.isNotNull(data.timestamp); + }); + }); + + it('rejects if no repository found', function() { + process.chdir('tests/fixtures/not-a-repo'); + + var plugin = { + stubConfig: { + versionFile: 'package.json' + }, + readConfig: function(key) { return this.stubConfig[key]; } + }; + + var subject = new DataGenerator({ + plugin: plugin + }); + + return assert.isRejected(subject.generate()) + .then(function(error) { + assert.equal(error, 'Could not find git repository'); }); }); From f53a9829e6af591dba95648a7c5ce4e58aa72578 Mon Sep 17 00:00:00 2001 From: Aaron Chambers Date: Mon, 31 Aug 2015 20:17:10 +0100 Subject: [PATCH 4/4] Implement the prepare hook instead of didBuild --- README.md | 4 ++-- index.js | 2 +- package.json | 3 +-- tests/unit/index-nodetest.js | 6 +++--- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index d0ef9d5..bc25722 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ ember install ember-cli-deploy-revision-data For detailed information on what plugin hooks are and how they work, please refer to the [Plugin Documentation][1]. - `configure` -- `didBuild` +- `prepare` ## Configuration Options @@ -152,4 +152,4 @@ The following properties are expected to be present on the deployment `context` [1]: http://ember-cli.github.io/ember-cli-deploy/plugins "Plugin Documentation" [2]: https://github.com/zapnito/ember-cli-deploy-build "ember-cli-deploy-build" -[3]: https://github.com/ember-cli/ember-cli-deploy "ember-cli-deploy" \ No newline at end of file +[3]: https://github.com/ember-cli/ember-cli-deploy "ember-cli-deploy" diff --git a/index.js b/index.js index d6d6ec8..65f0b6a 100644 --- a/index.js +++ b/index.js @@ -22,7 +22,7 @@ module.exports = { }, versionFile: 'package.json', }, - didBuild: function(context) { + prepare: function(context) { var self = this; var type = this.readConfig('type'); var DataGenerator = require('./lib/data-generators')[type]; diff --git a/package.json b/package.json index f66864c..0866bbd 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,6 @@ "rsvp": "^3.0.18" }, "ember-addon": { - "configPath": "tests/dummy/config", - "after": "ember-cli-deploy-json-config" + "configPath": "tests/dummy/config" } } diff --git a/tests/unit/index-nodetest.js b/tests/unit/index-nodetest.js index d514d74..80dc2d4 100644 --- a/tests/unit/index-nodetest.js +++ b/tests/unit/index-nodetest.js @@ -30,7 +30,7 @@ describe('the index', function() { }); assert.typeOf(plugin.configure, 'function'); - assert.typeOf(plugin.didBuild, 'function'); + assert.typeOf(plugin.prepare, 'function'); }); describe('configure hook', function() { @@ -101,7 +101,7 @@ describe('the index', function() { }); }); - describe('didBuild hook', function() { + describe('prepare hook', function() { it('returns the revisionData', function() { var plugin = subject.createDeployPlugin({ name: 'revision-data' @@ -126,7 +126,7 @@ describe('the index', function() { }; plugin.beforeHook(context); - return assert.isFulfilled(plugin.didBuild(context)) + return assert.isFulfilled(plugin.prepare(context)) .then(function(result) { assert.equal(result.revisionData.revisionKey, 'ae1569f72495012cd5e8588e0f2f5d49'); assert.isNotNull(result.revisionData.timestamp);