@@ -34,8 +34,6 @@ function getPlatformModule(packageName, source) {
34
34
return Q . reject ( new CustomError ( 'Failed to resolve module: \'' + packageName + '\'.' , err ) ) ;
35
35
}
36
36
37
- // queue the installation of the package, it will be installed once installQueuedPackages
38
- // is called, then re-attempt to require the package.
39
37
return packageTools . queuePackageInstallation ( packageName , source ) . then ( function ( ) {
40
38
var module = require ( packageName ) ;
41
39
return Q . resolve ( module ) ;
@@ -51,14 +49,11 @@ function loadPlatform(packageName, source, callback) {
51
49
. nodeify ( callback ) ;
52
50
}
53
51
54
- // configures the platforms with the provided configuration or attempts to load
55
- // the configuration from a 'platforms.json' file in the root of the main app
56
52
function configurePlatforms ( config ) {
57
53
if ( ! config ) {
58
54
config = getDefaultConfigPath ( ) ;
59
55
}
60
56
61
- // if config is a file path, load the file
62
57
if ( config && typeof config === 'string' ) {
63
58
try {
64
59
config = require ( config ) ;
@@ -71,7 +66,6 @@ function configurePlatforms(config) {
71
66
platformConfiguration = config ;
72
67
}
73
68
74
- // returns the modules implementing the requested platforms
75
69
function loadPlatforms ( platforms , config , callback ) {
76
70
77
71
if ( arguments . length < 3 ) {
@@ -81,25 +75,19 @@ function loadPlatforms(platforms, config, callback) {
81
75
}
82
76
}
83
77
84
- // if configurePlatforms has not been called yet, loads the default configuration
85
78
configurePlatforms ( config || platformConfiguration ) ;
86
79
87
80
var platformMap = { } ;
88
- // load all platform modules and map the corresponding platforms to each one, taking into account that
89
- // multiple platforms may map to a single module (e.g. pwabuilder-cordova => android, ios, windows...)
90
81
var tasks = ( platforms || [ ] ) . reduce ( function ( taskList , platformId ) {
91
82
92
- // ensure that the platform is registered and is assigned a package name
93
83
var platformInfo = platformConfiguration [ platformId ] ;
94
84
if ( platformInfo && platformInfo . packageName ) {
95
85
var packageName = platformInfo . packageName ;
96
86
97
- // check if the module has already been loaded
98
87
var platformList = platformMap [ packageName ] ;
99
88
100
89
if ( ! platformList ) {
101
90
102
- // create a new task to load the platform module
103
91
platformMap [ packageName ] = platformList = [ ] ;
104
92
var task = loadPlatform ( packageName , platformInfo . source ) . then ( function ( Platform ) {
105
93
return { packageName : packageName , Platform : Platform , platforms : platformList } ;
@@ -108,7 +96,6 @@ function loadPlatforms(platforms, config, callback) {
108
96
taskList . push ( task ) ;
109
97
}
110
98
111
- // assign the current platform to the module
112
99
platformList . push ( platformId ) ;
113
100
}
114
101
else {
@@ -118,14 +105,11 @@ function loadPlatforms(platforms, config, callback) {
118
105
return taskList ;
119
106
} , [ ] ) ;
120
107
121
- // launch the installation of all queued packages
122
108
packageTools . installQueuedPackages ( ) ;
123
109
124
- // wait for all modules to load
125
110
return Q . allSettled ( tasks ) . then ( function ( results ) {
126
111
return results . reduce ( function ( modules , result ) {
127
112
if ( result . state === 'fulfilled' ) {
128
- // create instances of each platform module
129
113
var module = result . value ;
130
114
modules . push ( new module . Platform ( module . packageName , module . platforms ) ) ;
131
115
}
@@ -136,25 +120,19 @@ function loadPlatforms(platforms, config, callback) {
136
120
. nodeify ( callback ) ;
137
121
}
138
122
139
- // get the platform package information (package.json)
140
123
function getPlatformPackageInfo ( id , callback ) {
141
- /* jshint unused: vars */
142
- // check if package is in the npm registry
143
124
return packageTools . getNpmPackageInfo ( id ) . catch ( function ( err ) {
144
125
log . debug ( 'Failed to locate the plaform package in the npm registry...' ) ;
145
- // check if package is in a GitHub repository
146
126
return packageTools . getGitHubPackageInformation ( id ) ;
147
127
} )
148
128
. catch ( function ( err ) {
149
129
log . debug ( 'Failed to locate the plaform package in GitHub...' ) ;
150
130
try {
151
- // check if package is in a local path
152
131
return packageTools . getModuleInformation ( id ) ;
153
132
}
154
133
catch ( err ) {
155
134
log . debug ( 'Failed to locate the plaform package in the local disk...' ) ;
156
135
try {
157
- // check if package is in an installed module
158
136
return packageTools . getPackageInformation ( id ) ;
159
137
}
160
138
catch ( err ) {
@@ -212,15 +190,12 @@ function removePlatform(platformId, configPath, callback) {
212
190
}
213
191
214
192
function getConfiguredPlatforms ( configPath ) {
215
- // if configurePlatforms has not been called yet, loads the default configuration
216
193
configurePlatforms ( configPath || platformConfiguration ) ;
217
194
218
- // return all registered platforms
219
195
return platformConfiguration ;
220
196
}
221
197
222
198
function listPlatforms ( configPath ) {
223
- // return all registered platforms
224
199
return Object . keys ( getConfiguredPlatforms ( configPath ) ) ;
225
200
}
226
201
0 commit comments