Skip to content

Commit 04e4c03

Browse files
author
Aaron Chambers
committed
Merge pull request #5 from strange-studios/update-to-handle-context-data
[WIP] Updated to be in line with how ember-cli-deploy handles context data
2 parents aedbe5e + 202c059 commit 04e4c03

File tree

3 files changed

+30
-35
lines changed

3 files changed

+30
-35
lines changed

index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ module.exports = {
1717
return {
1818
name: options.name,
1919

20-
build: function(context) {
21-
var project = context.project;
20+
didBuild: function(context) {
21+
var deployment = context.deployment;
22+
var project = deployment.project;
2223
var root = project.root;
23-
var distPath = path.join(root, 'dist');
24-
var indexPath = path.join(distPath, 'index.html');
25-
var outputPath = path.join(distPath, 'index.json');
24+
var indexPath = path.join(root, (context.indexPath || 'dist/index.html'));
25+
var outputPath = path.join(path.dirname(indexPath), 'index.json');
2626

2727
return readFile(indexPath)
2828
.then(this._extractConfig.bind(this), this._handleMissingFile)
2929
.then(writeFile.bind(this, outputPath))
3030
.then(function() {
31-
context.data.indexPath = outputPath;
31+
return { indexPath: outputPath };
3232
});
3333
}.bind(this)
3434
}

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
"rsvp": "^3.0.18"
4848
},
4949
"ember-addon": {
50-
"configPath": "tests/dummy/config",
51-
"after": "ember-cli-deploy-build"
50+
"configPath": "tests/dummy/config"
5251
}
5352
}

tests/unit/index-nodetest.js

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,24 @@ describe('the deploy plugin object', function() {
3333
name: 'test-plugin'
3434
});
3535

36-
assert.equal(typeof result.build, 'function');
36+
assert.equal(typeof result.didBuild, 'function');
3737
});
3838

39-
describe('build hook', function() {
40-
it('generates index.json from index.html', function(done) {
41-
var build = subject.createDeployPlugin({
39+
describe('didBuild hook', function() {
40+
it('generates index.json from index.html', function() {
41+
var didBuild = subject.createDeployPlugin({
4242
name: 'test-plugin'
43-
}).build;
43+
}).didBuild;
4444

45-
var buildOptions = {
46-
project: { root: fakeRoot },
45+
var context = {
46+
deployment: {
47+
project: { root: fakeRoot }
48+
},
4749
data: {}
4850
};
4951

50-
build(buildOptions)
52+
var promise = didBuild(context);
53+
return assert.isFulfilled(promise)
5154
.then(function() {
5255
var json = require(fakeRoot + '/dist/index.json');
5356

@@ -59,33 +62,26 @@ describe('the deploy plugin object', function() {
5962
assert.deepEqual(json.link[1], { rel: 'stylesheet', href: 'assets/app.css' });
6063
assert.deepEqual(json.script[0], { src: 'assets/vendor.js' });
6164
assert.deepEqual(json.script[1], { src: 'assets/app.js' });
62-
63-
done();
64-
})
65-
.catch(function(error) {
66-
done(error);
6765
});
6866
});
6967

70-
it ('sets the index.json path in the data object', function(done) {
71-
var build = subject.createDeployPlugin({
68+
it ('returns the index.json path', function() {
69+
var didBuild = subject.createDeployPlugin({
7270
name: 'test-plugin'
73-
}).build;
71+
}).didBuild;
7472

7573
var data = {};
76-
var buildOptions = {
77-
project: { root: fakeRoot },
78-
data: data
74+
var context = {
75+
indexPath: 'dist/index.html',
76+
deployment: {
77+
project: { root: fakeRoot }
78+
}
7979
};
8080

81-
build(buildOptions)
82-
.then(function() {
83-
assert.deepEqual(data, { indexPath: fakeRoot + '/dist/index.json' });
84-
85-
done()
86-
})
87-
.catch(function(error) {
88-
done(error);
81+
var promise = didBuild(context);
82+
return assert.isFulfilled(promise)
83+
.then(function(result) {
84+
assert.equal(result.indexPath, fakeRoot + '/dist/index.json');
8985
});
9086
});
9187
});

0 commit comments

Comments
 (0)