@getik-public/cli 1.4.1 → 1.5.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.5.0
2
+ - Added build scripts for WEB projects
3
+
4
+
5
+ ### v1.4.1
6
+ - FIXED: when `--syncOnly` option was run without `--platform` parameter the files with version where not created and updated
7
+
8
+
1
9
  ### v1.4.0
2
10
  - Parameter `--platform` is now optional, but only when used with `--syncOnly`.
3
11
  - Parameter `--syncOnly` now will run `cap sync` for all platforms if `--platform` parameter is missing.
package/README.md CHANGED
@@ -11,6 +11,7 @@ Add next line in your `package.json` file under `devDependencies`:
11
11
 
12
12
  # Available scripts
13
13
  - [`mobile-build`](#mobile-build)
14
+ - [`web-build`](#web-build)
14
15
  - [`upload-to-getik-cloud`](#upload-to-getik-cloud)
15
16
 
16
17
 
@@ -31,6 +32,17 @@ Example: `getik-cli mobile-build --platform ios --environment getik --upload`
31
32
 
32
33
 
33
34
 
35
+ ## <a name="web-build" href="#web-build">`web-build`</a>
36
+ ### Usage: `getik-cli web-build [-e, --environment] [--syncOnly]`
37
+ Example: `getik-cli web-build -e getik --syncOnly`
38
+ Example: `getik-cli web-build -e getik`
39
+
40
+ | Option | Required | Values | Description |
41
+ |---------------------|----------|-----------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
42
+ | `-e`, `--environment` | YES | `<string>` | While environment can be any name, be consistent and use these: `getik`, `vbox`, `qa`, `preprod`, `prod`. |
43
+ | `--syncOnly` | NO | `-` | For development only, it will create a file named `version.ts` with version found in `package.json`. Use this version in all `environment.ts` files. This will not go further to trigger the actual build script. |
44
+
45
+
34
46
  ## <a name="upload-to-getik-cloud" href="#upload-to-getik-cloud">`upload-to-getik-cloud`</a>
35
47
  ### Usage: `getik-cli upload-to-getik-cloud ./path/to/my-file.apk`
36
48
  Use this command to upload apk files to getik cloud. If successful, in command line you will find a direct link to fresh uploaded file alongside a link to the full list.
package/bin/index.js CHANGED
@@ -6,11 +6,13 @@ import figlet from 'figlet';
6
6
 
7
7
  import { mobileBuild } from '../src/mobile-build.js';
8
8
  import { uploadToGetikCloud } from '../src/upload-to-getik-cloud.js';
9
+ import { webBuild } from '../src/web-build.js';
9
10
 
10
11
 
11
12
  console.log(chalk.green(figlet.textSync('Getik CLI', {horizontalLayout: 'full'})));
12
13
 
13
14
  mobileBuild();
15
+ webBuild();
14
16
  uploadToGetikCloud();
15
17
 
16
18
  program.parse(process.argv);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getik-public/cli",
3
- "version": "1.4.1",
3
+ "version": "1.5.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/lib.js ADDED
@@ -0,0 +1,272 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import { spawn } from 'child_process';
4
+
5
+
6
+ export const readVersionsFromPackageJson = () => {
7
+ console.log('Checking versions in package.json file...');
8
+ const packageJsonBuffer = fs.readFileSync(path.join(process.cwd(), 'package.json'));
9
+ const packageJson = JSON.parse(packageJsonBuffer);
10
+
11
+ const versionName = packageJson.version;
12
+
13
+ if (!versionName) {
14
+ throw new Error(`Missing properties in "package.json". Make sure you have defined next properties: "version".`);
15
+ }
16
+ const splitVersion = versionName.split('.');
17
+ const x = parseInt(splitVersion[0], 10);
18
+ const y = parseInt(splitVersion[1], 10);
19
+ const z = parseInt(splitVersion[2], 10);
20
+
21
+ if (y > 99 || z > 99) {
22
+ throw new Error(`Second and last number in versionName can't be bigger than 99.`);
23
+ }
24
+
25
+ const yTransformed = (y < 10) ? `0${y}` : y;
26
+ const zTransformed = (z < 10) ? `0${z}` : z;
27
+ const versionCode = `${x}${yTransformed}${zTransformed}`;
28
+
29
+ console.log(`Extracted versions: versionName = \x1b[32m${versionName}\x1b[0m, versionCode = \x1b[32m${versionCode}\x1b[0m.`);
30
+
31
+ return {
32
+ versionName: versionName,
33
+ versionCode: versionCode,
34
+ }
35
+ }
36
+
37
+
38
+ export const runCliCommand = (command, callback, path) => {
39
+ console.log('COMMAND: ', '\x1b[96m', command, '\x1b[0m');
40
+ callback = callback || function() {};
41
+ const ls = spawn(command, [], {shell: true, env: { ...process.env, FORCE_COLOR: true }, cwd: path || ''});
42
+
43
+ ls.stdout.on('data', data => {
44
+ console.log(data.toString());
45
+ });
46
+
47
+ ls.stderr.on('data', data => {
48
+ console.log(data.toString());
49
+ });
50
+
51
+ ls.on('error', (error) => {
52
+ console.log(error.message);
53
+ });
54
+
55
+ ls.on('close', code => {
56
+ console.log(`child process exited with code ${code}`);
57
+ if (code !== 0) {
58
+ console.log('\x1b[31m');
59
+ throw new Error(`Command FAILED: ${command}`);
60
+ }
61
+ callback();
62
+ });
63
+ }
64
+
65
+
66
+ export const runCliCommandSilent = (command, callback, path) => {
67
+ callback = callback || function() {};
68
+ const ls = spawn(command, [], {shell: true, env: { ...process.env, FORCE_COLOR: true }, cwd: path || ''});
69
+ const output = [];
70
+ ls.stdout.on('data', (data) => {
71
+ output.push(data);
72
+ });
73
+
74
+ ls.on('close', (code) => {
75
+ callback(code, output.toString());
76
+ });
77
+ }
78
+
79
+
80
+ export const applyReleaseBuildChecks = (versions, options, callback) => {
81
+ console.log('----------------------------------------------------------------------------------------------------------------------');
82
+ if (options.force) {
83
+ console.log('\x1b[31mWARNING: All checks before release build are skipped! Never use "--force" when deploying build! \x1b[0m');
84
+ console.log('----------------------------------------------------------------------------------------------------------------------');
85
+ callback();
86
+
87
+ return;
88
+ }
89
+
90
+ console.log('RUNNING CHECKS BEFORE PRODUCTION BUILD...');
91
+ let checkFailed = false;
92
+
93
+ console.log('');
94
+ checkForUncommitedFiles((checkForUncommitedFilesStatus) => {
95
+ checkFailed = (checkFailed || checkForUncommitedFilesStatus);
96
+
97
+ console.log('');
98
+ checkRemoteBranch((checkRemoteBranchStatus) => {
99
+ checkFailed = (checkFailed || checkRemoteBranchStatus);
100
+
101
+ console.log('');
102
+ checkEnvironmentToBranchScheme(versions, options, (checkEnvironmentToBranchSchemeStatus) => {
103
+ checkFailed = (checkFailed || checkEnvironmentToBranchSchemeStatus);
104
+
105
+ console.log('');
106
+ checkVersionInCommit(versions, (checkVersionInCommitStatus) => {
107
+ checkFailed = (checkFailed || checkVersionInCommitStatus);
108
+
109
+ console.log('');
110
+ checkLintErrors((checkLintErrorsStatus) => {
111
+ checkFailed = (checkFailed || checkLintErrorsStatus);
112
+
113
+ console.log('');
114
+ console.log('END "RUNNING CHECKS BEFORE PRODUCTION BUILD..."');
115
+ console.log('----------------------------------------------------------------------------------------------------------------------');
116
+ if (checkFailed) {
117
+ throw new Error('Some prebuild checks failed, see logs to find out which ones.');
118
+ }
119
+ callback();
120
+ });
121
+ });
122
+ });
123
+ });
124
+ });
125
+ }
126
+
127
+
128
+ export const checkForUncommitedFiles = (callback) => {
129
+ console.log('- Check if branch is clear. No uncommited changes are allowed.');
130
+ const cliCommand = 'git status -u --porcelain';
131
+ runCliCommandSilent(cliCommand, (code, output) => {
132
+ let checkFailed = false;
133
+ if (code !== 0) {
134
+ console.log('\x1b[31m FAILED! "git status" command failed. \x1b[0m');
135
+ checkFailed = true;
136
+ } else if (output.length > 0) {
137
+ console.log('\x1b[31m FAILED! You have uncommited changes. \x1b[0m');
138
+ checkFailed = true;
139
+ } else {
140
+ console.log('\x1b[32m PASSED! \x1b[0m');
141
+ }
142
+ callback(checkFailed);
143
+ });
144
+ }
145
+
146
+
147
+ export const checkRemoteBranch = (callback) => {
148
+ console.log('- Check if local branch is up to date with remote branch.');
149
+ const cliGetCurrentBranchName = 'git rev-parse --abbrev-ref HEAD';
150
+ runCliCommandSilent(cliGetCurrentBranchName, (code, branchName) => {
151
+ if (code !== 0) {
152
+ console.log('\x1b[31m FAILED! "git rev-parse" command failed. \x1b[0m');
153
+ callback(true);
154
+ } else {
155
+ branchName = branchName.trim();
156
+ const cliGitFetch = `git fetch origin ${branchName}`;
157
+ runCliCommandSilent(cliGitFetch, (code) => {
158
+ if (code !== 0) {
159
+ console.log('\x1b[31m FAILED! "git fetch" command failed. \x1b[0m');
160
+ callback(true);
161
+ } else {
162
+ const cliGitDiff = `git diff origin/${branchName} ${branchName} --name-only`;
163
+ runCliCommandSilent(cliGitDiff, (code, diffData) => {
164
+ if (code !== 0) {
165
+ console.log('\x1b[31m FAILED! "git diff" command failed. \x1b[0m');
166
+ callback(true);
167
+ } else if (diffData.length > 0) {
168
+ console.log('\x1b[31m FAILED! Local branch is not up to date with remote branch. \x1b[0m');
169
+ callback(true);
170
+ } else {
171
+ console.log('\x1b[32m PASSED! \x1b[0m');
172
+ callback(false);
173
+ }
174
+ });
175
+ }
176
+ });
177
+ }
178
+ });
179
+ }
180
+
181
+
182
+ export const checkEnvironmentToBranchScheme = (versions, options, callback) => {
183
+ console.log('- Check if build for selected environment can be made from current branch.');
184
+
185
+ const cliGetCurrentBranchName = 'git rev-parse --abbrev-ref HEAD';
186
+ runCliCommandSilent(cliGetCurrentBranchName, (code, branchName) => {
187
+ if (code !== 0) {
188
+ console.log('\x1b[31m FAILED! "git rev-parse" command failed. \x1b[0m');
189
+ callback(true);
190
+ } else {
191
+ branchName = branchName.trim();
192
+ if (options.environment === 'getik') {
193
+ if (branchName === 'develop') {
194
+ console.log('\x1b[32m PASSED! \x1b[0m');
195
+ callback(false);
196
+ } else {
197
+ console.log('\x1b[31m FAILED! You can build for "getik" environment only from "develop". \x1b[0m');
198
+ callback(true);
199
+ }
200
+ } else if (options.environment === 'qa') {
201
+ const splitVersionName = versions.versionName.split('.');
202
+ const requiredBranchName = `release/${splitVersionName[0]}.${splitVersionName[1]}.x`;
203
+ if (branchName === requiredBranchName) {
204
+ console.log('\x1b[32m PASSED! \x1b[0m');
205
+ callback(false);
206
+ } else {
207
+ console.log(`\x1b[31m FAILED! You can build for "qa" environment only from "${requiredBranchName}". \x1b[0m`);
208
+ callback(true);
209
+ }
210
+ } else if (options.environment === 'preprod' || options.environment === 'prod') {
211
+ if (branchName === 'master') {
212
+ console.log('\x1b[32m PASSED! \x1b[0m');
213
+ callback(false);
214
+ } else {
215
+ console.log(`\x1b[31m FAILED! You can build for "${options.environment}" environment only from "master". \x1b[0m`);
216
+ callback(true);
217
+ }
218
+ } else {
219
+ console.log('\x1b[32m PASSED! \x1b[0m');
220
+ callback(false);
221
+ }
222
+ }
223
+ });
224
+ }
225
+
226
+
227
+ export const checkVersionInCommit = (versions, callback) => {
228
+ console.log('- Check if latest commit is a version update commit and it is the same as in "package.json".');
229
+ const cliCommand = 'git log -1 --pretty=%B';
230
+ runCliCommandSilent(cliCommand, (code, commitMessage) => {
231
+ commitMessage = commitMessage.trim();
232
+ let checkFailed = false;
233
+ if (code !== 0) {
234
+ console.log('\x1b[31m FAILED! "git log" command failed. \x1b[0m');
235
+ checkFailed = true;
236
+ } else {
237
+ const expectedMessage = `APP VERSION UPDATE: versionName: ${versions.versionName}`;
238
+ if (commitMessage && commitMessage.indexOf(expectedMessage) === 0) {
239
+ console.log('\x1b[32m PASSED! \x1b[0m');
240
+ checkFailed = false;
241
+ } else {
242
+ console.log('\x1b[31m FAILED! Version in "package.json" is not the same as in commit message. \x1b[0m');
243
+ checkFailed = true;
244
+ }
245
+ }
246
+ callback(checkFailed);
247
+ });
248
+ }
249
+
250
+
251
+ export const checkLintErrors = (callback) => {
252
+ console.log('- Check for lint errors.');
253
+ const P = ['\\', '|', '/', '-'];
254
+ let x = 0;
255
+ const ref = setInterval(() => {
256
+ process.stdout.write('\r' + P[x++]);
257
+ x &= 3;
258
+ }, 250);
259
+ const cliCommand = 'npm run lint';
260
+ runCliCommandSilent(cliCommand, (code, output) => {
261
+ clearInterval(ref);
262
+ process.stdout.write('\r');
263
+ let checkFailed = false;
264
+ if (code !== 0) {
265
+ console.log('\x1b[31m FAILED! There are "lint" errors. \x1b[0m');
266
+ checkFailed = true;
267
+ } else {
268
+ console.log('\x1b[32m PASSED! \x1b[0m');
269
+ }
270
+ callback(checkFailed);
271
+ });
272
+ }
@@ -0,0 +1,73 @@
1
+ import { program } from 'commander';
2
+ import fs from 'fs';
3
+ import path from 'path';
4
+
5
+ import {
6
+ readVersionsFromPackageJson,
7
+ runCliCommand,
8
+ applyReleaseBuildChecks,
9
+ } from './lib.js';
10
+
11
+
12
+ const buildFolder = 'build';
13
+
14
+
15
+ function applyVersion(versions) {
16
+ const pathToVersionsProperties = path.join(process.cwd(), 'src', 'environments', 'version.ts');
17
+
18
+ if (fs.existsSync(pathToVersionsProperties)) {
19
+ fs.rmSync(pathToVersionsProperties);
20
+ }
21
+
22
+ fs.writeFileSync(pathToVersionsProperties, (
23
+ `export const version = {
24
+ name: '${versions.versionName}',
25
+ code: ${versions.versionCode},
26
+ };
27
+ `
28
+ ));
29
+ }
30
+
31
+
32
+ function cleanBuildFolder(folder) {
33
+ if (fs.existsSync(folder)) {
34
+ fs.rmSync(folder, {recursive: true});
35
+ }
36
+ fs.mkdirSync(folder, {recursive: true});
37
+ }
38
+
39
+
40
+ function buildApp(environmentName, callback) {
41
+ cleanBuildFolder('dist');
42
+ runCliCommand(`ng build --configuration=${environmentName}`, function() {
43
+ runCliCommand(`zip -q -r ../../${buildFolder}/${environmentName}.zip .`, function() {
44
+ callback();
45
+ }, './dist/browser');
46
+ });
47
+ }
48
+
49
+
50
+ export const webBuild = () => {
51
+ program
52
+ .command('web-build')
53
+ .option('-e, --environment <type>', 'Environment: getik, vbox, qa, preprod, prod')
54
+ .option('--syncOnly', 'Generates the version.ts file only so no errors when running app locally')
55
+ .option('--force', 'Skip all checks for builds of type release')
56
+ .action((options) => {
57
+ console.log('INPUT OPTIONS: ', options);
58
+ cleanBuildFolder(buildFolder);
59
+ const versions = readVersionsFromPackageJson();
60
+ applyVersion(versions);
61
+ if (options.sync) {
62
+ return;
63
+ }
64
+ applyReleaseBuildChecks(versions, options, () => {
65
+ buildApp(options.environment, () => {
66
+ const demoEnvName = `${options.environment}Demo`;
67
+ buildApp(demoEnvName, () => {
68
+ console.log('\x1b[32m SUCCESS! \x1b[0m');
69
+ });
70
+ });
71
+ });
72
+ });
73
+ };