Skip to content

Commit ea4712f

Browse files
committed
format js files using prettier
1 parent e787c3c commit ea4712f

23 files changed

+1126
-1004
lines changed

extra/hooks/iosrtc-swift-support.js

+146-54
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55
// This hook automates this:
66
// https://github.com/cordova-rtc/cordova-plugin-iosrtc/blob/master/docs/Building.md
77

8-
var
9-
fs = require("fs"),
10-
path = require("path"),
8+
var fs = require('fs'),
9+
path = require('path'),
1110
xcode = require('xcode'),
1211
xmlEntities = new (require('html-entities').XmlEntities)(),
13-
1412
DISABLE_IOSRTC_HOOK = process.env.DISABLE_IOSRTC_HOOK ? true : false,
1513
IPHONEOS_DEPLOYMENT_TARGET = process.env.IPHONEOS_DEPLOYMENT_TARGET || '10.2',
1614
IPHONEOS_DEPLOYMENT_TARGET_XCODE = '"' + IPHONEOS_DEPLOYMENT_TARGET + '"',
@@ -21,28 +19,26 @@ var
2119
ENABLE_BITCODE = 'NO',
2220
ENABLE_BITCODE_XCODE = '"' + ENABLE_BITCODE + '"',
2321
UNIFIED_BRIDGING_HEADER = 'Plugins/Unified-Bridging-Header.h',
24-
IOSRTC_BRIDGING_HEADER = "cordova-plugin-iosrtc-Bridging-Header.h",
22+
IOSRTC_BRIDGING_HEADER = 'cordova-plugin-iosrtc-Bridging-Header.h',
2523
BRIDGING_HEADER_END = '/Plugins/cordova-plugin-iosrtc/' + IOSRTC_BRIDGING_HEADER,
2624
TEST_UNIFIED_BRIDGING_HEADER = process.env.TEST_UNIFIED_BRIDGING_HEADER ? true : false; // Set to true to test handling of existing swift bridging header
2725

2826
// Helpers
2927

3028
// Returns the project name
3129
function getProjectName(protoPath) {
32-
var
33-
cordovaConfigPath = path.join(protoPath, 'config.xml'),
30+
var cordovaConfigPath = path.join(protoPath, 'config.xml'),
3431
content = fs.readFileSync(cordovaConfigPath, 'utf-8');
3532

36-
var name = /<name>([ \S]*)<\/name>/mi.exec(content)[1].trim();
33+
var name = /<name>([ \S]*)<\/name>/im.exec(content)[1].trim();
3734

3835
return xmlEntities.decode(name);
3936
}
4037

4138
// Drops the comments
4239
var COMMENT_KEY = /_comment$/;
4340
function nonComments(obj) {
44-
var
45-
keys = Object.keys(obj),
41+
var keys = Object.keys(obj),
4642
newObj = {},
4743
i = 0;
4844

@@ -60,11 +56,14 @@ function matchBuildSettingsValue(value, expectedValue) {
6056
}
6157

6258
function hasBuildSettingsValue(value, expectedValue) {
63-
return value && (matchBuildSettingsValue(value, expectedValue) || value.indexOf(expectedValue) !== -1);
59+
return (
60+
value &&
61+
(matchBuildSettingsValue(value, expectedValue) || value.indexOf(expectedValue) !== -1)
62+
);
6463
}
6564

6665
function convertToFloat(value) {
67-
return parseFloat(value.replace(/[^\d.-]/g,''), 10);
66+
return parseFloat(value.replace(/[^\d.-]/g, ''), 10);
6867
}
6968

7069
function matchMinValue(value, minValue) {
@@ -73,13 +72,18 @@ function matchMinValue(value, minValue) {
7372
}
7473

7574
function matchBuildSettingsMinValue(value, expectedValue) {
76-
return value && (matchBuildSettingsValue(value, expectedValue) || matchMinValue(value, expectedValue));
75+
return (
76+
value &&
77+
(matchBuildSettingsValue(value, expectedValue) || matchMinValue(value, expectedValue))
78+
);
7779
}
7880

7981
function matchXcconfigPathValue(swiftOptions, path, expectedValue) {
80-
return swiftOptions.filter(function (swiftOption) {
81-
return swiftOption === path + ' = ' + expectedValue;
82-
}).length > 0;
82+
return (
83+
swiftOptions.filter(function (swiftOption) {
84+
return swiftOption === path + ' = ' + expectedValue;
85+
}).length > 0
86+
);
8387
}
8488

8589
function getXcconfigPathValue(swiftOptions, path) {
@@ -103,7 +107,7 @@ function getRelativeToProjectRootPath(path, projectRoot) {
103107
}
104108

105109
function readFileLines(filePath) {
106-
return fs.readFileSync(filePath).toString().split("\n");
110+
return fs.readFileSync(filePath).toString().split('\n');
107111
}
108112

109113
function debug(msg) {
@@ -118,7 +122,6 @@ function debugError(msg) {
118122
// Starting here
119123

120124
module.exports = function (context) {
121-
122125
// This script has to be executed depending on the command line arguments, not
123126
// on the hook execution cycle.
124127
/*
@@ -132,8 +135,7 @@ module.exports = function (context) {
132135
return;
133136
}
134137

135-
var
136-
projectRoot = context.opts.projectRoot,
138+
var projectRoot = context.opts.projectRoot,
137139
projectName = getProjectName(projectRoot),
138140
platformPath = path.join(projectRoot, 'platforms', 'ios'),
139141
platformProjectPath = path.join(platformPath, projectName),
@@ -147,7 +149,10 @@ module.exports = function (context) {
147149

148150
// Showing info about the tasks to do
149151
debug('cordova-plugin-iosrtc hook is checking issues in the generated project files:');
150-
debug('- Minimum "iOS Deployment Target" and "Deployment Target" to: ' + IPHONEOS_DEPLOYMENT_TARGET_XCODE);
152+
debug(
153+
'- Minimum "iOS Deployment Target" and "Deployment Target" to: ' +
154+
IPHONEOS_DEPLOYMENT_TARGET_XCODE
155+
);
151156
debug('- "Runpath Search Paths" to: ' + RUNPATH_SEARCH_PATHS_XCODE);
152157
if (TEST_UNIFIED_BRIDGING_HEADER) {
153158
debug('- "Objective-C Bridging Header" to: ' + UNIFIED_BRIDGING_HEADER);
@@ -159,18 +164,25 @@ module.exports = function (context) {
159164

160165
// Checking if the project files are in the right place
161166
if (!fs.existsSync(xcodeProjectConfigPath)) {
162-
debugError('an error occurred searching the project file at: "' + xcodeProjectConfigPath + '"');
167+
debugError(
168+
'an error occurred searching the project file at: "' + xcodeProjectConfigPath + '"'
169+
);
163170

164171
return;
165172
}
166-
debug('".pbxproj" project file found: ' + getRelativeToProjectRootPath(xcodeProjectConfigPath, projectRoot));
173+
debug(
174+
'".pbxproj" project file found: ' +
175+
getRelativeToProjectRootPath(xcodeProjectConfigPath, projectRoot)
176+
);
167177

168178
if (!fs.existsSync(xcconfigPath)) {
169179
debugError('an error occurred searching the project file at: "' + xcconfigPath + '"');
170180

171181
return;
172182
}
173-
debug('".xcconfig" project file found: ' + getRelativeToProjectRootPath(xcconfigPath, projectRoot));
183+
debug(
184+
'".xcconfig" project file found: ' + getRelativeToProjectRootPath(xcconfigPath, projectRoot)
185+
);
174186

175187
xcodeProject = xcode.project(xcodeProjectConfigPath);
176188

@@ -186,12 +198,24 @@ module.exports = function (context) {
186198
currentSwiftOptions = readFileLines(xcconfigPath);
187199
}
188200

189-
if (!matchXcconfigPathValue(currentSwiftOptions, 'LD_RUNPATH_SEARCH_PATHS', RUNPATH_SEARCH_PATHS)) {
201+
if (
202+
!matchXcconfigPathValue(
203+
currentSwiftOptions,
204+
'LD_RUNPATH_SEARCH_PATHS',
205+
RUNPATH_SEARCH_PATHS
206+
)
207+
) {
190208
swiftOptions.push('LD_RUNPATH_SEARCH_PATHS = ' + RUNPATH_SEARCH_PATHS);
191209
xcconfigPathChanged = true;
192210
}
193211

194-
if (!matchXcconfigMinValue(currentSwiftOptions, 'IPHONEOS_DEPLOYMENT_TARGET', IPHONEOS_DEPLOYMENT_TARGET)) {
212+
if (
213+
!matchXcconfigMinValue(
214+
currentSwiftOptions,
215+
'IPHONEOS_DEPLOYMENT_TARGET',
216+
IPHONEOS_DEPLOYMENT_TARGET
217+
)
218+
) {
195219
swiftOptions.push('IPHONEOS_DEPLOYMENT_TARGET = ' + IPHONEOS_DEPLOYMENT_TARGET);
196220
xcconfigPathChanged = true;
197221
}
@@ -210,13 +234,25 @@ module.exports = function (context) {
210234
if (TEST_UNIFIED_BRIDGING_HEADER) {
211235
existingSwiftBridgingHeaderPath = path.join(platformProjectPath, UNIFIED_BRIDGING_HEADER);
212236
} else {
213-
if (!matchXcconfigPathValue(currentSwiftOptions, 'SWIFT_OBJC_BRIDGING_HEADER', swiftBridgingHeaderPath)) {
214-
var currentSwiftBridgingHeader = getXcconfigPathValue(currentSwiftOptions, 'SWIFT_OBJC_BRIDGING_HEADER').replace('$(PROJECT_DIR)/$(PROJECT_NAME)/', '');
237+
if (
238+
!matchXcconfigPathValue(
239+
currentSwiftOptions,
240+
'SWIFT_OBJC_BRIDGING_HEADER',
241+
swiftBridgingHeaderPath
242+
)
243+
) {
244+
var currentSwiftBridgingHeader = getXcconfigPathValue(
245+
currentSwiftOptions,
246+
'SWIFT_OBJC_BRIDGING_HEADER'
247+
).replace('$(PROJECT_DIR)/$(PROJECT_NAME)/', '');
215248
if (!existingSwiftBridgingHeaderPath) {
216249
swiftOptions.push('SWIFT_OBJC_BRIDGING_HEADER = ' + swiftBridgingHeaderPath);
217250
xcconfigPathChanged = true;
218251
} else {
219-
existingSwiftBridgingHeaderPath = path.join(platformProjectPath, currentSwiftBridgingHeader);
252+
existingSwiftBridgingHeaderPath = path.join(
253+
platformProjectPath,
254+
currentSwiftBridgingHeader
255+
);
220256
}
221257
}
222258
}
@@ -236,9 +272,11 @@ module.exports = function (context) {
236272

237273
// Parsing it
238274
xcodeProject.parse(function (error) {
239-
240275
if (error) {
241-
debugError('an error occurred during the parsing of the project file: ' + xcodeProjectConfigPath);
276+
debugError(
277+
'an error occurred during the parsing of the project file: ' +
278+
xcodeProjectConfigPath
279+
);
242280

243281
return;
244282
}
@@ -248,7 +286,6 @@ module.exports = function (context) {
248286
var hasSwiftBridgingHeaderPathXcodes = [];
249287
var configurations = nonComments(xcodeProject.pbxXCBuildConfigurationSection());
250288
Object.keys(configurations).forEach(function (config) {
251-
252289
var configuration = configurations[config],
253290
buildSettings = configuration.buildSettings;
254291

@@ -257,12 +294,22 @@ module.exports = function (context) {
257294
return;
258295
}
259296

260-
if (!hasBuildSettingsValue(buildSettings.LD_RUNPATH_SEARCH_PATHS, RUNPATH_SEARCH_PATHS_XCODE)) {
297+
if (
298+
!hasBuildSettingsValue(
299+
buildSettings.LD_RUNPATH_SEARCH_PATHS,
300+
RUNPATH_SEARCH_PATHS_XCODE
301+
)
302+
) {
261303
buildSettings.LD_RUNPATH_SEARCH_PATHS = RUNPATH_SEARCH_PATHS_XCODE;
262304
buildSettingsChanged = true;
263305
}
264306

265-
if (!matchBuildSettingsMinValue(buildSettings.IPHONEOS_DEPLOYMENT_TARGET, IPHONEOS_DEPLOYMENT_TARGET_XCODE)) {
307+
if (
308+
!matchBuildSettingsMinValue(
309+
buildSettings.IPHONEOS_DEPLOYMENT_TARGET,
310+
IPHONEOS_DEPLOYMENT_TARGET_XCODE
311+
)
312+
) {
266313
buildSettings.IPHONEOS_DEPLOYMENT_TARGET = IPHONEOS_DEPLOYMENT_TARGET_XCODE;
267314
buildSettingsChanged = true;
268315
}
@@ -282,48 +329,87 @@ module.exports = function (context) {
282329
xcodeProject.addHeaderFile(UNIFIED_BRIDGING_HEADER);
283330
}
284331

285-
if (!hasBuildSettingsValue(buildSettings.SWIFT_OBJC_BRIDGING_HEADER, swiftBridgingHeaderPathXcode)) {
286-
332+
if (
333+
!hasBuildSettingsValue(
334+
buildSettings.SWIFT_OBJC_BRIDGING_HEADER,
335+
swiftBridgingHeaderPathXcode
336+
)
337+
) {
287338
// Play nice with existing Swift Bridging Header value
288339
if (existingSwiftBridgingHeaderPath) {
289-
290340
// Sync SWIFT_OBJC_BRIDGING_HEADER with existingSwiftBridgingHeaderPath if do not match
291-
var existingSwiftBridgingHeaderPathXcode = '"' + existingSwiftBridgingHeaderPath + '"';
292-
if (buildSettings.SWIFT_OBJC_BRIDGING_HEADER !== existingSwiftBridgingHeaderPathXcode) {
341+
var existingSwiftBridgingHeaderPathXcode =
342+
'"' + existingSwiftBridgingHeaderPath + '"';
343+
if (
344+
buildSettings.SWIFT_OBJC_BRIDGING_HEADER !==
345+
existingSwiftBridgingHeaderPathXcode
346+
) {
293347
buildSettings.SWIFT_OBJC_BRIDGING_HEADER = existingSwiftBridgingHeaderPathXcode;
294348
buildSettingsChanged = true;
295349
}
296350

297-
if (hasSwiftBridgingHeaderPathXcodes.indexOf(existingSwiftBridgingHeaderPath) === -1) {
298-
351+
if (
352+
hasSwiftBridgingHeaderPathXcodes.indexOf(
353+
existingSwiftBridgingHeaderPath
354+
) === -1
355+
) {
299356
// Check if existing existingSwiftBridgingHeaderPath exists and get file lines
300357

301-
debug('checking file: ' + getRelativeToProjectRootPath(existingSwiftBridgingHeaderPath, projectRoot));
358+
debug(
359+
'checking file: ' +
360+
getRelativeToProjectRootPath(
361+
existingSwiftBridgingHeaderPath,
362+
projectRoot
363+
)
364+
);
302365

303366
var existingSwiftBridgingHeaderFileLines = [];
304367
if (fs.existsSync(existingSwiftBridgingHeaderPath)) {
305-
existingSwiftBridgingHeaderFileLines = readFileLines(existingSwiftBridgingHeaderPath);
368+
existingSwiftBridgingHeaderFileLines = readFileLines(
369+
existingSwiftBridgingHeaderPath
370+
);
306371
}
307372

308373
// Check if existing existingSwiftBridgingHeaderFileLines contains swiftBridgingHeaderPath
309374
var swiftBridgingHeaderImport = '#import "' + IOSRTC_BRIDGING_HEADER + '"';
310-
var hasSwiftBridgingHeaderPathXcode = existingSwiftBridgingHeaderFileLines.filter(function (line) {
311-
return line === swiftBridgingHeaderImport;
312-
}).length > 0;
375+
var hasSwiftBridgingHeaderPathXcode =
376+
existingSwiftBridgingHeaderFileLines.filter(function (line) {
377+
return line === swiftBridgingHeaderImport;
378+
}).length > 0;
313379

314380
if (!hasSwiftBridgingHeaderPathXcode) {
315-
debug('updating existing swift bridging header file: ' + getRelativeToProjectRootPath(existingSwiftBridgingHeaderPath, projectRoot));
381+
debug(
382+
'updating existing swift bridging header file: ' +
383+
getRelativeToProjectRootPath(
384+
existingSwiftBridgingHeaderPath,
385+
projectRoot
386+
)
387+
);
316388
existingSwiftBridgingHeaderFileLines.push(swiftBridgingHeaderImport);
317-
fs.writeFileSync(existingSwiftBridgingHeaderPath, existingSwiftBridgingHeaderFileLines.join('\n'), 'utf-8');
318-
debug('file correctly fixed: ' + getRelativeToProjectRootPath(existingSwiftBridgingHeaderPath, projectRoot));
389+
fs.writeFileSync(
390+
existingSwiftBridgingHeaderPath,
391+
existingSwiftBridgingHeaderFileLines.join('\n'),
392+
'utf-8'
393+
);
394+
debug(
395+
'file correctly fixed: ' +
396+
getRelativeToProjectRootPath(
397+
existingSwiftBridgingHeaderPath,
398+
projectRoot
399+
)
400+
);
319401
} else {
320-
debug('file is correct: ' + getRelativeToProjectRootPath(existingSwiftBridgingHeaderPath, projectRoot));
402+
debug(
403+
'file is correct: ' +
404+
getRelativeToProjectRootPath(
405+
existingSwiftBridgingHeaderPath,
406+
projectRoot
407+
)
408+
);
321409
}
322410

323411
hasSwiftBridgingHeaderPathXcodes.push(existingSwiftBridgingHeaderPath);
324412
}
325-
326-
327413
} else {
328414
buildSettings.SWIFT_OBJC_BRIDGING_HEADER = swiftBridgingHeaderPathXcode;
329415
buildSettingsChanged = true;
@@ -334,9 +420,15 @@ module.exports = function (context) {
334420
// Writing the file only if changed
335421
if (buildSettingsChanged) {
336422
fs.writeFileSync(xcodeProjectConfigPath, xcodeProject.writeSync(), 'utf-8');
337-
debug('file correctly fixed: ' + getRelativeToProjectRootPath(xcodeProjectConfigPath, projectRoot));
423+
debug(
424+
'file correctly fixed: ' +
425+
getRelativeToProjectRootPath(xcodeProjectConfigPath, projectRoot)
426+
);
338427
} else {
339-
debug('file is correct: ' + getRelativeToProjectRootPath(xcodeProjectConfigPath, projectRoot));
428+
debug(
429+
'file is correct: ' +
430+
getRelativeToProjectRootPath(xcodeProjectConfigPath, projectRoot)
431+
);
340432
}
341433
});
342434
};

0 commit comments

Comments
 (0)