contensis-cli 1.1.2-beta.9 → 1.2.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.
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.1.2-beta.9";
24
+ const LIB_VERSION = "1.2.0";
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.1.2-beta.9\";\n"],
4
+ "sourcesContent": ["export const LIB_VERSION = \"1.2.0\";\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.1.2-beta.9",
3
+ "version": "1.2.0",
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/cli",
6
6
  "homepage": "https://github.com/contensis/cli/tree/main/packages/contensis-cli#readme",
@@ -18,7 +18,8 @@
18
18
  "build:watch": "node esbuild.config.js --watch",
19
19
  "cli": "node --inspect=9229 ./cli.js",
20
20
  "postinstall": "npx patch-package",
21
- "test": "echo \"Error: no test specified\" && exit 1"
21
+ "test": "echo \"Error: no test specified\" && exit 1",
22
+ "package-lock": "npm i --package-lock-only --workspaces false"
22
23
  },
23
24
  "author": "Zengenti",
24
25
  "license": "ISC",
@@ -39,7 +40,7 @@
39
40
  "jsonpath-mapper": "^1.1.0",
40
41
  "keytar": "^7.9.0",
41
42
  "lodash": "^4.17.21",
42
- "migratortron": "^1.0.0-beta.46",
43
+ "migratortron": "^1.0.0-beta.48",
43
44
  "nanospinner": "^1.1.0",
44
45
  "node-fetch": "^2.6.7",
45
46
  "parse-git-config": "^3.0.0",
@@ -4,9 +4,11 @@ import { cliCommand } from '~/services/ContensisCliService';
4
4
  import {
5
5
  commit,
6
6
  concurrency,
7
+ entryId,
7
8
  ignoreErrors,
8
9
  mapContensisOpts,
9
10
  outputEntries,
11
+ zenql,
10
12
  } from './globalOptions';
11
13
 
12
14
  export const makeCopyCommand = () => {
@@ -34,6 +36,16 @@ export const makeCopyCommand = () => {
34
36
  .addOption(concurrency)
35
37
  .addOption(ignoreErrors)
36
38
  .addOption(outputEntries)
39
+ .option(
40
+ '--search <phrase>',
41
+ 'get entries with the search phrase, use quotes for multiple words'
42
+ )
43
+ .addOption(entryId)
44
+ .addOption(zenql)
45
+ .option(
46
+ '-s --save-entries',
47
+ "save the entries we're migrating instead of the migration preview when using --output option"
48
+ )
37
49
  .usage('<contentTypeId> <fieldId> <destinationId> (all arguments required)')
38
50
  .addHelpText(
39
51
  'after',
@@ -49,6 +61,7 @@ Example call:
49
61
  destinationId: string,
50
62
  opts: any
51
63
  ) => {
64
+ const { template, ...restOpts } = opts;
52
65
  const copyField: CopyField = {
53
66
  contentTypeId,
54
67
  fieldId,
@@ -59,11 +72,12 @@ Example call:
59
72
  return await cliCommand(
60
73
  ['copy', 'project', contentTypeId, fieldId, destinationId],
61
74
  opts,
62
- mapContensisOpts({ copyField })
75
+ mapContensisOpts({ copyField, ...restOpts })
63
76
  ).CopyEntryField({
64
77
  commit: opts.commit,
65
78
  fromFile: opts.fromFile,
66
79
  logOutput: opts.outputEntries,
80
+ saveEntries: opts.saveEntries,
67
81
  });
68
82
  }
69
83
  );
@@ -18,7 +18,7 @@ export const makeCreateCommand = () => {
18
18
  .argument('<name>', 'the name of the project to create')
19
19
  .argument('[description]', 'optional description of the project')
20
20
  .option(
21
- '-l --language',
21
+ '-l --language <language>',
22
22
  'the default language of the project to create',
23
23
  'en-GB'
24
24
  )
@@ -5,6 +5,7 @@ import {
5
5
  addGlobalOptions,
6
6
  assetTypes,
7
7
  contentTypes,
8
+ delivery,
8
9
  entryId,
9
10
  mapContensisOpts,
10
11
  zenql,
@@ -184,7 +185,8 @@ Example call:
184
185
  '-ob --order-by <orderBy...>',
185
186
  'field name(s) to order the results by (prefix "-" for descending)'
186
187
  )
187
- );
188
+ )
189
+ .addOption(delivery);
188
190
 
189
191
  sharedGetEntryOptions(
190
192
  program
@@ -204,13 +206,13 @@ Example call:
204
206
  > get assets --zenql "sys.contentTypeId = blog" --fields sys.id sys.properties.filePath sys.properties.filename
205
207
  `
206
208
  )
207
- .action(async (phrase: string, opts) => {
209
+ .action(async (search: string, opts) => {
208
210
  // Maintaining a separate command for assets vs entries
209
211
  // allows us to offer up more options when dealing with just assets
210
212
  await cliCommand(
211
213
  ['get', 'assets'],
212
214
  opts,
213
- mapContensisOpts({ dataFormat: 'asset', phrase, ...opts })
215
+ mapContensisOpts({ dataFormat: 'asset', search, ...opts })
214
216
  ).GetEntries({});
215
217
  });
216
218
 
@@ -244,13 +246,11 @@ Example call:
244
246
  > get entries --content-type blog --fields entryTitle sys.version.modified --order-by -sys.version.modified
245
247
  `
246
248
  )
247
- .action(async (phrase: string, opts, cmd) => {
248
- // console.log('phrase: ', phrase, '\nopts:', JSON.stringify(opts, null, 2));
249
- // console.log('opts:', JSON.stringify(opts, null, 2));
249
+ .action(async (search: string, opts, cmd) => {
250
250
  await cliCommand(
251
251
  ['get', 'entries'],
252
252
  opts,
253
- mapContensisOpts({ phrase, ...opts })
253
+ mapContensisOpts({ search, ...opts })
254
254
  ).GetEntries({
255
255
  withDependents: opts.dependents,
256
256
  });
@@ -20,13 +20,14 @@ export const mapContensisOpts = (opts: any = {}): MigrateRequest => ({
20
20
  query:
21
21
  opts.id ||
22
22
  opts.entryIds ||
23
- opts.phrase ||
23
+ opts.search ||
24
24
  opts.fields ||
25
25
  opts.orderBy ||
26
26
  opts.paths ||
27
27
  opts.assetType ||
28
28
  opts.contentType ||
29
- opts.dataFormat
29
+ opts.dataFormat ||
30
+ opts.deliveryApi
30
31
  ? {
31
32
  assetTypes: opts.assetType,
32
33
  contentTypeIds: opts.contentType,
@@ -35,7 +36,8 @@ export const mapContensisOpts = (opts: any = {}): MigrateRequest => ({
35
36
  includeIds: opts.id || opts.entryIds,
36
37
  includePaths: opts.paths,
37
38
  orderBy: opts.orderBy,
38
- searchTerm: opts.phrase,
39
+ searchTerm: opts.search,
40
+ useDelivery: opts.deliveryApi,
39
41
  }
40
42
  : undefined,
41
43
  zenQL: opts.zenql,
@@ -85,6 +87,14 @@ const sharedSecret = new Option(
85
87
  );
86
88
 
87
89
  /* Entry get options */
90
+ export const delivery = new Option(
91
+ '-delivery --delivery-api',
92
+ 'use delivery api to get the entries'
93
+ );
94
+ export const search = new Option(
95
+ '--search <phrase>',
96
+ 'get entries with the search phrase, use quotes for multiple words'
97
+ );
88
98
  export const zenql = new Option(
89
99
  '-q --zenql <zenql>',
90
100
  'get entries with a supplied ZenQL statement'
@@ -126,11 +126,11 @@ Example call:
126
126
  > import entries --from-file myImportData.json --preserve-guids
127
127
  `
128
128
  )
129
- .action(async (phrase: string, opts, cmd) => {
129
+ .action(async (search: string, opts, cmd) => {
130
130
  await cliCommand(
131
131
  ['import', 'entries'],
132
132
  opts,
133
- mapContensisOpts({ phrase, ...opts })
133
+ mapContensisOpts({ search, ...opts })
134
134
  ).ImportEntries({
135
135
  commit: opts.commit,
136
136
  fromFile: opts.fromFile,
@@ -183,9 +183,9 @@ export const LogMessages = {
183
183
  removed: (env: string, id: string, commit: boolean) =>
184
184
  `[${env}] ${
185
185
  commit ? `Deleted` : `Will delete`
186
- } content type ${Logger.highlightText(id)}`,
186
+ } content type(s) ${Logger.highlightText(id)}`,
187
187
  failedRemove: (env: string, id: string) =>
188
- `[${env}] Unable to delete content type ${Logger.highlightText(id)}`,
188
+ `[${env}] Unable to delete content type(s) ${Logger.highlightText(id)}`,
189
189
  },
190
190
  components: {
191
191
  list: (projectId: string) =>
@@ -199,9 +199,9 @@ export const LogMessages = {
199
199
  removed: (env: string, id: string, commit: boolean) =>
200
200
  `[${env}] ${
201
201
  commit ? `Deleted` : `Will delete`
202
- } component ${Logger.highlightText(id)}`,
202
+ } component(s) ${Logger.highlightText(id)}`,
203
203
  failedRemove: (env: string, id: string) =>
204
- `[${env}] Unable to delete component ${Logger.highlightText(id)}`,
204
+ `[${env}] Unable to delete component(s) ${Logger.highlightText(id)}`,
205
205
  },
206
206
  version: {
207
207
  set: (env: string, versionStatus: string) =>
@@ -1406,7 +1406,7 @@ class ContensisCli {
1406
1406
  log.error(
1407
1407
  messages.contenttypes.failedRemove(
1408
1408
  currentProject,
1409
- contentTypeIds.join('", "')
1409
+ contentTypeIds.join(', ')
1410
1410
  ),
1411
1411
  err
1412
1412
  );
@@ -1414,14 +1414,12 @@ class ContensisCli {
1414
1414
  log.success(
1415
1415
  messages.contenttypes.removed(
1416
1416
  currentProject,
1417
- contentTypeIds.join('", "'),
1417
+ contentTypeIds.join(', '),
1418
1418
  !contensis.isPreview
1419
1419
  )
1420
1420
  );
1421
1421
  // print the results to console
1422
- await this.HandleFormattingAndOutput(result, () =>
1423
- log.object(jsonFormatter(result))
1424
- );
1422
+ await this.HandleFormattingAndOutput(result, log.object);
1425
1423
  }
1426
1424
  }
1427
1425
  };
@@ -1452,28 +1450,37 @@ class ContensisCli {
1452
1450
  });
1453
1451
 
1454
1452
  if (contensis) {
1455
- // Pass each content type to the target repo
1456
- for (const contentType of fileData) {
1457
- // Fix invalid data
1458
- contentType.projectId = currentProject;
1459
- delete contentType.uuid;
1460
-
1461
- const [err, created, createStatus] = await contensis.models.targetRepos[
1462
- currentProject
1463
- ].repo.UpsertContentType(false, contentType);
1464
-
1465
- if (err) log.error(err.message, err);
1466
- if (createStatus) {
1467
- log.success(
1468
- messages.contenttypes.created(
1469
- currentProject,
1470
- contentType.id,
1471
- createStatus
1472
- )
1473
- );
1474
- // print the content type to console
1475
- await this.HandleFormattingAndOutput(contentType, () => {});
1453
+ if (fromFile)
1454
+ // Pass each content type to the target repo
1455
+ for (const contentType of fileData) {
1456
+ // Fix invalid data
1457
+ contentType.projectId = currentProject;
1458
+ delete contentType.uuid;
1459
+
1460
+ const [err, created, createStatus] =
1461
+ await contensis.models.targetRepos[
1462
+ currentProject
1463
+ ].repo.UpsertContentType(false, contentType);
1464
+
1465
+ if (err) log.error(err.message, err);
1466
+ if (createStatus) {
1467
+ log.success(
1468
+ messages.contenttypes.created(
1469
+ currentProject,
1470
+ contentType.id,
1471
+ createStatus
1472
+ )
1473
+ );
1474
+ // print the content type to console
1475
+ await this.HandleFormattingAndOutput(contentType, () => {});
1476
+ }
1476
1477
  }
1478
+ else {
1479
+ const result = await contensis.simpleMigration.Migrate(
1480
+ contentTypeIds,
1481
+ []
1482
+ );
1483
+ await this.HandleFormattingAndOutput(result, log.object);
1477
1484
  }
1478
1485
  }
1479
1486
  };
@@ -1590,7 +1597,7 @@ class ContensisCli {
1590
1597
  log.error(
1591
1598
  messages.components.failedRemove(
1592
1599
  currentProject,
1593
- componentIds.join('", "')
1600
+ componentIds.join(', ')
1594
1601
  ),
1595
1602
  err
1596
1603
  );
@@ -1598,14 +1605,12 @@ class ContensisCli {
1598
1605
  log.success(
1599
1606
  messages.components.removed(
1600
1607
  currentProject,
1601
- componentIds.join('", "'),
1608
+ componentIds.join(', '),
1602
1609
  !contensis.isPreview
1603
1610
  )
1604
1611
  );
1605
1612
  // print the results to console
1606
- await this.HandleFormattingAndOutput(result, () =>
1607
- log.info(jsonFormatter(result))
1608
- );
1613
+ await this.HandleFormattingAndOutput(result, log.object);
1609
1614
  }
1610
1615
  }
1611
1616
  };
@@ -1637,27 +1642,36 @@ class ContensisCli {
1637
1642
 
1638
1643
  if (contensis) {
1639
1644
  // Pass each component to the target repo
1640
- for (const component of fileData) {
1641
- // Fix invalid data
1642
- component.projectId = currentProject;
1643
- delete component.uuid;
1644
-
1645
- const [err, created, createStatus] = await contensis.models.targetRepos[
1646
- currentProject
1647
- ].repo.UpsertComponent(false, component);
1648
-
1649
- if (err) log.error(err.message, err);
1650
- if (createStatus) {
1651
- log.success(
1652
- messages.components.created(
1653
- currentProject,
1654
- component.id,
1655
- createStatus
1656
- )
1657
- );
1658
- // print the component to console
1659
- await this.HandleFormattingAndOutput(component, () => {});
1645
+ if (fromFile)
1646
+ for (const component of fileData) {
1647
+ // Fix invalid data
1648
+ component.projectId = currentProject;
1649
+ delete component.uuid;
1650
+
1651
+ const [err, created, createStatus] =
1652
+ await contensis.models.targetRepos[
1653
+ currentProject
1654
+ ].repo.UpsertComponent(false, component);
1655
+
1656
+ if (err) log.error(err.message, err);
1657
+ if (createStatus) {
1658
+ log.success(
1659
+ messages.components.created(
1660
+ currentProject,
1661
+ component.id,
1662
+ createStatus
1663
+ )
1664
+ );
1665
+ // print the component to console
1666
+ await this.HandleFormattingAndOutput(component, () => {});
1667
+ }
1660
1668
  }
1669
+ else {
1670
+ const result = await contensis.simpleMigration.Migrate(
1671
+ [],
1672
+ componentIds
1673
+ );
1674
+ await this.HandleFormattingAndOutput(result, log.object);
1661
1675
  }
1662
1676
  }
1663
1677
  };
@@ -1801,10 +1815,12 @@ class ContensisCli {
1801
1815
  commit,
1802
1816
  fromFile,
1803
1817
  logOutput,
1818
+ saveEntries,
1804
1819
  }: {
1805
1820
  commit: boolean;
1806
1821
  fromFile: string;
1807
1822
  logOutput: string;
1823
+ saveEntries: boolean;
1808
1824
  }) => {
1809
1825
  const { currentEnv, currentProject, log, messages } = this;
1810
1826
 
@@ -1827,8 +1843,13 @@ class ContensisCli {
1827
1843
  );
1828
1844
 
1829
1845
  if (err) logError(err);
1830
- if (result)
1831
- await this.HandleFormattingAndOutput(result, () => {
1846
+ if (result) {
1847
+ const output = saveEntries
1848
+ ? contensis.content.copy.targets[currentProject].migrateEntries?.map(
1849
+ me => me.finalEntry
1850
+ )
1851
+ : result;
1852
+ await this.HandleFormattingAndOutput(output, () => {
1832
1853
  // print the migrateResult to console
1833
1854
  printEntriesMigrateResult(this, result, {
1834
1855
  showAll: logOutput === 'all',
@@ -1836,6 +1857,7 @@ class ContensisCli {
1836
1857
  showChanged: logOutput === 'changes',
1837
1858
  });
1838
1859
  });
1860
+ }
1839
1861
 
1840
1862
  if (
1841
1863
  result &&
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const LIB_VERSION = "1.1.2-beta.9";
1
+ export const LIB_VERSION = "1.2.0";
package/tsconfig.json CHANGED
@@ -11,6 +11,7 @@
11
11
  "strict": true,
12
12
  "declaration": true,
13
13
  "resolveJsonModule": true,
14
+ "forceConsistentCasingInFileNames": true,
14
15
  "outDir": "dist",
15
16
  "baseUrl": ".",
16
17
  "paths": {