Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use arrow functions #747

Merged
merged 8 commits into from
Dec 24, 2019
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions bin/lib/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function copyScripts (projectPath, projectName) {
shell.sed('-i', /__PROJECT_NAME__/g, project_name_esc, path.join(destScriptsDir, 'build-release.xcconfig'));

// Make sure they are executable (sometimes zipping them can remove executable bit)
shell.find(destScriptsDir).forEach(function (entry) {
shell.find(destScriptsDir).forEach(entry => {
shell.chmod(755, entry);
});
}
Expand Down Expand Up @@ -195,7 +195,7 @@ function relpath (_path, start) {
* - <project_template_dir>: Path to a project template (override)
*
*/
exports.createProject = function (project_path, package_name, project_name, opts, config) {
exports.createProject = (project_path, package_name, project_name, opts, config) => {
package_name = package_name || 'my.cordova.project';
project_name = project_name || 'CordovaExample';
const use_shared = !!opts.link;
Expand Down Expand Up @@ -238,7 +238,7 @@ exports.createProject = function (project_path, package_name, project_name, opts
return Q.resolve();
};

exports.updateProject = function (projectPath, opts) {
exports.updateProject = (projectPath, opts) => {
const errorString =
'An in-place platform update is not supported. \n' +
'The `platforms` folder is always treated as a build artifact.\n' +
Expand Down
113 changes: 44 additions & 69 deletions bin/templates/scripts/cordova/Api.js

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions bin/templates/scripts/cordova/lib/BridgingHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ BridgingHeader.prototype.write = function () {
};

BridgingHeader.prototype.__stringifyForBridgingHeader = function (bridgingHeaders) {
return bridgingHeaders.map(function (obj) {
return obj.code;
}).join('');
return bridgingHeaders.map(obj => obj.code).join('');
};

BridgingHeader.prototype.__parseForBridgingHeader = function (text) {
Expand Down
47 changes: 21 additions & 26 deletions bin/templates/scripts/cordova/lib/Podfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Podfile.prototype.__parseForDeclarations = function (text) {
const declarationsPostRE = new RegExp('target\\s+\'[^\']+\'\\s+do');
const declarationRE = new RegExp('^\\s*[^#]');

return arr.reduce(function (acc, line) {
return arr.reduce((acc, line) => {
switch (acc.state) {
case 0:
if (declarationsPreRE.exec(line)) {
Expand All @@ -101,10 +101,8 @@ Podfile.prototype.__parseForDeclarations = function (text) {
return acc;
}, { state: 0, lines: [] })
.lines
.filter(function (line) {
return declarationRE.exec(line);
})
.reduce(function (obj, line) {
.filter(line => declarationRE.exec(line))
.reduce((obj, line) => {
obj[line] = line;
return obj;
}, {});
Expand All @@ -115,12 +113,12 @@ Podfile.prototype.__parseForSources = function (text) {
const arr = text.split('\n');

const sourceRE = new RegExp('source \'(.*)\'');
return arr.filter(function (line) {
return arr.filter(line => {
const m = sourceRE.exec(line);

return (m !== null);
})
.reduce(function (obj, line) {
.reduce((obj, line) => {
const m = sourceRE.exec(line);
if (m !== null) {
const source = m[1];
Expand All @@ -142,12 +140,12 @@ Podfile.prototype.__parseForPods = function (text) {
const podRE = new RegExp('pod \'([^\']*)\'\\s*(?:,\\s*\'([^\']*)\'\\s*)?,?\\s*(.*)');

// only grab lines that don't have the pod spec'
return arr.filter(function (line) {
return arr.filter(line => {
const m = podRE.exec(line);

return (m !== null);
})
.reduce(function (obj, line) {
.reduce((obj, line) => {
const m = podRE.exec(line);

if (m !== null) {
Expand Down Expand Up @@ -262,8 +260,8 @@ Podfile.prototype.removeDeclaration = function (declaration) {
events.emit('verbose', util.format('Removed source line for `%s`', declaration));
};

Podfile.proofDeclaration = function (declaration) {
const list = Object.keys(Podfile.declarationRegexpMap).filter(function (key) {
Podfile.proofDeclaration = declaration => {
const list = Object.keys(Podfile.declarationRegexpMap).filter(key => {
const regexp = new RegExp(Podfile.declarationRegexpMap[key]);
return regexp.test(declaration);
});
Expand Down Expand Up @@ -294,7 +292,7 @@ Podfile.prototype.write = function () {
const self = this;

const podsString =
Object.keys(this.pods).map(function (key) {
Object.keys(this.pods).map(key => {
const name = key;
const json = self.pods[key];

Expand All @@ -317,13 +315,12 @@ Podfile.prototype.write = function () {
list.push('\'' + json.spec + '\'');
}

let options = ['tag', 'branch', 'commit', 'git', 'podspec'].filter(function (tag) {
return tag in json;
}).map(function (tag) {
return ':' + tag + ' => \'' + json[tag] + '\'';
});
let options = ['tag', 'branch', 'commit', 'git', 'podspec']
.filter(tag => tag in json)
.map(tag => ':' + tag + ' => \'' + json[tag] + '\'');

if ('configurations' in json) {
options.push(':configurations => [' + json['configurations'].split(',').map(function (conf) { return '\'' + conf.trim() + '\''; }).join(',') + ']');
options.push(':configurations => [' + json['configurations'].split(',').map(conf => '\'' + conf.trim() + '\'').join(',') + ']');
}
if ('options' in json) {
options = [json.options];
Expand All @@ -336,13 +333,13 @@ Podfile.prototype.write = function () {
}).join('\n');

const sourcesString =
Object.keys(this.sources).map(function (key) {
Object.keys(this.sources).map(key => {
const source = self.sources[key];
return util.format('source \'%s\'', source);
}).join('\n');

const declarationString =
Object.keys(this.declarations).map(function (key) {
Object.keys(this.declarations).map(key => {
const declaration = self.declarations[key];
return declaration;
}).join('\n');
Expand Down Expand Up @@ -394,17 +391,15 @@ Podfile.prototype.install = function (requirementsCheckerFunction) {
}

return requirementsCheckerFunction()
.then(function (toolOptions) {
return self.before_install(toolOptions);
})
.then(function (toolOptions) {
.then(toolOptions => self.before_install(toolOptions))
.then(toolOptions => {
if (toolOptions.ignore) {
events.emit('verbose', '==== pod install start ====\n');
events.emit('verbose', toolOptions.ignoreMessage);
return Q.resolve();
} else {
return superspawn.spawn('pod', ['install', '--verbose'], opts)
.progress(function (stdio) {
.progress(stdio => {
if (stdio.stderr) { console.error(stdio.stderr); }
if (stdio.stdout) {
if (first) {
Expand All @@ -416,7 +411,7 @@ Podfile.prototype.install = function (requirementsCheckerFunction) {
});
}
})
.then(function () { // done
.then(() => { // done
events.emit('verbose', '==== pod install end ====\n');
});
};
Expand Down
35 changes: 16 additions & 19 deletions bin/templates/scripts/cordova/lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ function getBundleIdentifier (projectObject) {
*/
function getDefaultSimulatorTarget () {
return require('./list-emulator-build-targets').run()
.then(function (emulators) {
.then(emulators => {
let targetEmulator;
if (emulators.length > 0) {
targetEmulator = emulators[0];
}
emulators.forEach(function (emulator) {
emulators.forEach(emulator => {
if (emulator.name.indexOf('iPhone') === 0) {
targetEmulator = emulator;
}
Expand All @@ -103,7 +103,7 @@ function getDefaultSimulatorTarget () {
});
}

module.exports.run = function (buildOpts) {
module.exports.run = buildOpts => {
let emulatorTarget = '';
const projectPath = path.join(__dirname, '..', '..');
let projectName = '';
Expand All @@ -130,22 +130,22 @@ module.exports.run = function (buildOpts) {
const config = buildConfig.ios[buildType];
if (config) {
['codeSignIdentity', 'codeSignResourceRules', 'provisioningProfile', 'developmentTeam', 'packageType', 'buildFlag', 'iCloudContainerEnvironment', 'automaticProvisioning'].forEach(
function (key) {
key => {
buildOpts[key] = buildOpts[key] || config[key];
});
}
}
}

return require('./list-devices').run()
.then(function (devices) {
.then(devices => {
if (devices.length > 0 && !(buildOpts.emulator)) {
// we also explicitly set device flag in options as we pass
// those parameters to other api (build as an example)
buildOpts.device = true;
return check_reqs.check_ios_deploy();
}
}).then(function () {
}).then(() => {
// CB-12287: Determine the device we should target when building for a simulator
if (!buildOpts.device) {
let newTarget = buildOpts.target || '';
Expand All @@ -156,9 +156,9 @@ module.exports.run = function (buildOpts) {
}
// a target was given to us, find the matching Xcode destination name
const promise = require('./list-emulator-build-targets').targetForSimIdentifier(newTarget);
return promise.then(function (theTarget) {
return promise.then(theTarget => {
if (!theTarget) {
return getDefaultSimulatorTarget().then(function (defaultTarget) {
return getDefaultSimulatorTarget().then(defaultTarget => {
emulatorTarget = defaultTarget.name;
events.emit('warn', `No simulator found for "${newTarget}. Falling back to the default target.`);
events.emit('log', `Building for "${emulatorTarget}" Simulator (${defaultTarget.identifier}, ${defaultTarget.simIdentifier}).`);
Expand All @@ -171,11 +171,10 @@ module.exports.run = function (buildOpts) {
}
});
}
}).then(function () {
return check_reqs.run();
}).then(function () {
return findXCodeProjectIn(projectPath);
}).then(function (name) {
})
.then(() => check_reqs.run())
.then(() => findXCodeProjectIn(projectPath))
.then(name => {
projectName = name;
let extraConfig = '';
if (buildOpts.codeSignIdentity) {
Expand Down Expand Up @@ -212,7 +211,7 @@ module.exports.run = function (buildOpts) {
}

return Q.nfcall(fs.writeFile, path.join(__dirname, '..', 'build-extras.xcconfig'), extraConfig, 'utf-8');
}).then(function () {
}).then(() => {
const configuration = buildOpts.release ? 'Release' : 'Debug';

events.emit('log', 'Building project: ' + path.join(projectPath, projectName + '.xcworkspace'));
Expand All @@ -227,7 +226,7 @@ module.exports.run = function (buildOpts) {

const xcodebuildArgs = getXcodeBuildArgs(projectName, projectPath, configuration, buildOpts.device, buildOpts.buildFlag, emulatorTarget, buildOpts.automaticProvisioning);
return superspawn.spawn('xcodebuild', xcodebuildArgs, { cwd: projectPath, printCommand: true, stdio: 'inherit' });
}).then(function () {
}).then(() => {
if (!buildOpts.device || buildOpts.noSign) {
return;
}
Expand Down Expand Up @@ -290,9 +289,7 @@ module.exports.run = function (buildOpts) {
*/
function findXCodeProjectIn (projectPath) {
// 'Searching for Xcode project in ' + projectPath);
const xcodeProjFiles = shell.ls(projectPath).filter(function (name) {
return path.extname(name) === '.xcodeproj';
});
const xcodeProjFiles = shell.ls(projectPath).filter(name => path.extname(name) === '.xcodeproj');

if (xcodeProjFiles.length === 0) {
return Q.reject('No Xcode project found in ' + projectPath);
Expand Down Expand Up @@ -330,7 +327,7 @@ function getXcodeBuildArgs (projectName, projectPath, configuration, isDevice, b
if (typeof buildFlags === 'string' || buildFlags instanceof String) {
parseBuildFlag(buildFlags, customArgs);
} else { // buildFlags is an Array of strings
buildFlags.forEach(function (flag) {
buildFlags.forEach(flag => {
parseBuildFlag(flag, customArgs);
});
}
Expand Down
Loading