@corva/create-app 0.45.0-4 → 0.45.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.
@@ -48,7 +48,6 @@ export class Api {
48
48
  .json();
49
49
 
50
50
  const app = data.find((app) => app.attributes.app_key === appKey);
51
-
52
51
  if (!app) {
53
52
  throw new Error(`App with key - ${appKey}, not exist`);
54
53
  }
@@ -300,7 +299,6 @@ export class Api {
300
299
  console.log(`v2/apps/${appId}/packages/${id}`, {
301
300
  json: { package: { status: 'published' } },
302
301
  });
303
-
304
302
  const { data } = await this.#api
305
303
  .patch(`v2/apps/${appId}/packages/${id}`, {
306
304
  json: { package: { status: 'published' } },
@@ -324,7 +322,6 @@ export class Api {
324
322
  */
325
323
  async getAppPackages(appId) {
326
324
  const { data } = await this.#api.get(`v2/apps/${appId}/packages`).json();
327
-
328
325
  return data;
329
326
  }
330
327
 
@@ -91,7 +91,6 @@ export class Notification {
91
91
  */
92
92
  getStreamLink(title, streamId) {
93
93
  const streamUrl = `${this.#prefixUrl}/config/streams/${streamId}`;
94
-
95
94
  return this._createLink(title, streamUrl);
96
95
  }
97
96
 
@@ -107,7 +106,6 @@ export class Notification {
107
106
  */
108
107
  printStreamLink(title, streamId) {
109
108
  const link = this.getStreamLink(title, streamId);
110
-
111
109
  this.print(link);
112
110
  }
113
111
 
@@ -123,7 +121,6 @@ export class Notification {
123
121
  */
124
122
  getAssetLink(title, assetId) {
125
123
  const assetUrl = `${this.#prefixUrl}/assets/${assetId}`;
126
-
127
124
  return this._createLink(title, assetUrl);
128
125
  }
129
126
 
@@ -65,7 +65,6 @@ const getAssetsListWithPrompt = (assets, notification) => {
65
65
  const mapAssetsStreamsData = (assets, streamsData) => {
66
66
  return assets.map((asset) => {
67
67
  const currentStreams = streamsData.filter((stream) => stream.asset_id === parseInt(asset.id));
68
-
69
68
  return {
70
69
  assetId: asset.id,
71
70
  assetName: asset.attributes.name,
@@ -104,7 +103,6 @@ const getAssetsStreamsWithPrompt = async (mappedAssetsStreamsData, appId, notifi
104
103
 
105
104
  if (streamsWithoutCurrentApp.length === 1) {
106
105
  mappedData.selectedStreams = streamsWithoutCurrentApp;
107
-
108
106
  continue;
109
107
  }
110
108
 
@@ -9,7 +9,6 @@ import { Notification } from '../../lib/notification.js';
9
9
  async function getVarsFromDotEnv({ dirName }) {
10
10
  try {
11
11
  const envFile = await fs.readFile(resolve(dirName, '.env'));
12
-
13
12
  return dotenv.parse(envFile);
14
13
  } catch (error) {
15
14
  return {};
@@ -45,7 +45,6 @@ export const CREATE_TASK_STEP = {
45
45
  .queueAppRun(app.id, version, interval, wellId, appDatasetsNames, streamId)
46
46
  .catch((e) => {
47
47
  console.log(e.response.body);
48
-
49
48
  throw e;
50
49
  });
51
50
 
@@ -33,7 +33,6 @@ export const GET_APP_VERSION_TASK_STEP = {
33
33
  */
34
34
  const getAppVersion = async (appId, optionAppVersion, api) => {
35
35
  logger.write('\n Checking app versions...');
36
-
37
36
  const appPackages = await api.getAppPackages(appId);
38
37
 
39
38
  if (!appPackages.length) {
@@ -69,7 +69,6 @@ export const PREPARE_DATA_TASK_STEP = {
69
69
  */
70
70
  const promptAreYouSure = async () => {
71
71
  logger.log('\n');
72
-
73
72
  const answers = await inquirer.prompt([
74
73
  {
75
74
  message:
@@ -83,7 +82,6 @@ const promptAreYouSure = async () => {
83
82
  default: false,
84
83
  },
85
84
  ]);
86
-
87
85
  return answers.option;
88
86
  };
89
87
 
@@ -104,7 +104,6 @@ const getWellWithPrompt = async (wells, api) => {
104
104
  const [well] = choices;
105
105
 
106
106
  logger.write(`\n\n${chalk.black.underline.bold(`Process well - ${chalk.green(well.name)}`)}`);
107
-
108
107
  return well.value;
109
108
  }
110
109
 
@@ -144,7 +143,6 @@ const prepareWellAndStreamData = async (assets, api, manifest) => {
144
143
 
145
144
  const wells = await api.getWellByAssetId(assetId);
146
145
  const well = await getWellWithPrompt(wells, api);
147
-
148
146
  mappedAssetsToWells.set(well.attributes.asset_id, well);
149
147
 
150
148
  logger.write('\n Loading streams...');
@@ -166,7 +164,6 @@ const prepareWellAndStreamData = async (assets, api, manifest) => {
166
164
  assetsToDelete.push(assetId);
167
165
 
168
166
  if (mappedAssetsToWells.has(assetId)) mappedAssetsToWells.delete(assetId);
169
-
170
167
  if (mappedAssetsToStreams.has(assetId)) mappedAssetsToStreams.delete(assetId);
171
168
  }
172
169
  }
@@ -16,7 +16,6 @@ export function isInGitRepository(appPath) {
16
16
  return true;
17
17
  } catch (e) {
18
18
  debug(e);
19
-
20
19
  return false;
21
20
  }
22
21
  }
@@ -33,12 +32,10 @@ export function tryGitInit(appPath) {
33
32
 
34
33
  execSync('git init', { stdio: 'ignore', cwd: appPath });
35
34
  logger.log('Initialized git repo in app');
36
-
37
35
  return true;
38
36
  } catch (e) {
39
37
  debug(e);
40
38
  console.warn('Git repo not initialized');
41
-
42
39
  return false;
43
40
  }
44
41
  }
@@ -51,7 +48,6 @@ export function tryGitCommit(appPath) {
51
48
  cwd: appPath,
52
49
  });
53
50
  logger.log('Added first git commit');
54
-
55
51
  return true;
56
52
  } catch (e) {
57
53
  // We couldn't commit in already initialized git repo,
@@ -82,7 +78,6 @@ export function shouldUseYarn(appPath) {
82
78
  return true;
83
79
  } catch (e) {
84
80
  debug(e);
85
-
86
81
  return false;
87
82
  }
88
83
  }
package/lib/main.js CHANGED
@@ -1,45 +1,44 @@
1
- /* eslint-disable no-undef */
2
1
  import chalk from 'chalk';
3
- import { Command, CommanderError, Option } from 'commander';
4
2
  import figlet from 'figlet';
3
+ import { Command, CommanderError, Option } from 'commander';
5
4
  import fs from 'fs-extra';
6
5
  import inquirer from 'inquirer';
7
6
  import os from 'node:os';
8
7
  import path, { resolve } from 'node:path';
9
8
  import semver from 'semver';
10
9
 
11
- import * as manifestHelpers from './helpers/manifest.js';
10
+ import { ensureLatestVersion, warnIfOutdated, ensureBumpVersion } from './scripts/utils/version.js';
12
11
  import * as utils from './helpers/utils.js';
12
+ import * as manifestHelpers from './helpers/manifest.js';
13
13
  import * as versioning from './helpers/versioning.js';
14
- import { ensureBumpVersion, ensureLatestVersion, warnIfOutdated } from './scripts/utils/version.js';
15
14
 
16
- import * as manifestConstants from './constants/manifest.js';
17
15
  import { getDefaultsForPackageJson } from './constants/package.js';
16
+ import * as manifestConstants from './constants/manifest.js';
18
17
 
19
- import spawn from 'cross-spawn';
20
- import _ from 'lodash/fp.js';
21
- import { clear } from 'node:console';
22
- import { existsSync } from 'node:fs';
23
- import { fileURLToPath } from 'node:url';
24
18
  import packageJson from '../package.json' assert { type: 'json' };
19
+ import { clear } from 'node:console';
20
+ import spawn from 'cross-spawn';
21
+ import { runFlow } from './flow.js';
22
+ import { ERROR_ICON } from './constants/messages.js';
23
+ import { StepError } from './flows/lib/step-error.js';
24
+ import { RELEASE_FLOW } from './flows/release.js';
25
+ import { RERUN_FLOW } from './flows/rerun.js';
26
+ import { ATTACH_FLOW } from './flows/attach.js';
27
+ import { ZIP_FLOW } from './flows/zip.js';
25
28
  import {
26
- apiKeyOption,
27
- appVersion,
28
29
  bumpVersionOption,
30
+ apiKeyOption,
29
31
  envOption,
30
- originalCwdOption,
31
32
  silentOption,
33
+ appVersion,
34
+ originalCwdOption,
32
35
  } from './bump-version.option.js';
33
- import { ERROR_ICON } from './constants/messages.js';
34
- import { runFlow } from './flow.js';
35
- import { ATTACH_FLOW } from './flows/attach.js';
36
36
  import { Manifest } from './flows/lib/manifest.js';
37
- import { StepError } from './flows/lib/step-error.js';
38
- import { RELEASE_FLOW } from './flows/release.js';
39
- import { RERUN_FLOW } from './flows/rerun.js';
40
- import { ZIP_FLOW } from './flows/zip.js';
41
- import { logger } from './helpers/logger.js';
42
37
  import { IS_WINDOWS, resolveAppRuntime } from './helpers/resolve-app-runtime.js';
38
+ import { existsSync } from 'node:fs';
39
+ import { fileURLToPath } from 'node:url';
40
+ import { logger } from './helpers/logger.js';
41
+ import _ from 'lodash/fp.js';
43
42
 
44
43
  const __filename = fileURLToPath(import.meta.url);
45
44
  const __dirname = path.dirname(__filename);
@@ -59,7 +58,7 @@ const silencer =
59
58
  }
60
59
  };
61
60
 
62
- const getRealWorkingDir = (relativePath, options) => resolve(options.originalCwd, relativePath);
61
+ const getRealWorkingDir = (relativePath, options) => resolve(options.originalCwd, relativePath)
63
62
 
64
63
  function startingMessage() {
65
64
  clear();
@@ -71,19 +70,16 @@ function checkNodeVersion() {
71
70
  logger.write('Checking node version...');
72
71
 
73
72
  const unsupportedNodeVersion = !semver.satisfies(process.version, '>=16');
74
-
75
73
  if (unsupportedNodeVersion) {
76
74
  logger.log(
77
75
  chalk.red(
78
76
  `\nYou are using Node ${process.version}.\n\n` +
79
- `Please update to Node 16 or higher for a better, fully supported experience.\n`,
80
- ),
77
+ `Please update to Node 16 or higher for a better, fully supported experience.\n`
78
+ )
81
79
  );
82
-
83
80
  // Fall back to latest supported react-scripts on Node 4
84
81
  return process.exit(1);
85
82
  }
86
-
87
83
  logger.write(' ✅ \n');
88
84
  }
89
85
 
@@ -105,10 +101,10 @@ function checkOptions(opts) {
105
101
  };
106
102
  }
107
103
 
108
- // eslint-disable-next-line no-unused-vars
109
104
  const printDeprecationNotice = (param) =>
110
105
  console.warn(
111
- chalk.bgYellowBright`DEPRECATED OPTION: ${param}` + ` Use ${chalk.cyan(`create-corva-app ${param} .`)} instead`,
106
+ chalk.bgYellowBright`DEPRECATED OPTION: ${param}` +
107
+ ` Use ${chalk.cyan(`create-corva-app ${param} .`)} instead`
112
108
  );
113
109
 
114
110
  export async function run() {
@@ -131,7 +127,9 @@ export async function run() {
131
127
  manifestConstants.manifestOptions().forEach((value) => {
132
128
  const type = typeof value.default;
133
129
  const option = new Option(
134
- `${value.alias ? `-${value.alias}, ` : ''}--${value.name} [${(type !== 'undefined' && type) || 'string'}]`,
130
+ `${value.alias ? `-${value.alias}, ` : ''}--${value.name} [${
131
+ (type !== 'undefined' && type) || 'string'
132
+ }]`,
135
133
  value.message,
136
134
  );
137
135
 
@@ -139,7 +137,9 @@ export async function run() {
139
137
  if (typeof value.choices === 'function') {
140
138
  option.choices(value.choices());
141
139
  } else {
142
- option.choices(value.choices.map((choice) => `${typeof choice === 'object' ? choice.value : choice}`));
140
+ option.choices(
141
+ value.choices.map((choice) => `${typeof choice === 'object' ? choice.value : choice}`)
142
+ );
143
143
  }
144
144
  }
145
145
 
@@ -180,14 +180,10 @@ export async function run() {
180
180
  silencer(async (dirName, patterns, options) => {
181
181
  options.bumpVersion = await ensureBumpVersion(options.bumpVersion);
182
182
 
183
- console.log(getRealWorkingDir(dirName, options), options);
183
+ console.log(getRealWorkingDir(dirName, options), options)
184
184
 
185
- return runFlow(ZIP_FLOW, {
186
- dirName: getRealWorkingDir(dirName, options),
187
- patterns,
188
- options,
189
- }).then(_.get('zipFileName'));
190
- }),
185
+ return runFlow(ZIP_FLOW, { dirName: getRealWorkingDir(dirName, options), patterns, options }).then(_.get('zipFileName'));
186
+ })
191
187
  );
192
188
 
193
189
  program
@@ -202,20 +198,26 @@ export async function run() {
202
198
  .addOption(apiKeyOption)
203
199
  .addOption(originalCwdOption)
204
200
  .addOption(new Option('--notes [string]', 'Add custom notes to published app'))
205
- .addOption(new Option('--label [string]', 'Put a label on the release').choices(['BETA', 'PROD']))
206
- .addOption(new Option('--remove-on-fail [boolean]', 'Remove release if it fails during deployment').default(false))
207
201
  .addOption(
208
- new Option('--remove-on-success [boolean]', 'App package (.zip) will not be deleted after upload').default(true),
202
+ new Option('--label [string]', 'Put a label on the release').choices(['BETA', 'PROD'])
203
+ )
204
+ .addOption(
205
+ new Option(
206
+ '--remove-on-fail [boolean]',
207
+ 'Remove release if it fails during deployment'
208
+ ).default(false)
209
+ )
210
+ .addOption(
211
+ new Option(
212
+ '--remove-on-success [boolean]',
213
+ 'App package (.zip) will not be deleted after upload'
214
+ ).default(true)
209
215
  )
210
216
  // .addOption(new Option('--zip-file-name [string]', 'Prebuilt zip file name in dir'))
211
217
  .action(async (dirName, patterns, options) => {
212
218
  options.bumpVersion = await ensureBumpVersion(options.bumpVersion);
213
219
 
214
- await runFlow(RELEASE_FLOW, {
215
- dirName: getRealWorkingDir(dirName, options),
216
- patterns,
217
- options,
218
- });
220
+ await runFlow(RELEASE_FLOW, { dirName: getRealWorkingDir(dirName, options), patterns, options });
219
221
  });
220
222
 
221
223
  program
@@ -226,8 +228,7 @@ export async function run() {
226
228
  .addOption(envOption)
227
229
  .addOption(silentOption)
228
230
  .addOption(appVersion)
229
- .addOption(new Option('--assets [assets...]', 'Assets IDs list', []).conflicts('companyId'))
230
- .addOption(new Option('--company-id [number]', 'Company ID', []))
231
+ .addOption(new Option('--assets [assets...]', 'Assets ids list', []))
231
232
  .addOption(new Option('--interval [number]', 'Interval for scheduler apps (exp. 1200)'))
232
233
  .addOption(originalCwdOption)
233
234
  .action(async (dirName, options) => {
@@ -250,15 +251,15 @@ export async function run() {
250
251
  try {
251
252
  await program.parseAsync(process.argv);
252
253
  } catch (e) {
253
- handleError(program, e);
254
+ handleError(e);
254
255
 
255
256
  process.exit(1);
256
257
  }
257
258
  }
258
259
 
259
- const handleError = (program, e) => {
260
+ const handleError = (e) => {
260
261
  if (e instanceof CommanderError) {
261
- handleCommanderError(program, e);
262
+ handleCommanderError(e);
262
263
 
263
264
  return;
264
265
  }
@@ -275,7 +276,7 @@ const handleError = (program, e) => {
275
276
  e.cause && console.error(chalk.red(e.cause));
276
277
  };
277
278
 
278
- const handleCommanderError = (program, e) => {
279
+ const handleCommanderError = (e) => {
279
280
  switch (e.code) {
280
281
  case 'commander.missingArgument': {
281
282
  const match = /error:.*'(.*)'/.exec(e.message);
@@ -284,12 +285,16 @@ const handleCommanderError = (program, e) => {
284
285
  const commandName = program.args[0] || program._defaultCommandName;
285
286
 
286
287
  console.error('Please specify the project directory:');
287
- logger.log(` ${chalk.cyan(program.name())} ${commandName} ${chalk.green('<project-directory>')}`);
288
+ logger.log(
289
+ ` ${chalk.cyan(program.name())} ${commandName} ${chalk.green('<project-directory>')}`
290
+ );
288
291
  logger.log();
289
292
  logger.log('For example:');
290
293
  logger.log(` ${chalk.cyan(program.name())} ${commandName} ${chalk.green('my-react-app')}`);
291
294
  logger.log();
292
- logger.log(`Run ${chalk.cyan(`${program.name()} help ${commandName}`)} to see all options.`);
295
+ logger.log(
296
+ `Run ${chalk.cyan(`${program.name()} help ${commandName}`)} to see all options.`
297
+ );
293
298
  } else {
294
299
  console.error('❌', e.message);
295
300
  }
@@ -334,8 +339,8 @@ async function initPackage(projectName, opts) {
334
339
  if (!(await runtime.isRuntimeAvailable())) {
335
340
  throw new Error(
336
341
  `Runtime "${opts.runtime}" is not available locally. Please proceed to ${chalk.green(
337
- getEnvManagementLink(manifest),
338
- )} to install it locally.`,
342
+ getEnvManagementLink(manifest)
343
+ )} to install it locally.`
339
344
  );
340
345
  }
341
346
 
@@ -347,26 +352,10 @@ async function initPackage(projectName, opts) {
347
352
 
348
353
  logger.log(`Creating a new Corva app in ${chalk.green(root)}.`);
349
354
 
350
- await fs.ensureDir(root);
351
-
352
- if ((await fs.readdir(root)).length) {
353
- const shouldCleanup = await inquirer
354
- .prompt([
355
- {
356
- message: `Directory "${root}" is not empty. Clean it to proceed?`,
357
- name: 'cleanup',
358
- type: 'confirm',
359
- },
360
- ])
361
- .then(_.get('cleanup'));
362
-
363
- if (shouldCleanup) {
364
- await fs.emptyDir(root);
365
- } else {
366
- throw new Error(`Directory is not empty: ${root}`);
367
- }
355
+ if (fs.existsSync(root)) {
356
+ throw new Error(`Directory already exists: ${root}`);
368
357
  }
369
-
358
+ await fs.mkdir(root);
370
359
  await fs.writeJSON(path.join(root, 'manifest.json'), manifest.manifest, writejsonOptions);
371
360
 
372
361
  await addTemplate(root, manifest, runtime);
@@ -404,7 +393,13 @@ async function addTemplate(root, manifest, runtime) {
404
393
  logger.log(chalk.green('Copying app template...'));
405
394
  logger.log();
406
395
 
407
- const templateFolder = path.resolve(__dirname, '..', 'templates', runtime.language, manifest.type);
396
+ const templateFolder = path.resolve(
397
+ __dirname,
398
+ '..',
399
+ 'templates',
400
+ runtime.language,
401
+ manifest.type
402
+ );
408
403
 
409
404
  utils.copyFolderRecursiveSync(templateFolder, root);
410
405
 
@@ -467,7 +462,7 @@ const addTsConfigs = (root, manifest, runtime) => {
467
462
  inlineSourceMap: true,
468
463
  },
469
464
  },
470
- writejsonOptions,
465
+ writejsonOptions
471
466
  ),
472
467
  fs.writeJson(
473
468
  path.resolve(root, 'tsconfig.build.json'),
@@ -476,7 +471,7 @@ const addTsConfigs = (root, manifest, runtime) => {
476
471
  include: ['lib/**/*.ts', 'index.ts'],
477
472
  exclude: ['node_modules', '**/*.spec.ts'],
478
473
  },
479
- writejsonOptions,
474
+ writejsonOptions
480
475
  ),
481
476
  ]);
482
477
  };
@@ -488,7 +483,13 @@ function patchSchedulerForPython(root, manifest, runtime) {
488
483
  return;
489
484
  }
490
485
 
491
- const templateFolder = path.resolve(__dirname, '..', 'templates', runtime.language, manifest.type);
486
+ const templateFolder = path.resolve(
487
+ __dirname,
488
+ '..',
489
+ 'templates',
490
+ runtime.language,
491
+ manifest.type
492
+ );
492
493
  const originalType = 'ScheduledDataTimeEvent';
493
494
  const replacementType =
494
495
  schedulerType === manifestConstants.SCHEDULER_TYPE_DEPTH.value
@@ -543,7 +544,6 @@ async function installApp(root, manifest, runtime) {
543
544
  }
544
545
 
545
546
  logger.log(chalk.yellow(`Installing template dependencies using ${runtime.packageManager}...`));
546
-
547
547
  const proc =
548
548
  manifest.isJs() && existsSync(`${os.homedir()}/.nvm/nvm.sh`)
549
549
  ? spawn.sync(`\\. ${os.homedir()}/.nvm/nvm.sh && nvm i && ${command} ${args.join(' ')}`, {
@@ -559,13 +559,11 @@ async function installApp(root, manifest, runtime) {
559
559
  // NOTE: filter out warnings caused by @corva/ui peer dependencies
560
560
  .filter((line) => !line.includes('@corva/ui'))
561
561
  .join('\n');
562
-
563
562
  console.log(error);
564
563
  }
565
564
 
566
565
  if (proc.status !== 0) {
567
566
  console.error(`\`${command} ${args.join(' ')}\` failed`);
568
-
569
567
  return;
570
568
  }
571
569
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@corva/create-app",
3
- "version": "0.45.0-4",
3
+ "version": "0.45.0",
4
4
  "private": false,
5
5
  "description": "Create an app to use it in CORVA.AI",
6
6
  "keywords": [
@@ -0,0 +1 @@
1
+ module.exports = { extends: '@corva/eslint-config-node' };
@@ -0,0 +1 @@
1
+ "@corva/eslint-config-node/prettier"
@@ -0,0 +1 @@
1
+ module.exports = { extends: '@corva/eslint-config-node' };
@@ -0,0 +1 @@
1
+ "@corva/eslint-config-node/prettier"
@@ -0,0 +1 @@
1
+ module.exports = { extends: '@corva/eslint-config-node' };
@@ -0,0 +1 @@
1
+ "@corva/eslint-config-node/prettier"
@@ -0,0 +1 @@
1
+ "@corva/eslint-config-node/prettier"
@@ -0,0 +1 @@
1
+ "@corva/eslint-config-node/prettier"
@@ -0,0 +1 @@
1
+ "@corva/eslint-config-node/prettier"