@corva/create-app 0.43.0-3 → 0.43.0-rc.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.
@@ -4,12 +4,21 @@ const { sync: spawnSync } = require('cross-spawn');
4
4
  const { resolve } = require('path');
5
5
 
6
6
  const cmd = 'node';
7
+ const originalCwd = process.cwd()
8
+
9
+ process.chdir(__dirname)
10
+
11
+ const preparedOriginalArgs = process.argv.slice(2)
12
+ // after changing the cwd need to pass the original path
13
+ .concat(['--original-cwd', originalCwd])
14
+ // leave spaces in place for arguments
15
+ .map(a => a.includes(" ") ? `"${a}"` : a);
16
+
7
17
  const args = [
8
18
  '--no-warnings',
9
19
  '--experimental-json-modules',
10
- resolve(__dirname, 'cca.js'),
11
- ...process.argv.slice(2),
12
- ];
20
+ 'cca.js',
21
+ ].concat(preparedOriginalArgs);
13
22
 
14
23
  const { signal, status, error } = spawnSync(cmd, args, {
15
24
  stdio: 'inherit',
@@ -37,6 +37,8 @@ export const silentOption = new Option(
37
37
  'Only log result of the operation'
38
38
  ).default(false);
39
39
 
40
+ export const originalCwdOption = (new Option('--original-cwd <string>')).hideHelp();
41
+
40
42
  export const bumpVersionOptionDeprecated = new Option(
41
43
  flags,
42
44
  chalk.bgYellow`DEPRECATED` +
@@ -50,6 +50,8 @@ const checkNodeVersion = (version) => async () => {
50
50
  }
51
51
  };
52
52
 
53
+ export const IS_WINDOWS = process.platform === 'win32';
54
+
53
55
  export const resolveAppRuntime = (opts) => {
54
56
  if (opts.appType === APP_TYPES.UI) {
55
57
  const version = '16';
@@ -77,7 +79,8 @@ export const resolveAppRuntime = (opts) => {
77
79
 
78
80
  return {
79
81
  language: 'python',
80
- isRuntimeAvailable: () => checkCliVersion('python3', version),
82
+ isRuntimeAvailable: async () =>
83
+ IS_WINDOWS ? await checkCliVersion('python', version) || await checkCliVersion('python3', version) : checkCliVersion('python3', version),
81
84
  packageManager: 'pip',
82
85
  version,
83
86
  };
@@ -1,5 +1,8 @@
1
1
  import { execSync } from 'node:child_process';
2
2
  import { logger } from './logger.js';
3
+ import Debug from 'debug';
4
+
5
+ const debug = Debug('cca:versioning');
3
6
 
4
7
  export function isInGitRepository(appPath) {
5
8
  try {
@@ -9,6 +12,7 @@ export function isInGitRepository(appPath) {
9
12
  });
10
13
  return true;
11
14
  } catch (e) {
15
+ debug(e);
12
16
  return false;
13
17
  }
14
18
  }
@@ -16,6 +20,8 @@ export function isInGitRepository(appPath) {
16
20
  export function tryGitInit(appPath) {
17
21
  try {
18
22
  if (isInGitRepository()) {
23
+ debug('is in git repository');
24
+
19
25
  return false;
20
26
  }
21
27
  execSync('git --version', { stdio: 'ignore', cwd: appPath });
@@ -24,7 +30,8 @@ export function tryGitInit(appPath) {
24
30
  logger.log('Initialized git repo in app');
25
31
  return true;
26
32
  } catch (e) {
27
- console.warn('Git repo not initialized', e);
33
+ debug(e);
34
+ console.warn('Git repo not initialized');
28
35
  return false;
29
36
  }
30
37
  }
@@ -44,12 +51,14 @@ export function tryGitCommit(appPath) {
44
51
  // In the future, we might supply our own committer
45
52
  // like Ember CLI does, but for now, let's just
46
53
  // remove the Git files to avoid a half-done state.
47
- console.warn('Git commit not created', e);
54
+ debug(e);
55
+ console.warn('Git commit not created');
48
56
  console.warn('Removing .git directory...');
49
57
  try {
50
58
  // unlinkSync() doesn't work on directories.
51
59
  fs.removeSync(path.join(appPath, '.git'));
52
60
  } catch (removeErr) {
61
+ debug(removeErr);
53
62
  // Ignore.
54
63
  }
55
64
  return false;
@@ -61,6 +70,7 @@ export function shouldUseYarn(appPath) {
61
70
  execSync('yarnpkg --version', { stdio: 'ignore', cwd: appPath });
62
71
  return true;
63
72
  } catch (e) {
73
+ debug(e);
64
74
  return false;
65
75
  }
66
76
  }
package/lib/main.js CHANGED
@@ -4,7 +4,7 @@ import { Command, CommanderError, Option } from 'commander';
4
4
  import fs from 'fs-extra';
5
5
  import inquirer from 'inquirer';
6
6
  import os from 'node:os';
7
- import path from 'node:path';
7
+ import path, { resolve } from 'node:path';
8
8
  import semver from 'semver';
9
9
 
10
10
  import { ensureLatestVersion, warnIfOutdated, ensureBumpVersion } from './scripts/utils/version.js';
@@ -31,9 +31,10 @@ import {
31
31
  envOption,
32
32
  silentOption,
33
33
  appVersion,
34
+ originalCwdOption,
34
35
  } from './bump-version.option.js';
35
36
  import { Manifest } from './flows/lib/manifest.js';
36
- import { resolveAppRuntime } from './helpers/resolve-app-runtime.js';
37
+ import { IS_WINDOWS, resolveAppRuntime } from './helpers/resolve-app-runtime.js';
37
38
  import { existsSync } from 'node:fs';
38
39
  import { fileURLToPath } from 'node:url';
39
40
  import { logger } from './helpers/logger.js';
@@ -57,6 +58,8 @@ const silencer =
57
58
  }
58
59
  };
59
60
 
61
+ const getRealWorkingDir = (relativePath, options) => resolve(options.originalCwd, relativePath)
62
+
60
63
  function startingMessage() {
61
64
  clear();
62
65
  console.log(chalk.green(' Welcome to apps generator for:'));
@@ -105,7 +108,7 @@ const printDeprecationNotice = (param) =>
105
108
  );
106
109
 
107
110
  export async function run() {
108
- const program = new Command()
111
+ const program = new Command('create-corva-app')
109
112
  .hook('preAction', async () => {
110
113
  checkNodeVersion();
111
114
 
@@ -117,7 +120,8 @@ export async function run() {
117
120
  const createCommand = program
118
121
  .command('create', { isDefault: true })
119
122
  .description('Create a new app')
120
- .argument('[project-directory]', 'project directory to work with', process.cwd())
123
+ .argument('[project-directory]', 'project directory to work with', process.argv[process.argv.length - 1])
124
+ .addOption(originalCwdOption)
121
125
  .usage(`${chalk.green('<project-directory>')} [options]`);
122
126
 
123
127
  manifestConstants.manifestOptions().forEach((value) => {
@@ -170,12 +174,15 @@ export async function run() {
170
174
  .argument('[patterns...]', 'Additional patterns to zip', [])
171
175
  .addOption(bumpVersionOption)
172
176
  .addOption(new Option('--ignored-files [ignoredFiles...]', 'Patterns to skip zip', []))
177
+ .addOption(originalCwdOption)
173
178
  .addOption(silentOption)
174
179
  .action(
175
180
  silencer(async (dirName, patterns, options) => {
176
181
  options.bumpVersion = await ensureBumpVersion(options.bumpVersion);
177
182
 
178
- return runFlow(ZIP_FLOW, { dirName, patterns, options }).then(_.get('zipFileName'));
183
+ console.log(getRealWorkingDir(dirName, options), options)
184
+
185
+ return runFlow(ZIP_FLOW, { dirName: getRealWorkingDir(dirName, options), patterns, options }).then(_.get('zipFileName'));
179
186
  })
180
187
  );
181
188
 
@@ -189,6 +196,7 @@ export async function run() {
189
196
  .addOption(silentOption)
190
197
  .addOption(envOption)
191
198
  .addOption(apiKeyOption)
199
+ .addOption(originalCwdOption)
192
200
  .addOption(new Option('--notes [string]', 'Add custom notes to published app'))
193
201
  .addOption(
194
202
  new Option('--label [string]', 'Put a label on the release').choices(['BETA', 'PROD'])
@@ -209,7 +217,7 @@ export async function run() {
209
217
  .action(async (dirName, patterns, options) => {
210
218
  options.bumpVersion = await ensureBumpVersion(options.bumpVersion);
211
219
 
212
- await runFlow(RELEASE_FLOW, { dirName, patterns, options });
220
+ await runFlow(RELEASE_FLOW, { dirName: getRealWorkingDir(dirName, options), patterns, options });
213
221
  });
214
222
 
215
223
  program
@@ -222,8 +230,9 @@ export async function run() {
222
230
  .addOption(appVersion)
223
231
  .addOption(new Option('--assets [assets...]', 'Assets ids list', []))
224
232
  .addOption(new Option('--interval [number]', 'Interval for scheduler apps (exp. 1200)'))
233
+ .addOption(originalCwdOption)
225
234
  .action(async (dirName, options) => {
226
- await runFlow(RERUN_FLOW, { dirName, options });
235
+ await runFlow(RERUN_FLOW, { dirName: getRealWorkingDir(dirName, options), options });
227
236
  });
228
237
 
229
238
  program
@@ -234,8 +243,9 @@ export async function run() {
234
243
  .addOption(envOption)
235
244
  .addOption(silentOption)
236
245
  .addOption(appVersion)
246
+ .addOption(originalCwdOption)
237
247
  .action(async (dirName, options) => {
238
- await runFlow(ATTACH_FLOW, { dirName, options });
248
+ await runFlow(ATTACH_FLOW, { dirName: getRealWorkingDir(dirName, options), options });
239
249
  });
240
250
 
241
251
  try {
@@ -307,17 +317,15 @@ const handleCommanderError = (e) => {
307
317
  * @param {import('./flows/lib/manifest').Manifest} manifest
308
318
  */
309
319
  const getEnvManagementLink = (manifest) => {
310
- const isWindows = process.platform === 'win32';
311
-
312
320
  if (manifest.isJs()) {
313
- if (isWindows) {
321
+ if (IS_WINDOWS) {
314
322
  return 'https://github.com/coreybutler/nvm-windows';
315
323
  }
316
324
 
317
325
  return 'https://github.com/nvm-sh/nvm';
318
326
  }
319
327
 
320
- if (isWindows) {
328
+ if (IS_WINDOWS) {
321
329
  return 'https://github.com/pyenv-win/pyenv-win';
322
330
  }
323
331
 
@@ -340,7 +348,7 @@ async function initPackage(projectName, opts) {
340
348
  await ensureLatestVersion();
341
349
  }
342
350
 
343
- const root = path.resolve(projectName);
351
+ const root = getRealWorkingDir(projectName, opts);
344
352
 
345
353
  logger.log(`Creating a new Corva app in ${chalk.green(root)}.`);
346
354
 
@@ -526,38 +534,44 @@ function addPackageJSON(root, manifest, runtime) {
526
534
  */
527
535
  async function installApp(root, manifest, runtime) {
528
536
  const command = manifest.isJs() ? runtime.packageManager : 'make';
529
- const args = ['install'];
530
- const opts = { stdio: ['inherit', 'inherit', 'pipe'], cwd: root };
531
537
 
532
- if (process.env.CI && command === 'yarn') {
533
- args.push('--cache-folder=".yarn-cache"');
534
- }
538
+ if (!IS_WINDOWS || manifest.isJs()) {
539
+ const args = ['install'];
540
+ const opts = { stdio: ['inherit', 'inherit', 'pipe'], cwd: root };
535
541
 
536
- logger.log(chalk.yellow(`Installing template dependencies using ${runtime.packageManager}...`));
537
- const proc =
538
- manifest.isJs() && existsSync(`${os.homedir()}/.nvm/nvm.sh`)
539
- ? spawn.sync(`\\. ${os.homedir()}/.nvm/nvm.sh && nvm i && ${command} ${args.join(' ')}`, {
540
- shell: true,
541
- ...opts,
542
- })
543
- : spawn.sync(command, args, opts);
544
-
545
- if (proc.stderr) {
546
- const error = proc.stderr
547
- .toString('utf8')
548
- .split('\n')
549
- // NOTE: filter out warnings caused by @corva/ui peer dependencies
550
- .filter((line) => !line.includes('@corva/ui'))
551
- .join('\n');
552
- console.log(error);
553
- }
542
+ if (process.env.CI && command === 'yarn') {
543
+ args.push('--cache-folder=".yarn-cache"');
544
+ }
554
545
 
555
- if (proc.status !== 0) {
556
- console.error(`\`${command} ${args.join(' ')}\` failed`);
557
- return;
558
- }
546
+ logger.log(chalk.yellow(`Installing template dependencies using ${runtime.packageManager}...`));
547
+ const proc =
548
+ manifest.isJs() && existsSync(`${os.homedir()}/.nvm/nvm.sh`)
549
+ ? spawn.sync(`\\. ${os.homedir()}/.nvm/nvm.sh && nvm i && ${command} ${args.join(' ')}`, {
550
+ shell: true,
551
+ ...opts,
552
+ })
553
+ : spawn.sync(command, args, opts);
554
+
555
+ if (proc.stderr) {
556
+ const error = proc.stderr
557
+ .toString('utf8')
558
+ .split('\n')
559
+ // NOTE: filter out warnings caused by @corva/ui peer dependencies
560
+ .filter((line) => !line.includes('@corva/ui'))
561
+ .join('\n');
562
+ console.log(error);
563
+ }
564
+
565
+ if (proc.status !== 0) {
566
+ console.error(`\`${command} ${args.join(' ')}\` failed`);
567
+ return;
568
+ }
559
569
 
560
- logger.log(chalk.green('Successfull project install'));
570
+ logger.log(chalk.green('Successfull project install'));
571
+ } else {
572
+ logger.log();
573
+ logger.log(`⚠️ ${chalk.yellow('Please install project dependencies manually')}`);
574
+ }
561
575
 
562
576
  if (versioning.tryGitInit(root)) {
563
577
  logger.log();
@@ -570,7 +584,7 @@ async function installApp(root, manifest, runtime) {
570
584
  }
571
585
 
572
586
  logger.log();
573
- logger.log(`Success! Created ${manifest.name} at ${root}`);
587
+ logger.log(`Success! Created ${chalk.green(manifest.name)} at ${chalk.yellow(root)}`);
574
588
 
575
589
  helpCommands(manifest, runtime);
576
590
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@corva/create-app",
3
- "version": "0.43.0-3",
3
+ "version": "0.43.0-rc.0",
4
4
  "private": false,
5
5
  "description": "Create an app to use it in CORVA.AI",
6
6
  "keywords": [