@kdcloudjs/cli 0.0.3 → 0.0.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kdcloudjs/cli",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "Kingdee CLI",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -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) || {}
@@ -1,3 +1,3 @@
1
1
  module.exports = async function authWeb(options) {
2
- console.log('Web authentication initiated with options:', options)
2
+ console.log('Web authentication is not supported at the moment; OpenAPI authentication is recommended.')
3
3
  }
@@ -36,13 +36,13 @@ function createPageXml(name) {
36
36
  <name>region1</name>
37
37
  <controls>
38
38
  <!-- <control>
39
- <type>ReactDemoAp</type>
40
- <name>ReactDemo</name>
41
- <label>测试组件名称</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>3333</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
- const files = collectMeta(ctx)
23
+ try {
24
+ const files = collectMeta(ctx)
24
25
 
25
- if(!files || files.length === 0) {
26
- error('No files to deploy')
27
- return
28
- }
26
+ if(!files || files.length === 0) {
27
+ error('No files to deploy')
28
+ return
29
+ }
29
30
 
30
- // 更新isv信息到元数据描述文件 updateIsv
31
- // 在上传前,统一注入 ISV
32
- updateIsv(files, env?.isv)
31
+ // 更新isv信息到元数据描述文件 updateIsv
32
+ // 在上传前,统一注入 ISV
33
+ updateIsv(files, env?.isv)
33
34
 
34
- await upload(files, env)
35
+ await upload(files, env)
35
36
 
36
- // success('部署完成')
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
- const data = await resp.json()
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
- const respData = await resp.json()
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
- const respData = await resp.json()
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 {
@@ -1,7 +1,7 @@
1
1
  module.exports = function registerDebug(program) {
2
2
  program
3
3
  .command('debug')
4
- .description('Debug project')
4
+ .description('debug project')
5
5
  .option('-e, --target-env <env>', 'specified target environment')
6
6
  .action((options) =>
7
7
  require('../actions/debug')(options)
@@ -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('Environment management')
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('Create a new environment')
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('Set environment config')
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('Set default environment')
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('Show current environment info')
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('List all environments')
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('Delete an environment')
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('Authenticate environment')
56
+ .description('authenticate environment')
57
57
 
58
58
  auth
59
59
  .command('web')
60
- .description('Authenticate via Web (username/password)')
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('Authenticate via OpenAPI (client credentials)')
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('Project management')
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('Initialize a new project')
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('Create control or page xml')
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('Deploy current project')
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')
@@ -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
@@ -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': '', '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': ''
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
- throw new Error('.kd/config.json not found')
9
+ error('.kd/config.json not found, please run "kd project init" first')
10
+ process.exit(1)
9
11
  }
10
12
 
11
- return JSON.parse(fs.readFileSync(configPath, 'utf-8'))
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