@getik-public/cli 1.2.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/package.json +1 -1
- package/src/mobile-build.js +237 -18
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
package/src/mobile-build.js
CHANGED
|
@@ -19,7 +19,7 @@ async function applyPatchersForExternalNpmPackages() {
|
|
|
19
19
|
for (const filename of patchesInFolder) {
|
|
20
20
|
if (filename.indexOf(filenameEndsWith) === filename.length - filenameEndsWith.length) {
|
|
21
21
|
let pathToFile = path.join(process.cwd(), patchesFolderName, filename);
|
|
22
|
-
if (process.platform ===
|
|
22
|
+
if (process.platform === 'win32') {
|
|
23
23
|
pathToFile = path.join('file:\\', pathToFile);
|
|
24
24
|
}
|
|
25
25
|
const patcherImport = await import(pathToFile);
|
|
@@ -88,7 +88,7 @@ function readVersionsFromPackageJson() {
|
|
|
88
88
|
const zTransformed = (z < 10) ? `0${z}` : z;
|
|
89
89
|
const versionCode = `${x}${yTransformed}${zTransformed}`;
|
|
90
90
|
|
|
91
|
-
console.log(`Extracted versions: versionName = ${versionName}, versionCode = ${versionCode}.`);
|
|
91
|
+
console.log(`Extracted versions: versionName = \x1b[32m${versionName}\x1b[0m, versionCode = \x1b[32m${versionCode}\x1b[0m.`);
|
|
92
92
|
|
|
93
93
|
return {
|
|
94
94
|
versionName: versionName,
|
|
@@ -196,7 +196,7 @@ function createCommandsForAndroid(options) {
|
|
|
196
196
|
|
|
197
197
|
function createCommandsForIos(options) {
|
|
198
198
|
const workspace = './App/App.xcworkspace';
|
|
199
|
-
const debugMode = (options.environment.indexOf(
|
|
199
|
+
const debugMode = (options.environment.indexOf('Debug') >= 0);
|
|
200
200
|
const config = (debugMode ? 'Debug' : 'Release');
|
|
201
201
|
const environment = (options.environment.split('Debug')[0]);
|
|
202
202
|
const archive = `./build/archive/${environment}.xcarchive`;
|
|
@@ -343,6 +343,20 @@ function runCliCommand(command, callback, path) {
|
|
|
343
343
|
}
|
|
344
344
|
|
|
345
345
|
|
|
346
|
+
function runCliCommandSilent(command, callback, path) {
|
|
347
|
+
callback = callback || function() {};
|
|
348
|
+
const ls = spawn(command, [], {shell: true, env: { ...process.env, FORCE_COLOR: true }, cwd: path || ''});
|
|
349
|
+
const output = [];
|
|
350
|
+
ls.stdout.on('data', (data) => {
|
|
351
|
+
output.push(data);
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
ls.on('close', (code) => {
|
|
355
|
+
callback(code, output.toString());
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
|
|
346
360
|
function runCliCommandList(list, path, callback) {
|
|
347
361
|
if (list.length === 0) {
|
|
348
362
|
return;
|
|
@@ -357,6 +371,207 @@ function runCliCommandList(list, path, callback) {
|
|
|
357
371
|
}
|
|
358
372
|
|
|
359
373
|
|
|
374
|
+
function applyReleaseBuildChecks(versions, options, callback) {
|
|
375
|
+
const debugMode = (options.environment.indexOf('Debug') >= 0);
|
|
376
|
+
if (debugMode) {
|
|
377
|
+
callback()
|
|
378
|
+
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
console.log('----------------------------------------------------------------------------------------------------------------------');
|
|
383
|
+
if (options.force) {
|
|
384
|
+
console.log('\x1b[31mWARNING: All checks before release build are skipped! Never use "--force" when uploading build to store! \x1b[0m');
|
|
385
|
+
console.log('----------------------------------------------------------------------------------------------------------------------');
|
|
386
|
+
callback();
|
|
387
|
+
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
console.log('RUNNING CHECKS BEFORE PRODUCTION BUILD...');
|
|
392
|
+
let checkFailed = false;
|
|
393
|
+
|
|
394
|
+
console.log('');
|
|
395
|
+
checkForUncommitedFiles((checkForUncommitedFilesStatus) => {
|
|
396
|
+
checkFailed = (checkFailed || checkForUncommitedFilesStatus);
|
|
397
|
+
|
|
398
|
+
console.log('');
|
|
399
|
+
checkRemoteBranch((checkRemoteBranchStatus) => {
|
|
400
|
+
checkFailed = (checkFailed || checkRemoteBranchStatus);
|
|
401
|
+
|
|
402
|
+
console.log('');
|
|
403
|
+
checkEnvironmentToBranchScheme(versions, options, (checkEnvironmentToBranchSchemeStatus) => {
|
|
404
|
+
checkFailed = (checkFailed || checkEnvironmentToBranchSchemeStatus);
|
|
405
|
+
|
|
406
|
+
console.log('');
|
|
407
|
+
checkVersionInCommit(versions, (checkVersionInCommitStatus) => {
|
|
408
|
+
checkFailed = (checkFailed || checkVersionInCommitStatus);
|
|
409
|
+
|
|
410
|
+
console.log('');
|
|
411
|
+
checkLintErrors((checkLintErrorsStatus) => {
|
|
412
|
+
checkFailed = (checkFailed || checkLintErrorsStatus);
|
|
413
|
+
|
|
414
|
+
console.log('');
|
|
415
|
+
console.log('END "RUNNING CHECKS BEFORE PRODUCTION BUILD..."');
|
|
416
|
+
console.log('----------------------------------------------------------------------------------------------------------------------');
|
|
417
|
+
if (checkFailed) {
|
|
418
|
+
throw new Error('Some prebuild checks failed, see logs to find out which ones.');
|
|
419
|
+
}
|
|
420
|
+
callback();
|
|
421
|
+
});
|
|
422
|
+
});
|
|
423
|
+
});
|
|
424
|
+
});
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
function checkForUncommitedFiles(callback) {
|
|
430
|
+
console.log('- Check if branch is clear. No uncommited changes are allowed.');
|
|
431
|
+
const cliCommand = 'git status -u --porcelain';
|
|
432
|
+
runCliCommandSilent(cliCommand, (code, output) => {
|
|
433
|
+
let checkFailed = false;
|
|
434
|
+
if (code !== 0) {
|
|
435
|
+
console.log('\x1b[31m FAILED! "git status" command failed. \x1b[0m');
|
|
436
|
+
checkFailed = true;
|
|
437
|
+
} else if (output.length > 0) {
|
|
438
|
+
console.log('\x1b[31m FAILED! You have uncommited changes. \x1b[0m');
|
|
439
|
+
checkFailed = true;
|
|
440
|
+
} else {
|
|
441
|
+
console.log('\x1b[32m PASSED! \x1b[0m');
|
|
442
|
+
}
|
|
443
|
+
callback(checkFailed);
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
function checkRemoteBranch(callback) {
|
|
449
|
+
console.log('- Check if local branch is up to date with remote branch.');
|
|
450
|
+
const cliGetCurrentBranchName = 'git rev-parse --abbrev-ref HEAD';
|
|
451
|
+
runCliCommandSilent(cliGetCurrentBranchName, (code, branchName) => {
|
|
452
|
+
if (code !== 0) {
|
|
453
|
+
console.log('\x1b[31m FAILED! "git rev-parse" command failed. \x1b[0m');
|
|
454
|
+
callback(true);
|
|
455
|
+
} else {
|
|
456
|
+
branchName = branchName.trim();
|
|
457
|
+
const cliGitFetch = `git fetch origin ${branchName}`;
|
|
458
|
+
runCliCommandSilent(cliGitFetch, (code) => {
|
|
459
|
+
if (code !== 0) {
|
|
460
|
+
console.log('\x1b[31m FAILED! "git fetch" command failed. \x1b[0m');
|
|
461
|
+
callback(true);
|
|
462
|
+
} else {
|
|
463
|
+
const cliGitDiff = `git diff origin/${branchName} ${branchName} --name-only`;
|
|
464
|
+
runCliCommandSilent(cliGitDiff, (code, diffData) => {
|
|
465
|
+
if (code !== 0) {
|
|
466
|
+
console.log('\x1b[31m FAILED! "git diff" command failed. \x1b[0m');
|
|
467
|
+
callback(true);
|
|
468
|
+
} else if (diffData.length > 0) {
|
|
469
|
+
console.log('\x1b[31m FAILED! Local branch is not up to date with remote branch. \x1b[0m');
|
|
470
|
+
callback(true);
|
|
471
|
+
} else {
|
|
472
|
+
console.log('\x1b[32m PASSED! \x1b[0m');
|
|
473
|
+
callback(false);
|
|
474
|
+
}
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
function checkEnvironmentToBranchScheme(versions, options, callback) {
|
|
484
|
+
console.log('- Check if build for selected environment can be made from current branch.');
|
|
485
|
+
|
|
486
|
+
const cliGetCurrentBranchName = 'git rev-parse --abbrev-ref HEAD';
|
|
487
|
+
runCliCommandSilent(cliGetCurrentBranchName, (code, branchName) => {
|
|
488
|
+
if (code !== 0) {
|
|
489
|
+
console.log('\x1b[31m FAILED! "git rev-parse" command failed. \x1b[0m');
|
|
490
|
+
callback(true);
|
|
491
|
+
} else {
|
|
492
|
+
branchName = branchName.trim();
|
|
493
|
+
if (options.environment === 'getik') {
|
|
494
|
+
if (branchName === 'develop') {
|
|
495
|
+
console.log('\x1b[32m PASSED! \x1b[0m');
|
|
496
|
+
callback(false);
|
|
497
|
+
} else {
|
|
498
|
+
console.log('\x1b[31m FAILED! You can build for "getik" environment only from "develop". \x1b[0m');
|
|
499
|
+
callback(true);
|
|
500
|
+
}
|
|
501
|
+
} else if (options.environment === 'qa') {
|
|
502
|
+
const requiredBranchName = `release/${versions.versionName.substring(0, versions.versionName.length - 2)}x`;
|
|
503
|
+
if (branchName === requiredBranchName) {
|
|
504
|
+
console.log('\x1b[32m PASSED! \x1b[0m');
|
|
505
|
+
callback(false);
|
|
506
|
+
} else {
|
|
507
|
+
console.log(`\x1b[31m FAILED! You can build for "qa" environment only from "${requiredBranchName}". \x1b[0m`);
|
|
508
|
+
callback(true);
|
|
509
|
+
}
|
|
510
|
+
} else if (options.environment === 'preprod' || options.environment === 'prod') {
|
|
511
|
+
if (branchName === 'master') {
|
|
512
|
+
console.log('\x1b[32m PASSED! \x1b[0m');
|
|
513
|
+
callback(false);
|
|
514
|
+
} else {
|
|
515
|
+
console.log(`\x1b[31m FAILED! You can build for "${options.environment}" environment only from "master". \x1b[0m`);
|
|
516
|
+
callback(true);
|
|
517
|
+
}
|
|
518
|
+
} else {
|
|
519
|
+
console.log('\x1b[32m PASSED! \x1b[0m');
|
|
520
|
+
callback(false);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
|
|
527
|
+
function checkVersionInCommit(versions, callback) {
|
|
528
|
+
console.log('- Check if latest commit is a version update commit and it is the same as in "package.json".');
|
|
529
|
+
const cliCommand = 'git log -1 --pretty=%B';
|
|
530
|
+
runCliCommandSilent(cliCommand, (code, commitMessage) => {
|
|
531
|
+
commitMessage = commitMessage.trim();
|
|
532
|
+
let checkFailed = false;
|
|
533
|
+
if (code !== 0) {
|
|
534
|
+
console.log('\x1b[31m FAILED! "git log" command failed. \x1b[0m');
|
|
535
|
+
checkFailed = true;
|
|
536
|
+
} else {
|
|
537
|
+
const expectedMessage = `APP VERSION UPDATE: versionName: ${versions.versionName}`;
|
|
538
|
+
if (commitMessage === expectedMessage) {
|
|
539
|
+
console.log('\x1b[32m PASSED! \x1b[0m');
|
|
540
|
+
checkFailed = false;
|
|
541
|
+
} else {
|
|
542
|
+
console.log('\x1b[31m FAILED! Version in "package.json" is not the same as in commit message. \x1b[0m');
|
|
543
|
+
checkFailed = true;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
callback(checkFailed);
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
|
|
551
|
+
function checkLintErrors(callback) {
|
|
552
|
+
console.log('- Check for lint errors.');
|
|
553
|
+
const P = ['\\', '|', '/', '-'];
|
|
554
|
+
let x = 0;
|
|
555
|
+
const ref = setInterval(() => {
|
|
556
|
+
process.stdout.write('\r' + P[x++]);
|
|
557
|
+
x &= 3;
|
|
558
|
+
}, 250);
|
|
559
|
+
const cliCommand = 'npm run lint';
|
|
560
|
+
runCliCommandSilent(cliCommand, (code, output) => {
|
|
561
|
+
clearInterval(ref);
|
|
562
|
+
process.stdout.write('\r');
|
|
563
|
+
let checkFailed = false;
|
|
564
|
+
if (code !== 0) {
|
|
565
|
+
console.log('\x1b[31m FAILED! There are "lint" errors. \x1b[0m');
|
|
566
|
+
checkFailed = true;
|
|
567
|
+
} else {
|
|
568
|
+
console.log('\x1b[32m PASSED! \x1b[0m');
|
|
569
|
+
}
|
|
570
|
+
callback(checkFailed);
|
|
571
|
+
});
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
|
|
360
575
|
export const mobileBuild = () => {
|
|
361
576
|
program
|
|
362
577
|
.command('mobile-build')
|
|
@@ -365,25 +580,29 @@ export const mobileBuild = () => {
|
|
|
365
580
|
.option('--syncOnly', 'Apply capacitor sync only, without platform build')
|
|
366
581
|
.option('--aab', 'Android platform only, final build as AAB')
|
|
367
582
|
.option('--upload', 'iOS platform only, upload directly to AppStore')
|
|
583
|
+
.option('--force', 'Skip all checks for builds of type release')
|
|
368
584
|
.action((options) => {
|
|
369
585
|
console.log('INPUT OPTIONS: ', options);
|
|
370
586
|
const cliCommands = createCliCommands(options);
|
|
371
|
-
|
|
372
587
|
const versions = readVersionsFromPackageJson();
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
588
|
+
|
|
589
|
+
applyReleaseBuildChecks(versions, options, () => {
|
|
590
|
+
if (options.platform === 'android') {
|
|
591
|
+
checkKeystorePropertiesFile();
|
|
592
|
+
applyVersionForAndroid(versions);
|
|
593
|
+
} else if (options.platform === 'ios') {
|
|
594
|
+
checkSensitiveDataJsonFile();
|
|
595
|
+
applyVersionForIos(versions);
|
|
596
|
+
}
|
|
597
|
+
applyPatchersForExternalNpmPackages().then(() => {
|
|
598
|
+
runCliCommand(cliCommands.buildAngular, function () {
|
|
599
|
+
runCliCommand(cliCommands.capacitorSync(), function () {
|
|
600
|
+
runCliCommandList(cliCommands.buildApp, options.platform, () => {
|
|
601
|
+
setTimeout(() => {
|
|
602
|
+
copyFinalBuildToRootFolder(options);
|
|
603
|
+
}, 100);
|
|
604
|
+
});
|
|
605
|
+
});
|
|
387
606
|
});
|
|
388
607
|
});
|
|
389
608
|
});
|