Skip to content

Commit 0c1a6d8

Browse files
committed
Initial working version
1 parent 491e495 commit 0c1a6d8

File tree

6 files changed

+363
-23
lines changed

6 files changed

+363
-23
lines changed

README.md

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,40 @@
11
# Ember-cli-deploy-display-revisions
22

3-
This README outlines the details of collaborating on this Ember addon.
3+
Display a list of deployed revisions using [ember-cli-deploy](https://github.com/ember-cli/ember-cli-deploy). This plugin is for `ember-cli-deploy` >= 0.5.0.
44

55
## Installation
66

7-
* `git clone` this repository
8-
* `npm install`
9-
* `bower install`
7+
* `npm install ember-cli-deploy-display-revisions`
108

11-
## Running
9+
## Usage
1210

13-
* `ember server`
14-
* Visit your app at http://localhost:4200.
11+
* `ember deploy:list <environment>` to list the latest 10 revisions
12+
* `ember deploy:list --amount <N> <environment>` to list the latest <N> revisions
1513

16-
## Running Tests
14+
## Passing revisions
1715

18-
* `ember test`
19-
* `ember test --server`
16+
`ember-cli-deploy-display-revisions` expects the `fetchRevisions` to be implemented by your index plugin, filling the `revisions` variable in context in the following format:
2017

21-
## Building
18+
```
19+
[
20+
{
21+
revision: 'abc123', // mandatory
22+
version: 'v1',
23+
timestamp: 1438232435000, // milliseconds since epoch
24+
deployer: 'cats'
25+
},
26+
{
27+
revision: 'def456',
28+
version: 'v2',
29+
timestamp: 1032123128000,
30+
deployer: 'dogs',
31+
active: true // indicate whether this revision is activated
32+
}
33+
]
34+
```
2235

23-
* `ember build`
36+
Omitted keys are not displayed in listing the results.
2437

25-
For more information on using ember-cli, visit [http://www.ember-cli.com/](http://www.ember-cli.com/).
38+
## Tests
39+
40+
* ember test

index.js

Lines changed: 110 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,115 @@
11
/* jshint node: true */
22
'use strict';
33

4+
var DeployPluginBase = require('ember-cli-deploy-plugin');
5+
var moment = require('moment');
6+
47
module.exports = {
5-
name: 'ember-cli-deploy-display-revisions'
8+
name: 'ember-cli-deploy-display-revisions',
9+
10+
createDeployPlugin: function(options) {
11+
var DeployPlugin = DeployPluginBase.extend({
12+
name: options.name,
13+
14+
defaultConfig: {
15+
amount: function(context) {
16+
return context.commandOptions.amount || 10;
17+
},
18+
},
19+
20+
displayRevisions: function(context) {
21+
if(!context.revisions) {
22+
this.log("Could not display latest revisions because no revisions were found in context.", {color: 'yellow'});
23+
return;
24+
}
25+
26+
var revisions = context.revisions.slice(0, this.readConfig("amount"));
27+
28+
var keys = this._getKeys(revisions);
29+
30+
this._displayHeader(keys, revisions);
31+
32+
revisions.forEach(function(revision) {
33+
this._displayRow(keys, revision);
34+
}.bind(this));
35+
},
36+
_displayRow: function(keys, revision) {
37+
var row = "";
38+
if(revision.active) {
39+
row += ">";
40+
} else {
41+
row += " ";
42+
}
43+
44+
var lastKey = keys[keys.length - 1];
45+
46+
keys.forEach(function(key) {
47+
var value = revision[key.name] ? revision[key.name] : "";
48+
49+
if(key.name === 'timestamp') {
50+
value = moment(value).format("YYYY/MM/DD HH:MM:SS");
51+
}
52+
53+
if(key.maxLength !== -1) {
54+
value = String(value).substr(0, key.maxLength);
55+
}
56+
57+
row += " " + value + " ";
58+
59+
var fillerLength = key.maxLength - value.length;
60+
for(var i = 0; i < fillerLength; i++) {
61+
row += " ";
62+
}
63+
if(key !== lastKey) {
64+
row += "|"
65+
}
66+
});
67+
68+
this.log(row);
69+
},
70+
_getKeys: function(revisions) {
71+
var keys = [{name: 'version', maxLength: 7}, {name: 'timestamp', maxLength: 19}, {name: 'deployer', maxLength: 10}, {name: 'revision', maxLength: -1}];
72+
var presentKeys = [];
73+
keys.forEach(function(key) {
74+
if(this._hasKey(key.name, revisions)) {
75+
presentKeys.push(key);
76+
}
77+
}.bind(this));
78+
return presentKeys;
79+
},
80+
_displayHeader: function(keys, revisions) {
81+
var keyHeader = " ";
82+
var lastKey = keys[keys.length - 1];
83+
84+
keys.forEach(function(key) {
85+
var shortKey = key.maxLength === -1 ? key.name : key.name.substr(0, key.maxLength);
86+
keyHeader += " " + shortKey + " ";
87+
88+
var fillerLength = key.maxLength === -1 ? 0 : key.maxLength - shortKey.length;
89+
for(var i = 0; i < fillerLength; i++) {
90+
keyHeader += " ";
91+
}
92+
93+
// revision hash needs an unknown amount of space, don't display closing |
94+
if(key !== lastKey) {
95+
keyHeader += "|"
96+
}
97+
});
98+
this.log(keyHeader);
99+
100+
var underline = "";
101+
for(var i = 0; i < keyHeader.length; i++) {
102+
underline += "=";
103+
}
104+
this.log(underline);
105+
},
106+
_hasKey: function(key, revisions) {
107+
return revisions.some(function(revision) {
108+
return Object.keys(revision).indexOf(key) !== -1;
109+
});
110+
}
111+
});
112+
113+
return new DeployPlugin();
114+
}
6115
};

package.json

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
{
22
"name": "ember-cli-deploy-display-revisions",
3-
"version": "0.0.0",
4-
"description": "The default blueprint for ember-cli addons.",
3+
"version": "0.0.1",
4+
"description": "Display a list of deployed revisions using ember-cli-deploy.",
55
"directories": {
66
"doc": "doc",
77
"test": "tests"
88
},
99
"scripts": {
1010
"start": "ember server",
1111
"build": "ember build",
12-
"test": "ember try:testall"
12+
"test": "node tests/runner.js"
1313
},
14-
"repository": "",
14+
"repository": "https://github.com/duizendnegen/ember-cli-deploy-display-revisions",
1515
"engines": {
1616
"node": ">= 0.10.0"
1717
},
1818
"author": "",
1919
"license": "MIT",
2020
"devDependencies": {
2121
"broccoli-asset-rev": "^2.0.2",
22+
"chai": "^2.2.0",
23+
"chai-as-promised": "^5.0.0",
2224
"ember-cli": "0.2.3",
2325
"ember-cli-app-version": "0.3.3",
2426
"ember-cli-content-security-policy": "0.4.0",
@@ -31,15 +33,20 @@
3133
"ember-data": "1.0.0-beta.16.1",
3234
"ember-export-application-global": "^1.0.2",
3335
"ember-disable-prototype-extensions": "^1.0.0",
34-
"ember-try": "0.0.4"
36+
"ember-try": "0.0.4",
37+
"glob": "^5.0.5",
38+
"mocha": "^2.2.4"
3539
},
3640
"keywords": [
37-
"ember-addon"
41+
"ember-addon",
42+
"ember-cli-deploy-plugin"
3843
],
3944
"dependencies": {
40-
"ember-cli-babel": "^5.0.0"
45+
"ember-cli-babel": "^5.0.0",
46+
"ember-cli-deploy-plugin": "^0.1.2",
47+
"moment": "2.10.6"
4148
},
4249
"ember-addon": {
4350
"configPath": "tests/dummy/config"
4451
}
45-
}
52+
}

tests/.jshintrc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@
2121
"andThen",
2222
"currentURL",
2323
"currentPath",
24-
"currentRouteName"
24+
"currentRouteName",
25+
"require",
26+
"describe",
27+
"before",
28+
"beforeEach",
29+
"it",
30+
"process"
2531
],
2632
"node": false,
2733
"browser": false,

tests/runner.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*jshint globalstrict: true*/
2+
'use strict';
3+
4+
var glob = require('glob');
5+
var Mocha = require('mocha');
6+
7+
var mocha = new Mocha({
8+
reporter: 'spec'
9+
});
10+
11+
var arg = process.argv[2];
12+
var root = 'tests/';
13+
14+
function addFiles(mocha, files) {
15+
glob.sync(root + files).forEach(mocha.addFile.bind(mocha));
16+
}
17+
18+
addFiles(mocha, '/**/*-nodetest.js');
19+
20+
if (arg === 'all') {
21+
addFiles(mocha, '/**/*-nodetest-slow.js');
22+
}
23+
24+
mocha.run(function(failures) {
25+
process.on('exit', function() {
26+
process.exit(failures);
27+
});
28+
});

0 commit comments

Comments
 (0)