@contentstack/cli-cm-export 1.3.0 → 1.5.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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2022 Contentstack
3
+ Copyright (c) 2023 Contentstack
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -38,7 +38,7 @@ $ npm install -g @contentstack/cli-cm-export
38
38
  $ csdx COMMAND
39
39
  running command...
40
40
  $ csdx (--version)
41
- @contentstack/cli-cm-export/1.3.0 linux-x64 node-v16.19.0
41
+ @contentstack/cli-cm-export/1.5.0 linux-x64 node-v16.20.0
42
42
  $ csdx --help [COMMAND]
43
43
  USAGE
44
44
  $ csdx COMMAND
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.3.0",
2
+ "version": "1.5.0",
3
3
  "commands": {
4
4
  "cm:stacks:export": {
5
5
  "id": "cm:stacks:export",
package/package.json CHANGED
@@ -1,17 +1,18 @@
1
1
  {
2
2
  "name": "@contentstack/cli-cm-export",
3
3
  "description": "Contentstack CLI plugin to export content from stack",
4
- "version": "1.3.0",
4
+ "version": "1.5.0",
5
5
  "author": "Contentstack",
6
6
  "bugs": "https://github.com/contentstack/cli/issues",
7
7
  "dependencies": {
8
- "@contentstack/cli-command": "^1.1.0",
9
- "@contentstack/cli-utilities": "^1.1.0",
8
+ "@contentstack/cli-command": "^1.2.1",
9
+ "@contentstack/cli-utilities": "^1.2.1",
10
10
  "@oclif/command": "^1.8.16",
11
11
  "@oclif/config": "^1.18.3",
12
12
  "async": "^3.2.4",
13
13
  "big-json": "^3.2.0",
14
14
  "bluebird": "^3.7.2",
15
+ "chalk": "^4.1.2",
15
16
  "is-valid-path": "^0.1.1",
16
17
  "lodash": "^4.17.20",
17
18
  "mkdirp": "^1.0.4",
@@ -22,10 +23,9 @@
22
23
  "winston": "^3.7.2"
23
24
  },
24
25
  "devDependencies": {
25
- "@contentstack/cli-auth": "^1.0.6",
26
- "@contentstack/cli-config": "^1.0.4",
27
- "@contentstack/cli-dev-dependencies": "^1.0.0",
28
- "@oclif/dev-cli": "^1.26.10",
26
+ "@contentstack/cli-auth": "^1.2.1",
27
+ "@contentstack/cli-config": "^1.2.1",
28
+ "@contentstack/cli-dev-dependencies": "^1.2.0",
29
29
  "@oclif/plugin-help": "^5.1.19",
30
30
  "@oclif/test": "^1.2.6",
31
31
  "assert": "^2.0.0",
@@ -33,14 +33,15 @@
33
33
  "dotenv": "^16.0.1",
34
34
  "dotenv-expand": "^9.0.0",
35
35
  "eslint": "^8.18.0",
36
- "eslint-config-oclif": "^3.1.0",
36
+ "eslint-config-oclif": "^4.0.0",
37
37
  "globby": "^10.0.2",
38
38
  "mocha": "10.1.0",
39
39
  "nyc": "^15.1.0",
40
- "sinon": "^15.0.1"
40
+ "sinon": "^15.0.1",
41
+ "oclif": "^3.1.2"
41
42
  },
42
43
  "engines": {
43
- "node": ">=8.0.0"
44
+ "node": ">=14.0.0"
44
45
  },
45
46
  "files": [
46
47
  "/npm-shrinkwrap.json",
@@ -60,6 +61,7 @@
60
61
  "prepack": "oclif manifest && oclif readme",
61
62
  "test": "nyc mocha --forbid-only \"test/**/*.test.js\"",
62
63
  "version": "oclif readme && git add README.md",
64
+ "clean": "rm -rf ./node_modules tsconfig.build.tsbuildinfo",
63
65
  "test:integration": "mocha --forbid-only \"test/run.test.js\" --integration-test",
64
66
  "test:unit": "mocha --forbid-only \"test/unit/*.test.js\" --unit-test"
65
67
  },
@@ -71,6 +73,10 @@
71
73
  "csdxConfig": {
72
74
  "expiredCommands": {
73
75
  "cm:export": "csdx cm:stacks:export"
76
+ },
77
+ "shortCommandName": {
78
+ "cm:stacks:export": "EXPRT",
79
+ "cm:export": "O-EXPRT"
74
80
  }
75
81
  },
76
82
  "main": "./src/commands/cm/stacks/export.js",
package/src/app.js CHANGED
@@ -6,7 +6,7 @@ const util = require('./lib/util');
6
6
  const login = require('./lib/util/login');
7
7
  const setupBranches = require('./lib/util/setup-branches');
8
8
  const { addlogs, unlinkFileLogger } = require('./lib/util/log');
9
- const { managementSDKClient } = require('@contentstack/cli-utilities');
9
+ const { managementSDKClient, isAuthenticated } = require('@contentstack/cli-utilities');
10
10
 
11
11
  exports.initial = async (config) => {
12
12
  return new Promise(async (resolve, reject) => {
@@ -56,7 +56,7 @@ exports.initial = async (config) => {
56
56
  if (
57
57
  (config.email && config.password) ||
58
58
  (!config.email && !config.password && config.source_stack && config.access_token) ||
59
- (config.auth_token && !config.management_token)
59
+ (isAuthenticated() && !config.management_token)
60
60
  ) {
61
61
  login
62
62
  .login(config)
@@ -1,7 +1,5 @@
1
1
  /* eslint-disable complexity */
2
- const { Command, flags } = require('@contentstack/cli-command');
3
- const { printFlagDeprecation } = require('@contentstack/cli-utilities');
4
-
2
+ const { Command } = require('@contentstack/cli-command');
5
3
  const {
6
4
  configWithMToken,
7
5
  parameterWithMToken,
@@ -11,7 +9,7 @@ const {
11
9
  withoutParametersWithAuthToken,
12
10
  } = require('../../../lib/util/export-flags');
13
11
  const config = require('../../../config/default');
14
- const { configHandler } = require('@contentstack/cli-utilities');
12
+ const { configHandler, printFlagDeprecation, flags, isAuthenticated } = require('@contentstack/cli-utilities');
15
13
 
16
14
  class ExportCommand extends Command {
17
15
  async run() {
@@ -24,7 +22,6 @@ class ExportCommand extends Command {
24
22
  const moduleName = exportCommandFlags.module;
25
23
  const contentTypes = exportCommandFlags['content-types'];
26
24
  const branchName = exportCommandFlags.branch;
27
- let _authToken = configHandler.get('authtoken');
28
25
  let host = this.region;
29
26
  let cmaHost = host.cma.split('//');
30
27
  let cdaHost = host.cda.split('//');
@@ -58,7 +55,6 @@ class ExportCommand extends Command {
58
55
  data,
59
56
  moduleName,
60
57
  host,
61
- _authToken,
62
58
  contentTypes,
63
59
  branchName,
64
60
  securedAssets,
@@ -68,7 +64,6 @@ class ExportCommand extends Command {
68
64
  managementTokens,
69
65
  moduleName,
70
66
  host,
71
- _authToken,
72
67
  contentTypes,
73
68
  branchName,
74
69
  securedAssets,
@@ -79,12 +74,11 @@ class ExportCommand extends Command {
79
74
  } else {
80
75
  this.log(alias + ' management token is not present, please add managment token first');
81
76
  }
82
- } else if (_authToken) {
77
+ } else if (isAuthenticated()) {
83
78
  if (extConfig) {
84
- await configWithAuthToken(extConfig, _authToken, moduleName, host, contentTypes, branchName, securedAssets);
79
+ await configWithAuthToken(extConfig, moduleName, host, contentTypes, branchName, securedAssets);
85
80
  } else if (sourceStack && data) {
86
81
  return await parametersWithAuthToken(
87
- _authToken,
88
82
  sourceStack,
89
83
  data,
90
84
  moduleName,
@@ -94,7 +88,7 @@ class ExportCommand extends Command {
94
88
  securedAssets,
95
89
  );
96
90
  } else if (data === undefined && sourceStack === undefined) {
97
- await withoutParametersWithAuthToken(_authToken, moduleName, host, contentTypes, branchName, securedAssets);
91
+ await withoutParametersWithAuthToken(moduleName, host, contentTypes, branchName, securedAssets);
98
92
  } else {
99
93
  this.log('Please provide a valid command. Run "csdx cm:export --help" command to view the command usage');
100
94
  }
@@ -33,6 +33,11 @@ module.exports = {
33
33
  fileName: 'locales.json',
34
34
  requiredKeys: ['code', 'uid', 'name', 'fallback_locale'],
35
35
  },
36
+ masterLocale: {
37
+ dirName: 'locales',
38
+ fileName: 'master-locale.json',
39
+ requiredKeys: ['code', 'uid', 'name'],
40
+ },
36
41
  customRoles: {
37
42
  dirName: 'custom-roles',
38
43
  fileName: 'custom-roles.json',
@@ -11,7 +11,7 @@ const Promise = require('bluebird');
11
11
  const _ = require('lodash');
12
12
  const chalk = require('chalk');
13
13
  const progress = require('progress-stream');
14
- const { HttpClient } = require('@contentstack/cli-utilities');
14
+ const { HttpClient, configHandler } = require('@contentstack/cli-utilities');
15
15
 
16
16
  const helper = require('../util/helper');
17
17
  const { addlogs } = require('../util/log');
@@ -350,7 +350,7 @@ module.exports = class ExportAssets {
350
350
  }
351
351
  self.assetStream = {
352
352
  url: self.config.securedAssets
353
- ? `${asset.url}?authtoken=${self.config.authtoken || self.config.auth_token}`
353
+ ? `${asset.url}?authtoken=${configHandler.get('authtoken')}`
354
354
  : asset.url,
355
355
  };
356
356
 
@@ -7,14 +7,10 @@ class LocaleExport {
7
7
  this.stackAPIClient = stackAPIClient;
8
8
  this.exportConfig = exportConfig;
9
9
  this.localeConfig = exportConfig.modules.locales;
10
+ this.masterLocaleConfig = exportConfig.modules.masterLocale;
10
11
  this.qs = {
11
12
  include_count: true,
12
13
  asc: 'updated_at',
13
- query: {
14
- code: {
15
- $nin: [exportConfig.master_locale.code],
16
- },
17
- },
18
14
  only: {
19
15
  BASE: this.localeConfig.requiredKeys,
20
16
  },
@@ -22,6 +18,7 @@ class LocaleExport {
22
18
 
23
19
  this.localesPath = path.resolve(exportConfig.data, exportConfig.branchName || '', this.localeConfig.dirName);
24
20
  this.locales = {};
21
+ this.masterLocale = {};
25
22
  this.fetchConcurrency = this.localeConfig.fetchConcurrency || this.exportConfig.fetchConcurrency;
26
23
  this.writeConcurrency = this.localeConfig.writeConcurrency || this.exportConfig.writeConcurrency;
27
24
  }
@@ -32,6 +29,7 @@ class LocaleExport {
32
29
  await fileHelper.makeDirectory(this.localesPath);
33
30
  await this.getLocales();
34
31
  await fileHelper.writeFile(path.join(this.localesPath, this.localeConfig.fileName), this.locales);
32
+ await fileHelper.writeFile(path.join(this.localesPath, this.masterLocaleConfig.fileName), this.masterLocale);
35
33
  addlogs(this.exportConfig, 'Completed locale export', 'success');
36
34
  } catch (error) {
37
35
  addlogs(this.exportConfig, chalk.red(`Failed to export locales ${formatError(error)}`), 'error');
@@ -61,7 +59,11 @@ class LocaleExport {
61
59
  delete locale[key];
62
60
  }
63
61
  }
64
- this.locales[locale.uid] = locale;
62
+ if(locale.code === this.exportConfig.master_locale.code){
63
+ this.masterLocale[locale.uid] = locale;
64
+ }else{
65
+ this.locales[locale.uid] = locale;
66
+ }
65
67
  });
66
68
  }
67
69
  }
@@ -7,7 +7,14 @@ const _ = require('lodash');
7
7
  const path = require('path');
8
8
  const chalk = require('chalk');
9
9
  const mkdirp = require('mkdirp');
10
- const { cliux, HttpClient, NodeCrypto, managementSDKClient } = require('@contentstack/cli-utilities');
10
+ const {
11
+ cliux,
12
+ HttpClient,
13
+ NodeCrypto,
14
+ managementSDKClient,
15
+ isAuthenticated,
16
+ configHandler
17
+ } = require('@contentstack/cli-utilities');
11
18
 
12
19
  const { formatError } = require('../util');
13
20
  const config = require('../../config/default');
@@ -29,9 +36,7 @@ module.exports = class ExportMarketplaceApps {
29
36
  }
30
37
 
31
38
  async start() {
32
- this.developerHubBaseUrl = this.config.developerHubBaseUrl || (await getDeveloperHubUrl());
33
-
34
- if (!this.config.auth_token) {
39
+ if (!isAuthenticated()) {
35
40
  cliux.print(
36
41
  'WARNING!!! To export Marketplace apps, you must be logged in. Please check csdx auth:login --help to log in',
37
42
  { color: 'yellow' },
@@ -39,10 +44,12 @@ module.exports = class ExportMarketplaceApps {
39
44
  return Promise.resolve();
40
45
  }
41
46
 
47
+ this.developerHubBaseUrl = this.config.developerHubBaseUrl || (await getDeveloperHubUrl());
48
+
42
49
  await this.getOrgUid();
43
50
 
44
51
  this.httpClient = new HttpClient().headers({
45
- authtoken: this.config.auth_token,
52
+ authtoken: configHandler.get('authtoken'),
46
53
  organization_uid: this.config.org_uid,
47
54
  });
48
55
 
@@ -58,7 +65,7 @@ module.exports = class ExportMarketplaceApps {
58
65
  }
59
66
 
60
67
  async getOrgUid() {
61
- if (this.config.auth_token) {
68
+ if (isAuthenticated()) {
62
69
  const tempAPIClient = await managementSDKClient({ host: this.config.host });
63
70
  const tempStackData = await tempAPIClient
64
71
  .stack({ api_key: this.config.source_stack })
@@ -10,7 +10,7 @@ const { merge } = require('lodash');
10
10
  const helper = require('../util/helper');
11
11
  const { addlogs } = require('../util/log');
12
12
  const config = require('../../config/default');
13
- const { managementSDKClient } = require('@contentstack/cli-utilities');
13
+ const { managementSDKClient, isAuthenticated } = require('@contentstack/cli-utilities');
14
14
  module.exports = class ExportStack {
15
15
  stackConfig = config.modules.stack;
16
16
 
@@ -27,7 +27,7 @@ module.exports = class ExportStack {
27
27
 
28
28
  async start() {
29
29
  const self = this;
30
- if (self.config.auth_token) {
30
+ if (isAuthenticated()) {
31
31
  const tempAPIClient = await managementSDKClient({ host: config.host });
32
32
  const tempStackData = await tempAPIClient
33
33
  .stack({ api_key: self.config.source_stack })
@@ -35,13 +35,11 @@ exports.parameterWithMToken = async function (
35
35
  data,
36
36
  moduleName,
37
37
  host,
38
- _authToken,
39
38
  contentTypes,
40
39
  branchName,
41
40
  securedAssets,
42
41
  ) {
43
42
  defaultConfig.management_token = managementTokens.token;
44
- defaultConfig.auth_token = _authToken;
45
43
  defaultConfig.host = host.cma;
46
44
  defaultConfig.cdn = host.cda;
47
45
  defaultConfig.branchName = branchName;
@@ -65,7 +63,6 @@ exports.withoutParameterMToken = async (
65
63
  managementTokens,
66
64
  moduleName,
67
65
  host,
68
- _authToken,
69
66
  contentTypes,
70
67
  branchName,
71
68
  securedAssets,
@@ -76,7 +73,6 @@ exports.withoutParameterMToken = async (
76
73
  defaultConfig.host = host.cma;
77
74
  defaultConfig.cdn = host.cda;
78
75
  defaultConfig.branchName = branchName;
79
- defaultConfig.auth_token = _authToken;
80
76
  defaultConfig.securedAssets = securedAssets;
81
77
  if (moduleName) {
82
78
  defaultConfig.moduleName = moduleName;
@@ -90,9 +86,8 @@ exports.withoutParameterMToken = async (
90
86
  await initial(defaultConfig);
91
87
  };
92
88
 
93
- exports.configWithAuthToken = async function (config, _authToken, moduleName, host, contentTypes, branchName, securedAssets) {
89
+ exports.configWithAuthToken = async function (config, moduleName, host, contentTypes, branchName, securedAssets) {
94
90
  let externalConfig = helper.readFile(path.resolve(config));
95
- defaultConfig.auth_token = _authToken;
96
91
  defaultConfig.host = host.cma;
97
92
  defaultConfig.cdn = host.cda;
98
93
  defaultConfig.branchName = branchName;
@@ -109,7 +104,6 @@ exports.configWithAuthToken = async function (config, _authToken, moduleName, ho
109
104
  };
110
105
 
111
106
  exports.parametersWithAuthToken = function (
112
- _authToken,
113
107
  sourceStack,
114
108
  data,
115
109
  moduleName,
@@ -119,7 +113,6 @@ exports.parametersWithAuthToken = function (
119
113
  securedAssets,
120
114
  ) {
121
115
  return new Promise(async (resolve, reject) => {
122
- defaultConfig.auth_token = _authToken;
123
116
  defaultConfig.source_stack = sourceStack;
124
117
  if (moduleName) {
125
118
  defaultConfig.moduleName = moduleName;
@@ -144,7 +137,6 @@ exports.parametersWithAuthToken = function (
144
137
  };
145
138
 
146
139
  exports.withoutParametersWithAuthToken = async (
147
- _authToken,
148
140
  moduleName,
149
141
  host,
150
142
  contentTypes,
@@ -153,7 +145,6 @@ exports.withoutParametersWithAuthToken = async (
153
145
  ) => {
154
146
  const stackUid = await cliux.prompt(message.promptMessageList.promptSourceStack);
155
147
  const pathOfExport = await cliux.prompt(message.promptMessageList.promptPathStoredData);
156
- defaultConfig.auth_token = _authToken;
157
148
  defaultConfig.source_stack = stackUid;
158
149
  defaultConfig.securedAssets = securedAssets;
159
150
  if (moduleName) {
@@ -8,6 +8,7 @@ var _ = require('lodash');
8
8
  var defaultConfig = require('../../config/default');
9
9
  const chalk = require('chalk');
10
10
  const promiseLimit = require('promise-limit');
11
+ const { isAuthenticated } = require('@contentstack/cli-utilities')
11
12
 
12
13
  exports.validateConfig = function (config) {
13
14
  if (!config.host || !config.cdn) {
@@ -22,7 +23,7 @@ exports.validateConfig = function (config) {
22
23
  !config.management_token &&
23
24
  config.source_stack &&
24
25
  !config.access_token &&
25
- !config.auth_token
26
+ !isAuthenticated()
26
27
  ) {
27
28
  throw new Error('Kindly provide management_token or email and password');
28
29
  } else if (
@@ -31,7 +32,7 @@ exports.validateConfig = function (config) {
31
32
  !config.access_token &&
32
33
  config.source_stack &&
33
34
  !config.management_token &&
34
- !config.auth_token
35
+ !isAuthenticated()
35
36
  ) {
36
37
  throw new Error('Kindly provide access_token or management_token');
37
38
  } else if (!config.email && !config.password && config.preserveStackVersion) {
@@ -9,7 +9,7 @@
9
9
 
10
10
  const chalk = require('chalk');
11
11
  const { addlogs } = require('../util/log');
12
- const { managementSDKClient } = require('@contentstack/cli-utilities');
12
+ const { managementSDKClient, isAuthenticated } = require('@contentstack/cli-utilities');
13
13
 
14
14
  module.exports.login = (config) => {
15
15
  return new Promise((resolve, reject) => {
@@ -22,11 +22,10 @@ module.exports.login = (config) => {
22
22
  .then((response) => {
23
23
  // eslint-disable-next-line no-console
24
24
  console.log(chalk.green('Contentstack account authenticated successfully!'));
25
- config.authtoken = response.user.authtoken;
26
25
  config.headers = {
27
26
  api_key: config.source_stack,
28
27
  access_token: config.access_token,
29
- authtoken: config.authtoken,
28
+ authtoken: response.user.authtoken,
30
29
  'X-User-Agent': 'contentstack-export/v',
31
30
  };
32
31
  resolve(config);
@@ -34,7 +33,7 @@ module.exports.login = (config) => {
34
33
  .catch((error) => {
35
34
  reject(error);
36
35
  });
37
- } else if (config.auth_token && !config.management_token) {
36
+ } else if (isAuthenticated() && !config.management_token) {
38
37
  const stackAPIClient = APIClient.stack({
39
38
  api_key: config.source_stack,
40
39
  management_token: config.management_token,
@@ -1,6 +1,7 @@
1
1
  const mkdirp = require('mkdirp');
2
2
  const path = require('path');
3
3
  const helper = require('./helper');
4
+ const {isAuthenticated, configHandler} = require('@contentstack/cli-utilities')
4
5
 
5
6
  const setupBranches = async (config, branch, stackAPIClient) => {
6
7
  if (typeof config !== 'object') {
@@ -9,8 +10,8 @@ const setupBranches = async (config, branch, stackAPIClient) => {
9
10
  let branches = [];
10
11
  const headers = { api_key: config.source_stack };
11
12
 
12
- if (config.auth_token) {
13
- headers['authtoken'] = config.auth_token;
13
+ if (isAuthenticated()) {
14
+ headers['authtoken'] = configHandler.get('authtoken');
14
15
  } else if (config.management_token) {
15
16
  headers['authorization'] = config.management_token;
16
17
  }