@getik-public/cli 1.0.2 → 1.2.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 CHANGED
@@ -1,3 +1,11 @@
1
+ ### v1.2.0
2
+ FEATURE: Generate `versionCode` from `versionName`, so no longer needed to maintain `versionCode` in `package.json` file, only `version` needs to be updated.
3
+
4
+
5
+ ### v1.1.0
6
+ FEATURE: read versions from package.json and apply to android or ios project for that specific environment
7
+
8
+
1
9
  ### v1.0.2
2
10
  Fixed on windows. When loading dynamic node module on windows absolute path must pe preceded by `file:\\`
3
11
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getik-public/cli",
3
- "version": "1.0.2",
3
+ "version": "1.2.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -65,6 +65,78 @@ async function applyPatchersForExternalNpmPackages() {
65
65
  }
66
66
 
67
67
 
68
+ function readVersionsFromPackageJson() {
69
+ console.log('Checking versions in package.json file...');
70
+ const packageJsonBuffer = fs.readFileSync(path.join(process.cwd(), 'package.json'));
71
+ const packageJson = JSON.parse(packageJsonBuffer);
72
+
73
+ const versionName = packageJson.version;
74
+
75
+ if (!versionName) {
76
+ throw new Error(`Missing properties in "package.json". Make sure you have defined next properties: "version".`);
77
+ }
78
+ const splitVersion = versionName.split('.');
79
+ const x = parseInt(splitVersion[0], 10);
80
+ const y = parseInt(splitVersion[1], 10);
81
+ const z = parseInt(splitVersion[2], 10);
82
+
83
+ if (y > 99 || z > 99) {
84
+ throw new Error(`Second and last number in versionName can't be bigger than 99.`);
85
+ }
86
+
87
+ const yTransformed = (y < 10) ? `0${y}` : y;
88
+ const zTransformed = (z < 10) ? `0${y}` : z;
89
+ const versionCode = `${x}${yTransformed}${zTransformed}`;
90
+
91
+ console.log(`Extracted versions: versionName = ${versionName}, versionCode = ${versionCode}.`);
92
+
93
+ return {
94
+ versionName: versionName,
95
+ versionCode: versionCode,
96
+ }
97
+ }
98
+
99
+
100
+ function checkKeystorePropertiesFile() {
101
+ const pathToKeystoreProperties = path.join(process.cwd(), 'android', 'keystore.properties');
102
+
103
+ if (!fs.existsSync(pathToKeystoreProperties)) {
104
+ throw new Error('Missing "android/keystore.properties" file. Open "android/keystore.properties.md" file and follow instructions.');
105
+ }
106
+ }
107
+
108
+
109
+ function checkSensitiveDataJsonFile() {
110
+ const pathToSensitiveDataJson = path.join(process.cwd(), 'ios', 'sensitive-data.json');
111
+
112
+ if (!fs.existsSync(pathToSensitiveDataJson)) {
113
+ throw new Error('Missing "ios/sensitive-data.json" file. Open "ios/sensitive-data.json.md" file and follow instructions.');
114
+ }
115
+ }
116
+
117
+
118
+ function applyVersionForAndroid(versions) {
119
+ const pathToVersionsProperties = path.join(process.cwd(), 'android', 'versions.properties');
120
+
121
+ if (fs.existsSync(pathToVersionsProperties)) {
122
+ fs.rmSync(pathToVersionsProperties);
123
+ }
124
+
125
+ fs.writeFileSync(pathToVersionsProperties, (`APP_VERSION_NAME=${versions.versionName}` + '\r\n' + `APP_VERSION_CODE=${versions.versionCode}`));
126
+ }
127
+
128
+
129
+ function applyVersionForIos(versions) {
130
+ const pathToVersionsXcconfig = path.join(process.cwd(), 'ios', 'App', 'Versions.xcconfig');
131
+
132
+ if (fs.existsSync(pathToVersionsXcconfig)) {
133
+ fs.rmSync(pathToVersionsXcconfig);
134
+ }
135
+
136
+ fs.writeFileSync(pathToVersionsXcconfig, (`APP_VERSION_NAME = ${versions.versionName}` + '\r\n' + `APP_VERSION_CODE = ${versions.versionCode}`));
137
+ }
138
+
139
+
68
140
  function showPatcherInvalidFormat() {
69
141
  const message = `
70
142
  Invalid patcher, make sure you have the right format. Example:
@@ -297,6 +369,14 @@ export const mobileBuild = () => {
297
369
  console.log('INPUT OPTIONS: ', options);
298
370
  const cliCommands = createCliCommands(options);
299
371
 
372
+ const versions = readVersionsFromPackageJson();
373
+ if (options.platform === 'android') {
374
+ checkKeystorePropertiesFile();
375
+ applyVersionForAndroid(versions);
376
+ } else if (options.platform === 'ios') {
377
+ checkSensitiveDataJsonFile();
378
+ applyVersionForIos(versions);
379
+ }
300
380
  applyPatchersForExternalNpmPackages();
301
381
  runCliCommand(cliCommands.buildAngular, function () {
302
382
  runCliCommand(cliCommands.capacitorSync(), function () {