-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
56 lines (40 loc) · 1.42 KB
/
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
/* jshint node: true */
'use strict';
var path = require('path');
var fs = require('fs');
var Promise = require('ember-cli/lib/ext/promise');
var SilentError = require('silent-error');
var redis = require('then-redis');
var readFile = Promise.denodeify(fs.readFile);
module.exports = {};
module.exports.name = 'ember-cli-redis-proxy'
var configPath = path.join(process.cwd(), 'config', 'deploy');
function indexFile(indexPath) {
return readFile(indexPath, {encoding: 'utf8'});
}
var fileNotFound = function() {
var message = 'index.html could not be found.\n';
return Promise.reject(new SilentError(message));
}
function successfullyWroteKey(key) {
var message = '\nwrote index.html to ' + key + '\n';
console.log(message);
}
module.exports.postBuild = function(result) {
var environment = process.env.EMBER_ENV || 'development';
if (environment !== 'development') {
return;
}
var redisConfig = require(configPath)[environment].store;
var projectName = this.project.name();
var indexKey = projectName + ":__development__";
var currentKey = projectName + ":current";
var indexPath = path.join(result.directory, 'index.html');
var adapter = redis.createClient(redisConfig);
var uploadToRedis = function(data) {
return adapter.mset(indexKey, data, currentKey, indexKey);
}
return indexFile(indexPath)
.then(uploadToRedis, fileNotFound)
.then(successfullyWroteKey.bind(null, indexKey))
};