forked from isleofcode/corber
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
95 lines (75 loc) · 2.84 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
92
93
94
95
'use strict';
var rasterizeIcons = require('./broccoli-plugins/rasterize-icons/plugin');
var rasterizeSplashscreen = require('./broccoli-plugins/rasterize-splashscreen/plugin');
var commands = require('./lib/commands');
var cordovaPath = require('./lib/utils/cordova-path');
var chalk = require('chalk');
var mergeTrees = require('broccoli-merge-trees');
var Funnel = require('broccoli-funnel');
var path = require('path');
var fs = require('fs');
module.exports = {
name: 'ember-cordova',
_isTargetCordova: function () {
return process.env.EMBER_CORDOVA === "true";
},
_isCordovaLiveReload: function() {
return process.env.CORDOVA_RELOAD_ADDRESS !== undefined;
},
config: function (env, baseConfig) {
if (this._isTargetCordova() && env !== 'test') {
if (baseConfig.locationType && baseConfig.locationType !== 'hash') {
throw new Error('ember-cli-cordova: You must specify the locationType as \'hash\' in your environment.js or rename it to defaultLocationType.');
}
}
if (this._isCordovaLiveReload()) {
var conf = {};
//If cordova live reload, set the reload url
var reloadUrl = process.env.CORDOVA_RELOAD_ADDRESS;
conf.cordova = {};
conf.cordova.reloadUrl = reloadUrl;
return conf;
}
},
contentFor: function (type) {
var is = this._isTargetCordova();
if (this._isTargetCordova() && type === 'body') {
return '<script src="cordova.js"></script>';
}
},
includedCommands: function () {
return commands;
},
treeForPublic: function (tree) {
if (this._isCordovaLiveReload() === true) {
var platform = process.env.CORDOVA_PLATFORM;
var platformsPath = path.join(cordovaPath(this.project), 'platforms');
var pluginsPath;
if (platform === 'ios') {
pluginsPath = path.join(platformsPath, 'ios', 'www');
} else if (platform === 'android') {
pluginsPath = path.join(platformsPath, 'android', 'assets', 'www');
}
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-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 = new Funnel(this.treeGenerator(pluginsPath), {
srcDir: '/',
include: files,
destDir: '/'
});
this.ui.writeLine(chalk.green('ember-cordova: Device LiveReload is enabled'));
return mergeTrees([tree, pluginsTree]);
}
return tree;
}
};