-
Notifications
You must be signed in to change notification settings - Fork 10
/
Api.js
130 lines (98 loc) · 3.76 KB
/
Api.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
this file is found by cordova-lib when you attempt to
'cordova platform add PATH' where path is this repo.
*/
/*jslint node: true */
var shell = require('shelljs');
var path = require('path');
var CordovaLogger = require('cordova-common').CordovaLogger;
var events = require('cordova-common').events;
var PLATFORM_NAME = 'testplatform';
function setupEvents(externalEventEmitter) {
if (externalEventEmitter) {
// This will make the platform internal events visible outside
events.forwardEventsTo(externalEventEmitter);
return externalEventEmitter;
}
// There is no logger if external emitter is not present,
// so attach a console logger
CordovaLogger.get().subscribe(events);
return events;
}
function Api(platform, platformRootDir, events) {
this.platform = platform || PLATFORM_NAME;
this.root = path.resolve(__dirname, '..');
this.locations = {
platformRootDir: platformRootDir,
root: this.root,
www: path.join(this.root, 'assets/www'),
res: path.join(this.root, 'res'),
platformWww: path.join(this.root, 'platform_www'),
configXml: path.join(this.root, 'res/xml/config.xml'),
defaultConfigXml: path.join(this.root, 'cordova/defaults.xml'),
build: path.join(this.root, 'build'),
// NOTE: Due to platformApi spec we need to return relative paths here
cordovaJs: 'bin/templates/project/assets/www/cordova.js',
cordovaJsSrc: 'cordova-js-src'
};
}
Api.createPlatform = function (destination, config, options, externalEvents) {
events = setupEvents(externalEvents);
// create the destination and the standard place for our api to live
// platforms/platformName/cordova/Api.js
var apiSrcPath = __dirname; // default value
// does options contain the info we desire?
var projectName = config ? config.name() : "HelloCordova";
events.emit('log', 'Creating Cordova project for cordova-platform-test:');
events.emit('log', '\tPath: ' + destination);
events.emit('log', '\tName: ' + projectName);
shell.mkdir('-p', destination);
// move a copy of our api to the new project
shell.cp('-r',apiSrcPath, destination);
// I promise I will return
return Promise.resolve(new Api(PLATFORM_NAME,destination,events));
};
Api.updatePlatform = function (destination, options) {
events.emit('log', "test-platform:Api:updatePlatform");
// todo?: create projectInstance and fulfill promise with it.
return Promise.resolve();
};
Api.prototype.getPlatformInfo = function () {
events.emit('log', "test-platform:Api:getPlatformInfo");
// return PlatformInfo object
return {
"locations":this.locations,
"root": this.root,
"name": this.platform,
"version": { "version" : "1.0.0" },
"projectConfig": this._config
};
};
Api.prototype.prepare = function (cordovaProject) {
events.emit('log', "test-platform:Api:prepare");
return Promise.resolve();
};
Api.prototype.addPlugin = function (plugin, installOptions) {
events.emit('log', "test-platform:Api:addPlugin");
return Promise.resolve();
};
Api.prototype.removePlugin = function (plugin, uninstallOptions) {
events.emit('log', "test-platform:Api:removePlugin");
return Promise.resolve();
};
Api.prototype.build = function (buildOptions) {
events.emit('log', "test-platform:Api:build");
return Promise.resolve();
};
Api.prototype.run = function(runOptions) {
events.emit('log', "test-platform:Api:run");
};
Api.prototype.clean = function(cleanOptions) {
events.emit('log', "test-platform:Api:clean");
return Promise.resolve();
};
Api.prototype.requirements = function() {
events.emit('log', "test-platform:Api:requirements");
return true;
};
module.exports = Api;