@corva/create-app 0.59.0-rc.0 → 0.59.0-rc.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.
@@ -23,7 +23,7 @@ import { getRealWorkingDir } from '../helpers/commands.js';
23
23
  import { Manifest } from '../flows/lib/manifest.js';
24
24
  import { fillManifest } from '../helpers/manifest.js';
25
25
  import { getManifestMandatoryKeys, manifestOptions } from '../constants/manifest.js';
26
- import { ERROR_ICON } from '../constants/messages.js';
26
+ import { StepError } from '../flows/lib/step-error.js';
27
27
 
28
28
  const __filename = fileURLToPath(import.meta.url);
29
29
  const __dirname = dirname(__filename);
@@ -36,12 +36,7 @@ const WRITE_TO_JSON_OPTS = {
36
36
  export const createCommand = new Command('create')
37
37
  .description('Create a new app')
38
38
  .argument('[project-directory]', 'project directory to work with', process.argv[process.argv.length - 1])
39
- .addOption(originalCwdOption)
40
- .showHelpAfterError()
41
- .showSuggestionAfterError(true)
42
- .configureOutput({
43
- outputError: (str, write) => write(chalk.red(`${ERROR_ICON} ${str}`)),
44
- });
39
+ .addOption(originalCwdOption);
45
40
 
46
41
  manifestOptions().forEach((value) => {
47
42
  const type = value.commaSeparated ? 'string' : typeof value.default;
@@ -99,7 +94,7 @@ const getEnvManagementLink = (manifest) => {
99
94
  }
100
95
 
101
96
  if (IS_WINDOWS) {
102
- return 'https://github.com/pyenv-win/pyenv-win';
97
+ return 'https://docs.python.org/3/using/windows.html#using-python-on-windows';
103
98
  }
104
99
 
105
100
  return 'https://github.com/pyenv/pyenv';
@@ -110,7 +105,7 @@ async function initPackage(projectName, opts) {
110
105
  const runtime = resolveAppRuntime(opts);
111
106
 
112
107
  if (!(await runtime.isRuntimeAvailable())) {
113
- throw new Error(
108
+ throw new StepError(
114
109
  `Runtime "${opts.runtime}" is not available locally. Please proceed to ${chalk.green(
115
110
  getEnvManagementLink(manifest),
116
111
  )} to install it locally.`,
@@ -141,7 +136,7 @@ async function initPackage(projectName, opts) {
141
136
  if (shouldCleanup) {
142
137
  await fs.emptyDir(root);
143
138
  } else {
144
- throw new Error(`Directory is not empty: ${root}`);
139
+ throw new StepError(`Directory is not empty: ${root}`);
145
140
  }
146
141
  }
147
142
 
package/lib/flow.js CHANGED
@@ -21,7 +21,7 @@ export const runFlow = async (flow, context, indent = '') => {
21
21
 
22
22
  return result;
23
23
  } catch (error) {
24
- logger.write(`\n${indent}${chalk.red('Error:')} ${error.message}\n`);
24
+ logger.write(`\n`);
25
25
 
26
26
  throw error;
27
27
  }
@@ -50,7 +50,7 @@ export class Api {
50
50
  const app = data.find((app) => app.attributes.app_key === appKey);
51
51
 
52
52
  if (!app) {
53
- throw new Error(
53
+ throw new StepError(
54
54
  `App with key - ${appKey}, does not exist.\nThe key search is case-sensitive. You might need to update the app key in your app to exactly match the key.`,
55
55
  );
56
56
  }
@@ -155,7 +155,7 @@ export class Api {
155
155
  .json();
156
156
 
157
157
  if (!wells || !wells.length) {
158
- throw new Error(`Could not found wells by asset ID - ${assetId}`);
158
+ throw new StepError(`Could not found wells by asset ID - ${assetId}`);
159
159
  }
160
160
 
161
161
  return wells;
@@ -3,6 +3,7 @@ import os from 'node:os';
3
3
  import { resolve } from 'node:path';
4
4
 
5
5
  import debugFn from 'debug';
6
+ import { StepError } from './step-error.js';
6
7
 
7
8
  const debug = debugFn('cca:json');
8
9
 
@@ -17,7 +18,7 @@ export const loadJson = async (dirName, fileName) => {
17
18
  return JSON.parse(manifest);
18
19
  } catch (e) {
19
20
  if (e.code === 'ENOENT') {
20
- throw new Error(`${fileName} was not found in ${resolve(dirName)}`);
21
+ throw new StepError(`${fileName} was not found in ${resolve(dirName)}`, { cause: e });
21
22
  }
22
23
 
23
24
  throw e;
@@ -1,5 +1,6 @@
1
1
  import { resolve } from 'node:path';
2
2
  import { unlink } from 'node:fs/promises';
3
+ import { StepError } from '../../lib/step-error.js';
3
4
 
4
5
  export const REMOVE_FAILED_UPLOAD_STEP = {
5
6
  message: 'Cleaning up...',
@@ -15,6 +16,6 @@ export const REMOVE_FAILED_UPLOAD_STEP = {
15
16
  await api.deleteAppUpload(appId, packageId);
16
17
  }
17
18
 
18
- throw new Error(`Got unexpected status '${uploadStatus}' while processing package ${packageId}.`);
19
+ throw new StepError(`Got unexpected status '${uploadStatus}' while processing package ${packageId}.`);
19
20
  },
20
21
  };
@@ -2,6 +2,7 @@ import chalk from 'chalk';
2
2
  import inquirer from 'inquirer';
3
3
 
4
4
  import { logger } from '../../../helpers/logger.js';
5
+ import { StepError } from '../../lib/step-error.js';
5
6
 
6
7
  export const GET_APP_VERSION_TASK_STEP = {
7
8
  message: 'Get app version...',
@@ -37,7 +38,7 @@ const getAppVersion = async (appId, optionAppVersion, api) => {
37
38
  const appPackages = await api.getAppPackages(appId);
38
39
 
39
40
  if (!appPackages.length) {
40
- throw new Error('No app versions found');
41
+ throw new StepError('No app versions found');
41
42
  }
42
43
 
43
44
  const confirmUseVersionMessage = (version) => {
@@ -35,7 +35,7 @@ export const FILE_LIST_RESOLVE_STEP = {
35
35
  return resolveDataForZipPythonApp(files, context);
36
36
  }
37
37
 
38
- throw new Error(`Unsupported runtime: ${manifest.runtime}`);
38
+ throw new StepError(`Unsupported runtime: ${manifest.runtime}`);
39
39
  },
40
40
  };
41
41
 
@@ -8,7 +8,13 @@ import { promises as fs } from 'fs';
8
8
  import os from 'os';
9
9
  import semver from 'semver';
10
10
 
11
- const checkCliVersion = async (command, version, stdErr = false) =>
11
+ /**
12
+ *
13
+ * @param {string} command
14
+ * @param {string} version
15
+ * @returns {Promise<boolean>}
16
+ */
17
+ const checkCliVersion = async (command, version) =>
12
18
  new Promise((resolve) => {
13
19
  const child = spawn(command, ['--version']);
14
20
 
@@ -103,10 +109,18 @@ export const resolveAppRuntime = (opts) => {
103
109
 
104
110
  return {
105
111
  language: 'python',
106
- isRuntimeAvailable: async () =>
107
- IS_WINDOWS
108
- ? (await checkCliVersion('python', version)) || (await checkCliVersion('python3', version))
109
- : checkCliVersion('python3', version),
112
+ isRuntimeAvailable: async () => {
113
+ if (!IS_WINDOWS) {
114
+ return checkCliVersion(`python${version}`, version);
115
+ }
116
+
117
+ return (
118
+ (await checkCliVersion(`py -${version}`, version)) ||
119
+ (await checkCliVersion('python', version)) ||
120
+ (await checkCliVersion('python3', version))
121
+ );
122
+ },
123
+
110
124
  packageManager: 'pip',
111
125
  version,
112
126
  semver: semverVersionsMapping.python[version],
package/lib/main.js CHANGED
@@ -12,6 +12,10 @@ import { attachCommand } from './commands/attach.js';
12
12
  import { createCommand } from './commands/create.js';
13
13
 
14
14
  import { ERROR_ICON } from './constants/messages.js';
15
+ import { StepError } from './flows/lib/step-error.js';
16
+ import debugFn from 'debug';
17
+
18
+ const debug = debugFn('cca:main');
15
19
 
16
20
  function checkNodeVersion() {
17
21
  logger.write('Checking node version...');
@@ -46,14 +50,19 @@ export async function run() {
46
50
  .addCommand(rerunCommand)
47
51
  .addCommand(attachCommand)
48
52
  .showHelpAfterError()
49
- .showSuggestionAfterError(true)
50
- .configureOutput({
51
- outputError: (str, write) => write(chalk.red(`${ERROR_ICON} ${str}`)),
52
- });
53
+ .showSuggestionAfterError(true);
53
54
 
54
55
  try {
55
56
  await program.parseAsync(process.argv);
56
57
  } catch (e) {
58
+ if (e instanceof StepError) {
59
+ console.error(chalk.red(`${ERROR_ICON} ${e.message}`));
60
+ } else {
61
+ debug(e);
62
+
63
+ console.error(chalk.red(`${ERROR_ICON} Unknown error occured, please contact support`));
64
+ }
65
+
57
66
  process.exit(1);
58
67
  }
59
68
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@corva/create-app",
3
- "version": "0.59.0-rc.0",
3
+ "version": "0.59.0-rc.1",
4
4
  "private": false,
5
5
  "description": "Create an app to use it in CORVA.AI",
6
6
  "keywords": [