@corva/create-app 0.44.0-1 → 0.44.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.
Files changed (43) hide show
  1. package/bin/create-corva-app.cjs +8 -11
  2. package/lib/bump-version.option.js +10 -17
  3. package/lib/constants/manifest.js +29 -10
  4. package/lib/constants/package.js +8 -4
  5. package/lib/flow.js +4 -6
  6. package/lib/flows/lib/api.js +14 -14
  7. package/lib/flows/lib/create-zip-archive.js +10 -4
  8. package/lib/flows/lib/json.js +4 -3
  9. package/lib/flows/lib/notification.js +3 -0
  10. package/lib/flows/steps/attach/add-app-to-stream.js +4 -5
  11. package/lib/flows/steps/attach/get-all-live-assets.js +7 -14
  12. package/lib/flows/steps/attach/index.js +1 -5
  13. package/lib/flows/steps/attach/prepare-data.js +0 -1
  14. package/lib/flows/steps/prepare-load-app-files.js +2 -4
  15. package/lib/flows/steps/release/get-config.js +1 -0
  16. package/lib/flows/steps/release/remove-failed-upload.js +2 -13
  17. package/lib/flows/steps/release/upload-zip-to-corva.js +3 -8
  18. package/lib/flows/steps/release/wait-for-build.js +3 -2
  19. package/lib/flows/steps/rerun/create-task.js +8 -9
  20. package/lib/flows/steps/rerun/ensure-that-app-in-stream.js +8 -12
  21. package/lib/flows/steps/rerun/get-app-version.js +8 -7
  22. package/lib/flows/steps/rerun/prepare-data.js +13 -12
  23. package/lib/flows/steps/rerun/prepare-well-and-stream-data.js +22 -18
  24. package/lib/flows/steps/zip-cleanup.js +2 -2
  25. package/lib/flows/steps/zip-create-archive.js +2 -2
  26. package/lib/flows/steps/zip-file-list-resolve.js +24 -14
  27. package/lib/flows/steps/zip-prepare.js +3 -3
  28. package/lib/flows/steps/zip.js +1 -6
  29. package/lib/helpers/resolve-app-runtime.js +8 -5
  30. package/lib/helpers/utils.js +5 -4
  31. package/lib/helpers/versioning.js +14 -2
  32. package/lib/main.js +59 -73
  33. package/lib/scripts/utils/version.js +2 -0
  34. package/package.json +76 -68
  35. package/templates/javascript/scheduler/.eslintrc.js +1 -0
  36. package/templates/javascript/scheduler/.prettierrc +1 -0
  37. package/templates/javascript/stream/.eslintrc.js +1 -0
  38. package/templates/javascript/stream/.prettierrc +1 -0
  39. package/templates/javascript/task/.eslintrc.js +1 -0
  40. package/templates/javascript/task/.prettierrc +1 -0
  41. package/templates/typescript/scheduler/.prettierrc +1 -0
  42. package/templates/typescript/stream/.prettierrc +1 -0
  43. package/templates/typescript/task/.prettierrc +1 -0
@@ -1,6 +1,4 @@
1
- import _ from 'lodash';
2
1
  import chalk from 'chalk';
3
- import inquirer from 'inquirer';
4
2
 
5
3
  import { logger } from '../../../helpers/logger.js';
6
4
 
@@ -16,7 +14,7 @@ export const ENSURE_APP_IN_STREAM_TASK_STEP = {
16
14
  await Promise.all(
17
15
  [...mappedAssetsToStreams].map(([assetId, stream]) => {
18
16
  return ensureAppIsInTheStream(assetId, stream, app.id, api, manifest);
19
- })
17
+ }),
20
18
  );
21
19
 
22
20
  return context;
@@ -35,15 +33,15 @@ export const ENSURE_APP_IN_STREAM_TASK_STEP = {
35
33
  * @returns {void}
36
34
  */
37
35
  const ensureAppIsInTheStream = async (assetId, stream, appId, api, manifest) => {
38
- const connectedApp = stream.app_connections.find(
39
- (connection) => connection.app_id === parseInt(appId)
40
- );
36
+ const connectedApp = stream.app_connections.find((connection) => connection.app_id === parseInt(appId));
37
+
41
38
  if (connectedApp) {
42
39
  logger.write(
43
40
  `\n\n${chalk.black.underline.bold(
44
- `App has been already connected to the stream ID: ${stream.id}, for asset ID: ${assetId}`
45
- )}`
41
+ `App has been already connected to the stream ID: ${stream.id}, for asset ID: ${assetId}`,
42
+ )}`,
46
43
  );
44
+
47
45
  return;
48
46
  }
49
47
 
@@ -51,9 +49,7 @@ const ensureAppIsInTheStream = async (assetId, stream, appId, api, manifest) =>
51
49
 
52
50
  logger.write(
53
51
  `\n\n${chalk.black.underline.bold(
54
- `Added app to the stream, connect ID - ${chalk.green(
55
- newConnection.id
56
- )}, for asset ID: ${assetId}`
57
- )}`
52
+ `Added app to the stream, connect ID - ${chalk.green(newConnection.id)}, for asset ID: ${assetId}`,
53
+ )}`,
58
54
  );
59
55
  };
@@ -1,4 +1,3 @@
1
- import _ from 'lodash';
2
1
  import chalk from 'chalk';
3
2
  import inquirer from 'inquirer';
4
3
 
@@ -34,6 +33,7 @@ export const GET_APP_VERSION_TASK_STEP = {
34
33
  */
35
34
  const getAppVersion = async (appId, optionAppVersion, api) => {
36
35
  logger.write('\n Checking app versions...');
36
+
37
37
  const appPackages = await api.getAppPackages(appId);
38
38
 
39
39
  if (!appPackages.length) {
@@ -47,25 +47,26 @@ const getAppVersion = async (appId, optionAppVersion, api) => {
47
47
  // try to get version from CLI option
48
48
  if (optionAppVersion) {
49
49
  const currentAppPackageByOption = appPackages.find(
50
- (appPackage) => appPackage.attributes.version == optionAppVersion
50
+ (appPackage) => appPackage.attributes.version === optionAppVersion,
51
51
  );
52
+
52
53
  if (currentAppPackageByOption) {
53
54
  const version = currentAppPackageByOption.attributes.version;
55
+
54
56
  confirmUseVersionMessage(version);
57
+
55
58
  return version;
56
59
  }
57
60
 
58
- logger.write(
59
- `\n\n${chalk.black.underline.bold(
60
- `Could not find app version - ${chalk.green(optionAppVersion)}`
61
- )}`
62
- );
61
+ logger.write(`\n\n${chalk.black.underline.bold(`Could not find app version - ${chalk.green(optionAppVersion)}`)}`);
63
62
  }
64
63
 
65
64
  // if there is only on version, use it.
66
65
  if (appPackages.length === 1) {
67
66
  const version = appPackages[0].attributes.version;
67
+
68
68
  confirmUseVersionMessage(version);
69
+
69
70
  return version;
70
71
  }
71
72
 
@@ -1,8 +1,8 @@
1
- import _ from 'lodash';
2
1
  import chalk from 'chalk';
3
2
  import inquirer from 'inquirer';
4
- import { StepError } from '../../lib/step-error.js';
3
+ import _ from 'lodash';
5
4
  import { logger } from '../../../helpers/logger.js';
5
+ import { StepError } from '../../lib/step-error.js';
6
6
 
7
7
  const MAX_ASSET_IDS_COUNT = 10;
8
8
 
@@ -31,17 +31,18 @@ export const PREPARE_DATA_TASK_STEP = {
31
31
  const appDatasetsNames = appDatasets.map((dataset) => dataset.attributes.dataset_name);
32
32
 
33
33
  const existingAppRuns = await getExistAppRuns(app.id, assets, appDatasetsNames, api);
34
+
34
35
  if (existingAppRuns.size) {
35
- for (let appRunAssetId of existingAppRuns.keys()) {
36
+ for (const appRunAssetId of existingAppRuns.keys()) {
36
37
  // remove asset ID if similar rerun already exists
37
- assets = assets.filter((assetId) => appRunAssetId != assetId);
38
+ assets = assets.filter((assetId) => appRunAssetId !== assetId);
38
39
 
39
40
  const run = existingAppRuns.get(appRunAssetId);
40
41
 
41
42
  logger.write(
42
43
  `\n\n${chalk.yellow.bold(
43
- `A similar rerun with ID ${run.id}, for asset ID ${appRunAssetId} - already exists. Will be skipped!`
44
- )}`
44
+ `A similar rerun with ID ${run.id}, for asset ID ${appRunAssetId} - already exists. Will be skipped!`,
45
+ )}`,
45
46
  );
46
47
  }
47
48
  }
@@ -64,6 +65,7 @@ export const PREPARE_DATA_TASK_STEP = {
64
65
  */
65
66
  const promptAreYouSure = async () => {
66
67
  logger.log('\n');
68
+
67
69
  const answers = await inquirer.prompt([
68
70
  {
69
71
  message:
@@ -77,6 +79,7 @@ const promptAreYouSure = async () => {
77
79
  default: false,
78
80
  },
79
81
  ]);
82
+
80
83
  return answers.option;
81
84
  };
82
85
 
@@ -96,14 +99,12 @@ const getExistAppRuns = async (appId, assets, appDatasetsNames, api) => {
96
99
 
97
100
  // go through all assets ids
98
101
  for (const assetId of assets) {
99
- const runsForCurrentAsset = existingAppRuns.filter(
100
- (run) => run.attributes.well_asset_id == assetId
101
- );
102
+ const runsForCurrentAsset = existingAppRuns.filter((run) => run.attributes.well_asset_id === assetId);
103
+
102
104
  // go through all existing runs for current asset ID
103
105
  for (const run of runsForCurrentAsset) {
104
- const currentAppDatasetsNames = run.attributes.app_run_datasets.map(
105
- (dataset) => dataset.name
106
- );
106
+ const currentAppDatasetsNames = run.attributes.app_run_datasets.map((dataset) => dataset.name);
107
+
107
108
  // if datasets names matched for the same asset ID - then run already exist
108
109
  if (appDatasetsNames.sort().toString() === currentAppDatasetsNames.sort().toString()) {
109
110
  appRuns.set(assetId, run);
@@ -1,4 +1,3 @@
1
- import _ from 'lodash';
2
1
  import chalk from 'chalk';
3
2
  import inquirer from 'inquirer';
4
3
 
@@ -14,8 +13,11 @@ export const PREPARE_WELL_AND_STREAM_TASK_STEP = {
14
13
  let { assets } = context;
15
14
  const { api, manifest } = context;
16
15
 
17
- const { mappedAssetsToWells, mappedAssetsToStreams, assetsToDelete } =
18
- await prepareWellAndStreamData(assets, api, manifest);
16
+ const { mappedAssetsToWells, mappedAssetsToStreams, assetsToDelete } = await prepareWellAndStreamData(
17
+ assets,
18
+ api,
19
+ manifest,
20
+ );
19
21
 
20
22
  if (assetsToDelete.length) {
21
23
  // remove asset ID if could not found stream or well
@@ -53,9 +55,8 @@ const getStreamWithPrompt = async (streams) => {
53
55
  if (choices.length === 1) {
54
56
  const [stream] = choices;
55
57
 
56
- logger.write(
57
- `\n\n${chalk.black.underline.bold(`Process stream - ${chalk.green(stream.name)}`)}`
58
- );
58
+ logger.write(`\n\n${chalk.black.underline.bold(`Process stream - ${chalk.green(stream.name)}`)}`);
59
+
59
60
  return stream.value;
60
61
  }
61
62
 
@@ -85,12 +86,14 @@ const getWellWithPrompt = async (wells, api) => {
85
86
  const choices = await Promise.all(
86
87
  wells.map(async (well) => {
87
88
  const assetDetails = await api.getAssetById(well.data.attributes.asset_id);
89
+
88
90
  well.data.name = assetDetails.attributes.name;
91
+
89
92
  return {
90
93
  value: well.data,
91
94
  name: well.data.name,
92
95
  };
93
- })
96
+ }),
94
97
  );
95
98
 
96
99
  if (!choices.length) {
@@ -101,6 +104,7 @@ const getWellWithPrompt = async (wells, api) => {
101
104
  const [well] = choices;
102
105
 
103
106
  logger.write(`\n\n${chalk.black.underline.bold(`Process well - ${chalk.green(well.name)}`)}`);
107
+
104
108
  return well.value;
105
109
  }
106
110
 
@@ -134,42 +138,42 @@ const prepareWellAndStreamData = async (assets, api, manifest) => {
134
138
 
135
139
  for (const assetId of assets) {
136
140
  try {
137
- logger.write(
138
- `\n\n${chalk.black.underline.bold(`Process asset ID - ${chalk.green(assetId)}`)}`
139
- );
141
+ logger.write(`\n\n${chalk.black.underline.bold(`Process asset ID - ${chalk.green(assetId)}`)}`);
140
142
 
141
143
  logger.write('\n Loading wells...');
142
144
 
143
145
  const wells = await api.getWellByAssetId(assetId);
144
146
  const well = await getWellWithPrompt(wells, api);
147
+
145
148
  mappedAssetsToWells.set(well.attributes.asset_id, well);
146
149
 
147
150
  logger.write('\n Loading streams...');
148
151
 
149
- const streams = await api.getStreamsByAssetIds(
150
- [assetId],
151
- manifest.manifest.application.segments
152
- );
152
+ const streams = await api.getStreamsByAssetIds([assetId], manifest.manifest.application.segments);
153
153
 
154
154
  if (!streams.length) {
155
155
  throw new Error(`Could not found streams for asset ID - ${assetId}`);
156
156
  }
157
157
 
158
158
  const stream = await getStreamWithPrompt(streams);
159
+
159
160
  mappedAssetsToStreams.set(stream.asset_id, stream);
160
161
  } catch (e) {
161
162
  logger.write(
162
- `\n\n${chalk.red.underline.bold(
163
- `Skipped the asset ID - ${assetId}, an error occurred: ${e.message}`
164
- )}`
163
+ `\n\n${chalk.red.underline.bold(`Skipped the asset ID - ${assetId}, an error occurred: ${e.message}`)}`,
165
164
  );
166
165
 
167
166
  assetsToDelete.push(assetId);
168
167
 
169
168
  if (mappedAssetsToWells.has(assetId)) mappedAssetsToWells.delete(assetId);
169
+
170
170
  if (mappedAssetsToStreams.has(assetId)) mappedAssetsToStreams.delete(assetId);
171
171
  }
172
172
  }
173
173
 
174
- return { mappedAssetsToWells, mappedAssetsToStreams, assetsToDelete };
174
+ return {
175
+ mappedAssetsToWells,
176
+ mappedAssetsToStreams,
177
+ assetsToDelete,
178
+ };
175
179
  };
@@ -1,9 +1,9 @@
1
1
  import { promises as fs } from 'node:fs';
2
2
  import { resolve } from 'node:path';
3
3
 
4
- import Debug from 'debug';
4
+ import debugFn from 'debug';
5
5
 
6
- const debug = Debug('cca:flow:zip:cleanup');
6
+ const debug = debugFn('cca:flow:zip:cleanup');
7
7
 
8
8
  export const CLEANUP_STEP = {
9
9
  message: 'Removing temporary files...',
@@ -1,7 +1,7 @@
1
+ import debugFn from 'debug';
1
2
  import { createZipArchive } from '../lib/create-zip-archive.js';
2
- import Debug from 'debug';
3
3
 
4
- const debug = Debug('cca:flow:zip:archive');
4
+ const debug = debugFn('cca:flow:zip:archive');
5
5
 
6
6
  export const CREATE_ARCHIVE_STEP = {
7
7
  message: 'Creating archive...',
@@ -1,18 +1,19 @@
1
- import _ from 'lodash/fp.js';
2
- import { resolve } from 'node:path';
3
- import { promises as fs } from 'node:fs';
4
- import Glob from 'glob';
5
1
  import chalk from 'chalk';
2
+ import Glob from 'glob';
6
3
  import isGlob from 'is-glob';
4
+ import _ from 'lodash/fp.js';
5
+ import { promises as fs } from 'node:fs';
6
+ import { resolve } from 'node:path';
7
7
  import { promisify } from 'node:util';
8
8
  import { getIncreasedVersion } from '../../scripts/utils/version.js';
9
9
  import { loadJson } from '../lib/json.js';
10
10
  import { StepError } from '../lib/step-error.js';
11
11
 
12
12
  const glob = promisify(Glob);
13
- import Debug from 'debug';
14
13
 
15
- const debug = Debug('cca:flow:zip:resolve');
14
+ import debugFn from 'debug';
15
+
16
+ const debug = debugFn('cca:flow:zip:resolve');
16
17
 
17
18
  const uniqueValues = (array) => Array.from(new Set(array));
18
19
 
@@ -86,7 +87,7 @@ const resolveDataToZipUiApp = async (itemsToZip = [], { options, pkg, dirName, m
86
87
  name: 'package.json',
87
88
  content: pkg,
88
89
  message: chalk(
89
- `\n${chalk.yellow`NOTE`}: Version of your app was updated to ${version} (package.json), please don't lower it.`
90
+ `\n${chalk.yellow`NOTE`}: Version of your app was updated to ${version} (package.json), please don't lower it.`,
90
91
  ),
91
92
  });
92
93
  }
@@ -98,7 +99,7 @@ const resolveDataToZipUiApp = async (itemsToZip = [], { options, pkg, dirName, m
98
99
  {
99
100
  build: 'webpack --config=./config-overrides.js --mode production',
100
101
  },
101
- pkg
102
+ pkg,
102
103
  ),
103
104
  });
104
105
 
@@ -111,8 +112,11 @@ const resolveDataToZipUiApp = async (itemsToZip = [], { options, pkg, dirName, m
111
112
  '.npmrc',
112
113
  '.nvmrc',
113
114
  'yarn.lock',
114
- { path: resolve(dirName, 'packageForSource.json'), name: 'package.json' },
115
- ...(await transformPatternsIntoFileNames(dirName, ['src/**/*'], options.ignoredFiles))
115
+ {
116
+ path: resolve(dirName, 'packageForSource.json'),
117
+ name: 'package.json',
118
+ },
119
+ ...(await transformPatternsIntoFileNames(dirName, ['src/**/*'], options.ignoredFiles)),
116
120
  );
117
121
 
118
122
  return {
@@ -143,7 +147,7 @@ const resolveDataForZipNodeJsApp = async (itemsToZip = [], { options, pkg, dirNa
143
147
  name: 'package.json',
144
148
  content: pkg,
145
149
  message: chalk(
146
- `\n${chalk.yellow`NOTE`}: Version of your app was updated to ${version} (package.json), please don't lower it.`
150
+ `\n${chalk.yellow`NOTE`}: Version of your app was updated to ${version} (package.json), please don't lower it.`,
147
151
  ),
148
152
  });
149
153
  }
@@ -174,13 +178,19 @@ const resolveDataForZipNodeJsApp = async (itemsToZip = [], { options, pkg, dirNa
174
178
  if (shouldPushDefaultSrc) {
175
179
  itemsToZip.push(
176
180
  'index.ts',
177
- ...(await glob('+(src|lib)/**/*.ts', { cwd: dirName, ignore: options.ignoredFiles }))
181
+ ...(await glob('+(src|lib)/**/*.ts', {
182
+ cwd: dirName,
183
+ ignore: options.ignoredFiles,
184
+ })),
178
185
  );
179
186
  }
180
187
  } else if (shouldPushDefaultSrc) {
181
188
  itemsToZip.push(
182
189
  'index.js',
183
- ...(await glob('+(src|lib)/**/*.js', { cwd: dirName, ignore: options.ignoredFiles }))
190
+ ...(await glob('+(src|lib)/**/*.js', {
191
+ cwd: dirName,
192
+ ignore: options.ignoredFiles,
193
+ })),
184
194
  );
185
195
  }
186
196
 
@@ -207,7 +217,7 @@ const resolveDataForZipPythonApp = async (itemsToZip = [], { manifest, dirName,
207
217
  ...(await glob('**/*.py', {
208
218
  cwd: dirName,
209
219
  ignore: [...(options.ignoredFiles || []), 'venv/**/*'],
210
- }))
220
+ })),
211
221
  );
212
222
  }
213
223
 
@@ -1,9 +1,9 @@
1
- import { saveJson } from '../lib/json.js';
2
1
  import { logger } from '../../helpers/logger.js';
2
+ import { saveJson } from '../lib/json.js';
3
3
 
4
- import Debug from 'debug';
4
+ import debugFn from 'debug';
5
5
 
6
- const debug = Debug('cca:flow:zip:prepare');
6
+ const debug = debugFn('cca:flow:zip:prepare');
7
7
 
8
8
  export const PREPARE_FILES_BEFORE_ZIP_STEP = {
9
9
  message: 'Preparing...',
@@ -3,9 +3,4 @@ import { CREATE_ARCHIVE_STEP } from './zip-create-archive.js';
3
3
  import { FILE_LIST_RESOLVE_STEP } from './zip-file-list-resolve.js';
4
4
  import { PREPARE_FILES_BEFORE_ZIP_STEP } from './zip-prepare.js';
5
5
 
6
- export const ZIP_STEPS = [
7
- FILE_LIST_RESOLVE_STEP,
8
- PREPARE_FILES_BEFORE_ZIP_STEP,
9
- CREATE_ARCHIVE_STEP,
10
- CLEANUP_STEP,
11
- ];
6
+ export const ZIP_STEPS = [FILE_LIST_RESOLVE_STEP, PREPARE_FILES_BEFORE_ZIP_STEP, CREATE_ARCHIVE_STEP, CLEANUP_STEP];
@@ -1,14 +1,15 @@
1
+ import debugFn from 'debug';
1
2
  import { APP_TYPES } from '../constants/cli.js';
2
- import Debug from 'debug';
3
3
 
4
- const debug = Debug('cca:resolve-app-runtime');
4
+ const debug = debugFn('cca:resolve-app-runtime');
5
+
5
6
  import spawn from 'cross-spawn';
6
7
  import { promises as fs } from 'fs';
7
- import semver from 'semver';
8
8
  import os from 'os';
9
+ import semver from 'semver';
9
10
 
10
11
  const checkCliVersion = async (command, version, stdErr = false) =>
11
- new Promise((resolve, reject) => {
12
+ new Promise((resolve) => {
12
13
  const child = spawn(command, ['--version']);
13
14
 
14
15
  let data = '';
@@ -80,7 +81,9 @@ export const resolveAppRuntime = (opts) => {
80
81
  return {
81
82
  language: 'python',
82
83
  isRuntimeAvailable: async () =>
83
- IS_WINDOWS ? await checkCliVersion('python', version) || await checkCliVersion('python3', version) : checkCliVersion('python3', version),
84
+ IS_WINDOWS
85
+ ? (await checkCliVersion('python', version)) || (await checkCliVersion('python3', version))
86
+ : checkCliVersion('python3', version),
84
87
  packageManager: 'pip',
85
88
  version,
86
89
  };
@@ -3,7 +3,8 @@ import fs from 'fs-extra';
3
3
 
4
4
  export function copyFileSync(source, target) {
5
5
  let targetFile = target;
6
- //if target is a directory a new file with the same name will be created
6
+
7
+ // if target is a directory a new file with the same name will be created
7
8
  if (fs.existsSync(target)) {
8
9
  if (fs.lstatSync(target).isDirectory()) {
9
10
  targetFile = path.join(target, path.basename(source));
@@ -14,7 +15,7 @@ export function copyFileSync(source, target) {
14
15
  }
15
16
 
16
17
  export function copyFolderRecursiveSync(sourceFolder, targetFolder) {
17
- //check if folder needs to be created or integrated
18
+ // check if folder needs to be created or integrated
18
19
  if (!fs.existsSync(targetFolder)) {
19
20
  fs.mkdirSync(targetFolder);
20
21
  }
@@ -23,7 +24,7 @@ export function copyFolderRecursiveSync(sourceFolder, targetFolder) {
23
24
  return;
24
25
  }
25
26
 
26
- //copy
27
+ // copy
27
28
  const items = fs.readdirSync(sourceFolder);
28
29
 
29
30
  for (const item of items) {
@@ -53,6 +54,6 @@ export const putVariablesInEnvFile = async (root, manifest) => {
53
54
  envFileContent
54
55
  .replace(new RegExp('\\${APP_KEY}', 'g'), manifest.manifest.application.key)
55
56
  .replace(new RegExp('\\${PROVIDER}', 'g'), manifest.manifest.application.key.split('.')[0])
56
- .replace(new RegExp('\\${APP_NAME}', 'g'), manifest.manifest.application.name)
57
+ .replace(new RegExp('\\${APP_NAME}', 'g'), manifest.manifest.application.name),
57
58
  );
58
59
  };
@@ -1,8 +1,10 @@
1
+ import debugFn from 'debug';
1
2
  import { execSync } from 'node:child_process';
3
+ import fs from 'node:fs';
4
+ import path from 'node:path';
2
5
  import { logger } from './logger.js';
3
- import Debug from 'debug';
4
6
 
5
- const debug = Debug('cca:versioning');
7
+ const debug = debugFn('cca:versioning');
6
8
 
7
9
  export function isInGitRepository(appPath) {
8
10
  try {
@@ -10,9 +12,11 @@ export function isInGitRepository(appPath) {
10
12
  stdio: 'ignore',
11
13
  cwd: appPath,
12
14
  });
15
+
13
16
  return true;
14
17
  } catch (e) {
15
18
  debug(e);
19
+
16
20
  return false;
17
21
  }
18
22
  }
@@ -24,14 +28,17 @@ export function tryGitInit(appPath) {
24
28
 
25
29
  return false;
26
30
  }
31
+
27
32
  execSync('git --version', { stdio: 'ignore', cwd: appPath });
28
33
 
29
34
  execSync('git init', { stdio: 'ignore', cwd: appPath });
30
35
  logger.log('Initialized git repo in app');
36
+
31
37
  return true;
32
38
  } catch (e) {
33
39
  debug(e);
34
40
  console.warn('Git repo not initialized');
41
+
35
42
  return false;
36
43
  }
37
44
  }
@@ -44,6 +51,7 @@ export function tryGitCommit(appPath) {
44
51
  cwd: appPath,
45
52
  });
46
53
  logger.log('Added first git commit');
54
+
47
55
  return true;
48
56
  } catch (e) {
49
57
  // We couldn't commit in already initialized git repo,
@@ -54,6 +62,7 @@ export function tryGitCommit(appPath) {
54
62
  debug(e);
55
63
  console.warn('Git commit not created');
56
64
  console.warn('Removing .git directory...');
65
+
57
66
  try {
58
67
  // unlinkSync() doesn't work on directories.
59
68
  fs.removeSync(path.join(appPath, '.git'));
@@ -61,6 +70,7 @@ export function tryGitCommit(appPath) {
61
70
  debug(removeErr);
62
71
  // Ignore.
63
72
  }
73
+
64
74
  return false;
65
75
  }
66
76
  }
@@ -68,9 +78,11 @@ export function tryGitCommit(appPath) {
68
78
  export function shouldUseYarn(appPath) {
69
79
  try {
70
80
  execSync('yarnpkg --version', { stdio: 'ignore', cwd: appPath });
81
+
71
82
  return true;
72
83
  } catch (e) {
73
84
  debug(e);
85
+
74
86
  return false;
75
87
  }
76
88
  }