@contentstack/cli-cm-clone 0.1.0-beta.1 → 0.1.0-beta.2

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,7 +1,7 @@
1
1
  {
2
2
  "name": "@contentstack/cli-cm-clone",
3
3
  "description": "Contentstack stack clone plugin",
4
- "version": "0.1.0-beta.1",
4
+ "version": "0.1.0-beta.2",
5
5
  "author": "Contentstack",
6
6
  "bugs": "https://github.com/rohitmishra209/cli-cm-clone/issues",
7
7
  "dependencies": {
@@ -1,29 +1,61 @@
1
- const { Command, flags } = require('@contentstack/cli-command')
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
- let _authToken = credStore.get('authtoken')
13
- if (_authToken && _authToken !== undefined) {
14
- config.auth_token = _authToken
15
- config.host = this.cmaHost
16
- config.cdn = this.cdaHost
17
- const cloneHandler = new CloneHandler(config)
18
- let result = await cloneHandler.start()
19
- var pathdir = path.join(__dirname.split("src")[0], 'contents')
20
- rimraf(pathdir, function(err) {
21
- console.log("Stack cloning process have been completed successfully");
22
- })
23
- } else {
24
- console.log("AuthToken is not present in local drive, Hence use 'csdx auth:login' command for login");
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
+ let result = 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
- module.exports = StackCloneCommand
69
+ module.exports = StackCloneCommand