@contentstack/cli-cm-clone 0.1.0-beta → 0.1.0-beta.3
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/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentstack/cli-cm-clone",
|
|
3
3
|
"description": "Contentstack stack clone plugin",
|
|
4
|
-
"version": "0.1.0-beta",
|
|
4
|
+
"version": "0.1.0-beta.3",
|
|
5
5
|
"author": "Contentstack",
|
|
6
6
|
"bugs": "https://github.com/rohitmishra209/cli-cm-clone/issues",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@contentstack/cli-cm-export": "^0.1.1-beta.
|
|
9
|
-
"@contentstack/cli-cm-import": "^0.1.1-beta.
|
|
10
|
-
"@contentstack/cli-command": "0.1.
|
|
11
|
-
"@contentstack/management": "^1.
|
|
8
|
+
"@contentstack/cli-cm-export": "^0.1.1-beta.10",
|
|
9
|
+
"@contentstack/cli-cm-import": "^0.1.1-beta.13",
|
|
10
|
+
"@contentstack/cli-command": "^0.1.1-beta.6",
|
|
11
|
+
"@contentstack/management": "^1.3.0",
|
|
12
12
|
"@oclif/command": "^1.8.0",
|
|
13
13
|
"@oclif/config": "^1.17.0",
|
|
14
14
|
"async": "^3.2.0",
|
|
@@ -1,29 +1,61 @@
|
|
|
1
|
-
const {
|
|
1
|
+
const {Command} = require('@contentstack/cli-command')
|
|
2
2
|
const Configstore = require('configstore')
|
|
3
3
|
const credStore = new Configstore('contentstack_cli')
|
|
4
4
|
const {CloneHandler} = require('../../lib/util/clone-handler')
|
|
5
5
|
let config = require('../../lib/util/dummyConfig.json')
|
|
6
6
|
const path = require('path')
|
|
7
|
-
const fs = require('fs');
|
|
8
7
|
const rimraf = require('rimraf')
|
|
8
|
+
let pathdir = path.join(__dirname.split('src')[0], 'contents')
|
|
9
9
|
|
|
10
10
|
class StackCloneCommand extends Command {
|
|
11
11
|
async run() {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
12
|
+
try {
|
|
13
|
+
this.registerCleanupOnInterrupt(pathdir)
|
|
14
|
+
let _authToken = credStore.get('authtoken')
|
|
15
|
+
if (_authToken && _authToken !== undefined) {
|
|
16
|
+
config.auth_token = _authToken
|
|
17
|
+
config.host = this.cmaHost
|
|
18
|
+
config.cdn = this.cdaHost
|
|
19
|
+
const cloneHandler = new CloneHandler(config)
|
|
20
|
+
await cloneHandler.start()
|
|
21
|
+
let successMessage = 'Stack cloning process have been completed successfully'
|
|
22
|
+
await this.cleanUp(pathdir, successMessage)
|
|
23
|
+
} else {
|
|
24
|
+
console.log("AuthToken is not present in local drive, Hence use 'csdx auth:login' command for login");
|
|
25
|
+
}
|
|
26
|
+
} catch (error) {
|
|
27
|
+
await this.cleanUp(pathdir)
|
|
28
|
+
// eslint-disable-next-line no-console
|
|
29
|
+
console.log(error.message || error)
|
|
25
30
|
}
|
|
26
31
|
}
|
|
32
|
+
|
|
33
|
+
async cleanUp(pathDir, message) {
|
|
34
|
+
return new Promise(resolve => {
|
|
35
|
+
rimraf(pathDir, function (err) {
|
|
36
|
+
if (err)
|
|
37
|
+
throw err
|
|
38
|
+
if (message) {
|
|
39
|
+
// eslint-disable-next-line no-console
|
|
40
|
+
console.log(message)
|
|
41
|
+
}
|
|
42
|
+
resolve()
|
|
43
|
+
})
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
registerCleanupOnInterrupt(pathDir) {
|
|
48
|
+
['SIGINT', 'SIGQUIT', 'SIGTERM']
|
|
49
|
+
.forEach(signal => process.on(signal, async () => {
|
|
50
|
+
// eslint-disable-next-line no-console
|
|
51
|
+
console.log('\nCleaning up')
|
|
52
|
+
await this.cleanUp(pathDir)
|
|
53
|
+
// eslint-disable-next-line no-console
|
|
54
|
+
console.log('done')
|
|
55
|
+
// eslint-disable-next-line no-process-exit
|
|
56
|
+
process.exit()
|
|
57
|
+
}))
|
|
58
|
+
}
|
|
27
59
|
}
|
|
28
60
|
|
|
29
61
|
StackCloneCommand.description = `Clone data (structure or content or both) of a stack into another stack
|
|
@@ -31,8 +63,7 @@ Use this plugin to automate the process of cloning a stack in a few steps.
|
|
|
31
63
|
`
|
|
32
64
|
|
|
33
65
|
StackCloneCommand.examples = [
|
|
34
|
-
'csdx cm:stack-clone'
|
|
66
|
+
'csdx cm:stack-clone',
|
|
35
67
|
]
|
|
36
68
|
|
|
37
|
-
|
|
38
69
|
module.exports = StackCloneCommand
|
|
@@ -28,6 +28,7 @@ let stackName = {
|
|
|
28
28
|
|
|
29
29
|
let orgUidList = {}
|
|
30
30
|
let stackUidList = {}
|
|
31
|
+
let masterLocaleList = {}
|
|
31
32
|
|
|
32
33
|
let structureList = ['locales',
|
|
33
34
|
'environments',
|
|
@@ -60,6 +61,7 @@ class CloneHandler {
|
|
|
60
61
|
.then(async (stackList)=> {
|
|
61
62
|
let stackSelected = await inquirer.prompt(stackList)
|
|
62
63
|
config.source_stack = stackUidList[stackSelected.stack]
|
|
64
|
+
master_locale = masterLocaleList[stackSelected.stack]
|
|
63
65
|
config.sourceStackName = stackSelected.stack
|
|
64
66
|
stackName.default = "Copy of " + stackSelected.stack
|
|
65
67
|
let cmdExport = this.cmdExport()
|
|
@@ -162,6 +164,7 @@ class CloneHandler {
|
|
|
162
164
|
.then(async stacklist => {
|
|
163
165
|
for (let j = 0; j < stacklist.items.length; j++) {
|
|
164
166
|
stackUidList[stacklist.items[j].name] = stacklist.items[j].api_key
|
|
167
|
+
masterLocaleList[stacklist.items[j].name] = stacklist.items[j].master_locale
|
|
165
168
|
stackChoice.choices.push(stacklist.items[j].name)
|
|
166
169
|
}
|
|
167
170
|
spinner.succeed("Fetched stack")
|
|
@@ -180,7 +183,7 @@ class CloneHandler {
|
|
|
180
183
|
async createNewStack(orgUid) {
|
|
181
184
|
return new Promise(async (resolve, reject) => {
|
|
182
185
|
let inputvalue = await inquirer.prompt(stackName)
|
|
183
|
-
let stack = { name: inputvalue.stack }
|
|
186
|
+
let stack = { name: inputvalue.stack, master_locale: master_locale }
|
|
184
187
|
const spinner = ora('Creating New stack').start()
|
|
185
188
|
let newStack = client.stack().create({ stack }, { organization_uid: orgUid })
|
|
186
189
|
newStack
|
|
@@ -188,7 +191,6 @@ class CloneHandler {
|
|
|
188
191
|
spinner.succeed("New Stack created Successfully name as " + result.name)
|
|
189
192
|
config.target_stack = result.api_key
|
|
190
193
|
config.destinationStackName = result.name
|
|
191
|
-
master_locale = result.master_locale
|
|
192
194
|
return resolve(result)
|
|
193
195
|
}).catch(error => {
|
|
194
196
|
spinner.fail()
|