Skip to content

Commit

Permalink
Merge pull request #1542 from contentstack/feat/import-setup-command
Browse files Browse the repository at this point in the history
import pre setup command base code
  • Loading branch information
shafeeqd959 authored Sep 4, 2024
2 parents 4ffeb88 + 0d3c3b7 commit 3c2b05f
Show file tree
Hide file tree
Showing 43 changed files with 1,618 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/contentstack-import-setup/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Build files
./lib
56 changes: 56 additions & 0 deletions packages/contentstack-import-setup/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"env": {
"node": true
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "tsconfig.json",
"sourceType": "module"
},
"extends": [
"oclif-typescript",
"plugin:@typescript-eslint/recommended"
],
"rules": {
"@typescript-eslint/no-unused-vars": [
"error",
{
"args": "none"
}
],
"@typescript-eslint/prefer-namespace-keyword": "error",
"@typescript-eslint/quotes": [
"error",
"single",
{
"avoidEscape": true,
"allowTemplateLiterals": true
}
],
"semi": "off",
"@typescript-eslint/type-annotation-spacing": "error",
"@typescript-eslint/no-redeclare": "off",
"eqeqeq": [
"error",
"smart"
],
"id-match": "error",
"no-eval": "error",
"no-var": "error",
"quotes": "off",
"indent": "off",
"camelcase": "off",
"comma-dangle": "off",
"arrow-parens": "off",
"operator-linebreak": "off",
"object-curly-spacing": "off",
"node/no-missing-import": "off",
"lines-between-class-members": "off",
"padding-line-between-statements": "off",
"@typescript-eslint/ban-ts-ignore": "off",
"unicorn/no-abusive-eslint-disable": "off",
"@typescript-eslint/no-explicit-any": "off",
"unicorn/consistent-function-scoping": "off",
"@typescript-eslint/no-use-before-define": "off"
}
}
14 changes: 14 additions & 0 deletions packages/contentstack-import-setup/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
*-debug.log
*-error.log
/.nyc_output
/dist
/lib
/tmp
/yarn.lock
node_modules
.DS_Store
coverage
.vscode/
/lib

.env
8 changes: 8 additions & 0 deletions packages/contentstack-import-setup/.mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"require": ["test/helpers/init.js", "ts-node/register", "source-map-support/register"],
"watch-extensions": [
"ts"
],
"recursive": true,
"timeout": 5000
}
5 changes: 5 additions & 0 deletions packages/contentstack-import-setup/.nycrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"inlcude": [
"lib/**/*.js"
]
}
7 changes: 7 additions & 0 deletions packages/contentstack-import-setup/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"semi": true,
"trailingComma": "all",
"singleQuote": true,
"printWidth": 120,
"tabWidth": 2
}
21 changes: 21 additions & 0 deletions packages/contentstack-import-setup/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Contentstack

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
3 changes: 3 additions & 0 deletions packages/contentstack-import-setup/bin/dev.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off

node "%~dp0\dev" %*
6 changes: 6 additions & 0 deletions packages/contentstack-import-setup/bin/dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env node_modules/.bin/ts-node
// eslint-disable-next-line node/shebang, unicorn/prefer-top-level-await
(async () => {
const oclif = await import('@oclif/core');
await oclif.execute({ development: true, dir: __dirname });
})();
3 changes: 3 additions & 0 deletions packages/contentstack-import-setup/bin/run.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off

node "%~dp0\run" %*
7 changes: 7 additions & 0 deletions packages/contentstack-import-setup/bin/run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env node

// eslint-disable-next-line unicorn/prefer-top-level-await
(async () => {
const oclif = await import('@oclif/core');
await oclif.execute({ development: false, dir: __dirname });
})();
18 changes: 18 additions & 0 deletions packages/contentstack-import-setup/example_config/auth_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"master_locale": {
"name": "English - United States",
"code": "en-us"
},
"data": "file path",
"target_stack": "bltXXXXXXXXXX",
"branchName": "example1",
"moduleName": "content-types",
"concurrency": 1,
"importConcurrency": 5,
"fetchConcurrency": 5,
"writeConcurrency": 5,
"securedAssets": false,
"developerHubBaseUrl": "",
"createBackupDir": "./temp",
"cliLogsPath": "./tmp"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"master_locale": {
"name": "English - United States",
"code": "en-us"
},
"data": "file path",
"branchName": "example1",
"moduleName": "content-types",
"concurrency": 1,
"importConcurrency": 5,
"fetchConcurrency": 5,
"writeConcurrency": 5,
"securedAssets": false,
"developerHubBaseUrl": "",
"cliLogsPath": "./tmp"
}
1 change: 1 addition & 0 deletions packages/contentstack-import-setup/messages/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
97 changes: 97 additions & 0 deletions packages/contentstack-import-setup/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
{
"name": "@contentstack/cli-cm-import-setup",
"description": "Contentstack CLI plugin to setup the mappers and configurations for the import command",
"version": "1.0.0",
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
"@contentstack/cli-command": "~1.3.0",
"@contentstack/cli-utilities": "~1.7.1",
"@contentstack/management": "~1.17.0",
"@oclif/core": "^3.26.5",
"big-json": "^3.2.0",
"bluebird": "^3.7.2",
"chalk": "^4.1.2",
"debug": "^4.1.0",
"fs-extra": "^11.1.1",
"lodash": "^4.17.20",
"marked": "^4.0.17",
"merge": "^2.1.1",
"mkdirp": "^1.0.4",
"promise-limit": "^2.7.0",
"tslib": "^2.4.1",
"uuid": "^9.0.1",
"winston": "^3.7.2"
},
"devDependencies": {
"@oclif/test": "^2.5.6",
"@types/big-json": "^3.2.0",
"@types/bluebird": "^3.5.38",
"@types/chai": "^4.2.18",
"@types/fs-extra": "^11.0.1",
"@types/mkdirp": "^1.0.2",
"@types/mocha": "^8.2.2",
"@types/node": "^14.14.32",
"@types/sinon": "^10.0.2",
"@types/tar": "^6.1.3",
"@types/uuid": "^9.0.7",
"@typescript-eslint/eslint-plugin": "^5.48.2",
"chai": "^4.2.0",
"eslint": "^8.18.0",
"eslint-config-oclif": "^4.0.0",
"globby": "^10.0.2",
"mocha": "^10.0.0",
"nyc": "^15.1.0",
"oclif": "^3.8.1",
"rimraf": "^2.7.1",
"sinon": "^11.1.1",
"tmp": "^0.2.2",
"ts-node": "^10.9.1",
"typescript": "^4.9.3"
},
"scripts": {
"build": "npm run clean && npm run compile",
"clean": "rm -rf ./lib ./node_modules tsconfig.build.tsbuildinfo",
"compile": "tsc -b tsconfig.json",
"postpack": "rm -f oclif.manifest.json",
"prepack": "pnpm compile && oclif manifest && oclif readme",
"version": "oclif readme && git add README.md",
"test:report": "tsc -p test && nyc --reporter=lcov --extension .ts mocha --forbid-only \"test/**/*.test.ts\"",
"pretest": "tsc -p test",
"test": "nyc --extension .ts mocha --forbid-only \"test/**/*.test.ts\"",
"posttest": "npm run lint",
"lint": "eslint src/**/*.ts",
"format": "eslint src/**/*.ts --fix",
"test:integration": "mocha --forbid-only \"test/run.test.js\" --integration-test --timeout 60000",
"test:unit": "mocha --forbid-only \"test/unit/*.test.ts\""
},
"engines": {
"node": ">=14.0.0"
},
"files": [
"/bin",
"/lib",
"/messages",
"/npm-shrinkwrap.json",
"/oclif.manifest.json"
],
"homepage": "https://github.com/contentstack/cli",
"keywords": [
"contentstack",
"cli",
"plugin"
],
"main": "./lib/commands/cm/stacks/import-setup.js",
"license": "MIT",
"oclif": {
"commands": "./lib/commands",
"bin": "csdx",
"repositoryPrefix": "<%- repo %>/blob/main/packages/contentstack-import-setup/<%- commandPath %>"
},
"csdxConfig": {
"shortCommandName": {
"cm:stacks:import": "IMPRTSTP"
}
},
"repository": "https://github.com/contentstack/cli"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import path from 'node:path';
import { Command } from '@contentstack/cli-command';
import {
messageHandler,
printFlagDeprecation,
managementSDKClient,
flags,
FlagInput,
ContentstackClient,
pathValidator,
} from '@contentstack/cli-utilities';

import { ImportConfig } from '../../../types';
import { setupImportConfig, formatError, log } from '../../../utils';
import { ImportSetup } from 'src/import';

export default class ImportSetupCommand extends Command {
static description = messageHandler.parse('Import content from a stack');

static examples: string[] = [
`csdx cm:stacks:import-setup --stack-api-key <stack_api_key> --data-dir <path/of/export/destination/dir> --modules <module_name, module_name>`,
];

static flags: FlagInput = {
'stack-api-key': flags.string({
char: 'k',
description: 'API key of the target stack',
}),
'data-dir': flags.string({
char: 'd',
description: 'path and location where data is stored',
}),
alias: flags.string({
char: 'a',
description: 'alias of the management token',
}),
modules: flags.string({
required: false,
description: '[optional] specific module name',
}),
};

static aliases: string[] = ['cm:import'];

static usage: string = 'cm:stacks:import [-k <value>] [-d <value>] [-a <value>] [--modules <value,value>]';

async run(): Promise<void> {
try {
const { flags } = await this.parse(ImportSetupCommand);
let importSetupConfig = await setupImportConfig(flags);
const importSetup = new ImportSetup(importSetupConfig);
await importSetup.start();
log(
importSetupConfig,
importSetupConfig.stackName
? `Successfully generated mapper files for the stack named ${importSetupConfig.stackName} with the API key ${importSetupConfig.apiKey}.`
: `Mapper files have been generated for the stack ${importSetupConfig.apiKey} successfully!`,
'success',
);
log(
importSetupConfig,
`The mapper files have been stored at '${pathValidator(path.join(importSetupConfig.backupDirPath, 'mapper'))}'`,
'success',
);
} catch (error) {
log({ data: '' } as ImportConfig, `Failed to generate mapper files - ${formatError(error)}`, 'error');
}
}
}
Loading

0 comments on commit 3c2b05f

Please sign in to comment.