-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathindex.js
91 lines (72 loc) · 2.48 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
'use strict';
var path = require('path');
var fs = require('fs');
var commands = require('./lib/commands');
var postBuild = require('./lib/tasks/post-build');
var defaults = require('lodash').defaults;
var chalk = require('chalk');
module.exports = {
name: 'ember-cli-cordova',
contentFor: function(type) {
if(type === 'body') {
return '<script src="cordova.js"></script>';
}
},
includedCommands: function() {
return commands;
},
cdvConfig: function() {
var cdvConfig = defaults(this.project.config('development').cordova || {}, {
liveReload: {
enabled: false,
platform: 'ios'
}
});
return cdvConfig;
},
postBuild: function() {
return postBuild(this.project, this.cdvConfig())();
},
treeForPublic: function(tree) {
var config = this.cdvConfig();
if(config.liveReload.enabled) {
if(!config.liveReload.platform) {
throw new Error('ember-cli-cordova: You must specify a liveReload.platform in your environment.js');
}
var platformsPath = path.join(this.project.root, 'cordova', 'platforms');
var pluginsPath;
if (config.liveReload.platform === 'ios') {
pluginsPath = path.join(platformsPath, 'ios', 'www');
} else if (config.liveReload.platform === 'android') {
pluginsPath = path.join(platformsPath, 'android', 'assets', 'www');
} else {
pluginsPath = path.join(platformsPath, config.liveReload.platform);
}
var files = ['cordova.js', 'cordova_plugins.js'];
files.forEach(function(file) {
var filePath = path.join(pluginsPath, file);
if(!fs.existsSync(filePath)) {
var err = new Error('ember-cli-cordova: ' + filePath + ' did not exist. It is required for Device LiveReload to work.');
err.stack = null;
throw err;
}
});
if(fs.existsSync(path.join(pluginsPath, 'plugins'))) {
files.push('plugins/*');
}
var pluginsTree = this.pickFiles(this.treeGenerator(pluginsPath), {
srcDir: '/',
files: files,
destDir: '/'
});
console.log(chalk.green('ember-cli-cordova: Device LiveReload is enabled'));
return this.mergeTrees([tree, pluginsTree]);
}
return tree;
},
config: function(env, baseConfig) {
if (env !== 'test' && baseConfig.locationType !== 'hash') {
throw new Error('ember-cli-cordova: You must specify the locationType as \'hash\' in your environment.js');
}
}
};