From a1c097f14813df3f3a17b32513634a90d80e84a7 Mon Sep 17 00:00:00 2001 From: Erisu Date: Fri, 29 Oct 2021 15:00:28 +0900 Subject: [PATCH 01/17] refactor(Api): convert Api func to class --- bin/templates/scripts/cordova/Api.js | 92 ++++++++++++++-------------- 1 file changed, 47 insertions(+), 45 deletions(-) diff --git a/bin/templates/scripts/cordova/Api.js b/bin/templates/scripts/cordova/Api.js index 34e1e62e9..bc61cbdac 100644 --- a/bin/templates/scripts/cordova/Api.js +++ b/bin/templates/scripts/cordova/Api.js @@ -56,58 +56,60 @@ function getVariableSpec (spec, options) { return spec.includes('$') ? options.cli_variables[spec.replace('$', '')] : spec; } -/** - * Creates a new PlatformApi instance. - * - * @param {String} [platform] Platform name, used for backward compatibility - * w/ PlatformPoly (CordovaLib). - * @param {String} [platformRootDir] Platform root location, used for backward - * compatibility w/ PlatformPoly (CordovaLib). - * @param {EventEmitter} [events] An EventEmitter instance that will be used for - * logging purposes. If no EventEmitter provided, all events will be logged to - * console - */ -function Api (platform, platformRootDir, events) { - // 'platform' property is required as per PlatformApi spec - this.platform = platform || 'ios'; - this.root = platformRootDir || path.resolve(__dirname, '..'); - - setupEvents(events); - - let xcodeProjDir; - let xcodeCordovaProj; - - try { - const xcodeProjDir_array = fs.readdirSync(this.root).filter(e => e.match(/\.xcodeproj$/i)); - if (xcodeProjDir_array.length > 1) { - for (let x = 0; x < xcodeProjDir_array.length; x++) { - if (xcodeProjDir_array[x].substring(0, 2) === '._') { - xcodeProjDir_array.splice(x, 1); +class Api { + /** + * Creates a new PlatformApi instance. + * + * @param {String} [platform] Platform name, used for backward compatibility + * w/ PlatformPoly (CordovaLib). + * @param {String} [platformRootDir] Platform root location, used for backward + * compatibility w/ PlatformPoly (CordovaLib). + * @param {EventEmitter} [events] An EventEmitter instance that will be used for + * logging purposes. If no EventEmitter provided, all events will be logged to + * console + */ + constructor (platform, platformRootDir, events) { + // 'platform' property is required as per PlatformApi spec + this.platform = platform || 'ios'; + this.root = platformRootDir || path.resolve(__dirname, '..'); + + setupEvents(events); + + let xcodeProjDir; + let xcodeCordovaProj; + + try { + const xcodeProjDir_array = fs.readdirSync(this.root).filter(e => e.match(/\.xcodeproj$/i)); + if (xcodeProjDir_array.length > 1) { + for (let x = 0; x < xcodeProjDir_array.length; x++) { + if (xcodeProjDir_array[x].substring(0, 2) === '._') { + xcodeProjDir_array.splice(x, 1); + } } } - } - xcodeProjDir = xcodeProjDir_array[0]; + xcodeProjDir = xcodeProjDir_array[0]; - if (!xcodeProjDir) { + if (!xcodeProjDir) { + throw new CordovaError(`The provided path "${this.root}" is not a Cordova iOS project.`); + } + + const cordovaProjName = xcodeProjDir.substring(xcodeProjDir.lastIndexOf(path.sep) + 1, xcodeProjDir.indexOf('.xcodeproj')); + xcodeCordovaProj = path.join(this.root, cordovaProjName); + } catch (e) { throw new CordovaError(`The provided path "${this.root}" is not a Cordova iOS project.`); } - const cordovaProjName = xcodeProjDir.substring(xcodeProjDir.lastIndexOf(path.sep) + 1, xcodeProjDir.indexOf('.xcodeproj')); - xcodeCordovaProj = path.join(this.root, cordovaProjName); - } catch (e) { - throw new CordovaError(`The provided path "${this.root}" is not a Cordova iOS project.`); + this.locations = { + root: this.root, + www: path.join(this.root, 'www'), + platformWww: path.join(this.root, 'platform_www'), + configXml: path.join(xcodeCordovaProj, 'config.xml'), + defaultConfigXml: path.join(this.root, 'cordova/defaults.xml'), + pbxproj: path.join(this.root, xcodeProjDir, 'project.pbxproj'), + xcodeProjDir: path.join(this.root, xcodeProjDir), + xcodeCordovaProj + }; } - - this.locations = { - root: this.root, - www: path.join(this.root, 'www'), - platformWww: path.join(this.root, 'platform_www'), - configXml: path.join(xcodeCordovaProj, 'config.xml'), - defaultConfigXml: path.join(this.root, 'cordova/defaults.xml'), - pbxproj: path.join(this.root, xcodeProjDir, 'project.pbxproj'), - xcodeProjDir: path.join(this.root, xcodeProjDir), - xcodeCordovaProj - }; } /** From 4876d97375505bf137757f2326619a0f1b5653cb Mon Sep 17 00:00:00 2001 From: Erisu Date: Fri, 29 Oct 2021 15:03:41 +0900 Subject: [PATCH 02/17] refactor(Api): move createPlatform to class as static --- bin/templates/scripts/cordova/Api.js | 80 ++++++++++++++-------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/bin/templates/scripts/cordova/Api.js b/bin/templates/scripts/cordova/Api.js index bc61cbdac..7336354f6 100644 --- a/bin/templates/scripts/cordova/Api.js +++ b/bin/templates/scripts/cordova/Api.js @@ -110,49 +110,49 @@ class Api { xcodeCordovaProj }; } -} -/** - * Creates platform in a specified directory. - * - * @param {String} destination Destination directory, where install platform to - * @param {ConfigParser} [config] ConfigParser instance, used to retrieve - * project creation options, such as package id and project name. - * @param {Object} [options] An options object. The most common options are: - * @param {String} [options.customTemplate] A path to custom template, that - * should override the default one from platform. - * @param {Boolean} [options.link] Flag that indicates that platform's - * sources will be linked to installed platform instead of copying. - * @param {EventEmitter} [events] An EventEmitter instance that will be used for - * logging purposes. If no EventEmitter provided, all events will be logged to - * console - * - * @return {Promise} Promise either fulfilled with PlatformApi - * instance or rejected with CordovaError. - */ -Api.createPlatform = (destination, config, options, events) => { - setupEvents(events); + /** + * Creates platform in a specified directory. + * + * @param {String} destination Destination directory, where install platform to + * @param {ConfigParser} [config] ConfigParser instance, used to retrieve + * project creation options, such as package id and project name. + * @param {Object} [options] An options object. The most common options are: + * @param {String} [options.customTemplate] A path to custom template, that + * should override the default one from platform. + * @param {Boolean} [options.link] Flag that indicates that platform's + * sources will be linked to installed platform instead of copying. + * @param {EventEmitter} [events] An EventEmitter instance that will be used for + * logging purposes. If no EventEmitter provided, all events will be logged to + * console + * + * @return {Promise} Promise either fulfilled with PlatformApi + * instance or rejected with CordovaError. + */ + static createPlatform (destination, config, options, events) { + setupEvents(events); - // CB-6992 it is necessary to normalize characters - // because node and shell scripts handles unicode symbols differently - // We need to normalize the name to NFD form since iOS uses NFD unicode form - const name = unorm.nfd(config.name()); - let result; - try { - result = require('../../../lib/create') - .createProject(destination, config.getAttribute('ios-CFBundleIdentifier') || config.packageName(), name, options, config) - .then(() => { - // after platform is created we return Api instance based on new Api.js location - // This is required to correctly resolve paths in the future api calls - const PlatformApi = require(path.resolve(destination, 'cordova/Api')); - return new PlatformApi('ios', destination, events); - }); - } catch (e) { - events.emit('error', 'createPlatform is not callable from the iOS project API.'); - throw e; + // CB-6992 it is necessary to normalize characters + // because node and shell scripts handles unicode symbols differently + // We need to normalize the name to NFD form since iOS uses NFD unicode form + const name = unorm.nfd(config.name()); + let result; + try { + result = require('../../../lib/create') + .createProject(destination, config.getAttribute('ios-CFBundleIdentifier') || config.packageName(), name, options, config) + .then(() => { + // after platform is created we return Api instance based on new Api.js location + // This is required to correctly resolve paths in the future api calls + const PlatformApi = require(path.resolve(destination, 'cordova/Api')); + return new PlatformApi('ios', destination, events); + }); + } catch (e) { + events.emit('error', 'createPlatform is not callable from the iOS project API.'); + throw e; + } + return result; } - return result; -}; +} /** * Updates already installed platform. From 24376e1a36122c7047d2047619a8e276a933ac24 Mon Sep 17 00:00:00 2001 From: Erisu Date: Fri, 29 Oct 2021 15:04:35 +0900 Subject: [PATCH 03/17] refactor(Api): move updatePlatform to class as static --- bin/templates/scripts/cordova/Api.js | 66 ++++++++++++++-------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/bin/templates/scripts/cordova/Api.js b/bin/templates/scripts/cordova/Api.js index 7336354f6..57d183855 100644 --- a/bin/templates/scripts/cordova/Api.js +++ b/bin/templates/scripts/cordova/Api.js @@ -152,41 +152,41 @@ class Api { } return result; } -} -/** - * Updates already installed platform. - * - * @param {String} destination Destination directory, where platform installed - * @param {Object} [options] An options object. The most common options are: - * @param {String} [options.customTemplate] A path to custom template, that - * should override the default one from platform. - * @param {Boolean} [options.link] Flag that indicates that platform's - * sources will be linked to installed platform instead of copying. - * @param {EventEmitter} [events] An EventEmitter instance that will be used for - * logging purposes. If no EventEmitter provided, all events will be logged to - * console - * - * @return {Promise} Promise either fulfilled with PlatformApi - * instance or rejected with CordovaError. - */ -Api.updatePlatform = (destination, options, events) => { - setupEvents(events); - - let result; - try { - result = require('../../../lib/create') - .updateProject(destination, options) - .then(() => { - const PlatformApi = require(path.resolve(destination, 'cordova/Api')); - return new PlatformApi('ios', destination, events); - }); - } catch (e) { - events.emit('error', 'updatePlatform is not callable from the iOS project API, you will need to do this manually.'); - throw e; + /** + * Updates already installed platform. + * + * @param {String} destination Destination directory, where platform installed + * @param {Object} [options] An options object. The most common options are: + * @param {String} [options.customTemplate] A path to custom template, that + * should override the default one from platform. + * @param {Boolean} [options.link] Flag that indicates that platform's + * sources will be linked to installed platform instead of copying. + * @param {EventEmitter} [events] An EventEmitter instance that will be used for + * logging purposes. If no EventEmitter provided, all events will be logged to + * console + * + * @return {Promise} Promise either fulfilled with PlatformApi + * instance or rejected with CordovaError. + */ + static updatePlatform (destination, options, events) { + setupEvents(events); + + let result; + try { + result = require('../../../lib/create') + .updateProject(destination, options) + .then(() => { + const PlatformApi = require(path.resolve(destination, 'cordova/Api')); + return new PlatformApi('ios', destination, events); + }); + } catch (e) { + events.emit('error', 'updatePlatform is not callable from the iOS project API, you will need to do this manually.'); + throw e; + } + return result; } - return result; -}; +} /** * Gets a CordovaPlatform object, that represents the platform structure. From 04e48f23f2b62d5e6205b76561dbb0da6b833209 Mon Sep 17 00:00:00 2001 From: Erisu Date: Fri, 29 Oct 2021 15:05:31 +0900 Subject: [PATCH 04/17] refactor(Api): move getPlatformInfo to class as func --- bin/templates/scripts/cordova/Api.js | 33 ++++++++++++++-------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/bin/templates/scripts/cordova/Api.js b/bin/templates/scripts/cordova/Api.js index 57d183855..e19d34f84 100644 --- a/bin/templates/scripts/cordova/Api.js +++ b/bin/templates/scripts/cordova/Api.js @@ -186,24 +186,25 @@ class Api { } return result; } + + /** + * Gets a CordovaPlatform object, that represents the platform structure. + * + * @return {CordovaPlatform} A structure that contains the description of + * platform's file structure and other properties of platform. + */ + getPlatformInfo () { + const result = {}; + result.locations = this.locations; + result.root = this.root; + result.name = this.platform; + result.version = Api.version(); + result.projectConfig = new ConfigParser(this.locations.configXml); + + return result; + } } -/** - * Gets a CordovaPlatform object, that represents the platform structure. - * - * @return {CordovaPlatform} A structure that contains the description of - * platform's file structure and other properties of platform. - */ -Api.prototype.getPlatformInfo = function () { - const result = {}; - result.locations = this.locations; - result.root = this.root; - result.name = this.platform; - result.version = Api.version(); - result.projectConfig = new ConfigParser(this.locations.configXml); - - return result; -}; /** * Updates installed platform with provided www assets and new app From a8401d1aa7de840576422f576774ac3a1b642fc7 Mon Sep 17 00:00:00 2001 From: Erisu Date: Fri, 29 Oct 2021 15:06:21 +0900 Subject: [PATCH 05/17] refactor(Api): move prepare to class as func --- bin/templates/scripts/cordova/Api.js | 39 ++++++++++++++-------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/bin/templates/scripts/cordova/Api.js b/bin/templates/scripts/cordova/Api.js index e19d34f84..6baef2e41 100644 --- a/bin/templates/scripts/cordova/Api.js +++ b/bin/templates/scripts/cordova/Api.js @@ -203,28 +203,27 @@ class Api { return result; } -} - -/** - * Updates installed platform with provided www assets and new app - * configuration. This method is required for CLI workflow and will be called - * each time before build, so the changes, made to app configuration and www - * code, will be applied to platform. - * - * @param {CordovaProject} cordovaProject A CordovaProject instance, that defines a - * project structure and configuration, that should be applied to platform - * (contains project's www location and ConfigParser instance for project's - * config). - * - * @return {Promise} Return a promise either fulfilled, or rejected with - * CordovaError instance. - */ -Api.prototype.prepare = function (cordovaProject) { - cordovaProject.projectConfig = new ConfigParser(cordovaProject.locations.rootConfigXml || cordovaProject.projectConfig.path); + /** + * Updates installed platform with provided www assets and new app + * configuration. This method is required for CLI workflow and will be called + * each time before build, so the changes, made to app configuration and www + * code, will be applied to platform. + * + * @param {CordovaProject} cordovaProject A CordovaProject instance, that defines a + * project structure and configuration, that should be applied to platform + * (contains project's www location and ConfigParser instance for project's + * config). + * + * @return {Promise} Return a promise either fulfilled, or rejected with + * CordovaError instance. + */ + prepare (cordovaProject) { + cordovaProject.projectConfig = new ConfigParser(cordovaProject.locations.rootConfigXml || cordovaProject.projectConfig.path); - return require('./lib/prepare').prepare.call(this, cordovaProject); -}; + return require('./lib/prepare').prepare.call(this, cordovaProject); + } +} /** * Installs a new plugin into platform. It doesn't resolves plugin dependencies. From c0c6163d4a2ac38db213d711694e46a0080c3c1e Mon Sep 17 00:00:00 2001 From: Erisu Date: Fri, 29 Oct 2021 15:07:21 +0900 Subject: [PATCH 06/17] refactor(Api): move addPlugin to class as func --- bin/templates/scripts/cordova/Api.js | 114 +++++++++++++-------------- 1 file changed, 57 insertions(+), 57 deletions(-) diff --git a/bin/templates/scripts/cordova/Api.js b/bin/templates/scripts/cordova/Api.js index 6baef2e41..64a43f8cf 100644 --- a/bin/templates/scripts/cordova/Api.js +++ b/bin/templates/scripts/cordova/Api.js @@ -223,66 +223,66 @@ class Api { return require('./lib/prepare').prepare.call(this, cordovaProject); } -} -/** - * Installs a new plugin into platform. It doesn't resolves plugin dependencies. - * - * @param {PluginInfo} plugin A PluginInfo instance that represents plugin - * that will be installed. - * @param {Object} installOptions An options object. Possible options below: - * @param {Boolean} installOptions.link: Flag that specifies that plugin - * sources will be symlinked to app's directory instead of copying (if - * possible). - * @param {Object} installOptions.variables An object that represents - * variables that will be used to install plugin. See more details on plugin - * variables in documentation: - * https://cordova.apache.org/docs/en/4.0.0/plugin_ref_spec.md.html - * - * @return {Promise} Return a promise either fulfilled, or rejected with - * CordovaError instance. - */ -Api.prototype.addPlugin = function (plugin, installOptions) { - const xcodeproj = projectFile.parse(this.locations); - - installOptions = installOptions || {}; - installOptions.variables = installOptions.variables || {}; - // Add PACKAGE_NAME variable into vars - if (!installOptions.variables.PACKAGE_NAME) { - installOptions.variables.PACKAGE_NAME = xcodeproj.getPackageName(); - } + /** + * Installs a new plugin into platform. It doesn't resolves plugin dependencies. + * + * @param {PluginInfo} plugin A PluginInfo instance that represents plugin + * that will be installed. + * @param {Object} installOptions An options object. Possible options below: + * @param {Boolean} installOptions.link: Flag that specifies that plugin + * sources will be symlinked to app's directory instead of copying (if + * possible). + * @param {Object} installOptions.variables An object that represents + * variables that will be used to install plugin. See more details on plugin + * variables in documentation: + * https://cordova.apache.org/docs/en/4.0.0/plugin_ref_spec.md.html + * + * @return {Promise} Return a promise either fulfilled, or rejected with + * CordovaError instance. + */ + addPlugin (plugin, installOptions) { + const xcodeproj = projectFile.parse(this.locations); + + installOptions = installOptions || {}; + installOptions.variables = installOptions.variables || {}; + // Add PACKAGE_NAME variable into vars + if (!installOptions.variables.PACKAGE_NAME) { + installOptions.variables.PACKAGE_NAME = xcodeproj.getPackageName(); + } - return PluginManager.get(this.platform, this.locations, xcodeproj) - .addPlugin(plugin, installOptions) - .then(() => { - if (plugin != null) { - const headerTags = plugin.getHeaderFiles(this.platform); - const bridgingHeaders = headerTags.filter(obj => obj.type === 'BridgingHeader'); - if (bridgingHeaders.length > 0) { - const project_dir = this.locations.root; - const project_name = this.locations.xcodeCordovaProj.split(path.sep).pop(); - const BridgingHeader = require('./lib/BridgingHeader').BridgingHeader; - const bridgingHeaderFile = new BridgingHeader(path.join(project_dir, project_name, 'Bridging-Header.h')); - events.emit('verbose', 'Adding Bridging-Headers since the plugin contained with type="BridgingHeader"'); - bridgingHeaders.forEach(obj => { - const bridgingHeaderPath = path.basename(obj.src); - bridgingHeaderFile.addHeader(plugin.id, bridgingHeaderPath); - }); - bridgingHeaderFile.write(); + return PluginManager.get(this.platform, this.locations, xcodeproj) + .addPlugin(plugin, installOptions) + .then(() => { + if (plugin != null) { + const headerTags = plugin.getHeaderFiles(this.platform); + const bridgingHeaders = headerTags.filter(obj => obj.type === 'BridgingHeader'); + if (bridgingHeaders.length > 0) { + const project_dir = this.locations.root; + const project_name = this.locations.xcodeCordovaProj.split(path.sep).pop(); + const BridgingHeader = require('./lib/BridgingHeader').BridgingHeader; + const bridgingHeaderFile = new BridgingHeader(path.join(project_dir, project_name, 'Bridging-Header.h')); + events.emit('verbose', 'Adding Bridging-Headers since the plugin contained with type="BridgingHeader"'); + bridgingHeaders.forEach(obj => { + const bridgingHeaderPath = path.basename(obj.src); + bridgingHeaderFile.addHeader(plugin.id, bridgingHeaderPath); + }); + bridgingHeaderFile.write(); + } } - } - }) - .then(() => { - if (plugin != null) { - const podSpecs = plugin.getPodSpecs ? plugin.getPodSpecs(this.platform) : []; - const frameworkTags = plugin.getFrameworks(this.platform); - const frameworkPods = frameworkTags.filter(obj => obj.type === 'podspec'); - return this.addPodSpecs(plugin, podSpecs, frameworkPods, installOptions); - } - }) - // CB-11022 Return truthy value to prevent running prepare after - .then(() => true); -}; + }) + .then(() => { + if (plugin != null) { + const podSpecs = plugin.getPodSpecs ? plugin.getPodSpecs(this.platform) : []; + const frameworkTags = plugin.getFrameworks(this.platform); + const frameworkPods = frameworkTags.filter(obj => obj.type === 'podspec'); + return this.addPodSpecs(plugin, podSpecs, frameworkPods, installOptions); + } + }) + // CB-11022 Return truthy value to prevent running prepare after + .then(() => true); + } +} /** * Removes an installed plugin from platform. From 59a7cd4f5dd2d16af5c9fc8f6ffab35f74ab94b0 Mon Sep 17 00:00:00 2001 From: Erisu Date: Fri, 29 Oct 2021 15:07:49 +0900 Subject: [PATCH 07/17] refactor(Api): move removePlugin to class as func --- bin/templates/scripts/cordova/Api.js | 94 ++++++++++++++-------------- 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/bin/templates/scripts/cordova/Api.js b/bin/templates/scripts/cordova/Api.js index 64a43f8cf..3547060ae 100644 --- a/bin/templates/scripts/cordova/Api.js +++ b/bin/templates/scripts/cordova/Api.js @@ -282,55 +282,55 @@ class Api { // CB-11022 Return truthy value to prevent running prepare after .then(() => true); } -} -/** - * Removes an installed plugin from platform. - * - * Since method accepts PluginInfo instance as input parameter instead of plugin - * id, caller shoud take care of managing/storing PluginInfo instances for - * future uninstalls. - * - * @param {PluginInfo} plugin A PluginInfo instance that represents plugin - * that will be installed. - * - * @return {Promise} Return a promise either fulfilled, or rejected with - * CordovaError instance. - */ -Api.prototype.removePlugin = function (plugin, uninstallOptions) { - const xcodeproj = projectFile.parse(this.locations); - - return PluginManager.get(this.platform, this.locations, xcodeproj) - .removePlugin(plugin, uninstallOptions) - .then(() => { - if (plugin != null) { - const headerTags = plugin.getHeaderFiles(this.platform); - const bridgingHeaders = headerTags.filter(obj => obj.type === 'BridgingHeader'); - if (bridgingHeaders.length > 0) { - const project_dir = this.locations.root; - const project_name = this.locations.xcodeCordovaProj.split(path.sep).pop(); - const BridgingHeader = require('./lib/BridgingHeader').BridgingHeader; - const bridgingHeaderFile = new BridgingHeader(path.join(project_dir, project_name, 'Bridging-Header.h')); - events.emit('verbose', 'Removing Bridging-Headers since the plugin contained with type="BridgingHeader"'); - bridgingHeaders.forEach(obj => { - const bridgingHeaderPath = path.basename(obj.src); - bridgingHeaderFile.removeHeader(plugin.id, bridgingHeaderPath); - }); - bridgingHeaderFile.write(); + /** + * Removes an installed plugin from platform. + * + * Since method accepts PluginInfo instance as input parameter instead of plugin + * id, caller shoud take care of managing/storing PluginInfo instances for + * future uninstalls. + * + * @param {PluginInfo} plugin A PluginInfo instance that represents plugin + * that will be installed. + * + * @return {Promise} Return a promise either fulfilled, or rejected with + * CordovaError instance. + */ + removePlugin (plugin, uninstallOptions) { + const xcodeproj = projectFile.parse(this.locations); + + return PluginManager.get(this.platform, this.locations, xcodeproj) + .removePlugin(plugin, uninstallOptions) + .then(() => { + if (plugin != null) { + const headerTags = plugin.getHeaderFiles(this.platform); + const bridgingHeaders = headerTags.filter(obj => obj.type === 'BridgingHeader'); + if (bridgingHeaders.length > 0) { + const project_dir = this.locations.root; + const project_name = this.locations.xcodeCordovaProj.split(path.sep).pop(); + const BridgingHeader = require('./lib/BridgingHeader').BridgingHeader; + const bridgingHeaderFile = new BridgingHeader(path.join(project_dir, project_name, 'Bridging-Header.h')); + events.emit('verbose', 'Removing Bridging-Headers since the plugin contained with type="BridgingHeader"'); + bridgingHeaders.forEach(obj => { + const bridgingHeaderPath = path.basename(obj.src); + bridgingHeaderFile.removeHeader(plugin.id, bridgingHeaderPath); + }); + bridgingHeaderFile.write(); + } } - } - }) - .then(() => { - if (plugin != null) { - const podSpecs = plugin.getPodSpecs ? plugin.getPodSpecs(this.platform) : []; - const frameworkTags = plugin.getFrameworks(this.platform); - const frameworkPods = frameworkTags.filter(obj => obj.type === 'podspec'); - return this.removePodSpecs(plugin, podSpecs, frameworkPods, uninstallOptions); - } - }) - // CB-11022 Return truthy value to prevent running prepare after - .then(() => true); -}; + }) + .then(() => { + if (plugin != null) { + const podSpecs = plugin.getPodSpecs ? plugin.getPodSpecs(this.platform) : []; + const frameworkTags = plugin.getFrameworks(this.platform); + const frameworkPods = frameworkTags.filter(obj => obj.type === 'podspec'); + return this.removePodSpecs(plugin, podSpecs, frameworkPods, uninstallOptions); + } + }) + // CB-11022 Return truthy value to prevent running prepare after + .then(() => true); + } +} /** * adding CocoaPods libraries From fc47f4ee2b1866ae2dca998ee690a27f429ab915 Mon Sep 17 00:00:00 2001 From: Erisu Date: Fri, 29 Oct 2021 15:09:08 +0900 Subject: [PATCH 08/17] refactor(Api): move addPodSpecs to class as func --- bin/templates/scripts/cordova/Api.js | 221 +++++++++++++-------------- 1 file changed, 110 insertions(+), 111 deletions(-) diff --git a/bin/templates/scripts/cordova/Api.js b/bin/templates/scripts/cordova/Api.js index 3547060ae..8293c9296 100644 --- a/bin/templates/scripts/cordova/Api.js +++ b/bin/templates/scripts/cordova/Api.js @@ -330,134 +330,133 @@ class Api { // CB-11022 Return truthy value to prevent running prepare after .then(() => true); } -} - -/** - * adding CocoaPods libraries - * - * @param {PluginInfo} plugin A PluginInfo instance that represents plugin - * that will be installed. - * @param {Object} podSpecs: the return value of plugin.getPodSpecs(this.platform) - * @param {Object} frameworkPods: framework tags object with type === 'podspec' - * @return {Promise} Return a promise - */ - -Api.prototype.addPodSpecs = function (plugin, podSpecs, frameworkPods, installOptions) { - const project_dir = this.locations.root; - const project_name = this.locations.xcodeCordovaProj.split(path.sep).pop(); - const minDeploymentTarget = this.getPlatformInfo().projectConfig.getPreference('deployment-target', 'ios'); - const Podfile = require('./lib/Podfile').Podfile; - const PodsJson = require('./lib/PodsJson').PodsJson; - const podsjsonFile = new PodsJson(path.join(project_dir, PodsJson.FILENAME)); - const podfileFile = new Podfile(path.join(project_dir, Podfile.FILENAME), project_name, minDeploymentTarget); + /** + * adding CocoaPods libraries + * + * @param {PluginInfo} plugin A PluginInfo instance that represents plugin + * that will be installed. + * @param {Object} podSpecs: the return value of plugin.getPodSpecs(this.platform) + * @param {Object} frameworkPods: framework tags object with type === 'podspec' + * @return {Promise} Return a promise + */ + addPodSpecs (plugin, podSpecs, frameworkPods, installOptions) { + const project_dir = this.locations.root; + const project_name = this.locations.xcodeCordovaProj.split(path.sep).pop(); + const minDeploymentTarget = this.getPlatformInfo().projectConfig.getPreference('deployment-target', 'ios'); + + const Podfile = require('./lib/Podfile').Podfile; + const PodsJson = require('./lib/PodsJson').PodsJson; + const podsjsonFile = new PodsJson(path.join(project_dir, PodsJson.FILENAME)); + const podfileFile = new Podfile(path.join(project_dir, Podfile.FILENAME), project_name, minDeploymentTarget); + + if (podSpecs.length) { + events.emit('verbose', 'Adding pods since the plugin contained '); + podSpecs.forEach(obj => { + // declarations + if (obj.declarations) { + Object.keys(obj.declarations).forEach(key => { + if (obj.declarations[key] === 'true') { + const declaration = Podfile.proofDeclaration(key); + const podJson = { + declaration + }; + const val = podsjsonFile.getDeclaration(declaration); + if (val) { + podsjsonFile.incrementDeclaration(declaration); + } else { + podJson.count = 1; + podsjsonFile.setJsonDeclaration(declaration, podJson); + podfileFile.addDeclaration(podJson.declaration); + } + } + }); + } - if (podSpecs.length) { - events.emit('verbose', 'Adding pods since the plugin contained '); - podSpecs.forEach(obj => { - // declarations - if (obj.declarations) { - Object.keys(obj.declarations).forEach(key => { - if (obj.declarations[key] === 'true') { - const declaration = Podfile.proofDeclaration(key); + // sources + if (obj.sources) { + Object.keys(obj.sources).forEach(key => { const podJson = { - declaration + source: obj.sources[key].source }; - const val = podsjsonFile.getDeclaration(declaration); + const val = podsjsonFile.getSource(key); if (val) { - podsjsonFile.incrementDeclaration(declaration); + podsjsonFile.incrementSource(key); } else { podJson.count = 1; - podsjsonFile.setJsonDeclaration(declaration, podJson); - podfileFile.addDeclaration(podJson.declaration); + podsjsonFile.setJsonSource(key, podJson); + podfileFile.addSource(podJson.source); } - } - }); - } - - // sources - if (obj.sources) { - Object.keys(obj.sources).forEach(key => { - const podJson = { - source: obj.sources[key].source - }; - const val = podsjsonFile.getSource(key); - if (val) { - podsjsonFile.incrementSource(key); - } else { - podJson.count = 1; - podsjsonFile.setJsonSource(key, podJson); - podfileFile.addSource(podJson.source); - } - }); - } + }); + } - // libraries - if (obj.libraries) { - Object.keys(obj.libraries).forEach(key => { - const podJson = Object.assign({}, obj.libraries[key]); - if (podJson.spec) { - podJson.spec = getVariableSpec(podJson.spec, installOptions); - } - const val = podsjsonFile.getLibrary(key); - if (val) { - events.emit('warn', `${plugin.id} depends on ${podJson.name}, which may conflict with another plugin. ${podJson.name}@${val.spec} is already installed and was not overwritten.`); - podsjsonFile.incrementLibrary(key); - } else { - podJson.count = 1; - podsjsonFile.setJsonLibrary(key, podJson); - podfileFile.addSpec(podJson.name, podJson); - } - }); - } - }); - } + // libraries + if (obj.libraries) { + Object.keys(obj.libraries).forEach(key => { + const podJson = Object.assign({}, obj.libraries[key]); + if (podJson.spec) { + podJson.spec = getVariableSpec(podJson.spec, installOptions); + } + const val = podsjsonFile.getLibrary(key); + if (val) { + events.emit('warn', `${plugin.id} depends on ${podJson.name}, which may conflict with another plugin. ${podJson.name}@${val.spec} is already installed and was not overwritten.`); + podsjsonFile.incrementLibrary(key); + } else { + podJson.count = 1; + podsjsonFile.setJsonLibrary(key, podJson); + podfileFile.addSpec(podJson.name, podJson); + } + }); + } + }); + } - if (frameworkPods.length) { - events.emit('warn', '"framework" tag with type "podspec" is deprecated and will be removed. Please use the "podspec" tag.'); - events.emit('verbose', 'Adding pods since the plugin contained (s) with type="podspec"'); - frameworkPods.forEach(obj => { - const spec = getVariableSpec(obj.spec, installOptions); - const podJson = { - name: obj.src, - type: obj.type, - spec - }; + if (frameworkPods.length) { + events.emit('warn', '"framework" tag with type "podspec" is deprecated and will be removed. Please use the "podspec" tag.'); + events.emit('verbose', 'Adding pods since the plugin contained (s) with type="podspec"'); + frameworkPods.forEach(obj => { + const spec = getVariableSpec(obj.spec, installOptions); + const podJson = { + name: obj.src, + type: obj.type, + spec + }; - const val = podsjsonFile.getLibrary(podJson.name); - if (val) { // found - if (podJson.spec !== val.spec) { // exists, different spec, print warning - events.emit('warn', `${plugin.id} depends on ${podJson.name}@${podJson.spec}, which conflicts with another plugin. ${podJson.name}@${val.spec} is already installed and was not overwritten.`); + const val = podsjsonFile.getLibrary(podJson.name); + if (val) { // found + if (podJson.spec !== val.spec) { // exists, different spec, print warning + events.emit('warn', `${plugin.id} depends on ${podJson.name}@${podJson.spec}, which conflicts with another plugin. ${podJson.name}@${val.spec} is already installed and was not overwritten.`); + } + // increment count, but don't add in Podfile because it already exists + podsjsonFile.incrementLibrary(podJson.name); + } else { // not found, write new + podJson.count = 1; + podsjsonFile.setJsonLibrary(podJson.name, podJson); + // add to Podfile + podfileFile.addSpec(podJson.name, podJson.spec); } - // increment count, but don't add in Podfile because it already exists - podsjsonFile.incrementLibrary(podJson.name); - } else { // not found, write new - podJson.count = 1; - podsjsonFile.setJsonLibrary(podJson.name, podJson); - // add to Podfile - podfileFile.addSpec(podJson.name, podJson.spec); - } - }); - } + }); + } - if (podSpecs.length > 0 || frameworkPods.length > 0) { - // now that all the pods have been processed, write to pods.json - podsjsonFile.write(); + if (podSpecs.length > 0 || frameworkPods.length > 0) { + // now that all the pods have been processed, write to pods.json + podsjsonFile.write(); - // only write and pod install if the Podfile changed - if (podfileFile.isDirty()) { - podfileFile.write(); - events.emit('verbose', 'Running `pod install` (to install plugins)'); - projectFile.purgeProjectFileCache(this.locations.root); + // only write and pod install if the Podfile changed + if (podfileFile.isDirty()) { + podfileFile.write(); + events.emit('verbose', 'Running `pod install` (to install plugins)'); + projectFile.purgeProjectFileCache(this.locations.root); - return podfileFile.install(check_reqs.check_cocoapods) - .then(() => this.setSwiftVersionForCocoaPodsLibraries(podsjsonFile)); - } else { - events.emit('verbose', 'Podfile unchanged, skipping `pod install`'); + return podfileFile.install(check_reqs.check_cocoapods) + .then(() => this.setSwiftVersionForCocoaPodsLibraries(podsjsonFile)); + } else { + events.emit('verbose', 'Podfile unchanged, skipping `pod install`'); + } } + return Promise.resolve(); } - return Promise.resolve(); -}; +} /** * removing CocoaPods libraries From b26e6eeacde9dafdd7a95e90c6e340d9b7241b33 Mon Sep 17 00:00:00 2001 From: Erisu Date: Fri, 29 Oct 2021 15:09:39 +0900 Subject: [PATCH 09/17] refactor(Api): move removePodSpecs to class as func --- bin/templates/scripts/cordova/Api.js | 194 +++++++++++++-------------- 1 file changed, 97 insertions(+), 97 deletions(-) diff --git a/bin/templates/scripts/cordova/Api.js b/bin/templates/scripts/cordova/Api.js index 8293c9296..78f00cdb4 100644 --- a/bin/templates/scripts/cordova/Api.js +++ b/bin/templates/scripts/cordova/Api.js @@ -456,125 +456,125 @@ class Api { } return Promise.resolve(); } -} -/** - * removing CocoaPods libraries - * - * @param {PluginInfo} plugin A PluginInfo instance that represents plugin - * that will be installed. - * @param {Object} podSpecs: the return value of plugin.getPodSpecs(this.platform) - * @param {Object} frameworkPods: framework tags object with type === 'podspec' - * @return {Promise} Return a promise - */ + /** + * removing CocoaPods libraries + * + * @param {PluginInfo} plugin A PluginInfo instance that represents plugin + * that will be installed. + * @param {Object} podSpecs: the return value of plugin.getPodSpecs(this.platform) + * @param {Object} frameworkPods: framework tags object with type === 'podspec' + * @return {Promise} Return a promise + */ + + removePodSpecs (plugin, podSpecs, frameworkPods, uninstallOptions) { + const project_dir = this.locations.root; + const project_name = this.locations.xcodeCordovaProj.split(path.sep).pop(); -Api.prototype.removePodSpecs = function (plugin, podSpecs, frameworkPods, uninstallOptions) { - const project_dir = this.locations.root; - const project_name = this.locations.xcodeCordovaProj.split(path.sep).pop(); - - const Podfile = require('./lib/Podfile').Podfile; - const PodsJson = require('./lib/PodsJson').PodsJson; - const podsjsonFile = new PodsJson(path.join(project_dir, PodsJson.FILENAME)); - const podfileFile = new Podfile(path.join(project_dir, Podfile.FILENAME), project_name); - - if (podSpecs.length) { - events.emit('verbose', 'Adding pods since the plugin contained '); - podSpecs.forEach(obj => { - // declarations - Object.keys(obj.declarations).forEach(key => { - if (obj.declarations[key] === 'true') { - const declaration = Podfile.proofDeclaration(key); + const Podfile = require('./lib/Podfile').Podfile; + const PodsJson = require('./lib/PodsJson').PodsJson; + const podsjsonFile = new PodsJson(path.join(project_dir, PodsJson.FILENAME)); + const podfileFile = new Podfile(path.join(project_dir, Podfile.FILENAME), project_name); + + if (podSpecs.length) { + events.emit('verbose', 'Adding pods since the plugin contained '); + podSpecs.forEach(obj => { + // declarations + Object.keys(obj.declarations).forEach(key => { + if (obj.declarations[key] === 'true') { + const declaration = Podfile.proofDeclaration(key); + const podJson = { + declaration + }; + const val = podsjsonFile.getDeclaration(declaration); + if (val) { + podsjsonFile.decrementDeclaration(declaration); + } else { + const message = util.format('plugin \"%s\" declaration \"%s\" does not seem to be in pods.json, nothing to remove. Will attempt to remove from Podfile.', plugin.id, podJson.declaration); /* eslint no-useless-escape : 0 */ + events.emit('verbose', message); + } + if (!val || val.count === 0) { + podfileFile.removeDeclaration(podJson.declaration); + } + } + }); + // sources + Object.keys(obj.sources).forEach(key => { const podJson = { - declaration + source: obj.sources[key].source }; - const val = podsjsonFile.getDeclaration(declaration); + const val = podsjsonFile.getSource(key); if (val) { - podsjsonFile.decrementDeclaration(declaration); + podsjsonFile.decrementSource(key); } else { - const message = util.format('plugin \"%s\" declaration \"%s\" does not seem to be in pods.json, nothing to remove. Will attempt to remove from Podfile.', plugin.id, podJson.declaration); /* eslint no-useless-escape : 0 */ + const message = util.format('plugin \"%s\" source \"%s\" does not seem to be in pods.json, nothing to remove. Will attempt to remove from Podfile.', plugin.id, podJson.source); /* eslint no-useless-escape : 0 */ events.emit('verbose', message); } if (!val || val.count === 0) { - podfileFile.removeDeclaration(podJson.declaration); + podfileFile.removeSource(podJson.source); } - } + }); + // libraries + Object.keys(obj.libraries).forEach(key => { + const podJson = Object.assign({}, obj.libraries[key]); + if (podJson.spec) { + podJson.spec = getVariableSpec(podJson.spec, uninstallOptions); + } + const val = podsjsonFile.getLibrary(key); + if (val) { + podsjsonFile.decrementLibrary(key); + } else { + const message = util.format('plugin \"%s\" podspec \"%s\" does not seem to be in pods.json, nothing to remove. Will attempt to remove from Podfile.', plugin.id, podJson.name); /* eslint no-useless-escape : 0 */ + events.emit('verbose', message); + } + if (!val || val.count === 0) { + podfileFile.removeSpec(podJson.name); + } + }); }); - // sources - Object.keys(obj.sources).forEach(key => { + } + + if (frameworkPods.length) { + events.emit('warn', '"framework" tag with type "podspec" is deprecated and will be removed. Please use the "podspec" tag.'); + events.emit('verbose', 'Adding pods since the plugin contained (s) with type=\"podspec\"'); /* eslint no-useless-escape : 0 */ + frameworkPods.forEach(obj => { + const spec = getVariableSpec(obj.spec, uninstallOptions); const podJson = { - source: obj.sources[key].source + name: obj.src, + type: obj.type, + spec }; - const val = podsjsonFile.getSource(key); - if (val) { - podsjsonFile.decrementSource(key); - } else { - const message = util.format('plugin \"%s\" source \"%s\" does not seem to be in pods.json, nothing to remove. Will attempt to remove from Podfile.', plugin.id, podJson.source); /* eslint no-useless-escape : 0 */ - events.emit('verbose', message); - } - if (!val || val.count === 0) { - podfileFile.removeSource(podJson.source); - } - }); - // libraries - Object.keys(obj.libraries).forEach(key => { - const podJson = Object.assign({}, obj.libraries[key]); - if (podJson.spec) { - podJson.spec = getVariableSpec(podJson.spec, uninstallOptions); - } - const val = podsjsonFile.getLibrary(key); - if (val) { - podsjsonFile.decrementLibrary(key); - } else { + + const val = podsjsonFile.getLibrary(podJson.name); + if (val) { // found, decrement count + podsjsonFile.decrementLibrary(podJson.name); + } else { // not found (perhaps a sync error) const message = util.format('plugin \"%s\" podspec \"%s\" does not seem to be in pods.json, nothing to remove. Will attempt to remove from Podfile.', plugin.id, podJson.name); /* eslint no-useless-escape : 0 */ events.emit('verbose', message); } - if (!val || val.count === 0) { - podfileFile.removeSpec(podJson.name); - } - }); - }); - } - - if (frameworkPods.length) { - events.emit('warn', '"framework" tag with type "podspec" is deprecated and will be removed. Please use the "podspec" tag.'); - events.emit('verbose', 'Adding pods since the plugin contained (s) with type=\"podspec\"'); /* eslint no-useless-escape : 0 */ - frameworkPods.forEach(obj => { - const spec = getVariableSpec(obj.spec, uninstallOptions); - const podJson = { - name: obj.src, - type: obj.type, - spec - }; - - const val = podsjsonFile.getLibrary(podJson.name); - if (val) { // found, decrement count - podsjsonFile.decrementLibrary(podJson.name); - } else { // not found (perhaps a sync error) - const message = util.format('plugin \"%s\" podspec \"%s\" does not seem to be in pods.json, nothing to remove. Will attempt to remove from Podfile.', plugin.id, podJson.name); /* eslint no-useless-escape : 0 */ - events.emit('verbose', message); - } - // always remove from the Podfile - podfileFile.removeSpec(podJson.name); - }); - } + // always remove from the Podfile + podfileFile.removeSpec(podJson.name); + }); + } - if (podSpecs.length > 0 || frameworkPods.length > 0) { - // now that all the pods have been processed, write to pods.json - podsjsonFile.write(); + if (podSpecs.length > 0 || frameworkPods.length > 0) { + // now that all the pods have been processed, write to pods.json + podsjsonFile.write(); - if (podfileFile.isDirty()) { - podfileFile.write(); - events.emit('verbose', 'Running `pod install` (to uninstall pods)'); + if (podfileFile.isDirty()) { + podfileFile.write(); + events.emit('verbose', 'Running `pod install` (to uninstall pods)'); - return podfileFile.install(check_reqs.check_cocoapods) - .then(() => this.setSwiftVersionForCocoaPodsLibraries(podsjsonFile)); - } else { - events.emit('verbose', 'Podfile unchanged, skipping `pod install`'); + return podfileFile.install(check_reqs.check_cocoapods) + .then(() => this.setSwiftVersionForCocoaPodsLibraries(podsjsonFile)); + } else { + events.emit('verbose', 'Podfile unchanged, skipping `pod install`'); + } } + return Promise.resolve(); } - return Promise.resolve(); -}; +} /** * set Swift Version for all CocoaPods libraries From 4d74ded65e5bc0f43cbeb10ec7cd0499276cec28 Mon Sep 17 00:00:00 2001 From: Erisu Date: Fri, 29 Oct 2021 15:10:34 +0900 Subject: [PATCH 10/17] refactor(Api): move setSwiftVersionForCocoaPodsLibraries to class as func --- bin/templates/scripts/cordova/Api.js | 87 ++++++++++++++-------------- 1 file changed, 43 insertions(+), 44 deletions(-) diff --git a/bin/templates/scripts/cordova/Api.js b/bin/templates/scripts/cordova/Api.js index 78f00cdb4..b7afeef49 100644 --- a/bin/templates/scripts/cordova/Api.js +++ b/bin/templates/scripts/cordova/Api.js @@ -574,53 +574,52 @@ class Api { } return Promise.resolve(); } -} - -/** - * set Swift Version for all CocoaPods libraries - * - * @param {PodsJson} podsjsonFile A PodsJson instance that represents pods.json - */ -Api.prototype.setSwiftVersionForCocoaPodsLibraries = function (podsjsonFile) { - let __dirty = false; - return check_reqs.check_cocoapods().then(toolOptions => { - if (toolOptions.ignore) { - events.emit('verbose', '=== skip Swift Version Settings For Cocoapods Libraries'); - } else { - const podPbxPath = path.join(this.root, 'Pods', 'Pods.xcodeproj', 'project.pbxproj'); - const podXcodeproj = xcode.project(podPbxPath); - podXcodeproj.parseSync(); - const podTargets = podXcodeproj.pbxNativeTargetSection(); - const podConfigurationList = podXcodeproj.pbxXCConfigurationList(); - const podConfigs = podXcodeproj.pbxXCBuildConfigurationSection(); - - const libraries = podsjsonFile.getLibraries(); - Object.keys(libraries).forEach(key => { - const podJson = libraries[key]; - const name = podJson.name; - const swiftVersion = podJson['swift-version']; - if (swiftVersion) { - __dirty = true; - Object.keys(podTargets) - .filter(targetKey => podTargets[targetKey].productName === name) - .map(targetKey => podTargets[targetKey].buildConfigurationList) - .map(buildConfigurationListId => podConfigurationList[buildConfigurationListId]) - .map(buildConfigurationList => buildConfigurationList.buildConfigurations) - .reduce((acc, buildConfigurations) => acc.concat(buildConfigurations), []) - .map(buildConfiguration => buildConfiguration.value) - .forEach(buildId => { - __dirty = true; - podConfigs[buildId].buildSettings.SWIFT_VERSION = swiftVersion; - }); + /** + * set Swift Version for all CocoaPods libraries + * + * @param {PodsJson} podsjsonFile A PodsJson instance that represents pods.json + */ + setSwiftVersionForCocoaPodsLibraries (podsjsonFile) { + let __dirty = false; + return check_reqs.check_cocoapods().then(toolOptions => { + if (toolOptions.ignore) { + events.emit('verbose', '=== skip Swift Version Settings For Cocoapods Libraries'); + } else { + const podPbxPath = path.join(this.root, 'Pods', 'Pods.xcodeproj', 'project.pbxproj'); + const podXcodeproj = xcode.project(podPbxPath); + podXcodeproj.parseSync(); + const podTargets = podXcodeproj.pbxNativeTargetSection(); + const podConfigurationList = podXcodeproj.pbxXCConfigurationList(); + const podConfigs = podXcodeproj.pbxXCBuildConfigurationSection(); + + const libraries = podsjsonFile.getLibraries(); + Object.keys(libraries).forEach(key => { + const podJson = libraries[key]; + const name = podJson.name; + const swiftVersion = podJson['swift-version']; + if (swiftVersion) { + __dirty = true; + Object.keys(podTargets) + .filter(targetKey => podTargets[targetKey].productName === name) + .map(targetKey => podTargets[targetKey].buildConfigurationList) + .map(buildConfigurationListId => podConfigurationList[buildConfigurationListId]) + .map(buildConfigurationList => buildConfigurationList.buildConfigurations) + .reduce((acc, buildConfigurations) => acc.concat(buildConfigurations), []) + .map(buildConfiguration => buildConfiguration.value) + .forEach(buildId => { + __dirty = true; + podConfigs[buildId].buildSettings.SWIFT_VERSION = swiftVersion; + }); + } + }); + if (__dirty) { + fs.writeFileSync(podPbxPath, podXcodeproj.writeSync(), 'utf-8'); } - }); - if (__dirty) { - fs.writeFileSync(podPbxPath, podXcodeproj.writeSync(), 'utf-8'); } - } - }); -}; + }); + } +} /** * Builds an application package for current platform. From 33b40e52f4e65e06d0d74b005b178f7f1e24d180 Mon Sep 17 00:00:00 2001 From: Erisu Date: Fri, 29 Oct 2021 15:11:00 +0900 Subject: [PATCH 11/17] refactor(Api): move build to class as func --- bin/templates/scripts/cordova/Api.js | 74 ++++++++++++++-------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/bin/templates/scripts/cordova/Api.js b/bin/templates/scripts/cordova/Api.js index b7afeef49..49c49f144 100644 --- a/bin/templates/scripts/cordova/Api.js +++ b/bin/templates/scripts/cordova/Api.js @@ -619,44 +619,44 @@ class Api { } }); } -} -/** - * Builds an application package for current platform. - * - * @param {Object} buildOptions A build options. This object's structure is - * highly depends on platform's specific. The most common options are: - * @param {Boolean} buildOptions.debug Indicates that packages should be - * built with debug configuration. This is set to true by default unless the - * 'release' option is not specified. - * @param {Boolean} buildOptions.release Indicates that packages should be - * built with release configuration. If not set to true, debug configuration - * will be used. - * @param {Boolean} buildOptions.device Specifies that built app is intended - * to run on device - * @param {Boolean} buildOptions.emulator: Specifies that built app is - * intended to run on emulator - * @param {String} buildOptions.target Specifies the device id that will be - * used to run built application. - * @param {Boolean} buildOptions.nobuild Indicates that this should be a - * dry-run call, so no build artifacts will be produced. - * @param {String[]} buildOptions.archs Specifies chip architectures which - * app packages should be built for. List of valid architectures is depends on - * platform. - * @param {String} buildOptions.buildConfig The path to build configuration - * file. The format of this file is depends on platform. - * @param {String[]} buildOptions.argv Raw array of command-line arguments, - * passed to `build` command. The purpose of this property is to pass a - * platform-specific arguments, and eventually let platform define own - * arguments processing logic. - * - * @return {Promise} Return a promise either fulfilled, or rejected with - * CordovaError instance. - */ -Api.prototype.build = function (buildOptions) { - return check_reqs.run() - .then(() => require('./lib/build').run.call(this, buildOptions)); -}; + /** + * Builds an application package for current platform. + * + * @param {Object} buildOptions A build options. This object's structure is + * highly depends on platform's specific. The most common options are: + * @param {Boolean} buildOptions.debug Indicates that packages should be + * built with debug configuration. This is set to true by default unless the + * 'release' option is not specified. + * @param {Boolean} buildOptions.release Indicates that packages should be + * built with release configuration. If not set to true, debug configuration + * will be used. + * @param {Boolean} buildOptions.device Specifies that built app is intended + * to run on device + * @param {Boolean} buildOptions.emulator: Specifies that built app is + * intended to run on emulator + * @param {String} buildOptions.target Specifies the device id that will be + * used to run built application. + * @param {Boolean} buildOptions.nobuild Indicates that this should be a + * dry-run call, so no build artifacts will be produced. + * @param {String[]} buildOptions.archs Specifies chip architectures which + * app packages should be built for. List of valid architectures is depends on + * platform. + * @param {String} buildOptions.buildConfig The path to build configuration + * file. The format of this file is depends on platform. + * @param {String[]} buildOptions.argv Raw array of command-line arguments, + * passed to `build` command. The purpose of this property is to pass a + * platform-specific arguments, and eventually let platform define own + * arguments processing logic. + * + * @return {Promise} Return a promise either fulfilled, or rejected with + * CordovaError instance. + */ + build (buildOptions) { + return check_reqs.run() + .then(() => require('./lib/build').run.call(this, buildOptions)); + } +} /** * Builds an application package for current platform and runs it on From 1110606d15dabcd4b87fdd38b6511c8b2da7b67d Mon Sep 17 00:00:00 2001 From: Erisu Date: Fri, 29 Oct 2021 15:11:46 +0900 Subject: [PATCH 12/17] refactor(Api): move run to class as func --- bin/templates/scripts/cordova/Api.js | 34 ++++++++++++++-------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/bin/templates/scripts/cordova/Api.js b/bin/templates/scripts/cordova/Api.js index 49c49f144..6e7b360c0 100644 --- a/bin/templates/scripts/cordova/Api.js +++ b/bin/templates/scripts/cordova/Api.js @@ -656,24 +656,24 @@ class Api { return check_reqs.run() .then(() => require('./lib/build').run.call(this, buildOptions)); } -} -/** - * Builds an application package for current platform and runs it on - * specified/default device. If no 'device'/'emulator'/'target' options are - * specified, then tries to run app on default device if connected, otherwise - * runs the app on emulator. - * - * @param {Object} runOptions An options object. The structure is the same - * as for build options. - * - * @return {Promise} A promise either fulfilled if package was built and ran - * successfully, or rejected with CordovaError. - */ -Api.prototype.run = function (runOptions) { - return check_reqs.run() - .then(() => require('./lib/run').run.call(this, runOptions)); -}; + /** + * Builds an application package for current platform and runs it on + * specified/default device. If no 'device'/'emulator'/'target' options are + * specified, then tries to run app on default device if connected, otherwise + * runs the app on emulator. + * + * @param {Object} runOptions An options object. The structure is the same + * as for build options. + * + * @return {Promise} A promise either fulfilled if package was built and ran + * successfully, or rejected with CordovaError. + */ + run (runOptions) { + return check_reqs.run() + .then(() => require('./lib/run').run.call(this, runOptions)); + } +} /** * Cleans out the build artifacts from platform's directory. From 98237d8b9a73f1cf3807d0493d2722f09aac1ca6 Mon Sep 17 00:00:00 2001 From: Erisu Date: Fri, 29 Oct 2021 15:12:05 +0900 Subject: [PATCH 13/17] refactor(Api): move clean to class as func --- bin/templates/scripts/cordova/Api.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/bin/templates/scripts/cordova/Api.js b/bin/templates/scripts/cordova/Api.js index 6e7b360c0..31d5b50ee 100644 --- a/bin/templates/scripts/cordova/Api.js +++ b/bin/templates/scripts/cordova/Api.js @@ -673,19 +673,19 @@ class Api { return check_reqs.run() .then(() => require('./lib/run').run.call(this, runOptions)); } -} -/** - * Cleans out the build artifacts from platform's directory. - * - * @return {Promise} Return a promise either fulfilled, or rejected with - * CordovaError. - */ -Api.prototype.clean = function (cleanOptions) { - return check_reqs.run() - .then(() => require('./lib/clean').run.call(this, cleanOptions)) - .then(() => require('./lib/prepare').clean.call(this, cleanOptions)); -}; + /** + * Cleans out the build artifacts from platform's directory. + * + * @return {Promise} Return a promise either fulfilled, or rejected with + * CordovaError. + */ + clean (cleanOptions) { + return check_reqs.run() + .then(() => require('./lib/clean').run.call(this, cleanOptions)) + .then(() => require('./lib/prepare').clean.call(this, cleanOptions)); + } +} /** * Performs a requirements check for current platform. Each platform defines its From 5b7665151c0297c8e70a09de91ff578154b4dd58 Mon Sep 17 00:00:00 2001 From: Erisu Date: Fri, 29 Oct 2021 15:12:35 +0900 Subject: [PATCH 14/17] refactor(Api): move requirements to class as func --- bin/templates/scripts/cordova/Api.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/bin/templates/scripts/cordova/Api.js b/bin/templates/scripts/cordova/Api.js index 31d5b50ee..e1b251fd0 100644 --- a/bin/templates/scripts/cordova/Api.js +++ b/bin/templates/scripts/cordova/Api.js @@ -685,19 +685,19 @@ class Api { .then(() => require('./lib/clean').run.call(this, cleanOptions)) .then(() => require('./lib/prepare').clean.call(this, cleanOptions)); } -} -/** - * Performs a requirements check for current platform. Each platform defines its - * own set of requirements, which should be resolved before platform can be - * built successfully. - * - * @return {Promise} Promise, resolved with set of Requirement - * objects for current platform. - */ -Api.prototype.requirements = function () { - return check_reqs.check_all(); -}; + /** + * Performs a requirements check for current platform. Each platform defines its + * own set of requirements, which should be resolved before platform can be + * built successfully. + * + * @return {Promise} Promise, resolved with set of Requirement + * objects for current platform. + */ + requirements () { + return check_reqs.check_all(); + } +} Api.version = function () { return VERSION; From 5e12f174deba4175f10a06f3549b35701dcc1e15 Mon Sep 17 00:00:00 2001 From: Erisu Date: Fri, 29 Oct 2021 15:13:16 +0900 Subject: [PATCH 15/17] refactor(Api): move version to class as static --- bin/templates/scripts/cordova/Api.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/templates/scripts/cordova/Api.js b/bin/templates/scripts/cordova/Api.js index e1b251fd0..9fe5e17eb 100644 --- a/bin/templates/scripts/cordova/Api.js +++ b/bin/templates/scripts/cordova/Api.js @@ -697,10 +697,10 @@ class Api { requirements () { return check_reqs.check_all(); } -} -Api.version = function () { - return VERSION; -}; + static version () { + return VERSION; + } +} module.exports = Api; From 3d77b2950d3696bbb2ddf3e71a847669f6faa0a7 Mon Sep 17 00:00:00 2001 From: Erisu Date: Fri, 29 Oct 2021 15:17:16 +0900 Subject: [PATCH 16/17] refactor(Api): cleanup cordova-common require block --- bin/templates/scripts/cordova/Api.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/bin/templates/scripts/cordova/Api.js b/bin/templates/scripts/cordova/Api.js index 9fe5e17eb..6753c417f 100644 --- a/bin/templates/scripts/cordova/Api.js +++ b/bin/templates/scripts/cordova/Api.js @@ -33,13 +33,15 @@ const path = require('path'); const unorm = require('unorm'); const projectFile = require('./lib/projectFile'); const check_reqs = require('./lib/check_reqs'); -const CordovaError = require('cordova-common').CordovaError; -const CordovaLogger = require('cordova-common').CordovaLogger; -const events = require('cordova-common').events; -const PluginManager = require('cordova-common').PluginManager; +const { + ConfigParser, + CordovaError, + CordovaLogger, + events, + PluginManager +} = require('cordova-common'); const util = require('util'); const xcode = require('xcode'); -const ConfigParser = require('cordova-common').ConfigParser; function setupEvents (externalEventEmitter) { if (externalEventEmitter) { From 40ce76a2f955a527219bc716de63d77c463a1dfe Mon Sep 17 00:00:00 2001 From: Erisu Date: Fri, 29 Oct 2021 15:27:03 +0900 Subject: [PATCH 17/17] refactor(Api): cleanup getPlatformInfo syntax --- bin/templates/scripts/cordova/Api.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/bin/templates/scripts/cordova/Api.js b/bin/templates/scripts/cordova/Api.js index 6753c417f..325597907 100644 --- a/bin/templates/scripts/cordova/Api.js +++ b/bin/templates/scripts/cordova/Api.js @@ -196,14 +196,13 @@ class Api { * platform's file structure and other properties of platform. */ getPlatformInfo () { - const result = {}; - result.locations = this.locations; - result.root = this.root; - result.name = this.platform; - result.version = Api.version(); - result.projectConfig = new ConfigParser(this.locations.configXml); - - return result; + return { + locations: this.locations, + root: this.root, + name: this.platform, + version: Api.version(), + projectConfig: new ConfigParser(this.locations.configXml) + }; } /**