@contentstack/cli-cm-clone 0.1.0-beta.1 → 0.1.0-beta.4
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 +5 -5
- package/src/commands/cm/stack-clone.js +48 -17
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.4",
|
|
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.14",
|
|
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
|