shoplazza-cli 1.0.2 → 1.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.
@@ -1,4 +1,4 @@
1
- import { extend } from "@shoplazza/extension-ui";
1
+ import { extend } from "shoplazza-extension-ui";
2
2
 
3
3
  extend({
4
4
  extensionPoint: "Checkout::ShippingLinesTitle::RenderAfter",
@@ -1,4 +1,4 @@
1
- import { extend } from '@shoplazza/extension-ui';
1
+ import { extend } from 'shoplazza-extension-ui';
2
2
  import index from './index.html';
3
3
 
4
4
  function App() {
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": "1.0",
3
+ "deleteTarget": [],
4
+ "placeholder": {},
5
+ "templateName": "checkout",
6
+ "themeName": "",
7
+ "extensionId": "",
8
+ "extensionName": "product-list",
9
+ "extensionDescription": ""
10
+ }
@@ -0,0 +1,5 @@
1
+ const productList = CheckoutAPI.summary.getProductList();
2
+
3
+ console.debug('productList', productList);
4
+
5
+ // do something, such as report
@@ -1,4 +1,4 @@
1
- import { extend } from '@shoplazza/extension-ui';
1
+ import { extend } from 'shoplazza-extension-ui';
2
2
  import index from './index.html';
3
3
 
4
4
  function App() {
@@ -0,0 +1,121 @@
1
+ {
2
+ "name": "checkout-extension",
3
+ "version": "1.0.0",
4
+ "lockfileVersion": 3,
5
+ "requires": true,
6
+ "packages": {
7
+ "": {
8
+ "name": "checkout-extension",
9
+ "version": "1.0.0",
10
+ "license": "ISC",
11
+ "dependencies": {
12
+ "fs-extra": "11.1.1",
13
+ "shoplazza-extension-ui": "1.0.0"
14
+ },
15
+ "devDependencies": {}
16
+ },
17
+ "node_modules/fs-extra": {
18
+ "version": "11.1.1",
19
+ "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.1.1.tgz",
20
+ "integrity": "sha512-MGIE4HOvQCeUCzmlHs0vXpih4ysz4wg9qiSAu6cd42lVwPbTM1TjV7RusoyQqMmk/95gdQZX72u+YW+c3eEpFQ==",
21
+ "license": "MIT",
22
+ "dependencies": {
23
+ "graceful-fs": "^4.2.0",
24
+ "jsonfile": "^6.0.1",
25
+ "universalify": "^2.0.0"
26
+ },
27
+ "engines": {
28
+ "node": ">=14.14"
29
+ }
30
+ },
31
+ "node_modules/graceful-fs": {
32
+ "version": "4.2.11",
33
+ "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz",
34
+ "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==",
35
+ "license": "ISC"
36
+ },
37
+ "node_modules/js-tokens": {
38
+ "version": "4.0.0",
39
+ "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
40
+ "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==",
41
+ "license": "MIT"
42
+ },
43
+ "node_modules/jsonfile": {
44
+ "version": "6.1.0",
45
+ "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz",
46
+ "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==",
47
+ "license": "MIT",
48
+ "dependencies": {
49
+ "universalify": "^2.0.0"
50
+ },
51
+ "optionalDependencies": {
52
+ "graceful-fs": "^4.1.6"
53
+ }
54
+ },
55
+ "node_modules/loose-envify": {
56
+ "version": "1.4.0",
57
+ "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz",
58
+ "integrity": "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==",
59
+ "license": "MIT",
60
+ "dependencies": {
61
+ "js-tokens": "^3.0.0 || ^4.0.0"
62
+ },
63
+ "bin": {
64
+ "loose-envify": "cli.js"
65
+ }
66
+ },
67
+ "node_modules/react": {
68
+ "version": "18.3.1",
69
+ "resolved": "https://registry.npmjs.org/react/-/react-18.3.1.tgz",
70
+ "integrity": "sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==",
71
+ "license": "MIT",
72
+ "dependencies": {
73
+ "loose-envify": "^1.1.0"
74
+ },
75
+ "engines": {
76
+ "node": ">=0.10.0"
77
+ }
78
+ },
79
+ "node_modules/react-dom": {
80
+ "version": "18.3.1",
81
+ "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.3.1.tgz",
82
+ "integrity": "sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw==",
83
+ "license": "MIT",
84
+ "dependencies": {
85
+ "loose-envify": "^1.1.0",
86
+ "scheduler": "^0.23.2"
87
+ },
88
+ "peerDependencies": {
89
+ "react": "^18.3.1"
90
+ }
91
+ },
92
+ "node_modules/scheduler": {
93
+ "version": "0.23.2",
94
+ "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.23.2.tgz",
95
+ "integrity": "sha512-UOShsPwz7NrMUqhR6t0hWjFduvOzbtv7toDH1/hIrfRNIDBnnBWd0CwJTGvTpngVlmwGCdP9/Zl/tVrDqcuYzQ==",
96
+ "license": "MIT",
97
+ "dependencies": {
98
+ "loose-envify": "^1.1.0"
99
+ }
100
+ },
101
+ "node_modules/shoplazza-extension-ui": {
102
+ "version": "1.0.0",
103
+ "resolved": "https://registry.npmjs.org/shoplazza-extension-ui/-/shoplazza-extension-ui-1.0.0.tgz",
104
+ "integrity": "sha512-gW2sWnfyEXwbWfi9Sje4K+r0ECCHjF7lID/igWplMi8opOiTI+88JurPHuwtBAhC3V0T2WZvBlcykHWjNQzYBA==",
105
+ "license": "MIT",
106
+ "dependencies": {
107
+ "react": "^18.2.0",
108
+ "react-dom": "^18.2.0"
109
+ }
110
+ },
111
+ "node_modules/universalify": {
112
+ "version": "2.0.1",
113
+ "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz",
114
+ "integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==",
115
+ "license": "MIT",
116
+ "engines": {
117
+ "node": ">= 10.0.0"
118
+ }
119
+ }
120
+ }
121
+ }
@@ -5,7 +5,7 @@
5
5
  "main": "index.js",
6
6
  "dependencies": {
7
7
  "fs-extra": "11.1.1",
8
- "@shoplazza/extension-ui": "2.0.8"
8
+ "shoplazza-extension-ui": "1.0.0"
9
9
  },
10
10
  "devDependencies": {},
11
11
  "scripts": {
@@ -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,13 @@ request.interceptors.request.use((config) => {
39
40
  return config;
40
41
  });
41
42
 
42
- const handleResponseError = (response)=>{
43
+ const handleResponseError = (response) => {
43
44
  if (response.data?.status === 3 && response.data?.message === 'INVALID_ARGUMENT') {
44
45
  throw `Invalid argument at ${response.config.url}`;
45
- }else if(response.data?.status === 13 && response.data?.message === 'INTERNAL_ERROR'){
46
+ } else if (response.data?.status === 13 && response.data?.message === 'INTERNAL_ERROR') {
46
47
  throw `Internal error at ${response.config.url}`;
47
48
  }
48
- }
49
+ };
49
50
 
50
51
  request.interceptors.response.use(
51
52
  (response) => {
@@ -71,11 +72,11 @@ request.interceptors.response.use(
71
72
 
72
73
  async function upload(path, name) {
73
74
  const form = new FormData();
74
- await request(`${FILE_SIGN_URL}?key=${name}`)
75
+ const url = await request(`${FILE_SIGN_URL}?key=${name}`)
75
76
  .then((data) => {
76
77
  return data.data;
77
78
  })
78
- .then((data) => {
79
+ .then(async (data) => {
79
80
  const url = data.write_host;
80
81
  form.append('policy', data.policy);
81
82
  form.append('OSSAccessKeyId', data.access_id);
@@ -84,13 +85,25 @@ async function upload(path, name) {
84
85
  form.append('x-oss-forbid-overwrite', 'true');
85
86
  form.append('key', name);
86
87
  form.append('file', fs.createReadStream(path));
87
- return request.post(`https:${url}`, form, { headers: form.getHeaders() });
88
+ await request.post(`https:${url}`, form, { headers: form.getHeaders() }).catch((error) => {
89
+ if (error.response?.data.includes('<Code>FileAlreadyExists</Code>')) {
90
+ consoleWarn('The current file already exists, not need to upload.');
91
+ return;
92
+ } else {
93
+ return Promise.reject(error);
94
+ }
95
+ });
96
+ return `${data.read_host}${data.read_host.endsWith('/') ? '' : '/'}${name}`;
88
97
  });
89
98
  loading('succeed upload').succeed();
99
+ return url;
90
100
  }
91
101
 
102
+ async function uploadFile(dirPath, file) {
103
+ return upload(`${dirPath}/${file}`, `chick-extension/${file}`);
104
+ }
92
105
  async function uploadDir(dirPath, files) {
93
- await Promise.all(
106
+ return Promise.all(
94
107
  files.map((file) => {
95
108
  return upload(`${dirPath}/${file}`, `chick-extension/${file}`);
96
109
  })
@@ -98,8 +111,8 @@ async function uploadDir(dirPath, files) {
98
111
  }
99
112
 
100
113
  module.exports = {
101
- upload,
102
114
  uploadDir,
115
+ uploadFile,
103
116
  getExtensionList: async (params) => {
104
117
  const load = loading('Fetch extension list').start();
105
118
  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;
@@ -1,4 +1,4 @@
1
- import { extend } from '@shoplazza/extension-ui';
1
+ import { extend } from 'shoplazza-extension-ui';
2
2
  import index from './index.html';
3
3
 
4
4
  function App() {
@@ -5,7 +5,7 @@
5
5
  "main": "index.js",
6
6
  "dependencies": {
7
7
  "fs-extra": "11.1.1",
8
- "@shoplazza/extension-ui": "2.0.8"
8
+ "shoplazza-extension-ui": "1.0.0"
9
9
  },
10
10
  "devDependencies": {},
11
11
  "scripts": {
@@ -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.2",
3
+ "version": "1.0.4",
4
4
  "description": "",
5
5
  "main": "bin/shoplazza",
6
6
  "engines": {
@@ -13,10 +13,6 @@
13
13
  "prettier": "prettier --write ./lib",
14
14
  "test": "jest --runInBand --forceExit"
15
15
  },
16
- "repository": {
17
- "type": "git",
18
- "url": "git@gitlab.shoplazza.site:shoplaza/frontend/openapi/shoplazza-cli.git"
19
- },
20
16
  "keywords": [],
21
17
  "author": "",
22
18
  "license": "ISC",
@@ -28,7 +24,6 @@
28
24
  "dependencies": {
29
25
  "@sentry/node": "^6.19.7",
30
26
  "@sentry/tracing": "^6.19.7",
31
- "@shoplazza/extension-ui": "^1.0.0",
32
27
  "adm-zip": "^0.5.9",
33
28
  "ali-oss": "^6.17.1",
34
29
  "archiver": "^5.3.1",