Skip to content

Commit

Permalink
merge changes
Browse files Browse the repository at this point in the history
  • Loading branch information
shafeeqd959 committed Feb 5, 2024
2 parents 4e9bdea + 60d8a69 commit aa624d3
Show file tree
Hide file tree
Showing 43 changed files with 341 additions and 638 deletions.
568 changes: 72 additions & 496 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/contentstack-audit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ $ npm install -g @contentstack/cli-audit
$ csdx COMMAND
running command...
$ csdx (--version|-v)
@contentstack/cli-audit/1.3.4 darwin-arm64 node-v20.8.0
@contentstack/cli-audit/1.3.5 darwin-arm64 node-v20.8.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
4 changes: 2 additions & 2 deletions packages/contentstack-audit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/cli-audit",
"version": "1.3.4",
"version": "1.3.5",
"description": "Contentstack audit plugin",
"author": "Contentstack CLI",
"homepage": "https://github.com/contentstack/cli",
Expand Down Expand Up @@ -31,7 +31,7 @@
},
"devDependencies": {
"@contentstack/cli-dev-dependencies": "^1.2.4",
"@oclif/test": "^2.0.3",
"@oclif/test": "^2.5.6",
"@types/chai": "^4.3.5",
"@types/fs-extra": "^11.0.2",
"@types/mocha": "^10.0.6",
Expand Down
13 changes: 0 additions & 13 deletions packages/contentstack-audit/src/audit-base-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
* `gfSchema`. The values of these properties are the parsed JSON data from two different files.
*/
getCtAndGfSchema() {
const modules = this.sharedConfig.flags.modules || this.sharedConfig.modules;
const ctPath = join(
this.sharedConfig.basePath,
this.sharedConfig.moduleConfig['content-types'].dirName,
Expand All @@ -176,18 +175,6 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
this.sharedConfig.moduleConfig['global-fields'].fileName,
);

if (modules.includes('content-types')) {
if (!existsSync(ctPath)) {
this.log(this.$t(auditMsg.NOT_VALID_PATH, { path: ctPath }), 'error');
}
}

if (modules.includes('global-fields')) {
if (!existsSync(gfPath)) {
this.log(this.$t(auditMsg.NOT_VALID_PATH, { path: ctPath }), 'error');
}
}

const gfSchema = existsSync(gfPath) ? (JSON.parse(readFileSync(gfPath, 'utf8')) as ContentTypeStruct[]) : [];
const ctSchema = existsSync(ctPath) ? (JSON.parse(readFileSync(ctPath, 'utf8')) as ContentTypeStruct[]) : [];

Expand Down
4 changes: 3 additions & 1 deletion packages/contentstack-audit/src/modules/content-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ export default class ContentType {
this.inMemoryFix = returnFixSchema;

if (!existsSync(this.folderPath)) {
throw new Error($t(auditMsg.NOT_VALID_PATH, { path: this.folderPath }));
this.log(`Skipping ${this.moduleName} audit`, 'warn');
this.log($t(auditMsg.NOT_VALID_PATH, { path: this.folderPath }), { color: 'yellow' });
return returnFixSchema ? [] : {};
}

this.schema = this.moduleName === 'content-types' ? this.ctSchema : this.gfSchema;
Expand Down
11 changes: 8 additions & 3 deletions packages/contentstack-audit/src/modules/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ export default class Entries {
*/
async run() {
if (!existsSync(this.folderPath)) {
throw new Error($t(auditMsg.NOT_VALID_PATH, { path: this.folderPath }));
this.log(`Skipping ${this.moduleName} audit`, 'warn');
this.log($t(auditMsg.NOT_VALID_PATH, { path: this.folderPath }), { color: 'yellow' });
return {};
}

await this.prepareEntryMetaData();
Expand Down Expand Up @@ -799,8 +801,11 @@ export default class Entries {
const localesFolderPath = resolve(this.config.basePath, this.config.moduleConfig.locales.dirName);
const localesPath = join(localesFolderPath, this.config.moduleConfig.locales.fileName);
const masterLocalesPath = join(localesFolderPath, 'master-locale.json');
this.locales = values(JSON.parse(readFileSync(masterLocalesPath, 'utf8')));
this.locales.push(...values(JSON.parse(readFileSync(localesPath, 'utf8'))));
this.locales = existsSync(masterLocalesPath) ? values(JSON.parse(readFileSync(masterLocalesPath, 'utf8'))) : [];

if (existsSync(localesPath)) {
this.locales.push(...values(JSON.parse(readFileSync(localesPath, 'utf8'))));
}

for (const { code } of this.locales) {
for (const { uid } of this.ctSchema) {
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"devDependencies": {
"@fancy-test/nock": "^0.1.1",
"@oclif/plugin-help": "^5.1.19",
"@oclif/test": "^2.2.10",
"@oclif/test": "^2.5.6",
"@types/chai": "^4.2.18",
"@types/inquirer": "^9.0.3",
"@types/mkdirp": "^1.0.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-bootstrap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"tar": "^6.1.13"
},
"devDependencies": {
"@oclif/test": "^2.2.10",
"@oclif/test": "^2.5.6",
"@types/inquirer": "^9.0.3",
"@types/mkdirp": "^1.0.1",
"@types/node": "^14.14.32",
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-branches/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@contentstack/cli-config": "~1.6.1",
"@contentstack/cli-dev-dependencies": "~1.2.4",
"@oclif/plugin-help": "^5.1.19",
"@oclif/test": "^1.2.6",
"@oclif/test": "^2.5.6",
"@types/flat": "^5.0.2",
"assert": "^2.0.0",
"chai": "^4.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-bulk-publish/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"winston": "^3.7.2"
},
"devDependencies": {
"@oclif/test": "^1.2.6",
"@oclif/test": "^2.5.6",
"chai": "^4.2.0",
"eslint": "^8.18.0",
"eslint-config-oclif": "^4.0.0",
Expand Down
4 changes: 3 additions & 1 deletion packages/contentstack-clone/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ $ npm install -g @contentstack/cli-cm-clone
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-clone/1.9.0 darwin-arm64 node-v20.8.0
@contentstack/cli-cm-clone/1.10.0 darwin-arm64 node-v20.8.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down Expand Up @@ -51,6 +51,7 @@ USAGE
[--destination-stack-api-key <value>] [--import-webhook-status disable|current]
FLAGS
-c, --config=<value> Path for the external configuration
-n, --stack-name=<value> Name for the new stack to store the cloned content.
-y, --yes [Optional] Override marketplace prompts
--destination-management-token-alias=<value> Source API key of the target stack token alias.
Expand Down Expand Up @@ -101,6 +102,7 @@ USAGE
[--destination-stack-api-key <value>] [--import-webhook-status disable|current]
FLAGS
-c, --config=<value> Path for the external configuration
-n, --stack-name=<value> Name for the new stack to store the cloned content.
-y, --yes [Optional] Override marketplace prompts
--destination-management-token-alias=<value> Source API key of the target stack token alias.
Expand Down
8 changes: 5 additions & 3 deletions packages/contentstack-clone/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@contentstack/cli-cm-clone",
"description": "Contentstack stack clone plugin",
"version": "1.9.0",
"version": "1.10.0",
"author": "Contentstack",
"bugs": "https://github.com/rohitmishra209/cli-cm-clone/issues",
"dependencies": {
Expand All @@ -18,10 +18,12 @@
"ora": "^5.1.0",
"prompt": "^1.3.0",
"rimraf": "^3.0.2",
"winston": "^3.7.2"
"winston": "^3.7.2",
"merge": "^2.1.1",
"lodash": "^4.17.20"
},
"devDependencies": {
"@oclif/test": "^1.2.7",
"@oclif/test": "^2.5.6",
"chai": "^4.2.0",
"eslint": "^8.18.0",
"eslint-config-oclif": "^4.0.0",
Expand Down
14 changes: 13 additions & 1 deletion packages/contentstack-clone/src/commands/cm/stacks/clone.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ const { configHandler, flags, isAuthenticated, managementSDKClient } = require('
const { CloneHandler } = require('../../../lib/util/clone-handler');
const path = require('path');
const rimraf = require('rimraf');
const merge = require("merge")
let pathdir = path.join(__dirname.split('src')[0], 'contents');
const { readdirSync } = require('fs');
const { readdirSync, readFileSync } = require('fs');
let config = {};

class StackCloneCommand extends Command {
Expand All @@ -23,11 +24,17 @@ class StackCloneCommand extends Command {
'source-management-token-alias': sourceManagementTokenAlias,
'destination-management-token-alias': destinationManagementTokenAlias,
'import-webhook-status': importWebhookStatus,
'config': externalConfigPath
} = cloneCommandFlags;

const handleClone = async () => {
const listOfTokens = configHandler.get('tokens');

if (externalConfigPath) {
let externalConfig = readFileSync(externalConfigPath, 'utf-8')
externalConfig = JSON.parse(externalConfig);
config = merge.recursive(config, externalConfig);
}
config.forceStopMarketplaceAppsPrompt = yes;
config.skipAudit = cloneCommandFlags['skip-audit'];

Expand Down Expand Up @@ -249,6 +256,11 @@ b) Structure with content (all modules including entries & assets)
'skip-audit': flags.boolean({
description: 'Skips the audit fix.',
}),
'config': flags.string({
char: 'c',
required: false,
description: 'Path for the external configuration',
}),
};

StackCloneCommand.usage =
Expand Down
57 changes: 35 additions & 22 deletions packages/contentstack-clone/src/lib/util/clone-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ let { default: importCmd } = require('@contentstack/cli-cm-import');
const { CustomAbortController } = require('./abort-controller');
const prompt = require('prompt');
const colors = require('@colors/colors/safe');
const cloneDeep = require("lodash/cloneDeep")

const {
HandleOrgCommand,
Expand Down Expand Up @@ -616,51 +617,63 @@ class CloneHandler {

async cmdExport() {
return new Promise((resolve, reject) => {
const cmd = ['-k', config.source_stack, '-d', __dirname.split('src')[0] + 'contents'];
if (config.cloneType === 'a') {
config.filteredModules = ['stack'].concat(structureList);
cmd.push('-c');
cmd.push(path.join(__dirname, 'dummyConfig.json'));
// Creating export specific config by merging external configurations
let exportConfig = Object.assign({}, cloneDeep(config), {...config?.export});
delete exportConfig.import;
delete exportConfig.export;

const cmd = ['-k', exportConfig.source_stack, '-d', __dirname.split('src')[0] + 'contents'];
if (exportConfig.cloneType === 'a') {
exportConfig.filteredModules = ['stack'].concat(structureList);
}

if (config.source_alias) {
cmd.push('-a', config.source_alias);
if (exportConfig.source_alias) {
cmd.push('-a', exportConfig.source_alias);
}
if (config.sourceStackBranch) {
cmd.push('--branch', config.sourceStackBranch);
if (exportConfig.sourceStackBranch) {
cmd.push('--branch', exportConfig.sourceStackBranch);
}

if (config.forceStopMarketplaceAppsPrompt) cmd.push('-y');
if (exportConfig.forceStopMarketplaceAppsPrompt) cmd.push('-y');

fs.writeFileSync(path.join(__dirname, 'dummyConfig.json'), JSON.stringify(config));
cmd.push('-c');
cmd.push(path.join(__dirname, 'dummyConfig.json'));

fs.writeFileSync(path.join(__dirname, 'dummyConfig.json'), JSON.stringify(exportConfig));
let exportData = exportCmd.run(cmd);
exportData.then(() => resolve(true)).catch(reject);
});
}

async cmdImport() {
return new Promise(async (resolve, _reject) => {
// Creating export specific config by merging external configurations
let importConfig = Object.assign({}, cloneDeep(config), {...config?.import});
delete importConfig.import;
delete importConfig.export;

const cmd = ['-c', path.join(__dirname, 'dummyConfig.json')];

if (config.destination_alias) {
cmd.push('-a', config.destination_alias);
if (importConfig.destination_alias) {
cmd.push('-a', importConfig.destination_alias);
}
if (!config.data && config.sourceStackBranch) {
cmd.push('-d', path.join(config.pathDir, config.sourceStackBranch));
if (!importConfig.data && importConfig.sourceStackBranch) {
cmd.push('-d', path.join(importConfig.pathDir, importConfig.sourceStackBranch));
}
if (config.targetStackBranch) {
cmd.push('--branch', config.targetStackBranch);
if (importConfig.targetStackBranch) {
cmd.push('--branch', importConfig.targetStackBranch);
}
if (config.importWebhookStatus) {
cmd.push('--import-webhook-status', config.importWebhookStatus);
if (importConfig.importWebhookStatus) {
cmd.push('--import-webhook-status', importConfig.importWebhookStatus);
}

if (config.skipAudit) cmd.push('--skip-audit');
if (importConfig.skipAudit) cmd.push('--skip-audit');

if (config.forceStopMarketplaceAppsPrompt) cmd.push('-y');
if (importConfig.forceStopMarketplaceAppsPrompt) cmd.push('-y');

fs.writeFileSync(path.join(__dirname, 'dummyConfig.json'), JSON.stringify(config));
fs.writeFileSync(path.join(__dirname, 'dummyConfig.json'), JSON.stringify(importConfig));
await importCmd.run(cmd);
fs.writeFileSync(path.join(__dirname, 'dummyConfig.json'), JSON.stringify({}))
return resolve();
});
}
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-command/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"contentstack": "^3.10.1"
},
"devDependencies": {
"@oclif/test": "^2.2.10",
"@oclif/test": "^2.5.6",
"@types/chai": "^4.2.18",
"@types/mkdirp": "^1.0.1",
"@types/mocha": "^8.2.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"winston": "^3.7.2"
},
"devDependencies": {
"@oclif/test": "^2.2.10",
"@oclif/test": "^2.5.6",
"@types/chai": "^4.2.18",
"@types/inquirer": "^9.0.3",
"@types/mkdirp": "^1.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@ describe('base-branch command', function () {
const branchStub = stub(cliux, 'table').callsFake(() => {});
await BranchGetCommand.run([]);
expect(branchStub.calledOnce).to.be.true;
branchStub.restore();
});
});
Loading

0 comments on commit aa624d3

Please sign in to comment.