@corva/create-app 0.40.0-1 → 0.41.0-2

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.
Files changed (50) hide show
  1. package/README.md +18 -19
  2. package/bin/cca.js +5 -0
  3. package/bin/create-corva-app.cjs +14 -0
  4. package/lib/bump-version.option.js +17 -8
  5. package/lib/constants/cli.js +5 -11
  6. package/lib/constants/manifest.js +10 -22
  7. package/lib/constants/messages.js +4 -10
  8. package/lib/constants/package.js +6 -8
  9. package/lib/flow.js +12 -10
  10. package/lib/flows/lib/api.js +153 -84
  11. package/lib/flows/lib/create-zip-archive.js +7 -7
  12. package/lib/flows/lib/json.js +8 -8
  13. package/lib/flows/lib/manifest.js +5 -7
  14. package/lib/flows/lib/step-error.js +1 -3
  15. package/lib/flows/lib/waitForMs.js +3 -0
  16. package/lib/flows/prepare.js +2 -4
  17. package/lib/flows/release.js +18 -10
  18. package/lib/flows/rerun.js +5 -7
  19. package/lib/flows/steps/prepare-load-app-files.js +3 -7
  20. package/lib/flows/steps/release/add-label.js +11 -0
  21. package/lib/flows/steps/release/add-notes.js +10 -0
  22. package/lib/flows/steps/release/get-config.js +37 -0
  23. package/lib/flows/steps/release/prepare-data.js +10 -0
  24. package/lib/flows/steps/release/publish.js +9 -0
  25. package/lib/flows/steps/release/remove-failed-upload.js +20 -0
  26. package/lib/flows/steps/release/upload-zip-to-corva.js +25 -0
  27. package/lib/flows/steps/release/wait-for-build.js +29 -0
  28. package/lib/flows/steps/rerun-create-task.js +22 -15
  29. package/lib/flows/steps/rerun-prepare-data.js +150 -127
  30. package/lib/flows/steps/rerun.js +3 -7
  31. package/lib/flows/steps/zip-cleanup.js +6 -6
  32. package/lib/flows/steps/zip-create-archive.js +5 -5
  33. package/lib/flows/steps/zip-file-list-resolve.js +34 -29
  34. package/lib/flows/steps/zip-prepare.js +6 -8
  35. package/lib/flows/steps/zip.js +5 -9
  36. package/lib/flows/zip-simple.js +2 -4
  37. package/lib/flows/zip.js +3 -5
  38. package/lib/helpers/logger.js +13 -5
  39. package/lib/helpers/manifest.js +6 -10
  40. package/lib/helpers/resolve-app-runtime.js +47 -45
  41. package/lib/helpers/utils.js +4 -9
  42. package/lib/helpers/versioning.js +6 -12
  43. package/lib/{index.js → main.js} +80 -89
  44. package/lib/scripts/utils/version.js +10 -12
  45. package/package.json +5 -3
  46. package/bin/create-corva-app.js +0 -5
  47. package/lib/app.js +0 -9
  48. package/lib/flows/steps/release-get-app-key.js +0 -16
  49. package/lib/flows/steps/release-get-config.js +0 -37
  50. package/lib/flows/steps/release-upload-zip-to-corva.js +0 -25
@@ -1,9 +1,11 @@
1
- const archiver = require('archiver');
2
- const debug = require('debug')('cca:zip');
3
- const { promises: fs, createWriteStream } = require('fs');
4
- const path = require('path');
1
+ import archiver from 'archiver';
2
+ import Debug from 'debug';
5
3
 
6
- const createZipArchive = async (dirName, zipName, itemsToZip = []) => {
4
+ const debug = Debug('cca:zip');
5
+ import { promises as fs, createWriteStream } from 'node:fs';
6
+ import path from 'node:path';
7
+
8
+ export const createZipArchive = async (dirName, zipName, itemsToZip = []) => {
7
9
  const filePath = path.resolve(dirName, zipName);
8
10
  const archive = archiver.create('zip', {});
9
11
  const output = createWriteStream(filePath);
@@ -73,5 +75,3 @@ const getDataToZip = async (itemsToZip, dirName) => {
73
75
 
74
76
  return allData.filter((f) => f.exists);
75
77
  };
76
-
77
- module.exports = { createZipArchive };
@@ -1,10 +1,12 @@
1
- const { resolve } = require('path');
2
- const { promises: fs } = require('fs');
3
- const os = require('os');
1
+ import { resolve } from 'node:path';
2
+ import { promises as fs } from 'node:fs';
3
+ import os from 'node:os';
4
4
 
5
- const debug = require('debug')('cca:json');
5
+ import Debug from 'debug';
6
6
 
7
- const loadJson = async (dirName, fileName) => {
7
+ const debug = Debug('cca:json');
8
+
9
+ export const loadJson = async (dirName, fileName) => {
8
10
  const fullPath = resolve(dirName, fileName);
9
11
 
10
12
  try {
@@ -21,8 +23,6 @@ const loadJson = async (dirName, fileName) => {
21
23
  }
22
24
  };
23
25
 
24
- const saveJson = async (dirName, fileName, data) => {
26
+ export const saveJson = async (dirName, fileName, data) => {
25
27
  return fs.writeFile(resolve(dirName, fileName), JSON.stringify(data, null, 2) + os.EOL);
26
28
  };
27
-
28
- module.exports = { loadJson, saveJson };
@@ -1,8 +1,8 @@
1
- const { APP_TYPES, APP_RUNTIMES } = require('../../constants/cli');
1
+ import { APP_TYPES, APP_RUNTIMES } from '../../constants/cli.js';
2
2
 
3
3
  const NODE_RUNTIMES = [APP_RUNTIMES.NODE12, APP_RUNTIMES.NODE14, APP_RUNTIMES.NODE16];
4
4
 
5
- class Manifest {
5
+ export class Manifest {
6
6
  constructor(manifest) {
7
7
  this.manifest = manifest;
8
8
  }
@@ -12,11 +12,11 @@ class Manifest {
12
12
  }
13
13
 
14
14
  get type() {
15
- return this.manifest.application.type
15
+ return this.manifest.application.type;
16
16
  }
17
17
 
18
18
  get name() {
19
- return this.manifest.application.name
19
+ return this.manifest.application.name;
20
20
  }
21
21
 
22
22
  get unix_name() {
@@ -25,7 +25,7 @@ class Manifest {
25
25
  }
26
26
 
27
27
  get description() {
28
- return this.manifest.application.description
28
+ return this.manifest.application.description;
29
29
  }
30
30
 
31
31
  isNode() {
@@ -48,5 +48,3 @@ class Manifest {
48
48
  return this.manifest.application.type === APP_TYPES.SCHEDULER;
49
49
  }
50
50
  }
51
-
52
- module.exports = { Manifest };
@@ -1,4 +1,4 @@
1
- class StepError extends Error {
1
+ export class StepError extends Error {
2
2
  cause;
3
3
  name;
4
4
 
@@ -8,5 +8,3 @@ class StepError extends Error {
8
8
  this.cause = cause;
9
9
  }
10
10
  }
11
-
12
- module.exports = { StepError };
@@ -0,0 +1,3 @@
1
+ export async function waitForMs(ms) {
2
+ return new Promise(resolve => setTimeout(resolve, ms));
3
+ }
@@ -1,8 +1,6 @@
1
- const { LOAD_APP_FILES_STEP } = require('./steps/prepare-load-app-files');
1
+ import { LOAD_APP_FILES_STEP } from './steps/prepare-load-app-files.js';
2
2
 
3
- const PREPARE_FLOW = {
3
+ export const PREPARE_FLOW = {
4
4
  name: 'prepare',
5
5
  steps: [LOAD_APP_FILES_STEP],
6
6
  };
7
-
8
- module.exports = { PREPARE_FLOW };
@@ -1,18 +1,26 @@
1
- const { PREPARE_FLOW } = require('./prepare');
2
- const { GET_APP_KEY_STEP } = require('./steps/release-get-app-key');
3
- const { GET_RELEASE_CONFIG_STEP } = require('./steps/release-get-config');
4
- const { UPLOAD_ZIP_TO_CORVA_STEP } = require('./steps/release-upload-zip-to-corva');
5
- const { ZIP_SIMPLE_FLOW } = require('./zip-simple');
1
+ import { PREPARE_FLOW } from './prepare.js';
2
+ import { SETUP_API_CLIENT_STEP } from './steps/release/get-config.js';
3
+ import { UPLOAD_ZIP_TO_CORVA_STEP } from './steps/release/upload-zip-to-corva.js';
4
+ import { ZIP_SIMPLE_FLOW } from './zip-simple.js';
5
+ import { WAIT_FOR_BUILD_FINISH_STEP } from './steps/release/wait-for-build.js';
6
+ import { REMOVE_FAILED_UPLOAD_STEP } from './steps/release/remove-failed-upload.js';
7
+ import { ADD_LABEL_STEP } from './steps/release/add-label.js';
8
+ import { ADD_NOTES_STEP } from './steps/release/add-notes.js';
9
+ import { PUBLISH_PACKAGE_STEP } from './steps/release/publish.js';
10
+ import { RELEASE_PREPARE_DATA_STEP } from './steps/release/prepare-data.js';
6
11
 
7
- const RELEASE_FLOW = {
12
+ export const RELEASE_FLOW = {
8
13
  name: 'release',
9
14
  steps: [
10
15
  PREPARE_FLOW,
11
- GET_RELEASE_CONFIG_STEP,
12
- GET_APP_KEY_STEP,
16
+ SETUP_API_CLIENT_STEP,
17
+ RELEASE_PREPARE_DATA_STEP,
13
18
  ZIP_SIMPLE_FLOW,
14
19
  UPLOAD_ZIP_TO_CORVA_STEP,
20
+ WAIT_FOR_BUILD_FINISH_STEP,
21
+ REMOVE_FAILED_UPLOAD_STEP,
22
+ PUBLISH_PACKAGE_STEP,
23
+ ADD_LABEL_STEP,
24
+ ADD_NOTES_STEP
15
25
  ],
16
26
  };
17
-
18
- module.exports = { RELEASE_FLOW };
@@ -1,10 +1,8 @@
1
- const { PREPARE_FLOW } = require('./prepare');
2
- const { RERUN_STEPS } = require('./steps/rerun');
3
- const { GET_RELEASE_CONFIG_STEP } = require('./steps/release-get-config');
1
+ import { PREPARE_FLOW } from './prepare.js';
2
+ import { RERUN_STEPS } from './steps/rerun.js';
3
+ import { SETUP_API_CLIENT_STEP } from './steps/release/get-config.js';
4
4
 
5
- const RERUN_FLOW = {
5
+ export const RERUN_FLOW = {
6
6
  name: 'rerun',
7
- steps: [PREPARE_FLOW, GET_RELEASE_CONFIG_STEP, ...RERUN_STEPS],
7
+ steps: [PREPARE_FLOW, SETUP_API_CLIENT_STEP, ...RERUN_STEPS],
8
8
  };
9
-
10
- module.exports = { RERUN_FLOW };
@@ -1,7 +1,7 @@
1
- const { loadJson } = require('../lib/json');
2
- const { Manifest } = require('../lib/manifest');
1
+ import { loadJson } from '../lib/json.js';
2
+ import { Manifest } from '../lib/manifest.js';
3
3
 
4
- const LOAD_APP_FILES_STEP = {
4
+ export const LOAD_APP_FILES_STEP = {
5
5
  message: "Loading Corva app's files...",
6
6
  async fn(context) {
7
7
  const manifest =
@@ -12,7 +12,3 @@ const LOAD_APP_FILES_STEP = {
12
12
  return { pkg, manifest };
13
13
  },
14
14
  };
15
-
16
- module.exports = {
17
- LOAD_APP_FILES_STEP,
18
- };
@@ -0,0 +1,11 @@
1
+
2
+ export const ADD_LABEL_STEP = {
3
+ message: 'Adding label...',
4
+ async fn({ options: { label }, api, appId, packageId }) {
5
+ if (!label) {
6
+ return;
7
+ }
8
+
9
+ await api.putLabel(appId, packageId, label);
10
+ }
11
+ }
@@ -0,0 +1,10 @@
1
+ export const ADD_NOTES_STEP = {
2
+ message: 'Adding notes...',
3
+ async fn({ api, appId, packageId, options: { notes } }) {
4
+ if (!notes) {
5
+ return;
6
+ }
7
+
8
+ await api.addNotes(appId, packageId, notes);
9
+ }
10
+ }
@@ -0,0 +1,37 @@
1
+ import { RELEASE } from '../../../constants/messages.js';
2
+ import { promises as fs } from 'node:fs';
3
+ import dotenv from 'dotenv';
4
+ import { resolve } from 'node:path';
5
+ import { StepError } from '../../lib/step-error.js';
6
+ import { Api } from '../../lib/api.js';
7
+
8
+ async function getVarsFromDotEnv({ dirName }) {
9
+ try {
10
+ const envFile = await fs.readFile(resolve(dirName, '.env'));
11
+ return dotenv.parse(envFile);
12
+ } catch (error) {
13
+ return {};
14
+ }
15
+ }
16
+
17
+ export const SETUP_API_CLIENT_STEP = {
18
+ message: RELEASE.getAuthToken,
19
+ fn: async ({ dirName, options: { apiKey, env } }) => {
20
+ const parsedEnv = await getVarsFromDotEnv({ dirName });
21
+
22
+ const CORVA_API_ENV = env || process.env.CORVA_API_ENV || parsedEnv.CORVA_API_ENV;
23
+ const AUTH_TOKEN = process.env.AUTH_TOKEN || parsedEnv.AUTH_TOKEN;
24
+ const API_KEY = apiKey || process.env.API_KEY || parsedEnv.API_KEY;
25
+
26
+ if (!AUTH_TOKEN && !API_KEY) {
27
+ throw new StepError(RELEASE.getAuthTokenError);
28
+ }
29
+
30
+ const api = new Api(CORVA_API_ENV, API_KEY, AUTH_TOKEN);
31
+
32
+ return {
33
+ CORVA_API_ENV: CORVA_API_ENV || 'qa',
34
+ api
35
+ };
36
+ },
37
+ };
@@ -0,0 +1,10 @@
1
+ export const RELEASE_PREPARE_DATA_STEP = {
2
+ message: 'Preparing data...',
3
+ async fn({ api, manifest }) {
4
+ const app = await api.getAppByKey(manifest.manifest.application.key.toLowerCase());
5
+
6
+ return {
7
+ appId: app.id,
8
+ }
9
+ }
10
+ }
@@ -0,0 +1,9 @@
1
+ export const PUBLISH_PACKAGE_STEP = {
2
+ message: 'Publishing app...',
3
+ /**
4
+ *
5
+ * @param {object} param0
6
+ * @param {import('../../lib/api').Api} param0.api
7
+ */
8
+ async fn({ api, appId, packageId }) { await api.publishApp(appId, packageId) }
9
+ }
@@ -0,0 +1,20 @@
1
+ import { resolve } from 'node:path'
2
+ import { unlink } from 'node:fs/promises'
3
+
4
+ export const REMOVE_FAILED_UPLOAD_STEP = {
5
+ message: 'Cleaning up...',
6
+ async fn({ api, appId, packageId, removeOnFail, uploadStatus, dirName, zipFileName }) {
7
+ if (uploadStatus === 'draft') {
8
+ await unlink(resolve(dirName, zipFileName));
9
+
10
+ return;
11
+ }
12
+
13
+ if (removeOnFail) {
14
+ await unlink(resolve(dirName, zipFileName));
15
+ await api.deleteAppUpload(appId, packageId);
16
+ }
17
+
18
+ throw new Error(`Got unexpected status '${uploadStatus}' while processing package ${packageId}.`);
19
+ }
20
+ }
@@ -0,0 +1,25 @@
1
+ import { RELEASE } from '../../../constants/messages.js';
2
+ import FormData from 'form-data';
3
+ import { resolve } from 'node:path';
4
+ import { createReadStream } from 'node:fs';
5
+ import { StepError } from '../../lib/step-error.js';
6
+ import _ from 'lodash/fp.js';
7
+
8
+ export const UPLOAD_ZIP_TO_CORVA_STEP = {
9
+ message: RELEASE.uploadApp,
10
+ /**
11
+ *
12
+ * @param {object} param0
13
+ * @param {import('../../lib/api').Api} param0.api
14
+ * @param {import('../../lib/manifest').Manifest} param0.manifest
15
+ */
16
+ fn: async ({ zipFileName, manifest, api, dirName }) => {
17
+ const form = new FormData();
18
+
19
+ form.append('package', createReadStream(resolve(dirName, zipFileName)), 'package.zip');
20
+
21
+ const { id: packageId, status: uploadStatus } = await api.uploadPackages(manifest.manifest.application.key, form)
22
+
23
+ return { packageId }
24
+ },
25
+ };
@@ -0,0 +1,29 @@
1
+ import Debug from 'debug';
2
+ import { waitForMs } from '../../lib/waitForMs.js';
3
+
4
+ const debug = Debug('cca:flow:release:step:wait-for-build');
5
+
6
+ const PROCESSING_STATUSES = ['pending', 'processing', 'queued', 'deploying'];
7
+
8
+ export const WAIT_FOR_BUILD_FINISH_STEP = {
9
+ message: 'Wait till the app will process to draft status...',
10
+ /**
11
+ * @param {object} param0
12
+ * @param {import('../../lib/api').Api} param0.api
13
+ */
14
+ async fn({ api, appId, packageId, progress }) {
15
+ do {
16
+ const { status } = await api.checkApp(appId, packageId);
17
+
18
+ progress()
19
+
20
+ debug(`Status: ${status}`);
21
+
22
+ if (!PROCESSING_STATUSES.includes(status)) {
23
+ return { uploadStatus: status };
24
+ }
25
+
26
+ await waitForMs(5000);
27
+ } while (true);
28
+ }
29
+ }
@@ -1,8 +1,15 @@
1
- const _ = require('lodash');
2
- const chalk = require('chalk');
1
+ import _ from 'lodash';
2
+ import chalk from 'chalk';
3
3
 
4
- const CREATE_TASK_STEP = {
4
+ import { logger } from '../../helpers/logger.js';
5
+
6
+ export const CREATE_TASK_STEP = {
5
7
  message: 'Creating tasks...',
8
+ /**
9
+ *
10
+ * @param {object} param0
11
+ * @param {import('../lib/api').Api} param0.api
12
+ */
6
13
  fn: async ({
7
14
  appId,
8
15
  assets,
@@ -14,38 +21,38 @@ const CREATE_TASK_STEP = {
14
21
  CORVA_API_ENV,
15
22
  }) => {
16
23
  if (!assets.length) {
17
- process.stdout.write(
24
+ logger.write(
18
25
  `\n\n${chalk.yellow.bold('There is not a asset ID to create new task')}`
19
26
  );
20
27
  }
21
28
 
22
29
  for (const assetId of assets) {
23
-
24
30
  try {
25
31
  const result = await api.queueAppRun(
26
32
  appId,
27
33
  version,
28
- mappedAssetsToWells.get(parseInt(assetId)),
34
+ assetId,
29
35
  appDatasetsNames,
30
36
  mappedAssetsToStreams.get(parseInt(assetId))
31
- );
32
-
33
- process.stdout.write(
37
+ ).catch(e => { console.log(e.response.body); throw e });
38
+
39
+ logger.write(
34
40
  `\n Created new task with ID ${chalk.yellow(result.id)} for asset ID - ${chalk.green(
35
41
  assetId
36
42
  )}`
37
43
  );
38
44
 
39
- process.stdout.write(
40
- `\n Task link - https://app${CORVA_API_ENV === 'production' ? '.' : `.${CORVA_API_ENV}.`}corva.ai/dev-center/apps/${appId}/runner`
45
+ logger.write(
46
+ `\n Task link - https://app${CORVA_API_ENV === 'production' ? '.' : `.${CORVA_API_ENV}.`
47
+ }corva.ai/dev-center/apps/${appId}/runner`
41
48
  );
42
49
  } catch (e) {
43
- process.stdout.write(
44
- `\n\n${chalk.red.underline.bold(`Could not rerun app for asset ID - ${assetId}, an error occured: ${e.message}`)}\n\n`
50
+ logger.write(
51
+ `\n\n${chalk.red.underline.bold(
52
+ `Could not rerun app for asset ID - ${assetId}, an error occured: ${e.message}`
53
+ )}\n\n`
45
54
  );
46
55
  }
47
56
  }
48
57
  },
49
58
  };
50
-
51
- module.exports = { CREATE_TASK_STEP };