@getik-public/cli 1.0.1 → 1.1.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.1.0
2
+ FEATURE: read versions from package.json and apply to android or ios project for that specific environment
3
+
4
+
5
+ ### v1.0.2
6
+ Fixed on windows. When loading dynamic node module on windows absolute path must pe preceded by `file:\\`
7
+
8
+
1
9
  ### v1.0.1
2
10
  Fixed typo: missing input options in mobile-build function
3
11
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getik-public/cli",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -18,7 +18,10 @@ async function applyPatchersForExternalNpmPackages() {
18
18
  let displayClosingSeparatorLine = false;
19
19
  for (const filename of patchesInFolder) {
20
20
  if (filename.indexOf(filenameEndsWith) === filename.length - filenameEndsWith.length) {
21
- const pathToFile = path.join(process.cwd(), patchesFolderName, filename);
21
+ let pathToFile = path.join(process.cwd(), patchesFolderName, filename);
22
+ if (process.platform === "win32") {
23
+ pathToFile = path.join('file:\\', pathToFile);
24
+ }
22
25
  const patcherImport = await import(pathToFile);
23
26
  const patcher = patcherImport.default;
24
27
  console.log('----------------------------------------------------------------------------------------------------------------------');
@@ -62,6 +65,69 @@ async function applyPatchersForExternalNpmPackages() {
62
65
  }
63
66
 
64
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
+
65
131
  function showPatcherInvalidFormat() {
66
132
  const message = `
67
133
  Invalid patcher, make sure you have the right format. Example:
@@ -294,6 +360,14 @@ export const mobileBuild = () => {
294
360
  console.log('INPUT OPTIONS: ', options);
295
361
  const cliCommands = createCliCommands(options);
296
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
+ }
297
371
  applyPatchersForExternalNpmPackages();
298
372
  runCliCommand(cliCommands.buildAngular, function () {
299
373
  runCliCommand(cliCommands.capacitorSync(), function () {