@getik-public/cli 1.0.2 → 1.1.1

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,7 @@
1
+ ### v1.1.0
2
+ FEATURE: read versions from package.json and apply to android or ios project for that specific environment
3
+
4
+
1
5
  ### v1.0.2
2
6
  Fixed on windows. When loading dynamic node module on windows absolute path must pe preceded by `file:\\`
3
7
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getik-public/cli",
3
- "version": "1.0.2",
3
+ "version": "1.1.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -19,8 +19,8 @@ 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 === "win32") {
23
- pathToFile = path.join('file:\\', pathToFile);
22
+ if (process.platform === 'win32') {
23
+ pathToFile = ('file:\\' + pathToFile);
24
24
  }
25
25
  const patcherImport = await import(pathToFile);
26
26
  const patcher = patcherImport.default;
@@ -65,6 +65,69 @@ async function applyPatchersForExternalNpmPackages() {
65
65
  }
66
66
 
67
67
 
68
+ function readVersionsFromPackageJson(options) {
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 environment = (options.environment.split('Debug')[0]);
74
+ const capitalizedEnvironment = (environment.charAt(0).toUpperCase() + environment.slice(1));
75
+
76
+ const versionName = packageJson.version;
77
+ const versionCode = packageJson['versionCode' + capitalizedEnvironment];
78
+
79
+ if (!versionName || !versionCode) {
80
+ throw new Error(`Missing properties in "package.json". Make sure you have defined next properties: "version", "versionCode${capitalizedEnvironment}".`);
81
+ }
82
+ console.log(`Extracted versions: versionName = ${versionName}, versionCode = ${versionCode}.`);
83
+
84
+ return {
85
+ versionName: versionName,
86
+ versionCode: versionCode,
87
+ }
88
+ }
89
+
90
+
91
+ function checkKeystorePropertiesFile() {
92
+ const pathToKeystoreProperties = path.join(process.cwd(), 'android', 'keystore.properties');
93
+
94
+ if (!fs.existsSync(pathToKeystoreProperties)) {
95
+ throw new Error('Missing "android/keystore.properties" file. Open "android/keystore.properties.md" file and follow instructions.');
96
+ }
97
+ }
98
+
99
+
100
+ function checkSensitiveDataJsonFile() {
101
+ const pathToSensitiveDataJson = path.join(process.cwd(), 'ios', 'sensitive-data.json');
102
+
103
+ if (!fs.existsSync(pathToSensitiveDataJson)) {
104
+ throw new Error('Missing "ios/sensitive-data.json" file. Open "ios/sensitive-data.json.md" file and follow instructions.');
105
+ }
106
+ }
107
+
108
+
109
+ function applyVersionForAndroid(versions) {
110
+ const pathToVersionsProperties = path.join(process.cwd(), 'android', 'versions.properties');
111
+
112
+ if (fs.existsSync(pathToVersionsProperties)) {
113
+ fs.rmSync(pathToVersionsProperties);
114
+ }
115
+
116
+ fs.writeFileSync(pathToVersionsProperties, (`APP_VERSION_NAME=${versions.versionName}` + '\r\n' + `APP_VERSION_CODE=${versions.versionCode}`));
117
+ }
118
+
119
+
120
+ function applyVersionForIos(versions) {
121
+ const pathToVersionsXcconfig = path.join(process.cwd(), 'ios', 'App', 'Versions.xcconfig');
122
+
123
+ if (fs.existsSync(pathToVersionsXcconfig)) {
124
+ fs.rmSync(pathToVersionsXcconfig);
125
+ }
126
+
127
+ fs.writeFileSync(pathToVersionsXcconfig, (`APP_VERSION_NAME = ${versions.versionName}` + '\r\n' + `APP_VERSION_CODE = ${versions.versionCode}`));
128
+ }
129
+
130
+
68
131
  function showPatcherInvalidFormat() {
69
132
  const message = `
70
133
  Invalid patcher, make sure you have the right format. Example:
@@ -297,6 +360,14 @@ export const mobileBuild = () => {
297
360
  console.log('INPUT OPTIONS: ', options);
298
361
  const cliCommands = createCliCommands(options);
299
362
 
363
+ const versions = readVersionsFromPackageJson(options);
364
+ if (options.platform === 'android') {
365
+ checkKeystorePropertiesFile();
366
+ applyVersionForAndroid(versions);
367
+ } else if (options.platform === 'ios') {
368
+ checkSensitiveDataJsonFile();
369
+ applyVersionForIos(versions);
370
+ }
300
371
  applyPatchersForExternalNpmPackages();
301
372
  runCliCommand(cliCommands.buildAngular, function () {
302
373
  runCliCommand(cliCommands.capacitorSync(), function () {