@corva/create-app 0.38.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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@corva/create-app",
3
- "version": "0.38.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": [