-
Notifications
You must be signed in to change notification settings - Fork 62
/
coho
executable file
·2080 lines (1907 loc) · 73.7 KB
/
coho
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
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env node
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
var fs = require('fs');
var path = require('path');
try {
var optimist = require('optimist');
var shjs = require('shelljs');
var request = require('request');
} catch (e) {
console.log('Please run "npm install" from this directory:\n\t' + __dirname);
process.exit(2);
}
var origWorkingDir = process.cwd();
var COMMON_RAT_EXCLUDES = [
'*.wav',
'*.webloc',
'*jasmine-1.2.0*',
'*.xcodeproj',
'.*',
'*-Info.plist',
'VERSION',
'node_modules',
'thirdparty',
'package.json',
];
var platformRepos = [
{
title: 'Android',
id: 'android',
repoName: 'cordova-android',
jiraComponentName: 'Android',
cordovaJsPaths: ['framework/assets/www/cordova.js'],
ratExcludes: [
'*.properties',
'bin',
'gen',
'proguard-project.txt'
]
}, {
title: 'iOS',
id: 'ios',
repoName: 'cordova-ios',
jiraComponentName: 'iOS',
cordovaJsPaths: ['CordovaLib/cordova.js'],
versionFilePaths: [path.join('CordovaLib', 'VERSION')]
}, {
title: 'BlackBerry',
id: 'blackberry',
repoName: 'cordova-blackberry',
jiraComponentName: 'BlackBerry',
cordovaJsSrcName: 'cordova.blackberry10.js',
cordovaJsPaths: [
path.join('blackberry10', 'javascript', 'cordova.blackberry10.js')
],
versionFilePaths: [
path.join('blackberry10', 'VERSION'),
]
}, {
title: 'Windows',
id: 'windows',
repoName: 'cordova-windows',
jiraComponentName: 'Windows 8',
cordovaJsSrcName: 'cordova.windows8.js',
cordovaJsPaths: ['windows8/cordova.js', 'windows8/template/www/cordova.js'],
versionFilePaths: [path.join('windows8', 'VERSION'), path.join('windows8', 'template', 'VERSION')]
}, {
title: 'Windows Phone 7 & 8',
id: 'wp8',
repoName: 'cordova-wp8',
jiraComponentName: 'WP8',
cordovaJsSrcName: 'cordova.windowsphone.js',
cordovaJsPaths: ['common/www/cordova.js']
}, {
title: 'Firefox OS',
id: 'firefoxos',
repoName: 'cordova-firefoxos',
jiraComponentName: 'FirefoxOS',
cordovaJsSrcName: 'cordova.firefoxos.js',
cordovaJsPaths: ['cordova-lib/cordova.js']
}, {
title: 'Mac OSX',
id: 'osx',
repoName: 'cordova-osx',
jiraComponentName: 'OSX',
cordovaJsPaths: ['CordovaFramework/cordova.js'],
inactive: true
}, {
title: 'Ubuntu',
id: 'ubuntu',
repoName: 'cordova-ubuntu',
jiraComponentName: 'Ubuntu',
cordovaJsPaths: ['www/cordova.js']
}, {
title: 'Amazon Fire OS',
id: 'amazon-fireos',
repoName: 'cordova-amazon-fireos',
jiraComponentName: 'Amazon FireOS',
cordovaJsPaths: ['framework/assets/www/cordova.js'],
ratExcludes: [
'*.properties',
'bin',
'gen',
'proguard-project.txt'
]
}, {
title: 'Bada',
id: 'bada',
repoName: 'cordova-bada',
jiraComponentName: 'Bada',
inactive: true
}, {
title: 'Bada WAC',
id: 'bada-wac',
repoName: 'cordova-bada-wac',
jiraComponentName: 'Bada',
inactive: true
}, {
title: 'WebOS',
id: 'webos',
repoName: 'cordova-webos',
jiraComponentName: 'webOS',
inactive: true
}, {
title: 'QT',
id: 'qt',
repoName: 'cordova-qt',
jiraComponentName: 'Qt',
inactive: true
}, {
title: 'Tizen',
id: 'tizen',
repoName: 'cordova-tizen',
jiraComponentName: 'Tizen',
inactive: true
}
];
var nonPlatformRepos = [
{
title: 'Docs',
id: 'docs',
repoName: 'cordova-docs',
jiraComponentName: 'Docs'
}, {
title: 'MobileSpec',
id: 'mobile-spec',
repoName: 'cordova-mobile-spec',
jiraComponentName: 'mobile-spec',
ratExcludes: [
'jasmine.*',
'html',
'uubench.js',
]
}, {
title: 'Cordova JS',
id: 'js',
repoName: 'cordova-js',
jiraComponentName: 'CordovaJS'
}, {
title: 'Hello World App',
id: 'app-hello-world',
repoName: 'cordova-app-hello-world',
jiraComponentName: 'App Hello World'
}
];
var pluginRepos = [
{
title: 'Plugin - Battery Status',
id: 'plugin-battery-status',
repoName: 'cordova-plugin-battery-status',
jiraComponentName: 'Plugin Battery Status',
inactive: true
}, {
title: 'Plugin - Camera',
id: 'plugin-camera',
repoName: 'cordova-plugin-camera',
jiraComponentName: 'Plugin Camera',
inactive: true
}, {
title: 'Plugin - Console',
id: 'plugin-console',
repoName: 'cordova-plugin-console',
jiraComponentName: 'Plugin Console',
inactive: true
}, {
title: 'Plugin - Contacts',
id: 'plugin-contacts',
repoName: 'cordova-plugin-contacts',
jiraComponentName: 'Plugin Contacts',
inactive: true
}, {
title: 'Plugin - Device Motion',
id: 'plugin-device-motion',
repoName: 'cordova-plugin-device-motion',
jiraComponentName: 'Plugin Device Motion',
inactive: true
}, {
title: 'Plugin - Device Orientation',
id: 'plugin-device-orientation',
repoName: 'cordova-plugin-device-orientation',
jiraComponentName: 'Plugin Device Orientation',
inactive: true
}, {
title: 'Plugin - Device',
id: 'plugin-device',
repoName: 'cordova-plugin-device',
jiraComponentName: 'Plugin Device',
inactive: true
}, {
title: 'Plugin - Dialogs',
id: 'plugin-dialogs',
repoName: 'cordova-plugin-dialogs',
jiraComponentName: 'Plugin Dialogs',
inactive: true
}, {
title: 'Plugin - File Transfer',
id: 'plugin-file-transfer',
repoName: 'cordova-plugin-file-transfer',
jiraComponentName: 'Plugin File Transfer',
inactive: true
}, {
title: 'Plugin - File',
id: 'plugin-file',
repoName: 'cordova-plugin-file',
jiraComponentName: 'Plugin File',
inactive: true
}, {
title: 'Plugin - Geolocation',
id: 'plugin-geolocation',
repoName: 'cordova-plugin-geolocation',
jiraComponentName: 'Plugin Geolocation',
inactive: true
}, {
title: 'Plugin - Globalization',
id: 'plugin-globalization',
repoName: 'cordova-plugin-globalization',
jiraComponentName: 'Plugin Globalization',
inactive: true
}, {
title: 'Plugin - InAppBrowser',
id: 'plugin-inappbrowser',
repoName: 'cordova-plugin-inappbrowser',
jiraComponentName: 'Plugin InAppBrowser',
inactive: true
}, {
title: 'Plugin - Media',
id: 'plugin-media',
repoName: 'cordova-plugin-media',
jiraComponentName: 'Plugin Media',
inactive: true
}, {
title: 'Plugin - Media Capture',
id: 'plugin-media-capture',
repoName: 'cordova-plugin-media-capture',
jiraComponentName: 'Plugin Media Capture',
inactive: true
}, {
title: 'Plugin - Network Information',
id: 'plugin-network-information',
repoName: 'cordova-plugin-network-information',
jiraComponentName: 'Plugin Network Information',
inactive: true
}, {
title: 'Plugin - Splash Screen',
id: 'plugin-splashscreen',
repoName: 'cordova-plugin-splashscreen',
jiraComponentName: 'Plugin SplashScreen',
inactive: true
}, {
title: 'Plugin - Vibration',
id: 'plugin-vibration',
repoName: 'cordova-plugin-vibration',
jiraComponentName: 'Plugin Vibration',
inactive: true
}/*, {
title: 'Plugins - Other',
id: 'cordova-plugins',
repoName: 'cordova-plugins',
jiraComponentName: 'Plugins',
inactive: true
}*/
];
var otherRepos = [
{
title: 'Cordova CLI',
id: 'cli',
repoName: 'cordova-cli',
jiraComponentName: 'CLI',
inactive: true
}, {
title: 'Cordova Plugman',
id: 'plugman',
repoName: 'cordova-plugman',
jiraComponentName: 'Plugman',
inactive: true
}, {
title: 'Cordova Medic',
id: 'medic',
repoName: 'cordova-medic',
inactive: true
}, {
title: 'Cordova App Harness',
id: 'app-harness',
repoName: 'cordova-app-harness',
inactive: true,
jiraComponentName: 'AppHarness'
}, {
title: 'Cordova Coho',
id: 'coho',
repoName: 'cordova-coho',
jiraComponentName: 'Coho',
inactive: true
}, {
title: 'Apache dist/release/cordova',
id: 'dist',
repoName: 'cordova-dist',
inactive: true,
svn: 'https://dist.apache.org/repos/dist/release/cordova'
}, {
title: 'Apache dist/dev/cordova',
id: 'dist/dev',
repoName: 'cordova-dist-dev',
inactive: true,
svn: 'https://dist.apache.org/repos/dist/dev/cordova'
}, {
title: 'Cordova Website',
id: 'website',
repoName: 'cordova-website',
inactive: true,
svn: 'https://svn.apache.org/repos/asf/cordova/site'
}
];
var allRepos = platformRepos.concat(nonPlatformRepos).concat(pluginRepos).concat(otherRepos);
var repoGroups = {
'all': allRepos,
'auto': computeExistingRepos(),
'platform': platformRepos,
'plugins': pluginRepos,
'active-platform': platformRepos.filter(function(r) { return !r.inactive }),
'release-repos': allRepos.filter(function(r) { return !r.inactive })
};
repoGroups['cadence'] = repoGroups['active-platform'].concat([getRepoById('cli'), getRepoById('js'), getRepoById('mobile-spec'), getRepoById('app-hello-world'), getRepoById('docs')]);
var gitCommitCount = 0;
var JIRA_API_URL = "https://issues.apache.org/jira/rest/api/latest/";
var JIRA_PROJECT_KEY = "CB";
var GITHUB_API_URL = "https://api.github.com/";
var GITHUB_ORGANIZATION = "apache";
function reportGitPushResult(repos, branches) {
print('');
if (gitCommitCount) {
var flagsStr = repos.map(function(r) { return '-r ' + r.id; }).join(' ') + ' ' + branches.map(function(b) { return '-b ' + b; }).join(' ');
print('All work complete. ' + gitCommitCount + ' commits were made locally.');
print('To review changes:');
print(' ' + process.argv[1] + ' repo-status ' + flagsStr + ' | less');
print('To push changes:');
print(' ' + process.argv[1] + ' repo-push ' + flagsStr);
print('To revert all local commits:');
print(' ' + process.argv[1] + ' repo-reset ' + flagsStr);
} else {
print('All work complete. No commits were made.');
}
}
function print() {
var newArgs = Array.prototype.slice.call(arguments);
// Prefix any prints() to distinguish them from command output.
if (newArgs.length > 1 || newArgs[0]) {
var curDir = path.relative(origWorkingDir, process.cwd());
var prefix = curDir ? './' + curDir + '/ =' : './ =';
var PREFIX_LEN = 30;
if (prefix.length < PREFIX_LEN) {
prefix += new Array(PREFIX_LEN - prefix.length + 1).join('=');
}
newArgs.unshift(prefix);
newArgs = newArgs.map(function(val) { return val.replace(/\n/g, '\n' + prefix + ' ') });
}
console.log.apply(console, newArgs);
}
function fatal() {
console.error.apply(console, arguments);
process.exit(1);
}
function createPlatformDevVersion(version) {
// e.g. "3.1.0" -> "3.2.0-dev".
// e.g. "3.1.2-0.8.0-rc2" -> "3.2.0-0.8.0-dev".
version = version.replace(/-rc.*$/, '');
var parts = version.split('.');
parts[1] = String(+parts[1] + 1);
var cliSafeParts = parts[2].split('-');
cliSafeParts[0] = '0';
parts[2] = cliSafeParts.join('-');
return parts.join('.') + '-dev';
}
function getVersionBranchName(version) {
if (/-dev$/.test(version)) {
return 'master';
}
return version.replace(/\d+(-?rc\d)?$/, 'x');
}
function validateVersionString(version, opt_allowNonSemver) {
var pattern = opt_allowNonSemver ? /^\d+\.\d+\.\d+(-?rc\d)?$/ : /^\d+\.\d+\.\d+(-rc\d)?$/;
if (!pattern.test(version)) {
fatal('Versions must be in the form #.#.#-[rc#]');
}
return version;
}
function registerRepoFlag(opt) {
return opt.options('r', {
alias: 'repo',
desc: 'Which repos to operate on. Multiple flags allowed. This can be repo IDs or repo groups. Use the list-repos command see valid values.',
default: 'auto'
});
}
function registerHelpFlag(opt) {
return opt.options('h', {
alias: 'help',
desc: 'Shows help information.'
});
}
function execHelper(cmd, silent, allowError) {
// Don't allow failure if being silent.
allowError = allowError || silent;
if (/^git commit/.exec(cmd)) {
gitCommitCount++;
}
if (!silent) {
print('Executing:', cmd);
}
// silent==2 is used only when modifying ulimit and re-exec'ing,
// so don't be silent but allow whatever to happen.
var result = shjs.exec(cmd, {silent: (silent && silent !== 2)});
if (result.code) {
if (allowError) {
return null;
}
process.exit(2);
}
return result.output.trim();
}
function cpAndLog(src, dest) {
print('Coping File:', src, '->', dest);
// Throws upon failure.
shjs.cp('-f', src, dest);
if (shjs.error()) {
fatal('Copy failed.');
}
}
function gitCheckout(branchName) {
var curBranch = retrieveCurrentBranchName(true);
if (curBranch != branchName) {
execHelper('git checkout -q ' + branchName);
}
}
var isInForEachRepoFunction = false;
function forEachRepo(repos, func) {
repos.forEach(function(repo) {
var origPath = isInForEachRepoFunction ? process.cwd() : '..';
var newPath = isInForEachRepoFunction ? path.join('..', repo.repoName) : repo.repoName;
isInForEachRepoFunction = true;
shjs.cd(newPath);
if (shjs.error()) {
fatal('Repo directory does not exist: ' + repo.repoName + '. First run coho repo-clone.');
}
func(repo);
shjs.cd(origPath);
isInForEachRepoFunction = origPath != '..';
});
}
function getRepoById(id, opt_repos) {
// Strip cordova- prefix if it exists.
id = id.replace(/^cordova-/, '');
var repos = opt_repos || allRepos;
for (var i = 0; i < repos.length; ++i) {
if (repos[i].id == id) {
return repos[i];
}
}
return null;
}
function createRepoUrl(repo) {
return 'https://git-wip-us.apache.org/repos/asf/' + repo.repoName + '.git';
}
function createArchiveCommand(argv) {
var opt = registerRepoFlag(optimist)
opt = opt
.options('tag', {
desc: 'The pre-existing tag to archive (defaults to newest tag on branch)'
})
.options('sign', {
desc: 'Whether to create .asc, .md5, .sha files',
default: true
})
.options('dest', {
desc: 'The directory to hold the resulting files.',
demand: true
});
opt = registerHelpFlag(opt);
var argv = opt
.usage('Creates a .zip, .asc, .md5, .sha for a repo at a tag.\n' +
'Refer to https://wiki.apache.org/cordova/SetUpGpg for how to set up gpg\n' +
'\n' +
'Usage: $0 create-archive -r plugman -r cli --dest cordova-dist-dev/CB-1111')
.argv;
if (argv.h) {
optimist.showHelp();
process.exit(1);
}
var repos = computeReposFromFlag(argv.r);
if (!shjs.which('gpg')) {
fatal('gpg command not found on your PATH. Refer to https://wiki.apache.org/cordova/SetUpGpg');
}
var outDir = argv.dest;
shjs.mkdir('-p', outDir);
var absOutDir = path.resolve(outDir);
forEachRepo(repos, function(repo) {
var tag = argv.tag || findMostRecentTag();
print('Creating archive of ' + repo.repoName + '@' + tag);
var outPath = path.join(absOutDir, repo.repoName + '-' + tag + '.zip');
execHelper('git archive --format zip -o "' + outPath + '" ' + tag);
if (argv.sign) {
execHelper('gpg --armor --detach-sig --output "' + outPath + '.asc" "' + outPath + '"');
fs.writeFileSync(outPath + '.md5', computeHash(outPath, 'MD5'));
fs.writeFileSync(outPath + '.sha', computeHash(outPath, 'SHA512'));
}
});
print();
print('Archives created.');
print('Verify them using: coho verify-archive ' + path.join(outDir, '*.zip'));
}
function computeHash(path, algo) {
print('Computing ' + algo + ' for: ' + path);
var result = execHelper('gpg --print-md ' + algo + ' "' + path + '"', true);
return extractHashFromOutput(result);
}
function extractHashFromOutput(output) {
return output.replace(/.*?:/, '').replace(/\s*/g, '').toLowerCase();
}
function verifyArchiveCommand(argv) {
var opt = registerRepoFlag(optimist)
opt = registerHelpFlag(opt);
var argv = opt
.usage('Ensures the given .zip files match their neighbouring .asc, .md5, .sha files.\n' +
'Refer to https://wiki.apache.org/cordova/SetUpGpg for how to set up gpg\n' +
'\n' +
'Usage: $0 verify-archive a.zip b.zip c.zip')
.argv;
var zipPaths = argv._.slice(1);
if (argv.h || !zipPaths.length) {
optimist.showHelp();
process.exit(1);
}
if (!shjs.which('gpg')) {
fatal('gpg command not found on your PATH. Refer to https://wiki.apache.org/cordova/SetUpGpg');
}
zipPaths.forEach(function(zipPath) {
execHelper('gpg --verify "' + zipPath + '.asc" "' + zipPath + '"');
var md5 = computeHash(zipPath, 'MD5');
if (extractHashFromOutput(fs.readFileSync(zipPath + '.md5', 'utf8')) !== md5) {
fatal('MD5 does not match.');
}
var sha = computeHash(zipPath, 'SHA512');
if (extractHashFromOutput(fs.readFileSync(zipPath + '.sha', 'utf8')) !== sha) {
fatal('SHA512 does not match.');
}
print(zipPath + ' signature and hashes verified.');
});
}
function printTagsCommand(argv) {
var opt = registerRepoFlag(optimist)
opt = registerHelpFlag(opt);
var argv = opt
.usage('Prints out tags & hashes for the given repos. Used in VOTE emails.\n' +
'\n' +
'Usage: $0 print-tags -r plugman -r cli')
.argv;
if (argv.h) {
optimist.showHelp();
process.exit(1);
}
var repos = computeReposFromFlag(argv.r);
forEachRepo(repos, function(repo) {
var tag = findMostRecentTag();
var ref = execHelper('git show-ref ' + tag, true);
console.log(' ' + repo.repoName + ': ' + tag.replace(/^r/, '') + ' (' + ref.slice(0, 10) + ')');
});
}
function createReleaseCommand(argv) {
var opt = registerRepoFlag(optimist)
opt = opt
.options('new-version', {
desc: 'The version to release. E.g. 2.7.1-rc2',
demand: true
})
.options('prev-version', {
desc: 'The previous release version (used to create changelog)',
demand: true
})
.options('update', {
type: 'boolean',
desc: 'Use --no-update to skip the "git fetch" step.',
default: true
})
.options('sign', {
type: 'boolean',
desc: 'Use --no-sign to skip the final zip+pgp signing step.',
default: true
});
opt = registerHelpFlag(opt);
var argv = opt
.usage('Clones all necessary repositories, and then stages the release.\n' +
'This involves:\n' +
' Cloning all repositories that are not already cloned.\n' +
' Updating all of them via git fetch\n' +
' Zipping them up\n' +
' Adding in extra release files\n' +
' Zipping up all files + zips into a master zip\n' +
' Signing the master zip via pgp\n' +
'\n' +
'Usage: $0 create-release-snapshot')
.argv;
if (argv.h) {
optimist.showHelp();
process.exit(1);
}
var repos = computeReposFromFlag(argv.r);
console.log(repos);
var prevVersion = validateVersionString(argv['prev-version'], true);
var newVersion = validateVersionString(argv['new-version']);
// Ensure we can find the path to the coho repo.
var scriptPath = path.dirname(process.argv[1]);
var keysPath = path.join(scriptPath, 'KEYS');
var binPath = path.join(scriptPath, 'bin');
if (!shjs.test('-f', keysPath)) {
fatal('Expected path to exist: ' + keysPath);
}
if (!shjs.test('-d', binPath)) {
fatal('Expected path to exist: ' + binPath);
}
cloneRepos(repos,false);
if (argv.update) {
// No need to update branches, just do a git fetch --tags.
updateRepos(repos, [], false);
}
// Check that the version tags exist.
forEachRepo(repos, function(repo) {
if (!tagExists(prevVersion)) {
fatal('Tag "' + prevVersion + '" does not exist in repo ' + repo.repoName);
}
if (!tagExists(newVersion)) {
fatal('Tag "' + newVersion + '" does not exist in repo ' + repo.repoName);
}
});
var releaseDir = path.join('releases', 'cordova-' + newVersion);
var destDir = path.join(releaseDir, 'cordova-' + newVersion);
shjs.rm('-rf', releaseDir);
shjs.mkdir('-p', destDir);
// Create zips.
forEachRepo(repos, function(repo) {
var zipPath = path.join('..', destDir, repo.repoName + '.zip');
if (shjs.test('-f', zipPath)) {
print('Skipping zip (already exists):', zipPath);
} else {
execHelper('git archive --format zip -o "' + zipPath + '" --prefix=' + repo.repoName + '/ ' + newVersion);
}
});
cpAndLog(keysPath, path.join(releaseDir, 'KEYS'));
cpAndLog(path.join(binPath, '*'), destDir);
print('Generating change logs...');
var changeLogData = 'Cordova Commits from ' + prevVersion + ' -> ' + newVersion + '\n';
forEachRepo(repos, function(repo) {
changeLogData += '\n' + repo.repoName + '\n---\n';
changeLogData += execHelper('git log --no-merges --format="%h %s" ' + prevVersion + '..' + newVersion, true) + '\n';
});
fs.writeFileSync(path.join(destDir, 'changelog'), changeLogData);
print('Generating final zip...');
var cordovaSrcZip = 'cordova-' + newVersion + '-src.zip';
var cordovaSrcSha = cordovaSrcZip + '.sha';
shjs.rm('-f', path.join(releaseDir, cordovaSrcZip + '*'));
var oldDir = shjs.pwd();
shjs.cd(releaseDir);
execHelper('zip -rq ' + cordovaSrcZip + ' cordova-' + newVersion);
execHelper('gpg --armor --detach-sig --output ' + cordovaSrcZip + '.asc ' + cordovaSrcZip);
fs.writeFileSync(cordovaSrcZip + '.md5', execHelper('gpg --print-md MD5 ' + cordovaSrcZip));
fs.writeFileSync(cordovaSrcZip + '.sha', execHelper('gpg --print-md SHA512 ' + cordovaSrcZip));
print('Final product is ready at:', path.join(releaseDir, cordovaSrcZip));
shjs.cd(oldDir);
process.exit(0);
}
function apacheUpload(){
var opt = registerRepoFlag(optimist)
opt = opt
.options('new-version', {
desc: 'The version to release. E.g. 3.0.0',
demand: true
})
.options('prev-version', {
desc: 'The previous release version (used to remove old version from download page)',
demand: false
});
opt = registerHelpFlag(opt);
var argv = opt
.usage('Uploads the release to the apache servers and optionally removes previous release files.\n' +
'This involves:\n' +
' Checking out Apache Cordova release repository if it does not already exist.\n' +
' Updating the repositoryvia svn update\n' +
' Optionally removing old release artifacts\n' +
' Copying in new relase artifacts\n' +
' Svn committing new release artifacts to the apache repo\n' +
'\n' +
'Usage: $0 upload-release --new-version 3.0.0 [--prev-version 2.9.0]')
.argv;
if (argv.h) {
optimist.showHelp();
process.exit(1);
}
if (shjs.test('-d','./apachecordova')){
print('apachecordova directory exists');
execHelper("cd apachecordova && svn update");
} else {
//grab apachecordova repo off apache svn servers
execHelper("svn checkout https://dist.apache.org/repos/dist/release/cordova apachecordova")
}
if (argv['prev-version'] && shjs.test('-d','./apachecordova/cordova-'+argv['prev-version']+'-src.zip')){
//remove old version
print('removing previous release from apache servers')
execHelper("cd apachecordova && svn delete cordova-"+argv['prev-version']+"-src.*");
}
print('copy over and commit new release files')
execHelper("cp -r releases/cordova-"+argv['new-version']+"/cordova-"+argv['new-version']+"-src* apachecordova/");
execHelper("cd apachecordova && svn add cordova-"+argv['new-version']+"-src*");
print("svn commit -m 'updated to "+argv['new-version']+"'")
execHelper("cd apachecordova && svn commit -m 'updated to "+opt.argv['new-version']+"'");
}
function computeReposFromFlag(flagValue) {
var values = Array.isArray(flagValue) ? flagValue : [flagValue];
var ret = [];
var addedIds = {};
function addRepo(repo) {
if (!addedIds[repo.id]) {
addedIds[repo.id] = true;
ret.push(repo);
}
}
values.forEach(function(value) {
var repo = getRepoById(value);
var group = repoGroups[value];
if (repo) {
addRepo(repo);
} else if (group) {
group.forEach(addRepo);
} else {
fatal('Invalid repo value: ' + value + '\nUse the list-repos command to see value values.');
}
});
return ret;
}
function listReleaseUrls(argv) {
var opt = registerRepoFlag(optimist)
opt = opt
.options('version', {
desc: 'The version of the release. E.g. 2.7.1-rc2',
demand: true
})
opt = registerHelpFlag(opt);
var argv = opt
.usage('.\n' +
'Usage: $0 list-release-urls')
.argv;
if (argv.h) {
optimist.showHelp();
process.exit(1);
}
var repos = computeReposFromFlag(argv.r);
var version = argv['version']; //validateVersionString(argv['version']);
var baseUrl = 'http://git-wip-us.apache.org/repos/asf?p=%s.git;a=shortlog;h=refs/tags/%s';
forEachRepo(repos, function(repo) {
if (!tagExists(version)) {
console.error('Tag "' + version + '" does not exist in repo ' + repo.repoName);
return;
}
var url = require('util').format(baseUrl, repo.repoName, version);
console.log(url);
execHelper('git show-ref ' + version, 2, true);
});
}
function computeExistingRepos() {
return allRepos.filter(function(repo) {
return shjs.test('-d', repo.repoName);
});
}
function localBranchExists(name) {
return !!execHelper('git branch --list ' + name, true);
}
function remoteBranchExists(repo, name) {
return !!execHelper('git branch -r --list ' + repo.remoteName + '/' + name, true);
}
function retrieveCurrentBranchName(allowDetached) {
var ref = execHelper('git symbolic-ref HEAD', true, true);
if (!ref) {
if (allowDetached) {
return null;
}
throw new Error('Aborted due to repo ' + shjs.pwd() + ' not being on a named branch');
}
var match = /refs\/heads\/(.*)/.exec(ref);
if (!match) {
throw new Error('Could not parse branch name from: ' + ref);
}
return match[1];
}
function findMostRecentTag() {
return execHelper('git describe --tags --abbrev=0 HEAD', true);
}
function retrieveCurrentTagName() {
// This will return the tag name plus commit info it not directly at a tag.
// That's fine since all users of this function are meant to use the result
// in an equality check.
return execHelper('git describe --tags HEAD', true, true);
}
function tagExists(tagName) {
return !!execHelper('git tag --list ' + tagName, true);
}
function listReposCommand(argv) {
print('Valid values for the --repo flag:');
print('');
print('Repositories:');
allRepos.forEach(function(repo) {
print(' ' + repo.id);
});
print('');
print('Repository Groups:');
var groupNames = Object.keys(repoGroups);
groupNames.sort();
groupNames.forEach(function(groupName) {
print(' ' + groupName + ' (' + repoGroups[groupName].map(function(repo) { return repo.id }).join(', ') + ')');
});
process.exit(0);
}
function repoCloneCommand(argv) {
var opt = registerRepoFlag(optimist)
opt = registerHelpFlag(opt);
var argv = opt
.usage('Clones git repositories into the current working directory. If the repositories are already cloned, then this is a no-op.\n\n' +
'Usage: $0 clone --repo=name [--repo=othername]')
.argv;
if (argv.h) {
optimist.showHelp();
process.exit(1);
}
var repos = computeReposFromFlag(argv.r);
cloneRepos(repos, false);
process.exit(0);
}
function checkoutDevBranch(repos) {
forEachRepo(repos, function(repo) {
var branchName = (repo.id == 'cordova-plugins' || pluginRepos.indexOf(repo) == -1) ? 'master' : 'dev';
gitCheckout(branchName);
});
}
function cloneRepos(repos, quiet) {
var failures = [];
var numSkipped = 0;
repos.forEach(function(repo) {
if (shjs.test('-d', repo.repoName)) {
if(!quiet) print('Repo already cloned: ' + repo.repoName);
numSkipped +=1 ;
} else if (repo.svn) {
execHelper('svn checkout ' + repo.svn + ' ' + repo.repoName);
} else {
execHelper('git clone --progress ' + createRepoUrl(repo));
}
});
var numCloned = repos.length - numSkipped;
if (numCloned) {
print('Successfully cloned ' + numCloned + ' repositories.');
}
}
function repoStatusCommand(argv) {
var opt = registerRepoFlag(optimist)
var opt = optimist
.options('b', {
alias: 'branch',
desc: 'The name of the branch to report on. Can be specified multiple times to specify multiple branches. The local version of the branch is compared with the origin\'s version unless --b2 is specified.'
})
.options('branch2', {
desc: 'The name of the branch to diff against. This is origin/$branch by default.'
})
.options('diff', {
desc: 'Show a diff of the changes (use --no-diff to disable)',
default: true
})
opt = registerHelpFlag(opt);
var argv = opt
.usage('Reports what changes exist locally that are not yet pushed.\n' +
'\n' +
'Example usage: $0 repo-status -r auto -b master -b 2.9.x\n' +
'Example usage: $0 repo-status -r plugins -b dev --branch2 master --no-diff')
.argv;
if (argv.h) {
optimist.showHelp();
process.exit(1);
}
var branches = argv.b && (Array.isArray(argv.b) ? argv.b : [argv.b]);
var branches2 = branches && argv.branch2 && (Array.isArray(argv.branch2) ? argv.branch2 : [argv.branch2]);