@getik-public/cli 1.2.0 → 1.3.0-beta1

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 CHANGED
@@ -1,3 +1,13 @@
1
+ ### v1.3.0-beta1
2
+ Added new features:
3
+ - new script: `getik-cli increment-version`(only for mobile for now)
4
+ - extended `getik-cli mobile-build` script to build only angular and zip it for OTA feature.
5
+
6
+
7
+ ### v1.2.1
8
+ Fixed typo on versionCode extraction.
9
+
10
+
1
11
  ### v1.2.0
2
12
  FEATURE: Generate `versionCode` from `versionName`, so no longer needed to maintain `versionCode` in `package.json` file, only `version` needs to be updated.
3
13
 
package/bin/index.js CHANGED
@@ -4,12 +4,14 @@ import { program } from 'commander';
4
4
  import chalk from 'chalk';
5
5
  import figlet from 'figlet';
6
6
 
7
+ import { incrementVersion } from '../src/increment-version.js';
7
8
  import { mobileBuild } from '../src/mobile-build.js';
8
9
  import { uploadToGetikCloud } from '../src/upload-to-getik-cloud.js';
9
10
 
10
11
 
11
12
  console.log(chalk.green(figlet.textSync('Getik CLI', {horizontalLayout: 'full'})));
12
13
 
14
+ incrementVersion();
13
15
  mobileBuild();
14
16
  uploadToGetikCloud();
15
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getik-public/cli",
3
- "version": "1.2.0",
3
+ "version": "1.3.0-beta1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -0,0 +1,141 @@
1
+ import { program } from 'commander';
2
+ import { spawn } from 'child_process';
3
+ import fs from 'fs';
4
+ import path from 'path';
5
+
6
+
7
+ function incrementMobileVersions(type, environment) {
8
+ const packageJsonBuffer = fs.readFileSync(path.join(process.cwd(), 'package.json'));
9
+ const packageJson = JSON.parse(packageJsonBuffer);
10
+
11
+ const allPackageJsonProperties = Object.keys(packageJson);
12
+ const otaVersionProperties = [];
13
+ if (environment) {
14
+ const env = (environment.charAt(0).toUpperCase() + environment.slice(1));
15
+ const versionPropertyName = `otaVersion${env.split('Debug')[0]}`;
16
+ const found = allPackageJsonProperties.find((property) => {
17
+ return (property === versionPropertyName);
18
+ });
19
+ if (found) {
20
+ otaVersionProperties.push(versionPropertyName);
21
+ }
22
+ } else {
23
+ const filtered = allPackageJsonProperties.filter((property) => {
24
+ const name = 'otaVersion';
25
+
26
+ return (property.indexOf(name) === 0) && (property.length > name.length);
27
+ });
28
+ otaVersionProperties.push(...filtered);
29
+
30
+ }
31
+
32
+ if (otaVersionProperties.length === 0) {
33
+ console.log(`WARNING: OTA version${environment ? 'for ' + environment : ''} not found in package.json. If project doesn't have OTA update ignore this warning. If project has OTA update feature, then make sure every environment has specific property with version defined in package.json`);
34
+ } else {
35
+ otaVersionProperties.forEach((propertyName) => {
36
+ packageJson[propertyName]++;
37
+ });
38
+ }
39
+
40
+ if (type === 'ota') {
41
+ if (otaVersionProperties.length === 0) {
42
+ console.log(`OTA version not incremented, no property found in package.json.`);
43
+ }
44
+ fs.writeFileSync(path.join(process.cwd(), 'package.json'), JSON.stringify(packageJson, null, 2));
45
+ createCommit(packageJson, otaVersionProperties);
46
+
47
+ return;
48
+ }
49
+
50
+ const splitVersion = packageJson.version.split('.');
51
+ let x = parseInt(splitVersion[0], 10);
52
+ let y = parseInt(splitVersion[1], 10);
53
+ let z = parseInt(splitVersion[2], 10);
54
+
55
+ if (type === 'major') {
56
+ x++;
57
+ y = 0;
58
+ z = 0;
59
+ } else if (type === 'minor') {
60
+ y++;
61
+ z = 0;
62
+ } else if (type === 'patch') {
63
+ z++;
64
+ } else {
65
+ console.log('Invalid version increment type. Options available: major, minor, patch, ota');
66
+ }
67
+
68
+ packageJson.version = `${x}.${y}.${z}`;
69
+
70
+ fs.writeFileSync(path.join(process.cwd(), 'package.json'), JSON.stringify(packageJson, null, 2));
71
+
72
+ const packageLockJsonBuffer = fs.readFileSync(path.join(process.cwd(), 'package-lock.json'));
73
+ const packageLockJson = JSON.parse(packageLockJsonBuffer);
74
+ packageLockJson.version = `${x}.${y}.${z}`;
75
+ packageLockJson.packages[''].version = `${x}.${y}.${z}`;
76
+ fs.writeFileSync(path.join(process.cwd(), 'package-lock.json'), JSON.stringify(packageLockJson, null, 2));
77
+
78
+ createCommit(packageJson, otaVersionProperties);
79
+ }
80
+
81
+
82
+ function createCommit(packageJsonRef, otaVersionProperties) {
83
+ let otaVersionMessage = '';
84
+ otaVersionProperties.forEach((property) => {
85
+ otaVersionMessage += `; ${property}: ${packageJsonRef[property]}`;
86
+ });
87
+ const message = `APP VERSION UPDATE: versionName: ${packageJsonRef.version}${otaVersionMessage}.`;
88
+
89
+ const cliCommand = `git commit -a -m "${message}"`;
90
+ const ls = spawn(cliCommand, [], {shell: true, env: { ...process.env, FORCE_COLOR: true }, cwd: ''});
91
+
92
+ ls.on('close', (code) => {
93
+ if (code !== 0) {
94
+ console.log('\x1b[31m');
95
+ throw new Error(`Command FAILED: ${cliCommand}`);
96
+ } else {
97
+ console.log(`A new commit was added with message "${message}"`);
98
+ }
99
+ });
100
+ }
101
+
102
+
103
+ function gitCheckIfCleanRepo(callback) {
104
+ const cliCommand = 'git status --porcelain';
105
+ const ls = spawn(cliCommand, [], {shell: true, env: { ...process.env, FORCE_COLOR: true }, cwd: ''});
106
+ const output = [];
107
+ ls.stdout.on('data', (data) => {
108
+ output.push(data);
109
+ });
110
+
111
+ ls.on('close', (code) => {
112
+ if (code !== 0) {
113
+ console.log('\x1b[31m');
114
+ throw new Error(`Command FAILED: ${cliCommand}`);
115
+ } else if (output.length > 0) {
116
+ console.log('\x1b[31m');
117
+ throw new Error('You have uncommited changes. Commit or clear changes before running this command.');
118
+ } else {
119
+ callback();
120
+ }
121
+ });
122
+ }
123
+
124
+
125
+ export const incrementVersion = () => {
126
+ program
127
+ .command('increment-version')
128
+ .requiredOption('-t, --type <type>', 'Type: major - 3.x.x -> 4.x.x; minor - 3.1.x -> 3.2.x; patch - 3.1.0 -> 3.1.1; ota - this is done by default in other types.')
129
+ .requiredOption('-p, --project <type>', 'Project: mobile')
130
+ .option('-e, --environment <type>', 'Environment: getik, getikDebug')
131
+ .action((options) => {
132
+ console.log('INPUT OPTIONS: ', options);
133
+ gitCheckIfCleanRepo(function() {
134
+ if (options.project === 'mobile') {
135
+ incrementMobileVersions(options.type, options.environment);
136
+ } else {
137
+ console.log('Other project types are not supported yet, now only "mobile" is available.');
138
+ }
139
+ });
140
+ });
141
+ };
@@ -65,7 +65,7 @@ async function applyPatchersForExternalNpmPackages() {
65
65
  }
66
66
 
67
67
 
68
- function readVersionsFromPackageJson() {
68
+ function readVersionsFromPackageJson(options) {
69
69
  console.log('Checking versions in package.json file...');
70
70
  const packageJsonBuffer = fs.readFileSync(path.join(process.cwd(), 'package.json'));
71
71
  const packageJson = JSON.parse(packageJsonBuffer);
@@ -85,15 +85,34 @@ function readVersionsFromPackageJson() {
85
85
  }
86
86
 
87
87
  const yTransformed = (y < 10) ? `0${y}` : y;
88
- const zTransformed = (z < 10) ? `0${y}` : z;
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
+ const env = (options.environment.charAt(0).toUpperCase() + options.environment.slice(1));
92
+ const otaVersionPropertyName = `otaVersion${env.split('Debug')[0]}`;
93
+ const otaVersionMessage = packageJson[otaVersionPropertyName] ? ` , ${otaVersionPropertyName} = ${packageJson[otaVersionPropertyName]}.` : '.';
94
+
95
+ console.log(`Extracted versions: versionName = ${versionName}, versionCode = ${versionCode}${otaVersionMessage}`);
92
96
 
93
97
  return {
94
98
  versionName: versionName,
95
99
  versionCode: versionCode,
100
+ ota: packageJson[otaVersionPropertyName],
101
+ }
102
+ }
103
+
104
+
105
+ function makeVersionsFileInTypescript(versions) {
106
+ const pathToVersionsFile = path.join(process.cwd(), 'src', 'environments', 'versions.ts');
107
+ if (fs.existsSync(pathToVersionsFile)) {
108
+ fs.rmSync(pathToVersionsFile);
96
109
  }
110
+ const versionsFileContent = `export const versions = {
111
+ ota: ${versions.ota},
112
+ native: '${versions.versionName}',
113
+ };
114
+ `;
115
+ fs.writeFileSync(pathToVersionsFile, versionsFileContent);
97
116
  }
98
117
 
99
118
 
@@ -184,6 +203,19 @@ function checkPatcherForPackageMatch(patcher) {
184
203
  }
185
204
 
186
205
 
206
+ function createCommandsForOTA(options, versions) {
207
+ cleanBuildFolder(options);
208
+ if (!versions.ota) {
209
+ throw new Error(`You are trying to build app for OTA but OTA version not found. Make sure you have defined properties "otaVersion<ENVIRONMENT>" for every environment in "package.json".`);
210
+ }
211
+ const buildAngular = `ng build --configuration=${options.environment}`;
212
+ const createZip = `zip -q -r ./${buildFolder}/ota/www-${versions.versionName}-${versions.ota}.zip ./www`;
213
+ const commands = [buildAngular, createZip];
214
+
215
+ return commands;
216
+ }
217
+
218
+
187
219
  function createCommandsForAndroid(options) {
188
220
  const isWindows = (process.platform === 'win32');
189
221
  const capitalizedEnvironment = (options.environment.charAt(0).toUpperCase() + options.environment.slice(1));
@@ -229,7 +261,7 @@ function createCommandsForIos(options) {
229
261
 
230
262
 
231
263
  function cleanBuildFolder(options) {
232
- const platformBuildFolder = `${buildFolder}/${options.platform}`;
264
+ const platformBuildFolder = `${buildFolder}/${options.ota ? 'ota' : options.platform}`;
233
265
  if (fs.existsSync(buildFolder)) {
234
266
  fs.rmSync(buildFolder, {recursive: true});
235
267
  }
@@ -360,16 +392,28 @@ function runCliCommandList(list, path, callback) {
360
392
  export const mobileBuild = () => {
361
393
  program
362
394
  .command('mobile-build')
363
- .requiredOption('-p, --platform <type>', 'Platform: android, ios')
364
395
  .requiredOption('-e, --environment <type>', 'Environment: getik, getikDebug')
396
+ .option('-p, --platform <type>', 'Platform: android, ios')
365
397
  .option('--syncOnly', 'Apply capacitor sync only, without platform build')
398
+ .option('--ota', 'Only build files for OTA update, not full application build')
366
399
  .option('--aab', 'Android platform only, final build as AAB')
367
400
  .option('--upload', 'iOS platform only, upload directly to AppStore')
368
- .action((options) => {
401
+ .action(async (options) => {
369
402
  console.log('INPUT OPTIONS: ', options);
403
+ const versions = readVersionsFromPackageJson(options);
404
+ makeVersionsFileInTypescript(versions);
405
+
406
+ if (options.ota) {
407
+ const otaCliCommands = createCommandsForOTA(options, versions);
408
+ runCliCommandList(otaCliCommands, undefined, () => {
409
+ console.log('ZIP file for OTA update created, check folder: ./build/ota/');
410
+ });
411
+
412
+ return;
413
+ }
414
+
370
415
  const cliCommands = createCliCommands(options);
371
416
 
372
- const versions = readVersionsFromPackageJson();
373
417
  if (options.platform === 'android') {
374
418
  checkKeystorePropertiesFile();
375
419
  applyVersionForAndroid(versions);
@@ -377,7 +421,7 @@ export const mobileBuild = () => {
377
421
  checkSensitiveDataJsonFile();
378
422
  applyVersionForIos(versions);
379
423
  }
380
- applyPatchersForExternalNpmPackages();
424
+ await applyPatchersForExternalNpmPackages();
381
425
  runCliCommand(cliCommands.buildAngular, function () {
382
426
  runCliCommand(cliCommands.capacitorSync(), function () {
383
427
  runCliCommandList(cliCommands.buildApp, options.platform, () => {