@corva/create-app 0.37.0-0 → 0.38.0-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.
@@ -1,28 +1,82 @@
1
1
  const { APP_TYPES } = require("../constants/cli");
2
+ const debug = require('debug')('cca:resolve-app-runtime');
3
+ const { spawn } = require("child_process");
4
+ const { promises: fs } = require("fs");
5
+ const semver = require("semver");
6
+ const os = require("os");
7
+
8
+ const checkCliVersion = async (command, version, stdErr = false) => new Promise((resolve, reject) => {
9
+ const child = spawn(command, ['--version']);
10
+
11
+ let data;
12
+
13
+ child.stderr.once('data', buffer => {
14
+ data = buffer;
15
+ });
16
+
17
+ child.stdout.once('data', buffer => {
18
+ data = buffer;
19
+ });
20
+
21
+ child.once('close', code => {
22
+ if (code !== 0) {
23
+ debug(`Command ${command} exited with code ${code}`);
24
+ debug(data.toString());
25
+
26
+ return reject(false);
27
+ }
28
+
29
+ debug(`%s version output: %s`, command, data.toString());
30
+
31
+ resolve(semver.satisfies(semver.coerce(data.toString('utf-8')), version))
32
+ })
33
+ })
34
+
35
+ const checkNodeVersion = version => async () => {
36
+ try {
37
+ await fs.access(`${os.homedir()}/.nvm/nvm.sh`);
38
+
39
+ debug('nvm is installed');
40
+
41
+ return true;
42
+ } catch (e) {
43
+ debug(e);
44
+ debug('nvm is not installed, checking node version');
45
+
46
+ return checkCliVersion("node", version)
47
+ }
48
+ }
2
49
 
3
50
  const resolveAppRuntime = (opts) => {
4
51
  if (opts.appType === APP_TYPES.UI) {
52
+ const version = "16";
53
+
5
54
  return {
6
55
  language: opts.useTypescript ? "typescript" : "javascript",
56
+ isRuntimeAvailable: checkNodeVersion(version),
7
57
  packageManager: opts.packageManager,
8
- version: 16,
58
+ version
9
59
  }
10
60
  }
11
61
 
12
- if (opts.runtime.startsWith('node')) {
62
+ if (opts.runtime.startsWith("node")) {
13
63
  const version = /nodejs(\d{2})\.x/.exec(opts.runtime)[1];
14
64
 
15
65
  return {
16
66
  language: opts.useTypescript ? "typescript" : "javascript",
67
+ isRuntimeAvailable: checkNodeVersion(version),
17
68
  packageManager: opts.packageManager,
18
69
  version
19
70
  }
20
71
  }
21
72
 
73
+ const version = /python(\d\.\d)/.exec(opts.runtime)[1]
74
+
22
75
  return {
23
76
  language: "python",
24
- packageManager: 'pip',
25
- version: '3.8'
77
+ isRuntimeAvailable: () => checkCliVersion('python', version),
78
+ packageManager: "pip",
79
+ version
26
80
  }
27
81
  };
28
82
 
package/lib/index.js CHANGED
@@ -268,6 +268,10 @@ async function initPackage(projectName, opts) {
268
268
  const manifest = new Manifest(manifestHelpers.fillManifest(opts));
269
269
  const runtime = resolveAppRuntime(opts);
270
270
 
271
+ if (!await runtime.isRuntimeAvailable()) {
272
+ throw new Error(`Runtime "${opts.runtime}" is not available locally`);
273
+ }
274
+
271
275
  if (manifest.isUi()) {
272
276
  await ensureLatestVersion();
273
277
  }
@@ -441,7 +445,7 @@ function addPackageJSON(root, manifest, runtime) {
441
445
  scripts: defaults.scripts,
442
446
  dependencies: defaults.dependencies,
443
447
  devDependencies: defaults.devDependencies,
444
- ...(defaults.jest && {jest: defaults.jest})
448
+ ...(defaults.jest && { jest: defaults.jest })
445
449
  };
446
450
 
447
451
  return fs.writeJSON(path.join(root, 'package.json'), packageJson, writejsonOptions);
@@ -5,7 +5,11 @@ const inquirer = require('inquirer');
5
5
 
6
6
  const packageJson = require('../../../package.json');
7
7
  const npm = new NpmApi();
8
- const errorStyle = chalk.bold.red;
8
+
9
+ const error = chalk.bold.red;
10
+ const warning = chalk.hex('#FFA500'); // Orange
11
+ const code = chalk.cyan;
12
+ const asterisks = '****************************************************************';
9
13
 
10
14
  const getCurrentVersion = () => packageJson.version;
11
15
  const getLatestVersion = async () => npm.repo('@corva/create-app').prop('version');
@@ -17,23 +21,23 @@ async function ensureLatestVersion() {
17
21
 
18
22
  const isCurrentVersionOutdated = semver.gt(latestVersion, currentVersion);
19
23
  if (isCurrentVersionOutdated) {
20
- console.log(errorStyle('****************************************************************'));
21
- console.log(chalk`
24
+ console.log(error(asterisks));
25
+ console.log(error`
22
26
  Your version of the @corva/create-app is outdated.
23
27
  There is a new version available ({green.bold ${latestVersion}}).
24
28
  Please update the @corva/create-app with the following command:
25
29
 
26
- npm i -g @corva/create-app@latest
30
+ ${code('npm i -g @corva/create-app@latest')}
27
31
 
28
32
  `);
29
- console.log(errorStyle('****************************************************************'));
33
+ console.log(error(asterisks));
30
34
  process.exit(0);
31
35
  }
32
36
  }
33
37
 
34
38
  // NOTE: Show user-friendly warning if version is outdated
35
39
  async function warnIfOutdated() {
36
- process.stdout.write('Checking for updates...');
40
+ process.stdout.write('Checking for updates...\n');
37
41
 
38
42
  const currentVersion = getCurrentVersion();
39
43
  const latestVersion = await getLatestVersion();
@@ -41,15 +45,15 @@ async function warnIfOutdated() {
41
45
  const isCurrentVersionOutdated = semver.gt(latestVersion, currentVersion);
42
46
 
43
47
  if (isCurrentVersionOutdated) {
44
- console.log('****************************************************************');
45
- console.log(chalk`
48
+ console.log(warning(asterisks));
49
+ console.log(warning`
46
50
  There is a new version available ({green.bold ${latestVersion}}).
47
51
  You can update the CLI version with the following command:
48
52
 
49
- npm i -g @corva/create-app@latest
53
+ ${code`npm i -g @corva/create-app@latest`}
50
54
 
51
55
  `);
52
- console.log('****************************************************************');
56
+ console.log(warning(asterisks));
53
57
  } else {
54
58
  process.stdout.write(' ✅ \n');
55
59
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@corva/create-app",
3
- "version": "0.37.0-0",
3
+ "version": "0.38.0-1",
4
4
  "private": false,
5
5
  "description": "Create app to use it in CORVA.AI",
6
6
  "keywords": [