-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathapp.js
More file actions
executable file
·90 lines (87 loc) · 3.49 KB
/
app.js
File metadata and controls
executable file
·90 lines (87 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/* eslint-disable no-redeclare */
var util = require('./lib/util')
var login = require('./lib/util/login')
var {addlogs} = require('./lib/util/log')
const chalk = require('chalk')
let path = require('path')
let _ = require('lodash')
exports.initial = async function (config) {
return new Promise(function (resolve, reject) {
config = util.buildAppConfig(config)
util.validateConfig(config)
exports.getConfig = function () {
return config
}
// try {
login.login(config).then(async function () {
var types = config.modules.types
if (config.moduleName && config.moduleName !== undefined) {
singleExport(config.moduleName, types, config)
return resolve()
} else {
allExport(config, types).then(() => {
return resolve()
})
}
}).catch(error => {
if (error.errors.api_key) {
addlogs(config, chalk.red('Stack Api key ' + error.errors.api_key[0], 'Please enter valid Key', 'error'))
addlogs(config, 'The log for this is stored at ' + config.data + '/export/logs', 'success')
} else {
let objKey = Object.keys(error.errors)
addlogs(config, chalk.red('Stack fail to export, ' + objKey + '' + error.errors[objKey][0]), 'error')
}
})
})
}
var singleExport = async (moduleName, types, config) => {
var types = config.modules.types
try {
if (types.indexOf(moduleName) > -1) {
let iterateList = ['stack', moduleName]
for (let i = 0; i < iterateList.length; i++) {
var exportedModule = require('./lib/export/' + iterateList[i])
await exportedModule.start(config).then(function (result) {
if (iterateList[i] === 'stack') {
let master_locale = { master_locale: { code: result.master_locale } }
config = _.merge(config, master_locale)
}
})
}
addlogs(config, moduleName + ' was exported successfully!', 'success')
addlogs(config, 'The log for this is stored at ' + path.join(config.data, 'logs', 'export'), 'success')
} else {
addlogs(config, 'Please provide valid module name.', 'error')
}
} catch (error) {
addlogs(config, 'Failed to migrate ' + moduleName, 'error')
addlogs(config, error, 'error')
addlogs(config, 'The log for this is stored at ' + path.join(config.data, 'logs', 'export'), 'error')
}
}
var allExport = async (config, types) => {
// eslint-disable-next-line no-async-promise-executor
return new Promise(async (resolve, reject) => {
try {
for (let i = 0; i < types.length; i++) {
let type = types[i]
var exportedModule = require('./lib/export/' + type)
await exportedModule.start(config).then(result => {
if (type === 'stack') {
let master_locale = { master_locale: { code: result.master_locale } }
config = _.merge(config, master_locale)
}
return
})
}
addlogs(config, chalk.green('The content of the ' + config.source_stack + ' has been exported succesfully!'), 'success')
addlogs(config, 'The log for this is stored at ' + path.join(config.data, 'logs', 'export'), 'success')
return resolve()
} catch (error) {
addlogs(config, chalk.red('Failed to migrate stack: ' + config.source_stack + '. Please check error logs for more info'), 'error')
addlogs(config, chalk.red(error.errorMessage), 'error')
addlogs(config, 'The log for this is stored at ' + path.join(config.data, 'logs', 'export'), 'error')
return reject()
}
})
}