-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
import pre setup command base code #1542
Merged
shafeeqd959
merged 7 commits into
feat/import-setup-command-base
from
feat/import-setup-command
Sep 4, 2024
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
adef4f3
import pre setup command base code
shafeeqd959 3bd147b
Merge branch 'development' into feat/import-setup-command
shafeeqd959 72f6685
Merge branch 'development' of github.com:contentstack/cli into feat/i…
shafeeqd959 e0e288e
Merge branch 'feat/import-setup-command' of github.com:contentstack/c…
shafeeqd959 3fd10b7
deleted env
shafeeqd959 29c9648
changes
shafeeqd959 4c0fa06
content type update
shafeeqd959 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Build files | ||
./lib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"inlcude": [ | ||
"lib/**/*.js" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"semi": true, | ||
"trailingComma": "all", | ||
"singleQuote": true, | ||
"printWidth": 120, | ||
"tabWidth": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@echo off | ||
|
||
node "%~dp0\dev" %* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@echo off | ||
|
||
node "%~dp0\run" %* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
18
packages/contentstack-import-setup/example_config/auth_config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
16 changes: 16 additions & 0 deletions
16
packages/contentstack-import-setup/example_config/management_config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @shafeeqd959 , Since we're using cli-utilities, so management sdk isn't required here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will remove in the upcoming commits |
||
"@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" | ||
} |
69 changes: 69 additions & 0 deletions
69
packages/contentstack-import-setup/src/commands/cm/stacks/import-setup.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shafeeqd959 what purpose we used this empty object file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will add messages in future commits