Skip to content

Commit 450dc03

Browse files
authored
refactor: do not alias this to self (#748)
1 parent b764944 commit 450dc03

File tree

3 files changed

+43
-58
lines changed

3 files changed

+43
-58
lines changed

bin/templates/scripts/cordova/Api.js

Lines changed: 29 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ Api.prototype.prepare = function (cordovaProject) {
234234
*/
235235
Api.prototype.addPlugin = function (plugin, installOptions) {
236236
const xcodeproj = projectFile.parse(this.locations);
237-
const self = this;
238237

239238
installOptions = installOptions || {};
240239
installOptions.variables = installOptions.variables || {};
@@ -243,15 +242,15 @@ Api.prototype.addPlugin = function (plugin, installOptions) {
243242
installOptions.variables.PACKAGE_NAME = xcodeproj.getPackageName();
244243
}
245244

246-
return PluginManager.get(self.platform, self.locations, xcodeproj)
245+
return PluginManager.get(this.platform, this.locations, xcodeproj)
247246
.addPlugin(plugin, installOptions)
248247
.then(() => {
249248
if (plugin != null) {
250-
const headerTags = plugin.getHeaderFiles(self.platform);
249+
const headerTags = plugin.getHeaderFiles(this.platform);
251250
const bridgingHeaders = headerTags.filter(obj => obj.type === 'BridgingHeader');
252251
if (bridgingHeaders.length > 0) {
253-
const project_dir = self.locations.root;
254-
const project_name = self.locations.xcodeCordovaProj.split('/').pop();
252+
const project_dir = this.locations.root;
253+
const project_name = this.locations.xcodeCordovaProj.split('/').pop();
255254
const BridgingHeader = require('./lib/BridgingHeader').BridgingHeader;
256255
const bridgingHeaderFile = new BridgingHeader(path.join(project_dir, project_name, 'Bridging-Header.h'));
257256
events.emit('verbose', 'Adding Bridging-Headers since the plugin contained <header-file> with type="BridgingHeader"');
@@ -265,10 +264,10 @@ Api.prototype.addPlugin = function (plugin, installOptions) {
265264
})
266265
.then(() => {
267266
if (plugin != null) {
268-
const podSpecs = plugin.getPodSpecs ? plugin.getPodSpecs(self.platform) : [];
269-
const frameworkTags = plugin.getFrameworks(self.platform);
267+
const podSpecs = plugin.getPodSpecs ? plugin.getPodSpecs(this.platform) : [];
268+
const frameworkTags = plugin.getFrameworks(this.platform);
270269
const frameworkPods = frameworkTags.filter(obj => obj.type === 'podspec');
271-
return self.addPodSpecs(plugin, podSpecs, frameworkPods, installOptions);
270+
return this.addPodSpecs(plugin, podSpecs, frameworkPods, installOptions);
272271
}
273272
})
274273
// CB-11022 return non-falsy value to indicate
@@ -291,17 +290,16 @@ Api.prototype.addPlugin = function (plugin, installOptions) {
291290
*/
292291
Api.prototype.removePlugin = function (plugin, uninstallOptions) {
293292
const xcodeproj = projectFile.parse(this.locations);
294-
const self = this;
295293

296-
return PluginManager.get(self.platform, self.locations, xcodeproj)
294+
return PluginManager.get(this.platform, this.locations, xcodeproj)
297295
.removePlugin(plugin, uninstallOptions)
298296
.then(() => {
299297
if (plugin != null) {
300-
const headerTags = plugin.getHeaderFiles(self.platform);
298+
const headerTags = plugin.getHeaderFiles(this.platform);
301299
const bridgingHeaders = headerTags.filter(obj => obj.type === 'BridgingHeader');
302300
if (bridgingHeaders.length > 0) {
303-
const project_dir = self.locations.root;
304-
const project_name = self.locations.xcodeCordovaProj.split('/').pop();
301+
const project_dir = this.locations.root;
302+
const project_name = this.locations.xcodeCordovaProj.split('/').pop();
305303
const BridgingHeader = require('./lib/BridgingHeader').BridgingHeader;
306304
const bridgingHeaderFile = new BridgingHeader(path.join(project_dir, project_name, 'Bridging-Header.h'));
307305
events.emit('verbose', 'Removing Bridging-Headers since the plugin contained <header-file> with type="BridgingHeader"');
@@ -315,10 +313,10 @@ Api.prototype.removePlugin = function (plugin, uninstallOptions) {
315313
})
316314
.then(() => {
317315
if (plugin != null) {
318-
const podSpecs = plugin.getPodSpecs ? plugin.getPodSpecs(self.platform) : [];
319-
const frameworkTags = plugin.getFrameworks(self.platform);
316+
const podSpecs = plugin.getPodSpecs ? plugin.getPodSpecs(this.platform) : [];
317+
const frameworkTags = plugin.getFrameworks(this.platform);
320318
const frameworkPods = frameworkTags.filter(obj => obj.type === 'podspec');
321-
return self.removePodSpecs(plugin, podSpecs, frameworkPods, uninstallOptions);
319+
return this.removePodSpecs(plugin, podSpecs, frameworkPods, uninstallOptions);
322320
}
323321
})
324322
// CB-11022 return non-falsy value to indicate
@@ -331,17 +329,15 @@ Api.prototype.removePlugin = function (plugin, uninstallOptions) {
331329
*
332330
* @param {PluginInfo} plugin A PluginInfo instance that represents plugin
333331
* that will be installed.
334-
* @param {Object} podSpecs: the return value of plugin.getPodSpecs(self.platform)
332+
* @param {Object} podSpecs: the return value of plugin.getPodSpecs(this.platform)
335333
* @param {Object} frameworkPods: framework tags object with type === 'podspec'
336334
* @return {Promise} Return a promise
337335
*/
338336

339337
Api.prototype.addPodSpecs = function (plugin, podSpecs, frameworkPods, installOptions) {
340-
const self = this;
341-
342-
const project_dir = self.locations.root;
343-
const project_name = self.locations.xcodeCordovaProj.split('/').pop();
344-
const minDeploymentTarget = self.getPlatformInfo().projectConfig.getPreference('deployment-target', 'ios');
338+
const project_dir = this.locations.root;
339+
const project_name = this.locations.xcodeCordovaProj.split('/').pop();
340+
const minDeploymentTarget = this.getPlatformInfo().projectConfig.getPreference('deployment-target', 'ios');
345341

346342
const Podfile = require('./lib/Podfile').Podfile;
347343
const PodsJson = require('./lib/PodsJson').PodsJson;
@@ -436,10 +432,10 @@ Api.prototype.addPodSpecs = function (plugin, podSpecs, frameworkPods, installOp
436432
if (podfileFile.isDirty()) {
437433
podfileFile.write();
438434
events.emit('verbose', 'Running `pod install` (to install plugins)');
439-
projectFile.purgeProjectFileCache(self.locations.root);
435+
projectFile.purgeProjectFileCache(this.locations.root);
440436

441437
return podfileFile.install(check_reqs.check_cocoapods)
442-
.then(() => self.setSwiftVersionForCocoaPodsLibraries(podsjsonFile));
438+
.then(() => this.setSwiftVersionForCocoaPodsLibraries(podsjsonFile));
443439
} else {
444440
events.emit('verbose', 'Podfile unchanged, skipping `pod install`');
445441
}
@@ -452,16 +448,14 @@ Api.prototype.addPodSpecs = function (plugin, podSpecs, frameworkPods, installOp
452448
*
453449
* @param {PluginInfo} plugin A PluginInfo instance that represents plugin
454450
* that will be installed.
455-
* @param {Object} podSpecs: the return value of plugin.getPodSpecs(self.platform)
451+
* @param {Object} podSpecs: the return value of plugin.getPodSpecs(this.platform)
456452
* @param {Object} frameworkPods: framework tags object with type === 'podspec'
457453
* @return {Promise} Return a promise
458454
*/
459455

460456
Api.prototype.removePodSpecs = function (plugin, podSpecs, frameworkPods, uninstallOptions) {
461-
const self = this;
462-
463-
const project_dir = self.locations.root;
464-
const project_name = self.locations.xcodeCordovaProj.split('/').pop();
457+
const project_dir = this.locations.root;
458+
const project_name = this.locations.xcodeCordovaProj.split('/').pop();
465459

466460
const Podfile = require('./lib/Podfile').Podfile;
467461
const PodsJson = require('./lib/PodsJson').PodsJson;
@@ -559,7 +553,7 @@ Api.prototype.removePodSpecs = function (plugin, podSpecs, frameworkPods, uninst
559553
events.emit('verbose', 'Running `pod install` (to uninstall pods)');
560554

561555
return podfileFile.install(check_reqs.check_cocoapods)
562-
.then(() => self.setSwiftVersionForCocoaPodsLibraries(podsjsonFile));
556+
.then(() => this.setSwiftVersionForCocoaPodsLibraries(podsjsonFile));
563557
} else {
564558
events.emit('verbose', 'Podfile unchanged, skipping `pod install`');
565559
}
@@ -574,13 +568,12 @@ Api.prototype.removePodSpecs = function (plugin, podSpecs, frameworkPods, uninst
574568
*/
575569

576570
Api.prototype.setSwiftVersionForCocoaPodsLibraries = function (podsjsonFile) {
577-
const self = this;
578571
let __dirty = false;
579572
return check_reqs.check_cocoapods().then(toolOptions => {
580573
if (toolOptions.ignore) {
581574
events.emit('verbose', '=== skip Swift Version Settings For Cocoapods Libraries');
582575
} else {
583-
const podPbxPath = path.join(self.root, 'Pods', 'Pods.xcodeproj', 'project.pbxproj');
576+
const podPbxPath = path.join(this.root, 'Pods', 'Pods.xcodeproj', 'project.pbxproj');
584577
const podXcodeproj = xcode.project(podPbxPath);
585578
podXcodeproj.parseSync();
586579
const podTargets = podXcodeproj.pbxNativeTargetSection();
@@ -647,9 +640,8 @@ Api.prototype.setSwiftVersionForCocoaPodsLibraries = function (podsjsonFile) {
647640
* CordovaError instance.
648641
*/
649642
Api.prototype.build = function (buildOptions) {
650-
const self = this;
651643
return check_reqs.run()
652-
.then(() => require('./lib/build').run.call(self, buildOptions));
644+
.then(() => require('./lib/build').run.call(this, buildOptions));
653645
};
654646

655647
/**
@@ -665,9 +657,8 @@ Api.prototype.build = function (buildOptions) {
665657
* successfully, or rejected with CordovaError.
666658
*/
667659
Api.prototype.run = function (runOptions) {
668-
const self = this;
669660
return check_reqs.run()
670-
.then(() => require('./lib/run').run.call(self, runOptions));
661+
.then(() => require('./lib/run').run.call(this, runOptions));
671662
};
672663

673664
/**
@@ -677,10 +668,9 @@ Api.prototype.run = function (runOptions) {
677668
* CordovaError.
678669
*/
679670
Api.prototype.clean = function (cleanOptions) {
680-
const self = this;
681671
return check_reqs.run()
682-
.then(() => require('./lib/clean').run.call(self, cleanOptions))
683-
.then(() => require('./lib/prepare').clean.call(self, cleanOptions));
672+
.then(() => require('./lib/clean').run.call(this, cleanOptions))
673+
.then(() => require('./lib/prepare').clean.call(this, cleanOptions));
684674
};
685675

686676
/**

bin/templates/scripts/cordova/lib/Podfile.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -289,12 +289,11 @@ Podfile.prototype.destroy = function () {
289289

290290
Podfile.prototype.write = function () {
291291
let text = this.getTemplate();
292-
const self = this;
293292

294293
const podsString =
295294
Object.keys(this.pods).map(key => {
296295
const name = key;
297-
const json = self.pods[key];
296+
const json = this.pods[key];
298297

299298
if (typeof json === 'string') { // compatibility for using framework tag.
300299
const spec = json;
@@ -334,13 +333,13 @@ Podfile.prototype.write = function () {
334333

335334
const sourcesString =
336335
Object.keys(this.sources).map(key => {
337-
const source = self.sources[key];
336+
const source = this.sources[key];
338337
return util.format('source \'%s\'', source);
339338
}).join('\n');
340339

341340
const declarationString =
342341
Object.keys(this.declarations).map(key => {
343-
const declaration = self.declarations[key];
342+
const declaration = this.declarations[key];
344343
return declaration;
345344
}).join('\n');
346345

@@ -384,14 +383,13 @@ Podfile.prototype.install = function (requirementsCheckerFunction) {
384383
opts.stdio = 'pipe';
385384
opts.printCommand = true;
386385
let first = true;
387-
const self = this;
388386

389387
if (!requirementsCheckerFunction) {
390388
requirementsCheckerFunction = Q();
391389
}
392390

393391
return requirementsCheckerFunction()
394-
.then(toolOptions => self.before_install(toolOptions))
392+
.then(toolOptions => this.before_install(toolOptions))
395393
.then(toolOptions => {
396394
if (toolOptions.ignore) {
397395
events.emit('verbose', '==== pod install start ====\n');

bin/templates/scripts/cordova/lib/prepare.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ const IMAGESET_COMPACT_SIZE_CLASS = 'compact';
4545
const CDV_ANY_SIZE_CLASS = 'any';
4646

4747
module.exports.prepare = function (cordovaProject, options) {
48-
const self = this;
49-
5048
const platformJson = PlatformJson.load(this.locations.root, 'ios');
5149
const munger = new PlatformMunger('ios', this.locations.root, platformJson, new PluginInfoProvider());
5250

@@ -55,12 +53,12 @@ module.exports.prepare = function (cordovaProject, options) {
5553
// Update own www dir with project's www assets and plugins' assets and js-files
5654
return Q.when(updateWww(cordovaProject, this.locations))
5755
// update project according to config.xml changes.
58-
.then(() => updateProject(self._config, self.locations))
56+
.then(() => updateProject(this._config, this.locations))
5957
.then(() => {
60-
updateIcons(cordovaProject, self.locations);
61-
updateSplashScreens(cordovaProject, self.locations);
62-
updateLaunchStoryboardImages(cordovaProject, self.locations);
63-
updateFileResources(cordovaProject, self.locations);
58+
updateIcons(cordovaProject, this.locations);
59+
updateSplashScreens(cordovaProject, this.locations);
60+
updateLaunchStoryboardImages(cordovaProject, this.locations);
61+
updateFileResources(cordovaProject, this.locations);
6462
})
6563
.then(() => {
6664
events.emit('verbose', 'Prepared iOS project successfully');
@@ -81,13 +79,12 @@ module.exports.clean = function (options) {
8179

8280
const projectConfig = new ConfigParser(this.locations.configXml);
8381

84-
const self = this;
8582
return Q().then(() => {
86-
cleanWww(projectRoot, self.locations);
87-
cleanIcons(projectRoot, projectConfig, self.locations);
88-
cleanSplashScreens(projectRoot, projectConfig, self.locations);
89-
cleanLaunchStoryboardImages(projectRoot, projectConfig, self.locations);
90-
cleanFileResources(projectRoot, projectConfig, self.locations);
83+
cleanWww(projectRoot, this.locations);
84+
cleanIcons(projectRoot, projectConfig, this.locations);
85+
cleanSplashScreens(projectRoot, projectConfig, this.locations);
86+
cleanLaunchStoryboardImages(projectRoot, projectConfig, this.locations);
87+
cleanFileResources(projectRoot, projectConfig, this.locations);
9188
});
9289
};
9390

0 commit comments

Comments
 (0)