contensis-cli 1.0.0-beta.94 → 1.0.0-beta.96

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.
@@ -21,10 +21,12 @@ import { mergeDotEnvFileContents } from '~/util/dotenv';
21
21
  import { findByIdOrName } from '~/util/find';
22
22
  import { GitHelper } from '~/util/git';
23
23
  import { jsonFormatter } from '~/util/json.formatter';
24
- import { normaliseLineEndings } from '~/util/os';
24
+ import { normaliseLineEndings, winSlash } from '~/util/os';
25
25
  import { stringifyYaml } from '~/util/yaml';
26
26
 
27
27
  class ContensisDev extends ContensisRole {
28
+ git!: GitHelper;
29
+
28
30
  constructor(
29
31
  args: string[],
30
32
  outputOpts?: OutputOptionsConstructorArg,
@@ -52,7 +54,7 @@ class ContensisDev extends ContensisRole {
52
54
  );
53
55
 
54
56
  // Retrieve git info
55
- const git = new GitHelper(projectHome);
57
+ const git = this.git = new GitHelper(projectHome);
56
58
 
57
59
  // Retrieve ci workflow info
58
60
  const workflowFiles = git.workflows;
@@ -103,6 +105,7 @@ class ContensisDev extends ContensisRole {
103
105
  ({ ciFileName } = await inquirer.prompt([
104
106
  {
105
107
  type: 'list',
108
+ prefix: '⧰',
106
109
  message: messages.devinit.ciMultipleChoices(),
107
110
  name: 'ciFileName',
108
111
  choices: workflowFiles,
@@ -116,7 +119,7 @@ class ContensisDev extends ContensisRole {
116
119
  log.raw(log.infoText(messages.devinit.ciDetails(ciFileName)));
117
120
 
118
121
  // Look at the workflow file content and make updates
119
- const mappedWorkflow = mapCIWorkflowContent(this, git);
122
+ const mappedWorkflow = await mapCIWorkflowContent(this);
120
123
 
121
124
  log.help(messages.devinit.ciIntro(git));
122
125
 
@@ -138,6 +141,7 @@ class ContensisDev extends ContensisRole {
138
141
  const { accessToken }: { accessToken: string } = await inquirer.prompt([
139
142
  {
140
143
  type: 'input',
144
+ prefix: '🛡️',
141
145
  message: messages.devinit.accessTokenPrompt(),
142
146
  name: 'accessToken',
143
147
  },
@@ -219,34 +223,41 @@ class ContensisDev extends ContensisRole {
219
223
 
220
224
  if (dryRun) {
221
225
  if (envDiff) {
222
- log.info(`updating .env file ${envFilePath}: ${envDiff}`);
226
+ log.info(`Updating .env file ${winSlash(envFilePath)}:\n${envDiff}`);
223
227
  log.raw('');
224
228
  }
225
229
  checkpoint('skip .env file update (dry-run)');
226
230
  } else {
227
- if (envDiff) log.info(`updating .env file ${envFilePath}`);
231
+ if (envDiff) log.info(`updating .env file ${winSlash(envFilePath)}`);
228
232
  writeFile(envFilePath, envFileLines.join('\n'));
229
233
  checkpoint('.env file updated');
230
234
  log.success(messages.devinit.writeEnvFile());
231
235
  // log.help(messages.devinit.useEnvFileTip());
232
236
  }
233
237
 
234
- // Update CI file -- different for GH/GL -- create a sample one with build?
238
+ // Update CI file -- different for GH/GL
239
+ if (mappedWorkflow?.diff) {
240
+ log.info(
241
+ `Updating ${winSlash(ciFileName)} file:\n${mappedWorkflow.diff}`
242
+ );
243
+ log.raw('');
244
+ }
235
245
  if (dryRun) {
236
- if (mappedWorkflow?.diff) {
237
- log.info(`updating${ciFileName} file: ${mappedWorkflow.diff}`);
238
- log.raw('');
239
- }
240
246
  checkpoint('skip CI file update (dry-run)');
241
247
  //log.object(ciFileLines);
242
248
  } else {
243
- if (mappedWorkflow?.diff) log.info(`updating${ciFileName} file`);
244
- writeFile(git.ciFilePath, [].join('\n'));
245
- log.success(messages.devinit.writeCiFile(`./${ciFileName}`));
246
- log.info(
247
- messages.devinit.ciBlockTip(blockId, currentEnv, currentProject)
248
- );
249
- checkpoint('CI file updated');
249
+ if (mappedWorkflow?.newWorkflow) {
250
+ if (mappedWorkflow?.diff) {
251
+ writeFile(git.ciFilePath, mappedWorkflow.newWorkflow);
252
+ log.success(messages.devinit.writeCiFile(`./${ciFileName}`));
253
+ log.info(
254
+ messages.devinit.ciBlockTip(blockId, currentEnv, currentProject)
255
+ );
256
+ } else {
257
+ log.info(messages.devinit.ciFileNoChanges(`./${ciFileName}`));
258
+ }
259
+ checkpoint('CI file updated');
260
+ }
250
261
  }
251
262
 
252
263
  // Echo Deployment API key to console, ask user to add secrets to repo
package/src/util/diff.ts CHANGED
@@ -40,12 +40,17 @@ export const diffFileContent = (
40
40
 
41
41
  const lnSpaces = Array(lnSpaceLength).join(' ');
42
42
 
43
+ let needsNewLine = false;
43
44
  for (let i = 0; i < diffRanges.length; i++) {
44
45
  const part = diffRanges[i];
45
46
  if (part.added || part.removed) {
46
47
  const colour = part.added ? 'green' : part.removed ? 'red' : 'grey';
47
48
 
48
- if (part.value !== '\n')
49
+ if (part.value !== '\n') {
50
+ if (needsNewLine) {
51
+ output.push('\n### --');
52
+ needsNewLine = false;
53
+ }
49
54
  output.push(
50
55
  `\n${part.value
51
56
  .split('\n')
@@ -60,11 +65,11 @@ export const diffFileContent = (
60
65
  )
61
66
  .join('\n')}`
62
67
  );
63
- }
68
+ } else needsNewLine = true;
69
+ } else needsNewLine = true;
64
70
  }
65
71
 
66
72
  return output.join('');
67
- // return retOutput.endsWith('\n') ? retOutput : `${retOutput}\n`;
68
73
  };
69
74
 
70
75
  const addDiffPositionInfo = (diff: Change[]) => {
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const LIB_VERSION = "1.0.0-beta.94";
1
+ export const LIB_VERSION = "1.0.0-beta.96";