Skip to content

Commit d18ff5b

Browse files
author
Aaron Chambers
committed
Merge pull request #7 from strange-studios/make-file-pattern-relative-to-dist-dir
Now we use the `context.distDir` as the distFiles prop is now relative
2 parents e6534de + 76745b5 commit d18ff5b

File tree

3 files changed

+35
-27
lines changed

3 files changed

+35
-27
lines changed

index.js

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,22 @@ module.exports = {
2121
name: 'ember-cli-deploy-json-config',
2222

2323
createDeployPlugin: function(options) {
24-
function _beginMessage(ui, inputPattern, outputPattern) {
25-
ui.write(blue('| '));
26-
ui.writeLine(blue('- generating `' + outputPattern + '` from `' + inputPattern + '`'));
24+
function _beginMessage(ui, inputPath, outputPath) {
25+
ui.write(blue('| '));
26+
ui.writeLine(blue('- generating `' + outputPath + '` from `' + inputPath + '`'));
2727

2828
return Promise.resolve();
2929
}
3030

31-
function _successMessage(ui, outputPattern) {
32-
ui.write(blue('| '));
33-
ui.writeLine(blue('- generated: `' + outputPattern + '`'));
31+
function _successMessage(ui, outputPath) {
32+
ui.write(blue('| '));
33+
ui.writeLine(blue('- generated: `' + outputPath + '`'));
3434

35-
return Promise.resolve(outputPattern);
35+
return Promise.resolve();
3636
}
3737

3838
function _errorMessage(ui, error) {
39-
ui.write(blue('| '));
39+
ui.write(blue('| '));
4040
ui.write(red('- ' + error + '`\n'));
4141

4242
return Promise.reject(error);
@@ -62,20 +62,26 @@ module.exports = {
6262
var ui = deployment.ui;
6363
var config = deployment.config[this.name];
6464
var project = deployment.project;
65-
var root = project.root;
66-
67-
var fileInputPattern = config.fileInputPattern;
68-
var fileOutputPattern = config.fileOutputPattern;
69-
var inputPath = path.join(root, fileInputPattern);
70-
var outputPath = path.join(root, fileOutputPattern);
7165

72-
return _beginMessage(ui, fileInputPattern, fileOutputPattern)
73-
.then(readFile.bind(readFile, inputPath))
66+
var root = project.root;
67+
var distDir = context.distDir;
68+
var fileInputPattern = config.fileInputPattern;
69+
var fileOutputPattern = config.fileOutputPattern;
70+
var inputPath = path.join(distDir, fileInputPattern);
71+
var outputPath = path.join(distDir, fileOutputPattern);
72+
var absoluteInputPath = path.join(root, inputPath);
73+
var absoluteOutputPath = path.join(root, outputPath);
74+
75+
return _beginMessage(ui, inputPath, outputPath)
76+
.then(readFile.bind(readFile, absoluteInputPath))
7477
.then(extractConfig.bind(this))
75-
.then(writeFile.bind(writeFile, outputPath))
76-
.then(_successMessage.bind(this, ui, fileOutputPattern))
77-
.then(function(outputPattern) {
78-
return { distFiles: [outputPattern] };
78+
.then(writeFile.bind(writeFile, absoluteOutputPath))
79+
.then(_successMessage.bind(this, ui, outputPath))
80+
.then(function() {
81+
ui.write(blue('| '));
82+
ui.writeLine(blue('- added `' + fileOutputPattern + '` to `context.distFiles`'));
83+
84+
return { distFiles: [fileOutputPattern] };
7985
})
8086
.catch(_errorMessage.bind(this, ui));
8187
}

lib/utilities/validate-config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ module.exports = function(ui, config) {
99
ui.writeLine(blue('- validating config'));
1010

1111
var defaultConfig = {
12-
fileInputPattern: 'dist/index.html',
13-
fileOutputPattern: 'dist/index.json'
12+
fileInputPattern: 'index.html',
13+
fileOutputPattern: 'index.json'
1414
};
1515

1616
['fileInputPattern', 'fileOutputPattern'].forEach(function(prop) {

tests/unit/index-nodetest.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,14 @@ describe('the deploy plugin object', function() {
6666
});
6767

6868
var context = {
69+
distDir: 'dist',
6970
deployment: {
7071
project: { root: fakeRoot },
7172
ui: {write: function() {}, writeLine: function() {}},
7273
config: {
7374
'json-config': {
74-
fileInputPattern: 'dist/index.html',
75-
fileOutputPattern: 'dist/index.json'
75+
fileInputPattern: 'index.html',
76+
fileOutputPattern: 'index.json'
7677
}
7778
}
7879
},
@@ -102,13 +103,14 @@ describe('the deploy plugin object', function() {
102103

103104
var data = {};
104105
var context = {
106+
distDir: 'dist',
105107
deployment: {
106108
project: { root: fakeRoot },
107109
ui: {write: function() {}, writeLine: function() {}},
108110
config: {
109111
'json-config': {
110-
fileInputPattern: 'dist/index.html',
111-
fileOutputPattern: 'dist/index.json'
112+
fileInputPattern: 'index.html',
113+
fileOutputPattern: 'index.json'
112114
}
113115
}
114116
}
@@ -117,7 +119,7 @@ describe('the deploy plugin object', function() {
117119
var promise = plugin.didBuild.call(plugin, context);
118120
return assert.isFulfilled(promise)
119121
.then(function(result) {
120-
assert.deepEqual(result.distFiles, ['dist/index.json']);
122+
assert.deepEqual(result.distFiles, ['index.json']);
121123
});
122124
});
123125
});

0 commit comments

Comments
 (0)