/
deploy-index.js
64 lines (54 loc) · 2.09 KB
/
deploy-index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
var ConfigurationReader = require('../utilities/configuration-reader');
var AdapterRegistry = require('../utilities/adapter-registry');
var Promise = require('ember-cli/lib/ext/promise');
var Task = require('ember-cli/lib/models/task');
var chalk = require('chalk');
var fs = require('fs');
var readFile = Promise.denodeify(fs.readFile);
module.exports = Task.extend({
run: function(options) {
var self = this;
var ui = this.ui;
return new ConfigurationReader({
environment: options.environment,
configFile: options.deployConfigFile,
project: this.project,
ui: ui
}).read().then(function(config){
var adapterType = config.get('store.type');
var taggingAdapterType = config.get('tagging');
var manifest = config.get('manifestPrefix');
var adapterRegistry = new AdapterRegistry({ project: self.project });
var Adapter = adapterRegistry
.lookup('index', adapterType);
var TaggingAdapter = adapterRegistry
.lookup('tagging', taggingAdapterType)
var taggingAdapter = new TaggingAdapter({
manifest: manifest
});
var deploy = new Adapter({
config: config.get('store'),
manifest: manifest,
manifestSize: config.get('store.manifestSize'),
taggingAdapter: taggingAdapter,
ui: ui
});
return readFile('dist/index.html')
.then(function(fileContent) {
ui.writeLine(chalk.blue('\nTrying to upload `dist/index.html`...\n'));
return deploy.upload(fileContent);
});
});
var indexFiles = config.get('indexFiles');
if(indexFiles) {
ui.writeLine(chalk.blue('\nUploading '+indexFiles.length+' files from `'+config.get('buildPath')+'`...\n'));
return deploy.uploadFiles(indexFiles);
} else {
return readFile(config.get('buildPath')+'index.html')
.then(function(fileContent) {
ui.writeLine(chalk.blue('\nUploading `'+config.get('buildPath')+'index.html`...\n'));
return deploy.upload(fileContent);
});
}
}
});