@contentstack/cli-cm-clone 0.1.0-beta.3 → 0.1.0-beta.6
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,12 +1,12 @@
|
|
|
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.6",
|
|
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.
|
|
8
|
+
"@contentstack/cli-cm-export": "^0.1.1-beta.15",
|
|
9
|
+
"@contentstack/cli-cm-import": "^0.1.1-beta.18",
|
|
10
10
|
"@contentstack/cli-command": "^0.1.1-beta.6",
|
|
11
11
|
"@contentstack/management": "^1.3.0",
|
|
12
12
|
"@oclif/command": "^1.8.0",
|
|
@@ -6,10 +6,13 @@ let config = require('../../lib/util/dummyConfig.json')
|
|
|
6
6
|
const path = require('path')
|
|
7
7
|
const rimraf = require('rimraf')
|
|
8
8
|
let pathdir = path.join(__dirname.split('src')[0], 'contents')
|
|
9
|
+
const { readdirSync } = require('fs')
|
|
9
10
|
|
|
10
11
|
class StackCloneCommand extends Command {
|
|
11
12
|
async run() {
|
|
12
13
|
try {
|
|
14
|
+
await this.removeContentDirIfNotEmptyBeforeClone(pathdir) // NOTE remove if folder not empty before clone
|
|
15
|
+
|
|
13
16
|
this.registerCleanupOnInterrupt(pathdir)
|
|
14
17
|
let _authToken = credStore.get('authtoken')
|
|
15
18
|
if (_authToken && _authToken !== undefined) {
|
|
@@ -30,6 +33,22 @@ class StackCloneCommand extends Command {
|
|
|
30
33
|
}
|
|
31
34
|
}
|
|
32
35
|
|
|
36
|
+
async removeContentDirIfNotEmptyBeforeClone(dir) {
|
|
37
|
+
try {
|
|
38
|
+
const dirNotEmpty = readdirSync(dir).length
|
|
39
|
+
|
|
40
|
+
if (dirNotEmpty) {
|
|
41
|
+
await this.cleanUp(dir)
|
|
42
|
+
}
|
|
43
|
+
} catch (error) {
|
|
44
|
+
const omit = ['ENOENT'] // NOTE add emittable error codes in the array
|
|
45
|
+
|
|
46
|
+
if (!omit.includes(error.code)) {
|
|
47
|
+
console.log(error.message)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
33
52
|
async cleanUp(pathDir, message) {
|
|
34
53
|
return new Promise(resolve => {
|
|
35
54
|
rimraf(pathDir, function (err) {
|
|
@@ -45,16 +64,30 @@ class StackCloneCommand extends Command {
|
|
|
45
64
|
}
|
|
46
65
|
|
|
47
66
|
registerCleanupOnInterrupt(pathDir) {
|
|
48
|
-
['SIGINT', 'SIGQUIT', 'SIGTERM']
|
|
49
|
-
|
|
67
|
+
const interrupt = ['SIGINT', 'SIGQUIT', 'SIGTERM']
|
|
68
|
+
const exceptions = ['unhandledRejection', 'uncaughtException']
|
|
69
|
+
|
|
70
|
+
const cleanUp = async (exitOrError = null) => {
|
|
50
71
|
// eslint-disable-next-line no-console
|
|
51
72
|
console.log('\nCleaning up')
|
|
52
73
|
await this.cleanUp(pathDir)
|
|
53
74
|
// eslint-disable-next-line no-console
|
|
54
75
|
console.log('done')
|
|
55
76
|
// eslint-disable-next-line no-process-exit
|
|
56
|
-
|
|
57
|
-
|
|
77
|
+
|
|
78
|
+
if (exitOrError instanceof Promise) {
|
|
79
|
+
exitOrError.catch(error => {
|
|
80
|
+
console.log(error && error.message || '')
|
|
81
|
+
})
|
|
82
|
+
} else if (exitOrError && exitOrError.message) {
|
|
83
|
+
console.log(exitOrError.message)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (exitOrError === true) process.exit()
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
exceptions.forEach(event => process.on(event, cleanUp))
|
|
90
|
+
interrupt.forEach(signal => process.on(signal, () => cleanUp(true)))
|
|
58
91
|
}
|
|
59
92
|
}
|
|
60
93
|
|