-
Notifications
You must be signed in to change notification settings - Fork 6
/
buildSymLinks.js
733 lines (682 loc) · 30 KB
/
buildSymLinks.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
//Program to build the symlinks from WeVoteCordova www directories to the WebApp build directory
/*
To debug this node program ...
node inspect buildSymLinks /Users/stevepodell/WebstormProjects/WebApp/build
Note:
Example program that adds to the plist
https://github.com/MaximBelov/cordova-plugin-fbsdk/blob/master/scripts/ios/after_prepare.js
*/
/*jshint esversion: 6 */
/*jslint node: true */
/*global process, __dirname */
const path = require('path');
const fs = require('fs');
const { rimrafSync } = require('rimraf');
const readline = require('readline');
function writeCordovaLibGradleWrapperProperties () {
// Needed for Gradle 8
const path0 = './platforms/android/gradle';
const path = './platforms/android/gradle/wrapper';
const file = path + '/gradle-wrapper.properties';
console.log(`> Processing ${file}`);
try {
if (!fs.existsSync(path)) {
console.log('Making directory ' + path0);
fs.mkdirSync(path0);
console.log('Making directory ' + path);
fs.mkdirSync(path);
}
} catch (err) {
console.error('Error: Making directory for ' + file + " - " + err);
}
// const newValue='distributionUrl=https\\://services.gradle.org/distributions/gradle-8.2.1-all.zip\n';
const newValue='distributionUrl=https://services.gradle.org/distributions/gradle-8.4-all.zip\n';
fs.writeFileSync(file, newValue, 'utf8');
console.log('Created file: ', file);
}
const updateMainAndroidManifest = () => {
// /Users/stevepodell/WebstormProjects/WeVoteCordova/platforms/android/app/src/main/AndroidManifest.xml
// Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported` when the corresponding component has an intent filter defined
// 10/27/23: play.console.com gave warning:
// Anomalous Permission Usage
// Your app is requesting permissions which are used by less than 1% of functionally similar apps:
// * android.permission.WRITE_CONTACTS
// And we don't need to update a user's contacts, so removing it here
const originalFile = './platforms/android/app/src/main/AndroidManifest.xml';
const saveOffFile = originalFile + '.previous'
console.log(`> Processing ${originalFile}`);
fs.rename(originalFile, saveOffFile, () => {
const rl = readline.createInterface({
input: fs.createReadStream(saveOffFile),
crlfDelay: Infinity,
});
const newGradle = [];
rl.on('line', (line) => {
if (line.startsWith('<manifest')) {
if (!line.includes('xmlns:android')) {
line = line.replace('>', ' xmlns:android="http://schemas.android.com/apk/res/android">')
console.log('adding::: xmlns:android="http://schemas.android.com/apk/res/android" ::: to android/app/src/main/AndroidManifest.xml');
}
newGradle.push(line);
} else if (line.includes('<service android:name')) {
if (!line.includes('android:exported="true"')) {
line = line.replace('>', ' android:exported="true">');
console.log('adding::: android:exported="true (for <service android:name) ::: to android/app/src/main/AndroidManifest.xml');
}
newGradle.push(line);
} else if (line.includes('<receiver ')) {
if (!line.includes('android:exported="true"')) {
line = line.replace('>', ' android:exported="true">');
console.log('adding::: android:exported="true (for <receiver ) ::: to android/app/src/main/AndroidManifest.xml');
}
newGradle.push(line);
} else if (line.includes('AdvertiserIDCollectionEnabled')) {
console.log('adding dummy::: com.facebook.sdk.ClientToken ::: from android/app/src/main/AndroidManifest.xml');
newGradle.push(line);
newGradle.push(' <meta-data android:name="com.facebook.sdk.ClientToken" android:value="YOUR-CLIENT-TOKEN-HERE" />');
} else if (line.includes('<uses-permission android:name="android.permission.WRITE_CONTACTS" />')) {
console.log('removing::: android.permission.WRITE_CONTACTS ::: from android/app/src/main/AndroidManifest.xml');
// Don't push the line, thereby deleting it
} else {
newGradle.push(line);
}
});
rl.on('close', () => {
const buildGradle = fs.openSync(originalFile, 'w');
newGradle.forEach((txt) => {
fs.writeSync(buildGradle, `${txt}\n`);
});
console.log(`updateAndroidBuildGradle added a classpath in ${originalFile}`);
});
});
};
const updateAndroidJson = () => {
// 10/27/23 Not sure if this is necessary, but just in case
// 10/27/23: play.console.com gave warning:
// Anomalous Permission Usage
// Your app is requesting permissions which are used by less than 1% of functionally similar apps:
// * android.permission.WRITE_CONTACTS
// And we don't need to update a user's contacts, so removing it here
const originalFile = './platforms/android/android.json';
const saveOffFile = originalFile + '.previous'
console.log(`> Processing ${originalFile}`);
fs.rename(originalFile, saveOffFile, () => {
fs.readFile(saveOffFile, 'utf8', function(err, data){
data = data.replace(/^.*?\{\n.*?android.permission.WRITE_CONTACTS[^}]*\},\n/gm, '');
fs.writeFile(originalFile, data, 'utf8', () => {
console.log(`updateAndroidJson removed 'android.permission.WRITE_CONTACTS' in ${originalFile}`);
});
});
});
};
const updateAppBuildGradle = () => {
const originalFile = './platforms/android/app/build.gradle';
const saveOffFile = originalFile + '.previous'
console.log(`> Processing ${originalFile}`);
fs.rename(originalFile, saveOffFile, () => {
const rl = readline.createInterface({
input: fs.createReadStream(saveOffFile),
crlfDelay: Infinity,
});
const newGradle = [];
rl.on('line', (line) => {
if (line.includes('minSdkVersion cordovaConfig.MIN_SDK_VERSION')) {
newGradle.push(line.replace('cordovaConfig.MIN_SDK_VERSION', '16'));
console.log('hardcoding::: minSdkVersion ::: to 16 in android/app/build.gradle (Hack needed for cordova-android 10.1.1)');
} else if (line.includes('targetSdkVersion cordovaConfig.SDK_VERSION')) {
newGradle.push(line.replace('cordovaConfig.SDK_VERSION', '31'));
console.log('hardcoding::: targetSdkVersion ::: to 31 in android/app/build.gradle (Hack needed for cordova-android 10.1.1)');
} else if (line.includes('maxSdkVersion cordovaConfig.MAX_SDK_VERSION')) {
newGradle.push(line.replace('cordovaConfig.MAX_SDK_VERSION', '34'));
console.log('hardcoding::: maxSdkVersion ::: to 34 in android/app/build.gradle (Hack needed for cordova-android 10.1.1)');
} else if (line.includes('compileSdkVersion cordovaConfig.SDK_VERSION')) {
newGradle.push(line.replace('cordovaConfig.SDK_VERSION', '34'));
console.log('hardcoding::: compileSdkVersion ::: to 34 in android/app/build.gradle (Hack needed for cordova-android 10.1.1)');
} else if (line.includes('String gradlePluginGoogleServicesClassPath =')) {
newGradle.push(line.replace('${cordovaConfig.GRADLE_PLUGIN_GOOGLE_SERVICES_VERSION}', '4.3.8'));
console.log('hardcoding::: gradlePluginGoogleServicesClassPath ::: version 4.3.8 in android/app/build.gradle (Hack needed for cordova-android 10.1.1)');
} else if (line.includes('implementation "androidx.core:core')) {
// implementation "androidx.core:core:1.3.+"
newGradle.push(' implementation "androidx.core:core:1.6.0"');
console.log('updated ::: androidx.core:core ::: to version 1.6.0 in android/app/build.gradle');
} else {
newGradle.push(line);
}
});
rl.on('close', () => {
const buildGradle = fs.openSync(originalFile, 'w');
newGradle.forEach((txt) => {
fs.writeSync(buildGradle, `${txt}\n`);
});
console.log(`updateAppBuildGradle hardcoded android versions in ${originalFile}`);
});
});
};
function getVersionsFromConfigXML () {
const path = './config.xml';
const versions = {
version: 'error',
iosBundleVersion: 'error',
androidBundleVersion: 'error',
};
const data = fs.readFileSync(path, 'utf-8');
let regex = /version="(.*?)"/;
let found = data.match(regex);
if (found.length > 0) {
console.log('version from config.xml: ', found[1]);
versions.version = found[1];
} else {
console.log('version from config.xml: error');
}
regex = /ios-CFBundleVersion="(.*?)"/;
found = data.match(regex);
if (found.length > 0) {
console.log('ios-CFBundleVersion from config.xml: ', found[1]);
versions.iosBundleVersion = found[1];
} else {
console.log('ios-CFBundleVersion from config.xml: error');
}
regex = /android-versionCode="(.*?)"/;
found = data.match(regex);
if (found.length > 0) {
console.log('android-versionCode from config.xml: ', found[1]);
versions.androidBundleVersion = found[1];
} else {
console.log('android-versionCode from config.xml: error');
}
return versions;
}
const updateXcodeProj = () => {
const originalFile = './platforms/ios/We Vote.xcodeproj/project.pbxproj';
const saveOffFile = originalFile + '.previous'
console.log(`> Processing ${originalFile}`);
fs.rename(originalFile, saveOffFile, () => {
const rl = readline.createInterface({
input: fs.createReadStream(saveOffFile),
crlfDelay: Infinity,
});
const newProjectPbxproj = [];
let conf = 'Debug';
rl.on('line', (line) => {
if (line.includes('PRODUCT_NAME = "$(TARGET_NAME)";')) {
newProjectPbxproj.push(line);
newProjectPbxproj.push("\t\t\t\tSWIFT_VERSION = 4.2;");
console.log('hardcoding::: SWIFT_VERSION (' + conf + ')::: to 4.2 in We Vote.xcodeproj/project.pbxproj ');
conf = 'Release';
} else {
newProjectPbxproj.push(line);
}
});
rl.on('close', () => {
const buildXproj = fs.openSync(originalFile, 'w');
newProjectPbxproj.forEach((txt) => {
// console.log(txt);
fs.writeSync(buildXproj, `${txt}\n`);
});
console.log(`updateXcodeProj hardcoded iOS Swift version in ${originalFile}`);
});
});
};
const patchFacebookConnectPluginJava = () => {
const originalFile = './platforms/android/app/src/main/java/org/apache/cordova/facebook/ConnectPlugin.java';
const saveOffFile = originalFile + '.previous'
console.log(`> Processing ${originalFile}`);
fs.rename(originalFile, saveOffFile, () => {
const rl = readline.createInterface({
input: fs.createReadStream(saveOffFile),
crlfDelay: Infinity,
});
const newConnectPluginJava = [];
let conf = 'Debug';
rl.on('line', (line) => {
if (line.includes('AppEventsLogger.deactivateApp')) {
newConnectPluginJava.push("/\/\ " + line);
console.log('patching ConnectPluginJava ::: removing deprecated AppEventsLogger.deactivateApp. No longer needed, and not allowed.');
conf = 'Release';
} else {
newConnectPluginJava.push(line);
}
});
rl.on('close', () => {
const connectPluginJava = fs.openSync(originalFile, 'w');
newConnectPluginJava.forEach((txt) => {
// console.log(txt);
fs.writeSync(connectPluginJava, `${txt}\n`);
});
console.log(`patchFacebookConnectPluginJava commented out deprecated "deactivateApp" in ${originalFile}`);
});
});
};
// November 2024: This "cordova-plugin-contacts-x" library is read-only and deprecated, this patch is needed until a replacement is found
const updateContactsCaseStatementNov2024 = () => {
const originalFile = './platforms/ios/We Vote/Plugins/cordova-plugin-contacts-x/ContactsX.swift';
const saveOffFile = originalFile + '.previous'
console.log(`> Processing ${originalFile}`);
fs.rename(originalFile, saveOffFile, () => {
const rl = readline.createInterface({
input: fs.createReadStream(saveOffFile),
crlfDelay: Infinity,
});
const newContactsXswift = [];
let conf = 'Debug';
let oneMore = false
rl.on('line', (line) => {
if (oneMore) {
oneMore = false;
newContactsXswift.push(line);
if (!line.includes('Modified')) {
newContactsXswift.push(' default:');
newContactsXswift.push(' completionHandler(false)');
console.log('patched ::: ContactsX.swift hasPermission() for exhaustive switch');
}
} else if (line.startsWith(' completionHandler(false)')) {
if (!line.includes('Modified')) {
oneMore = true;
newContactsXswift.push(line + ' // Modified'); // So we only modify it once
} else {
newContactsXswift.push(line);
}
} else {
newContactsXswift.push(line);
// console.log(line);
}
});
rl.on('close', () => {
const contactsX = fs.openSync(originalFile, 'w');
newContactsXswift.forEach((txt) => {
// console.log(txt);
fs.writeSync(contactsX, `${txt}\n`);
});
console.log(`updateContactsCaseStatementNov2024 resolved non-exhaustive switch ${originalFile}`);
});
});
};
const updateXcodePlist = () => {
const originalFile = './platforms/ios/We Vote/We Vote-Info.plist';
const saveOffFile = originalFile + '.previous'
console.log(`> Processing ${originalFile}`);
fs.rename(originalFile, saveOffFile, () => {
const rl = readline.createInterface({
input: fs.createReadStream(saveOffFile),
crlfDelay: Infinity,
});
const newWeVoteInfoPlist = [];
let deleteNextLine = false;
rl.on('line', (line) => {
if (deleteNextLine) {
// Do not push the line, ie delete it
console.log('deleting::: "' + line.trim() + '" that followed the previous deleted line in We Vote/We Vote-Info.plist');
deleteNextLine = false;
} else if (line.includes('<key>NSMainNibFile</key>')) {
// Do not push the line, ie delete it
deleteNextLine = true;
console.log('deleting::: <key>NSMainNibFile</key> in We Vote/We Vote-Info.plist');
} else if (line.includes('<key>NSMainNibFile~ipad</key>')) {
// Do not push the line, ie delete it
deleteNextLine = true;
console.log('deleting::: <key>NSMainNibFile</key> in We Vote/We Vote-Info.plist');
} else if (line.includes('FACEBOOK_URL_SCHEME_SUFFIX_PLACEHOLDER</string>')) {
newWeVoteInfoPlist.push(line.replace('FACEBOOK_URL_SCHEME_SUFFIX_PLACEHOLDER</string>', 'suffix</string>'));
console.log('hardcoding ::: spurious FACEBOOK_URL_SCHEME_SUFFIX_PLACEHOLDER from cordova-plugin-fbsdk ::: targetSdkVersion ::: to "suffix" in We Vote/We Vote-Info.plist');
} else if (line.includes('OTHER_APP_SCHEMES_PLACEHOLDER</string>')) {
newWeVoteInfoPlist.push(line.replace('OTHER_APP_SCHEMES_PLACEHOLDER</string>', 'other-app-schemes-placeholder</string>'));
console.log('hardcoding ::: spurious OTHER_APP_SCHEMES_PLACEHOLDER from cordova-plugin-fbsdk ::: targetSdkVersion ::: to "other-app-schemes-placeholder" in We Vote/We Vote-Info.plist');
} else {
newWeVoteInfoPlist.push(line);
}
});
rl.on('close', () => {
const buildXproj = fs.openSync(originalFile, 'w');
newWeVoteInfoPlist.forEach((txt) => {
// console.log(txt);
fs.writeSync(buildXproj, `${txt}\n`);
});
console.log(`updateXcodePlist updated ${originalFile}`);
});
});
};
const updateCordovaLibBuildGradle = () => {
const originalFile = './platforms/android/CordovaLib/build.gradle';
const saveOffFile = originalFile + '.previous'
console.log(`> Processing ${originalFile}`);
fs.rename(originalFile, saveOffFile, () => {
const rl = readline.createInterface({
input: fs.createReadStream(saveOffFile),
crlfDelay: Infinity,
});
const newGradle = [];
rl.on('line', (line) => {
if (line.includes('assets.srcDirs =')) {
newGradle.push(line);
newGradle.push(' namespace = \'org.wevote.cordova\'');
console.log('adding::: namespace = "org.wevote.cordova" ::: to android/CordovaLib/build.gradle');
} else {
newGradle.push(line);
}
});
rl.on('close', () => {
const buildGradle = fs.openSync(originalFile, 'w');
newGradle.forEach((txt) => {
fs.writeSync(buildGradle, `${txt}\n`);
});
console.log(`updateAndroidBuildGradle added a namespace in ${originalFile}`);
});
});
}
const updateBuildReleaseXCConfig = () => {
const originalFile = './platforms/ios/cordova/build-release.xcconfig';
const saveOffFile = originalFile + '.previous'
console.log(`> Processing ${originalFile}`);
fs.rename(originalFile, saveOffFile, () => {
const rl = readline.createInterface({
input: fs.createReadStream(saveOffFile),
crlfDelay: Infinity,
});
const newBuildReleaseXcconfig = [];
rl.on('line', (line) => {
if (line.includes('iPhone Distribution')) {
newBuildReleaseXcconfig.push(line.replace('iPhone Distribution', 'Apple Development'));
console.log('updated ::: "iPhone Distribution" to "Apple Development" in in ios/cordova/build-release.xcconfig');
} else {
newBuildReleaseXcconfig.push(line);
}
});
rl.on('close', () => {
const buildXcconfig = fs.openSync(originalFile, 'w');
newBuildReleaseXcconfig.forEach((txt) => {
// console.log(txt);
fs.writeSync(buildXcconfig, `${txt}\n`);
});
console.log(`updateBuildReleaseXCConfig updated ${originalFile}`);
});
});
};
const updatePodfile = () => {
const originalFile = './platforms/ios/Podfile';
const saveOffFile = originalFile + '.previous'
console.log(`> Processing ${originalFile}`);
fs.rename(originalFile, saveOffFile, () => {
const rl = readline.createInterface({
input: fs.createReadStream(saveOffFile),
crlfDelay: Infinity,
});
const newBuildReleaseXcconfig = [];
rl.on('line', (line) => {
if (line.includes('platform :ios')) {
newBuildReleaseXcconfig.push(line.replace('11.0', '15.0'));
console.log('updated ::: platform : ios 11.0 to 15.0 in ios/Podfile');
} else {
newBuildReleaseXcconfig.push(line);
}
});
rl.on('close', () => {
const buildXcconfig = fs.openSync(originalFile, 'w');
newBuildReleaseXcconfig.forEach((txt) => {
// console.log(txt);
fs.writeSync(buildXcconfig, `${txt}\n`);
});
console.log(`updatePodfile updated ${originalFile}`);
});
});
};
const removeSymLink = (path) => {
try {
rimrafSync(path);
console.log('rmdir: ' + path);
} catch (e) {
console.log('rimrafSync error ' + e);
}
}
const copyGoogleServices = () => {
const originalFile = './res/google/google-services.json';
const destinationFile = './platforms/android/app/google-services.json';
if (fs.existsSync(destinationFile)) {
console.log('google-services.json is good to go');
} else {
fs.copyFile(originalFile, destinationFile, fs.constants.COPYFILE_EXCL, (err) => {
if (err) {
console.log("Copy file error Found:", err);
} else {
console.log('Created file: ', destinationFile);
}
});
}
}
const copyJQueryFile = () => {
const originalFile = path.join(__dirname, 'www/jquery-3.7.1.min.js');
const iosFile = path.join(__dirname, 'platforms/ios/www/jquery-3.7.1.min.js');
const androidFile = path.join(__dirname, 'platforms/android/app/src/main/assets/www/jquery-3.7.1.min.js');
if (fs.existsSync(iosFile)) {
console.log('iOS jQuery in www dir is good go');
} else {
fs.copyFile(originalFile, iosFile, fs.constants.COPYFILE_EXCL, (err) => {
if (err) {
console.log("Copy file error for jQuery to iOS dir. Found:", err);
} else {
console.log('Created file: ', iosFile);
}
});
}
if (fs.existsSync(androidFile)) {
console.log('Android jQuery in www dir is good go');
} else {
fs.copyFile(originalFile, androidFile, fs.constants.COPYFILE_EXCL, (err) => {
if (err) {
console.log("Copy file error for jQuery to Android dir. Found:", err);
} else {
console.log('Created file: ', iosFile);
}
});
}
}
/* Sept 21, 2023
stevepodell@Steves-MBP-M1-Dec2021 WeVoteCordova % find . -type f -name "*.xcconfig"
To fix this temporarily until CocoaPods is updated, you can replace DT_TOOLCHAIN_DIR with TOOLCHAIN_DIR in the Firebase related files with the .xcconfig extension, this worked for me
*/
/*************************************************************************************************
* The following code is run inline when this script is loaded
*************************************************************************************************/
{
const myArgs = process.argv.slice(2);
if ((myArgs.length === 0) || ((!myArgs[0].includes('/build')))) {
console.log('Need to supply a path to the WebApp build directory! For example:');
console.log(' node buildSymLinks /Users/stevepodell/WebstormProjects/WebApp/build/');
process.exit();
}
let webAppPath = myArgs[0];
if (webAppPath.endsWith('build')) {
webAppPath += '/';
}
let buildAll = true;
let bundleOnlyArg = myArgs[1] || '';
if (bundleOnlyArg === 'bundleOnly') {
buildAll = false;
}
console.log('--------------------- buildAll ', buildAll);
console.log('__dirname', __dirname);
if (!__dirname.endsWith('/WeVoteCordova')) {
console.log('buildSymLinks must be run from the weVoteCordova directory');
process.exit();
}
const {symlink} = fs;
const iosDir = path.join(__dirname, 'platforms/ios/www/');
const androidDir = path.join(__dirname, 'platforms/android/app/src/main/assets/www/');
if (buildAll) {
removeSymLink(androidDir + 'css');
removeSymLink(iosDir + 'css');
removeSymLink(androidDir + 'img');
removeSymLink(iosDir + 'img');
removeSymLink(androidDir + 'index.html');
removeSymLink(iosDir + 'index.html');
}
removeSymLink(androidDir + 'bundle.js');
removeSymLink(androidDir + 'bundle.js.map');
removeSymLink(iosDir + 'bundle.js');
removeSymLink(iosDir + 'bundle.js.map');
symlink(webAppPath + 'bundle.js', androidDir + 'bundle.js', 'file', err => console.log(err ? err : 'ln android bundle.js successful'));
symlink(webAppPath + 'bundle.js', iosDir + 'bundle.js', 'file', err => console.log(err ? err : 'ln ios bundle.js successful'));
symlink(webAppPath + 'bundle.js.map', androidDir + 'bundle.js.map', 'file', err => console.log(err ? err : 'ln android bundle.js.map successful'));
symlink(webAppPath + 'bundle.js.map', iosDir + 'bundle.js.map', 'file', err => console.log(err ? err : 'ln ios bundle.js.map successful'));
if (buildAll) {
symlink(webAppPath + 'css', androidDir + 'css', 'dir', err => console.log(err ? err : 'ln android css successful'));
symlink(webAppPath + 'css', iosDir + 'css', 'dir', err => console.log(err ? err : 'ln ios css successful'));
symlink(webAppPath + 'img', androidDir + 'img', 'dir', err => console.log(err ? err : 'ln android img successful'));
symlink(webAppPath + 'img', iosDir + 'img', 'dir', err => console.log(err ? err : 'ln ios img successful'));
symlink(__dirname + '/www/index.html', androidDir + 'index.html', 'file', err => console.log(err ? err : 'ln android index.html successful'));
symlink(__dirname + '/www/index.html', iosDir + 'index.html', 'file', err => console.log(err ? err : 'ln ios index.html successful'));
updateXcodePlist();
updatePodfile();
updateBuildReleaseXCConfig()
updateMainAndroidManifest();
updateAndroidJson();
copyGoogleServices();
copyJQueryFile();
writeCordovaLibGradleWrapperProperties();
updateCordovaLibBuildGradle();
updateXcodeProj();
updateContactsCaseStatementNov2024();
// patchFacebookConnectPluginJava();
fs.readdir(iosDir, function (err, items) {
console.log(JSON.stringify(items));
});
}
}
// // /Users/stevepodell/WebstormProjects/WeVoteCordova/platforms/android/CordovaLib/build.gradle
// const updateCordovaLibBuildGradle = () => {
// const originalFile = './platforms/android/CordovaLib/build.gradle';
// const saveOffFile = originalFile + '.previous'
// console.log(`> Processing ${originalFile}`);
// fs.rename(originalFile, saveOffFile, () => {
// const rl = readline.createInterface({
// input: fs.createReadStream(saveOffFile),
// crlfDelay: Infinity,
// });
// const newGradle = [];
// rl.on('line', (line) => {
// if (line.includes('compileSdkVersion cordovaConfig.SDK_VERSION')) {
// newGradle.push(line.replace('cordovaConfig.SDK_VERSION', '31'));
// console.log('hardcoding::: compileSdkVersion ::: to 31 in CordovaLib/src/build.gradle (Hack needed for cordova-android 10.1.1)');
// } else if (line.includes('minSdkVersion cordovaConfig.MIN_SDK_VERSION')) {
// newGradle.push(line.replace('cordovaConfig.MIN_SDK_VERSION', '16'));
// console.log('hardcoding::: minSdkVersion ::: to 16 CordovaLib/src/build.gradle (Hack needed for cordova-android 10.1.1)');
// } else {
// newGradle.push(line);
// }
// });
// rl.on('close', () => {
// const buildGradle = fs.openSync(originalFile, 'w');
//
// newGradle.forEach((txt) => {
// fs.writeSync(buildGradle, `${txt}\n`);
// });
// });
// });
// };
// /Users/stevepodell/WebstormProjects/WeVoteCordova/platforms/android/cdv-gradle-config.json
// This should be solved in an upcoming version of cordova-android with <preference name="GradleVersion" value="7.2.2" /> -- Still not there Aug 2023
// Obsolete Aug 2023: MIN_SDK_VERSION is now a preference ... "android-minSdkVersion" and AGP_VERSION is now "7.4.2" when we get here
// const updateCdvGradleConfig = () => {
// const originalFile = './platforms/android/cdv-gradle-config.json';
// const saveOffFile = originalFile + '.previous'
// console.log(`> Processing ${originalFile}`);
// fs.rename(originalFile, saveOffFile, () => {
// const rl = readline.createInterface({
// input: fs.createReadStream(saveOffFile),
// crlfDelay: Infinity,
// });
// const newGradle = [];
// rl.on('line', (line) => {
// if (line.includes('AGP_VERSION')) {
// newGradle.push(' "AGP_VERSION": "7.2.2",');
// console.log('hardcoding::: AGP_VERSION ::: to 7.2.2 in android/cdv-gradle-config.json');
// } else if (line.includes('MIN_SDK_VERSION')) {
// newGradle.push(' "MIN_SDK_VERSION": 16,');
// console.log('hardcoding::: MIN_SDK_VERSION ::: to 16 in android/cdv-gradle-config.json');
// } else {
// newGradle.push(line);
// }
// });
// rl.on('close', () => {
// const buildGradle = fs.openSync(originalFile, 'w');
//
// newGradle.forEach((txt) => {
// fs.writeSync(buildGradle, `${txt}\n`);
// });
// });
// });
// };
// November 18, 2021: This has some code for cordova-android 9.1 (Which we need to use today) and cordova-android 10 (which was not ready for prime time)
// August 2023: No longer needed, these changes are already in the file when we get here
// const updateGradleProperties = () => {
// const originalFile = './platforms/android/gradle.properties';
// const saveOffFile = originalFile + '.previous'
// console.log(`> Processing ${originalFile}`);
// fs.rename(originalFile, saveOffFile, () => {
// const rl = readline.createInterface({
// input: fs.createReadStream(saveOffFile),
// crlfDelay: Infinity,
// });
// const newGradle = [];
// rl.on('line', (line) => {
// if (line.startsWith('android.useAndroidX')) {
// console.log('adding::: android.useAndroidX=true ::: in android/gradle.properties');
// newGradle.push('android.useAndroidX=true');
// } else if (line.startsWith('android.enableJetifier')) {
// console.log('adding::: android.enableJetifier=true ::: in android/gradle.properties');
// newGradle.push('android.enableJetifier=true');
// } else if (line.startsWith('cdvMinSdkVersion=')) {
// cdvMinSdkVersion=15
// console.log('updating::: cdvMinSdkVersion ::: to16 in android/gradle.properties');
// newGradle.push('cdvMinSdkVersion=16');
// } else {
// newGradle.push(line);
// }
// });
// rl.on('close', () => {
// const gradleProperties = fs.openSync(originalFile, 'w');
//
// newGradle.forEach((txt) => {
// fs.writeSync(gradleProperties, `${txt}\n`);
// });
// console.log(`updateGradleProperties changed settings in ${originalFile}`);
// updateAndroidBuildGradle();
//
// });
// });
// };
// const updateAndroidBuildGradle = () => {
// const originalFile = './platforms/android/build.gradle';
// const saveOffFile = originalFile + '.previous'
// console.log(`> Processing ${originalFile}`);
// fs.rename(originalFile, saveOffFile, () => {
// const rl = readline.createInterface({
// input: fs.createReadStream(saveOffFile),
// crlfDelay: Infinity,
// });
// const newGradle = [];
// rl.on('line', (line) => {
// if (line.startsWith(' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin')) {
// newGradle.push(line);
// console.log('adding::: classpath \'com.google.gms:google-services:4.3.10\' ::: to android/build.gradle');
// newGradle.push(' classpath \'com.google.gms:google-services:4.3.10\'');
// } else if (line.includes('project.ext')) {
// newGradle.push(line);
// console.log('adding::: androidXCore = "1.6.0" ::: (force a downgrade from 1.7.0) to android/build.gradle'); // https://stackoverflow.com/questions/69021225/resource-linking-fails-on-lstar#answer-69024140
// newGradle.push(' androidXCore = "1.6.0"');
// } else if (line.includes('defaultCompileSdkVersion=')) {
// console.log('changing ::: defaultCompileSdkVersion from 29 ::: to 31 to android/build.gradle');
// newGradle.push(line.replace('=29', '=31'));
// } else {
// newGradle.push(line);
// }
// });
// rl.on('close', () => {
// const buildGradle = fs.openSync(originalFile, 'w');
//
// newGradle.forEach((txt) => {
// fs.writeSync(buildGradle, `${txt}\n`);
// });
// console.log(`updateAndroidBuildGradle added a classpath in ${originalFile}`);
// });
// });
// };