shoplazza-cli 1.0.3 → 1.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/bin/shoplazza CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
 
3
+ process.noDeprecation = true; // 全局禁用废弃警告
3
4
  const { program } = require('commander');
4
5
  const updateNotifier = require('update-notifier');
5
6
  const Sentry = require('@sentry/node');
@@ -7,6 +7,7 @@ const { openAipVersion } = require('./config');
7
7
  const { isDebug } = require('./console');
8
8
  const { getProjectConfig } = require('./util');
9
9
  const chalk = require('chalk');
10
+ const { consoleWarn } = require('./console');
10
11
 
11
12
  const FILE_SIGN_URL = '/checkout_extensions/file/sign';
12
13
  const CREATE_URL = '/checkout_extensions/create';
@@ -39,13 +40,17 @@ request.interceptors.request.use((config) => {
39
40
  return config;
40
41
  });
41
42
 
42
- const handleResponseError = (response)=>{
43
- if (response.data?.status === 3 && response.data?.message === 'INVALID_ARGUMENT') {
44
- throw `Invalid argument at ${response.config.url}`;
45
- }else if(response.data?.status === 13 && response.data?.message === 'INTERNAL_ERROR'){
46
- throw `Internal error at ${response.config.url}`;
43
+ const errorMapping = {
44
+ INVALID_ARGUMENT: 'Invalid argument',
45
+ PERMISSION_DENIED: 'Permission denied',
46
+ INTERNAL_ERROR: 'Internal error'
47
+ };
48
+ const handleResponseError = (response) => {
49
+ const errorMsg = errorMapping[response.data?.message];
50
+ if (errorMsg) {
51
+ throw `${errorMsg} at ${response.config.url}`;
47
52
  }
48
- }
53
+ };
49
54
 
50
55
  request.interceptors.response.use(
51
56
  (response) => {
@@ -71,11 +76,11 @@ request.interceptors.response.use(
71
76
 
72
77
  async function upload(path, name) {
73
78
  const form = new FormData();
74
- await request(`${FILE_SIGN_URL}?key=${name}`)
79
+ const url = await request(`${FILE_SIGN_URL}?key=${name}`)
75
80
  .then((data) => {
76
81
  return data.data;
77
82
  })
78
- .then((data) => {
83
+ .then(async (data) => {
79
84
  const url = data.write_host;
80
85
  form.append('policy', data.policy);
81
86
  form.append('OSSAccessKeyId', data.access_id);
@@ -84,13 +89,25 @@ async function upload(path, name) {
84
89
  form.append('x-oss-forbid-overwrite', 'true');
85
90
  form.append('key', name);
86
91
  form.append('file', fs.createReadStream(path));
87
- return request.post(`https:${url}`, form, { headers: form.getHeaders() });
92
+ await request.post(`https:${url}`, form, { headers: form.getHeaders() }).catch((error) => {
93
+ if (error.response?.data.includes('<Code>FileAlreadyExists</Code>')) {
94
+ consoleWarn('The current file already exists, not need to upload.');
95
+ return;
96
+ } else {
97
+ return Promise.reject(error);
98
+ }
99
+ });
100
+ return `${data.read_host}${data.read_host.endsWith('/') ? '' : '/'}${name}`;
88
101
  });
89
102
  loading('succeed upload').succeed();
103
+ return url;
90
104
  }
91
105
 
106
+ async function uploadFile(dirPath, file) {
107
+ return upload(`${dirPath}/${file}`, `chick-extension/${file}`);
108
+ }
92
109
  async function uploadDir(dirPath, files) {
93
- await Promise.all(
110
+ return Promise.all(
94
111
  files.map((file) => {
95
112
  return upload(`${dirPath}/${file}`, `chick-extension/${file}`);
96
113
  })
@@ -98,8 +115,8 @@ async function uploadDir(dirPath, files) {
98
115
  }
99
116
 
100
117
  module.exports = {
101
- upload,
102
118
  uploadDir,
119
+ uploadFile,
103
120
  getExtensionList: async (params) => {
104
121
  const load = loading('Fetch extension list').start();
105
122
  try {
@@ -26,9 +26,9 @@ module.exports = async () => {
26
26
  }; // 兼容旧代码处理
27
27
  await viteBuild(composeCommands);
28
28
  consoleBlue('Starting to upload:');
29
- await uploadOSS(composeCommands);
29
+ const url = await uploadOSS(composeCommands);
30
30
  consoleBlue('Starting to push:');
31
- await pushExtension(composeCommands, extensionInfo);
31
+ await pushExtension(composeCommands, extensionInfo, url);
32
32
  } catch (error) {
33
33
  error.response ? consoleError(`Error: ${error.response.status}-${error.response.config.url}`) : consoleError(error);
34
34
  }
@@ -46,31 +46,27 @@ async function uploadOSS(command) {
46
46
  }
47
47
  const files = fsExtra.readdirSync(dir).filter((name) => name.includes(info.id));
48
48
  try {
49
- await api.uploadDir(dir, files);
49
+ const url = await api.uploadFile(dir, files[0]);
50
+ consoleSuccess('Successfully uploaded to OSS.');
51
+ return url;
50
52
  } catch (error) {
51
- if (error.response?.data.includes('<Code>FileAlreadyExists</Code>')) {
52
- consoleWarn('The current file already exists, not need to upload.');
53
- return;
54
- } else {
55
- consoleError('Failed to upload to OSS:', error);
56
- throw 'upload_failed';
57
- }
53
+ consoleError('Failed to upload to OSS:', error);
54
+ throw 'upload_failed';
58
55
  }
59
- consoleSuccess('Successfully uploaded to OSS.');
60
56
  }
61
57
 
62
58
  /**
63
59
  * 发布
64
60
  * @returns
65
61
  */
66
- async function pushExtension(command, extraInfo) {
62
+ async function pushExtension(command, extraInfo, url) {
67
63
  const info = getExtensionInfo(command.id);
68
64
  const load = loading(`start push the extension ${info.id}.`).start();
69
65
  try {
70
66
  const config = getExtensionConfig(command.id);
71
67
  // 兼容低版本extension配置文件
72
68
  const data = {
73
- resource_url: `https://cn.static.shoplazza.com/chick-extension/${info.distName}`,
69
+ resource_url: url,
74
70
  version: config.version,
75
71
  scope: '',
76
72
  template_name: config.templateName || config.template_name,
@@ -91,7 +87,7 @@ async function pushExtension(command, extraInfo) {
91
87
  setExtensionConfig(command.id, {
92
88
  ...config,
93
89
  extensionId: extensionInfo.extension_id,
94
- extensionName: extensionInfo.name,
90
+ extensionName: extensionInfo.name
95
91
  });
96
92
  }
97
93
 
@@ -111,7 +107,6 @@ async function pushExtension(command, extraInfo) {
111
107
  } catch (error) {
112
108
  consoleError(error);
113
109
  }
114
-
115
110
  } catch (err) {
116
111
  load.stop();
117
112
  throw '\nFailed to push the extension: ' + err;
@@ -170,11 +170,9 @@ function checkLocalExtension(extensionInfo) {
170
170
  const extensionJsonPath = path.resolve(extensionPath, './extension.json');
171
171
  const localExtensionInfo = JSON.parse(fs.readFileSync(extensionJsonPath, 'utf8'));
172
172
  if (localExtensionInfo.extensionId !== extensionInfo.extension_id) {
173
- consoleError(`The extension ${extensionInfo.name}(${extensionInfo.extension_id}) does not exist in your local project.`);
174
173
  throw `The extension ${extensionInfo.name}(${extensionInfo.extension_id}) does not exist in your local project.`;
175
174
  }
176
175
  } else {
177
- consoleError(`The extension ${extensionInfo.name}(${extensionInfo.extension_id}) does not exist in your local project.`);
178
176
  throw `The extension ${extensionInfo.name}(${extensionInfo.extension_id}) does not exist in your local project.`;
179
177
  }
180
178
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shoplazza-cli",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "",
5
5
  "main": "bin/shoplazza",
6
6
  "engines": {