@kdcloudjs/cli 0.0.3 → 0.0.5
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 +1 -1
- package/src/actions/debug/index.js +30 -25
- package/src/actions/env/auth/index.js +1 -1
- package/src/actions/env/auth/openapi.js +3 -1
- package/src/actions/env/auth/web.js +1 -1
- package/src/actions/project/create/page.js +4 -4
- package/src/actions/project/deploy/index.js +15 -10
- package/src/api/index.js +21 -3
- package/src/commands/debug.js +2 -1
- package/src/commands/env/index.js +10 -10
- package/src/commands/project/index.js +4 -4
- package/src/utils/index.js +2 -0
- package/src/utils/printTable.js +4 -4
- package/src/utils/projectConfig.js +10 -3
package/package.json
CHANGED
|
@@ -50,38 +50,43 @@ module.exports = async function debug(options = {}) {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
// 3. Get Form IDs
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
53
|
+
let formId = options.formid
|
|
54
|
+
|
|
55
|
+
if (!formId) {
|
|
56
|
+
const pagesDir = path.join(root, 'app/pages')
|
|
57
|
+
const pageFiles = walk(pagesDir)
|
|
58
|
+
const forms = []
|
|
59
|
+
|
|
60
|
+
for (const file of pageFiles) {
|
|
61
|
+
const id = getFormId(file)
|
|
62
|
+
if (id) {
|
|
63
|
+
forms.push({
|
|
64
|
+
title: id,
|
|
65
|
+
value: id
|
|
66
|
+
})
|
|
67
|
+
}
|
|
64
68
|
}
|
|
65
|
-
}
|
|
66
69
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
70
|
+
if (forms.length === 0) {
|
|
71
|
+
error('No pages found in app/pages')
|
|
72
|
+
return
|
|
73
|
+
}
|
|
71
74
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
75
|
+
// 4. Select Form
|
|
76
|
+
const response = await safePrompts({
|
|
77
|
+
type: 'select',
|
|
78
|
+
name: 'formId',
|
|
79
|
+
message: 'Select a form to debug',
|
|
80
|
+
choices: forms
|
|
81
|
+
})
|
|
79
82
|
|
|
80
|
-
|
|
83
|
+
if (!response.formId) return
|
|
84
|
+
formId = response.formId
|
|
85
|
+
}
|
|
81
86
|
|
|
82
87
|
// 5. Construct URL
|
|
83
88
|
const targetUrl = new URL(env.url)
|
|
84
|
-
targetUrl.searchParams.append('formId',
|
|
89
|
+
targetUrl.searchParams.append('formId', formId)
|
|
85
90
|
targetUrl.searchParams.append('kdkwc_cdn', 'http://localhost:3333')
|
|
86
91
|
const finalUrl = targetUrl.toString()
|
|
87
92
|
|
|
@@ -7,7 +7,7 @@ const openapiAuth = require('./openapi')
|
|
|
7
7
|
const { error } = require('../../../utils/log')
|
|
8
8
|
|
|
9
9
|
module.exports = async function doAuth(options ={}) {
|
|
10
|
-
let { type, env } = options
|
|
10
|
+
let { type, targetEnv: env } = options
|
|
11
11
|
|
|
12
12
|
if (env === undefined) {
|
|
13
13
|
env = loadDefaultEnv()?.name
|
|
@@ -3,7 +3,7 @@ const { getAllDataCenters, getAccessToken, getIsv } = require('../../../api')
|
|
|
3
3
|
const { safePrompts } = require('../../../utils/prompts')
|
|
4
4
|
const { encrypt } = require('../../../utils/crypto')
|
|
5
5
|
const { isValidUrl } = require('../../../utils/validator')
|
|
6
|
-
const { error } = require('../../../utils/log')
|
|
6
|
+
const { error, success } = require('../../../utils/log')
|
|
7
7
|
module.exports = async function authOpenAPI(options = {}) {
|
|
8
8
|
const { env } = options
|
|
9
9
|
|
|
@@ -63,6 +63,8 @@ module.exports = async function authOpenAPI(options = {}) {
|
|
|
63
63
|
error('Failed to obtain access_token. Please check your credentials and reauthentication.')
|
|
64
64
|
return
|
|
65
65
|
}
|
|
66
|
+
success(`Successfully authenticated with OpenAPI.`)
|
|
67
|
+
|
|
66
68
|
|
|
67
69
|
// 获取isv
|
|
68
70
|
const { isv } = await getIsv(url, token) || {}
|
|
@@ -36,13 +36,13 @@ function createPageXml(name) {
|
|
|
36
36
|
<name>region1</name>
|
|
37
37
|
<controls>
|
|
38
38
|
<!-- <control>
|
|
39
|
-
<type>
|
|
40
|
-
<name>
|
|
41
|
-
<label
|
|
39
|
+
<type>controlAp</type>
|
|
40
|
+
<name>controlKey</name>
|
|
41
|
+
<label>组件名称</label>
|
|
42
42
|
<propertys>
|
|
43
43
|
<property>
|
|
44
44
|
<name>StringValue</name>
|
|
45
|
-
<value>
|
|
45
|
+
<value>hello world</value>
|
|
46
46
|
</property>
|
|
47
47
|
</propertys>
|
|
48
48
|
</control> -->
|
|
@@ -20,19 +20,24 @@ module.exports = async function deploy(options = {}) {
|
|
|
20
20
|
|
|
21
21
|
validateDeploy(ctx)
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
try {
|
|
24
|
+
const files = collectMeta(ctx)
|
|
24
25
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
if(!files || files.length === 0) {
|
|
27
|
+
error('No files to deploy')
|
|
28
|
+
return
|
|
29
|
+
}
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
// 更新isv信息到元数据描述文件 updateIsv
|
|
32
|
+
// 在上传前,统一注入 ISV
|
|
33
|
+
updateIsv(files, env?.isv)
|
|
33
34
|
|
|
34
|
-
|
|
35
|
+
await upload(files, env)
|
|
35
36
|
|
|
36
|
-
|
|
37
|
+
// success('部署完成')
|
|
38
|
+
} catch (err) {
|
|
39
|
+
error(err.message)
|
|
40
|
+
return
|
|
41
|
+
}
|
|
37
42
|
|
|
38
43
|
}
|
package/src/api/index.js
CHANGED
|
@@ -7,7 +7,13 @@ async function getAllDataCenters (url) {
|
|
|
7
7
|
url = url.trim().replace(/\/+$/, '')
|
|
8
8
|
const resp = await fetch(`${url}/auth/getAllDatacenters.do`)
|
|
9
9
|
if (resp?.status === 200) {
|
|
10
|
-
|
|
10
|
+
let data
|
|
11
|
+
try {
|
|
12
|
+
data = await resp.json()
|
|
13
|
+
} catch (e) {
|
|
14
|
+
error(`⚠ Data center response parsing failed, error message: ${e?.message}`)
|
|
15
|
+
return []
|
|
16
|
+
}
|
|
11
17
|
if (Array.isArray(data) && data.length > 0) {
|
|
12
18
|
for (let i = 0; i < data.length; i++) {
|
|
13
19
|
const d = data[i]
|
|
@@ -54,7 +60,13 @@ async function getAccessToken (url, params) {
|
|
|
54
60
|
body: JSON.stringify(body)
|
|
55
61
|
})
|
|
56
62
|
if (resp?.status === 200) {
|
|
57
|
-
|
|
63
|
+
let respData
|
|
64
|
+
try {
|
|
65
|
+
respData = await resp.json()
|
|
66
|
+
} catch (e) {
|
|
67
|
+
error(`⚠ Token response parsing failed, error message: ${e?.message}`)
|
|
68
|
+
return {}
|
|
69
|
+
}
|
|
58
70
|
if (respData?.status) {
|
|
59
71
|
res = respData?.data || {}
|
|
60
72
|
} else {
|
|
@@ -81,7 +93,13 @@ async function getIsv (url, access_token) {
|
|
|
81
93
|
})
|
|
82
94
|
|
|
83
95
|
if (resp.status === 200) {
|
|
84
|
-
|
|
96
|
+
let respData
|
|
97
|
+
try {
|
|
98
|
+
respData = await resp.json()
|
|
99
|
+
} catch (e) {
|
|
100
|
+
error(`⚠ ISV response parsing failed, error message: ${e?.message}`)
|
|
101
|
+
return {}
|
|
102
|
+
}
|
|
85
103
|
if (respData?.status) {
|
|
86
104
|
res = respData?.data || {}
|
|
87
105
|
} else {
|
package/src/commands/debug.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
module.exports = function registerDebug(program) {
|
|
2
2
|
program
|
|
3
3
|
.command('debug')
|
|
4
|
-
.description('
|
|
4
|
+
.description('debug project')
|
|
5
5
|
.option('-e, --target-env <env>', 'specified target environment')
|
|
6
|
+
.option('-f, --formid <formId>', 'specified form id to debug')
|
|
6
7
|
.action((options) =>
|
|
7
8
|
require('../actions/debug')(options)
|
|
8
9
|
)
|
|
@@ -3,14 +3,14 @@ const KdHelp = require('../../utils/help')
|
|
|
3
3
|
module.exports = function registerEnv(program) {
|
|
4
4
|
const env = program
|
|
5
5
|
.command('env')
|
|
6
|
-
.description('
|
|
6
|
+
.description('environment management')
|
|
7
7
|
.usage('[command] [options]')
|
|
8
8
|
|
|
9
9
|
env.createHelp = () => new KdHelp(env.configureHelp())
|
|
10
10
|
|
|
11
11
|
env
|
|
12
12
|
.command('create <name>')
|
|
13
|
-
.description('
|
|
13
|
+
.description('create a new environment')
|
|
14
14
|
.option('--url <url>', 'environment url')
|
|
15
15
|
.action((name, options) =>
|
|
16
16
|
require('./create')(name, options)
|
|
@@ -18,46 +18,46 @@ module.exports = function registerEnv(program) {
|
|
|
18
18
|
|
|
19
19
|
const set = env
|
|
20
20
|
.command('set')
|
|
21
|
-
.description('
|
|
21
|
+
.description('set environment config')
|
|
22
22
|
.usage('[command] [options]')
|
|
23
23
|
|
|
24
24
|
set.createHelp = () => new KdHelp(set.configureHelp())
|
|
25
25
|
|
|
26
26
|
set
|
|
27
27
|
.command('target-env <name>')
|
|
28
|
-
.description('
|
|
28
|
+
.description('set default environment')
|
|
29
29
|
.action(name =>
|
|
30
30
|
require('./set')(name)
|
|
31
31
|
)
|
|
32
32
|
|
|
33
33
|
env
|
|
34
34
|
.command('info')
|
|
35
|
-
.description('
|
|
35
|
+
.description('show current environment info')
|
|
36
36
|
.action(() =>
|
|
37
37
|
require('./info')()
|
|
38
38
|
)
|
|
39
39
|
|
|
40
40
|
env
|
|
41
41
|
.command('list')
|
|
42
|
-
.description('
|
|
42
|
+
.description('list all environments')
|
|
43
43
|
.action(() =>
|
|
44
44
|
require('./list')()
|
|
45
45
|
)
|
|
46
46
|
|
|
47
47
|
env
|
|
48
48
|
.command('delete <name>')
|
|
49
|
-
.description('
|
|
49
|
+
.description('delete an environment')
|
|
50
50
|
.action(name =>
|
|
51
51
|
require('./delete')(name)
|
|
52
52
|
)
|
|
53
53
|
|
|
54
54
|
const auth = env
|
|
55
55
|
.command('auth')
|
|
56
|
-
.description('
|
|
56
|
+
.description('authenticate environment')
|
|
57
57
|
|
|
58
58
|
auth
|
|
59
59
|
.command('web')
|
|
60
|
-
.description('
|
|
60
|
+
.description('authenticate via Web (username/password)')
|
|
61
61
|
.option('-e --target-env <name>', 'target environment name')
|
|
62
62
|
.action((options) =>
|
|
63
63
|
require('./auth')('web', options)
|
|
@@ -65,7 +65,7 @@ module.exports = function registerEnv(program) {
|
|
|
65
65
|
|
|
66
66
|
auth
|
|
67
67
|
.command('openapi')
|
|
68
|
-
.description('
|
|
68
|
+
.description('authenticate via OpenAPI (client credentials)')
|
|
69
69
|
.option('-e --target-env <name>', 'target environment name')
|
|
70
70
|
.action((options) =>
|
|
71
71
|
require('./auth')('openapi', options)
|
|
@@ -3,20 +3,20 @@ const KdHelp = require('../../utils/help')
|
|
|
3
3
|
module.exports = function registerProject(program) {
|
|
4
4
|
const project = program
|
|
5
5
|
.command('project')
|
|
6
|
-
.description('
|
|
6
|
+
.description('project management')
|
|
7
7
|
.usage('[command] [options]')
|
|
8
8
|
|
|
9
9
|
project.createHelp = () => new KdHelp(project.configureHelp())
|
|
10
10
|
|
|
11
11
|
project
|
|
12
12
|
.command('init <name>')
|
|
13
|
-
.description('
|
|
13
|
+
.description('initialize a new project')
|
|
14
14
|
.option('-s, --source <source>', 'specified repository source', 'outer')
|
|
15
15
|
.action((name, options) => require('./init')(name, options))
|
|
16
16
|
|
|
17
17
|
project
|
|
18
18
|
.command('create <name>')
|
|
19
|
-
.description('
|
|
19
|
+
.description('create control or page xml')
|
|
20
20
|
.option('--type <type>', 'project type: kwc | page')
|
|
21
21
|
.action((name, options) =>
|
|
22
22
|
require('./create')(name, options)
|
|
@@ -24,7 +24,7 @@ module.exports = function registerProject(program) {
|
|
|
24
24
|
|
|
25
25
|
project
|
|
26
26
|
.command('deploy')
|
|
27
|
-
.description('
|
|
27
|
+
.description('deploy current project')
|
|
28
28
|
.option('-e --target-env <env>', 'specified target environment')
|
|
29
29
|
.option('-d --source-dir <dir>', 'specified source directory to deploy')
|
|
30
30
|
// .option('-f --force', 'force deploy, ignore warnings')
|
package/src/utils/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
exports.capitalize = function (name) {
|
|
2
|
+
if (!name || typeof name !== 'string') return ''
|
|
2
3
|
return name[0].toUpperCase() + name.slice(1)
|
|
3
4
|
}
|
|
4
5
|
|
|
5
6
|
exports.toPascalCase = function (name) {
|
|
7
|
+
if (!name || typeof name !== 'string') return ''
|
|
6
8
|
return name
|
|
7
9
|
.replace(/(-\w)/g, (match) => match[1].toUpperCase()) // kebab-case to camelCase
|
|
8
10
|
.replace(/^[a-z]/, (match) => match.toUpperCase()) // first char to Upper
|
package/src/utils/printTable.js
CHANGED
|
@@ -76,10 +76,10 @@ module.exports = function printTable(headers, rows, options = {}) {
|
|
|
76
76
|
head: headers,
|
|
77
77
|
// Keep internal and horizontal borders, but remove left and right outer borders
|
|
78
78
|
chars: {
|
|
79
|
-
'top': '
|
|
80
|
-
'bottom': '
|
|
81
|
-
'left': '', 'left-mid': '', 'mid': '
|
|
82
|
-
'right': '', 'right-mid': '', 'middle': '
|
|
79
|
+
'top': '-', 'top-mid': '+', 'top-left': '', 'top-right': '',
|
|
80
|
+
'bottom': '-', 'bottom-mid': '+', 'bottom-left': '', 'bottom-right': '',
|
|
81
|
+
'left': '', 'left-mid': '', 'mid': '-', 'mid-mid': '+',
|
|
82
|
+
'right': '', 'right-mid': '', 'middle': '|'
|
|
83
83
|
},
|
|
84
84
|
style: {
|
|
85
85
|
head: ['cyan'],
|
|
@@ -1,20 +1,27 @@
|
|
|
1
1
|
const fs = require('fs')
|
|
2
2
|
const path = require('path')
|
|
3
|
+
const { error } = require('./log')
|
|
3
4
|
|
|
4
5
|
function getConfig(root) {
|
|
5
6
|
const configPath = path.join(root, '.kd', 'config.json')
|
|
6
7
|
|
|
7
8
|
if (!fs.existsSync(configPath)) {
|
|
8
|
-
|
|
9
|
+
error('.kd/config.json not found, please run "kd project init" first')
|
|
10
|
+
process.exit(1)
|
|
9
11
|
}
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
try {
|
|
14
|
+
return JSON.parse(fs.readFileSync(configPath, 'utf-8'))
|
|
15
|
+
} catch (e) {
|
|
16
|
+
error('Failed to parse .kd/config.json, please check if the file is valid JSON')
|
|
17
|
+
process.exit(1)
|
|
18
|
+
}
|
|
12
19
|
}
|
|
13
20
|
|
|
14
21
|
function getConfigValue(root, key) {
|
|
15
22
|
const config = getConfig(root)
|
|
16
23
|
|
|
17
|
-
if (!config[key]) {
|
|
24
|
+
if (!config || !config[key]) {
|
|
18
25
|
throw new Error(`${key} is missing in config.json`)
|
|
19
26
|
}
|
|
20
27
|
|