contensis-cli 1.0.0-beta.66 → 1.0.0-beta.68

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.
package/dist/version.js CHANGED
@@ -21,7 +21,7 @@ __export(version_exports, {
21
21
  LIB_VERSION: () => LIB_VERSION
22
22
  });
23
23
  module.exports = __toCommonJS(version_exports);
24
- const LIB_VERSION = "1.0.0-beta.66";
24
+ const LIB_VERSION = "1.0.0-beta.68";
25
25
  // Annotate the CommonJS export names for ESM import in node:
26
26
  0 && (module.exports = {
27
27
  LIB_VERSION
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/version.ts"],
4
- "sourcesContent": ["export const LIB_VERSION = \"1.0.0-beta.66\";\n"],
4
+ "sourcesContent": ["export const LIB_VERSION = \"1.0.0-beta.68\";\n"],
5
5
  "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,MAAM,cAAc;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "contensis-cli",
3
- "version": "1.0.0-beta.66",
3
+ "version": "1.0.0-beta.68",
4
4
  "description": "A fully featured Contensis command line interface with a shell UI provides simple and intuitive ways to manage or profile your content in any NodeJS terminal.",
5
5
  "repository": "https://github.com/contensis/node-cli",
6
6
  "homepage": "https://github.com/contensis/node-cli/tree/main/packages/contensis-cli#readme",
@@ -0,0 +1,114 @@
1
+ import { Argument, Command } from 'commander';
2
+ import { cliCommand } from '~/services/ContensisCliService';
3
+
4
+ export const makeExecuteCommand = () => {
5
+ const execute = new Command()
6
+ .command('execute')
7
+ .description('execute block actions')
8
+ .addHelpText('after', `\n`)
9
+ .showHelpAfterError(true)
10
+ .exitOverride();
11
+
12
+ const block = execute
13
+ .command('block')
14
+ .description('execute block command to invoke block actions');
15
+
16
+ const action = block
17
+ .command('action')
18
+ .description('execute block action command to invoke block actions');
19
+
20
+ const blockIdArg = new Argument(
21
+ '<block-id>',
22
+ 'the name of the block to perform action with'
23
+ );
24
+ const blockVersionArg = new Argument(
25
+ '<version>',
26
+ 'the block version to perform action with'
27
+ );
28
+
29
+ action
30
+ .command('release')
31
+ .description('release a block version')
32
+ .addArgument(blockIdArg)
33
+ .argument('[version]', blockVersionArg.description, 'latest')
34
+ .usage('[block-id> <version]')
35
+ .addHelpText(
36
+ 'after',
37
+ `
38
+ Example call:
39
+ > execute block action release contensis-app
40
+
41
+ Note: block actions are executed on blocks deployed from a "main" or "master" branch\n`
42
+ )
43
+ .action(async (blockId: string, version: string, opts) => {
44
+ await cliCommand(
45
+ ['execute', 'block', 'action', 'release', blockId],
46
+ opts
47
+ ).ExecuteBlockAction('release', blockId, version);
48
+ });
49
+
50
+ action
51
+ .command('makelive')
52
+ .description('make a block version live')
53
+ .addArgument(blockIdArg)
54
+ .addArgument(blockVersionArg)
55
+ .usage('<block-id> <version>')
56
+ .addHelpText(
57
+ 'after',
58
+ `
59
+ Example call:
60
+ > execute block action makelive contensis-app 3
61
+
62
+ Note: block actions are executed on blocks deployed from a "main" or "master" branch\n`
63
+ )
64
+ .action(async (blockId: string, version: string, opts) => {
65
+ await cliCommand(
66
+ ['execute', 'block', 'action', 'makelive', blockId],
67
+ opts
68
+ ).ExecuteBlockAction('makeLive', blockId, version);
69
+ });
70
+
71
+ action
72
+ .command('rollback')
73
+ .description('rollback a live block version to last live version')
74
+ .addArgument(blockIdArg)
75
+ .addArgument(blockVersionArg)
76
+ .usage('<block-id> <version>')
77
+ .addHelpText(
78
+ 'after',
79
+ `
80
+ Example call:
81
+ > execute block action rollback contensis-app 3
82
+
83
+ Note: block actions are executed on blocks deployed from a "main" or "master" branch\n`
84
+ )
85
+ .action(async (blockId: string, version: string, opts) => {
86
+ await cliCommand(
87
+ ['execute', 'block', 'action', 'rollback', blockId],
88
+ opts
89
+ ).ExecuteBlockAction('rollback', blockId, version);
90
+ });
91
+
92
+ action
93
+ .command('markasbroken')
94
+ .description('mark a block version as broken')
95
+ .addArgument(blockIdArg)
96
+ .addArgument(blockVersionArg)
97
+ .usage('<block-id> <version>')
98
+ .addHelpText(
99
+ 'after',
100
+ `
101
+ Example call:
102
+ > execute block action markasbroken contensis-app 3
103
+
104
+ Note: block actions are executed on blocks deployed from a "main" or "master" branch\n`
105
+ )
106
+ .action(async (blockId: string, version: string, opts) => {
107
+ await cliCommand(
108
+ ['execute', 'block', 'action', 'markasbroken', blockId],
109
+ opts
110
+ ).ExecuteBlockAction('markAsBroken', blockId, version);
111
+ });
112
+
113
+ return execute;
114
+ };
@@ -5,6 +5,7 @@ import { mapContensisOpts } from './globalOptions';
5
5
  export const makeGetCommand = () => {
6
6
  const program = new Command()
7
7
  .command('get')
8
+ .description('get command')
8
9
  .addHelpText('after', `\n`)
9
10
  .showHelpAfterError(true)
10
11
  .exitOverride();
@@ -188,7 +189,7 @@ Example call:
188
189
  `
189
190
  )
190
191
  .action(async (blockId: string, branch: string, version: string, opts) => {
191
- await cliCommand(['get', 'block'], opts).PrintBlockVersions(
192
+ await cliCommand(['get', 'block', blockId], opts).PrintBlockVersions(
192
193
  blockId,
193
194
  branch,
194
195
  version
@@ -4,6 +4,7 @@ import { LIB_VERSION } from '~/version';
4
4
  import { makeConnectCommand } from './connect';
5
5
  import { makeCreateCommand } from './create';
6
6
  import { makeDiffCommand } from './diff';
7
+ import { makeExecuteCommand } from './execute';
7
8
  import { makeGetCommand } from './get';
8
9
  import {
9
10
  addAuthenticationOptions,
@@ -16,7 +17,6 @@ import { makeImportCommand } from './import';
16
17
  import { makeListCommand } from './list';
17
18
  import { makeLoginCommand } from './login';
18
19
  import { makePushCommand } from './push';
19
- import { makeReleaseCommand } from './release';
20
20
  import { makeRemoveCommand } from './remove';
21
21
  import { makeSetCommand } from './set';
22
22
 
@@ -31,6 +31,13 @@ const commands = () => {
31
31
  : str.trim() && Logger.help(str);
32
32
  },
33
33
  })
34
+ .addHelpText(
35
+ 'after',
36
+ Logger.helpText`
37
+ >> Each command has its own help - for example:
38
+ > login --help\n > get --help
39
+ `
40
+ )
34
41
  .exitOverride()
35
42
  .showHelpAfterError(true);
36
43
 
@@ -42,6 +49,9 @@ const commands = () => {
42
49
  program.addCommand(
43
50
  addGlobalOptions(makeCreateCommand()).copyInheritedSettings(program)
44
51
  );
52
+ program.addCommand(
53
+ addGlobalOptions(makeExecuteCommand()).copyInheritedSettings(program)
54
+ );
45
55
  program.addCommand(
46
56
  addGlobalOptions(
47
57
  addGetEntryOptions(addImportOptions(makeDiffCommand()))
@@ -64,9 +74,6 @@ const commands = () => {
64
74
  program.addCommand(
65
75
  addGlobalOptions(makePushCommand()).copyInheritedSettings(program)
66
76
  );
67
- program.addCommand(
68
- addGlobalOptions(makeReleaseCommand()).copyInheritedSettings(program)
69
- );
70
77
  program.addCommand(
71
78
  addGlobalOptions(makeRemoveCommand()).copyInheritedSettings(program)
72
79
  );
@@ -71,7 +71,7 @@ Example call:
71
71
  };
72
72
 
73
73
  const blockRequest = mapJson(mapSourceVars, {
74
- autoRelease: { $path: 'release', $default: () => false },
74
+ release: { $path: 'release', $default: () => false },
75
75
  id: ['blockId'],
76
76
  image: () => {
77
77
  const lastIndexOfColon = imageUri.lastIndexOf(':');
@@ -1,4 +1,5 @@
1
1
  import {
2
+ BlockActionType,
2
3
  BlockRunningStatus,
3
4
  MigrateModelsResult,
4
5
  MigrateStatus,
@@ -279,12 +280,35 @@ export const LogMessages = {
279
280
  `[${env}] Unable to push block ${Logger.highlightText(
280
281
  id
281
282
  )} in project ${projectId}`,
282
- released: (id: string, env: string, projectId?: string) =>
283
- `[${env}] Released block ${Logger.highlightText(
283
+ latestVersion: (
284
+ version: string,
285
+ id: string,
286
+ env: string,
287
+ projectId?: string
288
+ ) =>
289
+ `[${env}] Found latest block version ${Logger.highlightText(
284
290
  id
285
- )} in project ${projectId}`,
286
- failedRelease: (id: string, env: string, projectId?: string) =>
287
- `[${env}] Unable to release block ${Logger.highlightText(
291
+ )} in project ${projectId} ${Logger.highlightText(version)}`,
292
+ failedParsingVersion: () =>
293
+ `Could not parse ".[0].version.versionNo" from response`,
294
+ actionComplete: (
295
+ action: BlockActionType,
296
+ id: string,
297
+ env: string,
298
+ projectId?: string
299
+ ) =>
300
+ `[${env}] Action ${Logger.highlightText(
301
+ action
302
+ )} on ${Logger.highlightText(
303
+ id
304
+ )} in project ${projectId} requested successfully`,
305
+ actionFailed: (
306
+ action: BlockActionType,
307
+ id: string,
308
+ env: string,
309
+ projectId?: string
310
+ ) =>
311
+ `[${env}] Problem executing ${action} on block ${Logger.highlightText(
288
312
  id
289
313
  )} in project ${projectId}`,
290
314
  deleted: (id: string, env: string, projectId?: string) =>
@@ -20,6 +20,8 @@ import {
20
20
  ContentTypesResult,
21
21
  Model,
22
22
  MigrateModelsResult,
23
+ BlockActionType,
24
+ BlockVersion,
23
25
  } from 'migratortron';
24
26
  import { Entry, Role } from 'contensis-management-api/lib/models';
25
27
 
@@ -1901,32 +1903,108 @@ class ContensisCli {
1901
1903
  }
1902
1904
  };
1903
1905
 
1904
- ReleaseBlock = async (blockId: string, version: string) => {
1906
+ GetLastBlockVersionInMainOrMaster = async (
1907
+ blockId: string
1908
+ ): Promise<[AppError | null, string | undefined]> => {
1909
+ const { contensis, log, messages } = this;
1910
+
1911
+ // Look for block versions pushed to main branch first
1912
+ const [getErrMain, blockVersionMain] =
1913
+ (await contensis?.blocks.GetBlockVersions(blockId, 'main')) || [];
1914
+
1915
+ let blockVersionResponse = [] as BlockVersion[];
1916
+
1917
+ if (getErrMain?.code === '404') {
1918
+ // Try looking in master
1919
+ const [getErrMaster, blockVersionMaster] =
1920
+ (await contensis?.blocks.GetBlockVersions(blockId, 'master')) || [];
1921
+ if (getErrMaster) {
1922
+ return [getErrMaster, undefined];
1923
+ } else if (blockVersionMaster) blockVersionResponse = blockVersionMaster;
1924
+ } else if (getErrMain) {
1925
+ return [getErrMain, undefined];
1926
+ } else if (blockVersionMain) blockVersionResponse = blockVersionMain;
1927
+
1928
+ // Parse versionNo from response
1929
+ let blockVersionNo = 'latest';
1930
+ // The first blockVersion should be the latest one
1931
+ try {
1932
+ blockVersionNo = `${blockVersionResponse?.[0]?.version.versionNo}`;
1933
+
1934
+ if (!Number.isNaN(blockVersionNo) && Number(blockVersionNo) > 0)
1935
+ // Is a valid versionNo
1936
+ return [null, blockVersionNo];
1937
+ else
1938
+ throw new Error(
1939
+ `Value cannot be parsed as a number: ${blockVersionNo}`
1940
+ );
1941
+ } catch (parseVersionEx: any) {
1942
+ // Catch parsing errors in case of an unexpected response
1943
+ log.error(messages.blocks.failedParsingVersion(), parseVersionEx);
1944
+ log.info(`${blockVersionResponse}`);
1945
+ return [parseVersionEx, undefined];
1946
+ }
1947
+ };
1948
+
1949
+ ExecuteBlockAction = async (
1950
+ action: BlockActionType,
1951
+ blockId: string,
1952
+ version = 'latest'
1953
+ ) => {
1905
1954
  const { currentEnv, env, log, messages } = this;
1906
1955
  const contensis = await this.ConnectContensis();
1907
1956
  if (contensis) {
1908
- // Retrieve block version
1957
+ let actionOnBlockVersion = version;
1958
+
1959
+ // If action is release and version is latest, find the latest version number
1960
+ if (action === 'release' && version === 'latest') {
1961
+ const [getErr, blockVersion] =
1962
+ await this.GetLastBlockVersionInMainOrMaster(blockId);
1963
+
1964
+ if (getErr) {
1965
+ // Log error getting latest block version no
1966
+ log.error(jsonFormatter(getErr));
1967
+ // and throw the error message so the process can exit with a failure
1968
+ throw new Error(
1969
+ messages.blocks.noList(currentEnv, env.currentProject)
1970
+ );
1971
+ } else if (blockVersion) {
1972
+ actionOnBlockVersion = blockVersion;
1973
+ }
1974
+ }
1975
+
1976
+ // Execute block action
1909
1977
  const [err, blockVersion] = await contensis.blocks.BlockAction(
1910
1978
  blockId,
1911
- 'release',
1912
- version
1979
+ action,
1980
+ actionOnBlockVersion
1913
1981
  );
1914
1982
 
1915
1983
  if (blockVersion) {
1916
1984
  this.HandleFormattingAndOutput(blockVersion, () => {
1917
1985
  // print the version detail to console
1918
1986
  log.success(
1919
- messages.blocks.released(blockId, currentEnv, env.currentProject)
1987
+ messages.blocks.actionComplete(
1988
+ action,
1989
+ blockId,
1990
+ currentEnv,
1991
+ env.currentProject
1992
+ )
1920
1993
  );
1921
1994
  printBlockVersion(this, blockVersion);
1922
1995
  });
1923
1996
  }
1924
1997
 
1925
1998
  if (err) {
1926
- log.error(
1927
- messages.blocks.failedRelease(blockId, currentEnv, env.currentProject)
1928
- );
1929
1999
  log.error(jsonFormatter(err));
2000
+ throw new Error(
2001
+ messages.blocks.actionFailed(
2002
+ action,
2003
+ blockId,
2004
+ currentEnv,
2005
+ env.currentProject
2006
+ )
2007
+ );
1930
2008
  }
1931
2009
  }
1932
2010
  };
package/src/shell.ts CHANGED
@@ -139,6 +139,10 @@ class ContensisShell {
139
139
  'create project',
140
140
  'create role',
141
141
  'diff models',
142
+ 'execute block action release',
143
+ 'execute block action makelive',
144
+ 'execute block action rollback',
145
+ 'execute block action markasbroken',
142
146
  'get block',
143
147
  'get block logs',
144
148
  'get contenttype',
@@ -161,7 +165,6 @@ class ContensisShell {
161
165
  'list roles',
162
166
  'list webhooks',
163
167
  'push block',
164
- 'release block',
165
168
  'remove components',
166
169
  'remove contenttypes',
167
170
  'remove key',
@@ -182,7 +185,7 @@ class ContensisShell {
182
185
  {
183
186
  type: 'command',
184
187
  name: 'cmd',
185
- autoCompletion: availableCommands,
188
+ autoCompletion: availableCommands.sort(),
186
189
  autocompletePrompt: log.infoText(messages.app.autocomplete()),
187
190
  message: `${userId ? `${userId}@` : ''}${currentEnvironment || ''}>`,
188
191
  context: 0,
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const LIB_VERSION = "1.0.0-beta.66";
1
+ export const LIB_VERSION = "1.0.0-beta.68";
@@ -1,47 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var release_exports = {};
20
- __export(release_exports, {
21
- makeReleaseCommand: () => makeReleaseCommand
22
- });
23
- module.exports = __toCommonJS(release_exports);
24
- var import_commander = require("commander");
25
- var import_ContensisCliService = require("../services/ContensisCliService");
26
- const makeReleaseCommand = () => {
27
- const release = new import_commander.Command().command("release").description("release command").addHelpText("after", `
28
- `).showHelpAfterError(true).exitOverride();
29
- release.command("block").description("release a block version").argument("<block-id>", "the name of the block to release").argument("<version>", "the block version to release").usage("<block-id> <version>").addHelpText(
30
- "after",
31
- `
32
- Example call:
33
- > release block contensis-app 3
34
- `
35
- ).action(async (blockId, version, opts) => {
36
- await (0, import_ContensisCliService.cliCommand)(["release", "block", blockId], opts).ReleaseBlock(
37
- blockId,
38
- version
39
- );
40
- });
41
- return release;
42
- };
43
- // Annotate the CommonJS export names for ESM import in node:
44
- 0 && (module.exports = {
45
- makeReleaseCommand
46
- });
47
- //# sourceMappingURL=release.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/commands/release.ts"],
4
- "sourcesContent": ["import { Command } from 'commander';\nimport { cliCommand } from '~/services/ContensisCliService';\n\nexport const makeReleaseCommand = () => {\n const release = new Command()\n .command('release')\n .description('release command')\n .addHelpText('after', `\\n`)\n .showHelpAfterError(true)\n .exitOverride();\n\n release\n .command('block')\n .description('release a block version')\n .argument('<block-id>', 'the name of the block to release')\n .argument('<version>', 'the block version to release')\n .usage('<block-id> <version>')\n .addHelpText(\n 'after',\n `\nExample call:\n > release block contensis-app 3\\n`\n )\n .action(async (blockId: string, version: string, opts) => {\n await cliCommand(['release', 'block', blockId], opts).ReleaseBlock(\n blockId,\n version\n );\n });\n\n return release;\n};\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAwB;AACxB,iCAA2B;AAEpB,MAAM,qBAAqB,MAAM;AACtC,QAAM,UAAU,IAAI,yBAAQ,EACzB,QAAQ,SAAS,EACjB,YAAY,iBAAiB,EAC7B,YAAY,SAAS;AAAA,CAAI,EACzB,mBAAmB,IAAI,EACvB,aAAa;AAEhB,UACG,QAAQ,OAAO,EACf,YAAY,yBAAyB,EACrC,SAAS,cAAc,kCAAkC,EACzD,SAAS,aAAa,8BAA8B,EACpD,MAAM,sBAAsB,EAC5B;AAAA,IACC;AAAA,IACA;AAAA;AAAA;AAAA;AAAA,EAGF,EACC,OAAO,OAAO,SAAiB,SAAiB,SAAS;AACxD,cAAM,uCAAW,CAAC,WAAW,SAAS,OAAO,GAAG,IAAI,EAAE;AAAA,MACpD;AAAA,MACA;AAAA,IACF;AAAA,EACF,CAAC;AAEH,SAAO;AACT;",
6
- "names": []
7
- }
@@ -1,32 +0,0 @@
1
- import { Command } from 'commander';
2
- import { cliCommand } from '~/services/ContensisCliService';
3
-
4
- export const makeReleaseCommand = () => {
5
- const release = new Command()
6
- .command('release')
7
- .description('release command')
8
- .addHelpText('after', `\n`)
9
- .showHelpAfterError(true)
10
- .exitOverride();
11
-
12
- release
13
- .command('block')
14
- .description('release a block version')
15
- .argument('<block-id>', 'the name of the block to release')
16
- .argument('<version>', 'the block version to release')
17
- .usage('<block-id> <version>')
18
- .addHelpText(
19
- 'after',
20
- `
21
- Example call:
22
- > release block contensis-app 3\n`
23
- )
24
- .action(async (blockId: string, version: string, opts) => {
25
- await cliCommand(['release', 'block', blockId], opts).ReleaseBlock(
26
- blockId,
27
- version
28
- );
29
- });
30
-
31
- return release;
32
- };