shoplazza-cli 0.0.10 → 1.0.2
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/README.md +71 -7
- package/bin/shoplazza +6 -0
- package/examples/checkout-extension/README.md +19 -0
- package/examples/checkout-extension/extension.config.js +4 -0
- package/examples/checkout-extension/extensions/add-shipping-desc/extension.json +10 -0
- package/examples/checkout-extension/extensions/add-shipping-desc/src/index.js +7 -0
- package/examples/checkout-extension/extensions/ext-1/extension.json +10 -0
- package/examples/checkout-extension/extensions/ext-1/src/content.html +3 -0
- package/examples/checkout-extension/extensions/ext-1/src/index.html +5 -0
- package/examples/checkout-extension/extensions/ext-1/src/index.js +11 -0
- package/examples/checkout-extension/extensions/ext-1/src/script.html +3 -0
- package/examples/checkout-extension/extensions/ext-1/src/style.html +3 -0
- package/examples/checkout-extension/extensions/rewrite-navigate/extension.json +10 -0
- package/examples/checkout-extension/extensions/rewrite-navigate/src/content.html +38 -0
- package/examples/checkout-extension/extensions/rewrite-navigate/src/index.html +5 -0
- package/examples/checkout-extension/extensions/rewrite-navigate/src/index.js +12 -0
- package/examples/checkout-extension/extensions/rewrite-navigate/src/script.html +26 -0
- package/examples/checkout-extension/extensions/rewrite-navigate/src/style.html +23 -0
- package/examples/checkout-extension/package.json +17 -0
- package/lib/app/commands/deploy.js +0 -1
- package/lib/app/constants.js +22 -5
- package/lib/app/login.js +0 -1
- package/lib/auth/index.js +42 -0
- package/lib/checkout/api.js +169 -0
- package/lib/checkout/build/plugin/vite-plugin-add-extension-id.js +25 -0
- package/lib/checkout/build/plugin/vite-plugin-transform-extension-html.js +207 -0
- package/lib/checkout/build/vite.config.js +34 -0
- package/lib/checkout/build.js +38 -0
- package/lib/checkout/config.js +97 -0
- package/lib/checkout/console.js +32 -0
- package/lib/checkout/create.js +132 -0
- package/lib/checkout/delete.js +26 -0
- package/lib/checkout/deploy.js +59 -0
- package/lib/checkout/dev/client.js +73 -0
- package/lib/checkout/dev/index.js +142 -0
- package/lib/checkout/fields.js +29 -0
- package/lib/checkout/index.js +63 -0
- package/lib/checkout/preview.js +52 -0
- package/lib/checkout/pull.js +21 -0
- package/lib/checkout/push.js +146 -0
- package/lib/checkout/template/README.md +34 -0
- package/lib/checkout/template/_gitignore +4 -0
- package/lib/checkout/template/extension.config.js +4 -0
- package/lib/checkout/template/extensions/extension-template/extension.json +10 -0
- package/lib/checkout/template/extensions/extension-template/src/content.html +3 -0
- package/lib/checkout/template/extensions/extension-template/src/index.html +5 -0
- package/lib/checkout/template/extensions/extension-template/src/index.js +11 -0
- package/lib/checkout/template/extensions/extension-template/src/script.html +3 -0
- package/lib/checkout/template/extensions/extension-template/src/style.html +3 -0
- package/lib/checkout/template/package.json +17 -0
- package/lib/checkout/undeploy.js +40 -0
- package/lib/checkout/util.js +203 -0
- package/lib/checkout/verify.js +16 -0
- package/lib/checkout/version.js +7 -0
- package/lib/commands/login.js +3 -2
- package/lib/commands/theme/init.js +2 -2
- package/lib/commands/theme/pull.js +1 -1
- package/lib/config.js +4 -0
- package/lib/db/user.js +5 -2
- package/lib/utils.js +36 -4
- package/package.json +29 -3
package/README.md
CHANGED
|
@@ -10,21 +10,18 @@
|
|
|
10
10
|
|
|
11
11
|
Shoplazza CLI is a cross-platform command line tool that you can use to build Shoplazza themes.
|
|
12
12
|
|
|
13
|
-
## Node Version
|
|
14
|
-
|
|
15
|
-
use 14.18.2
|
|
16
|
-
|
|
17
13
|
## Features
|
|
18
14
|
|
|
19
15
|
Shoplazza CLI accelerates your theme development process with the following features:
|
|
20
16
|
|
|
21
17
|
- Safely preview, test, and share changes to themes using unpublish themes
|
|
22
18
|
- Hot reload CSS and section changes, or automatically refresh a page on file change, when previewing a theme.
|
|
23
|
-
- Initialize a new theme using
|
|
19
|
+
- Initialize a new theme using Nova 2023 as a starting point.
|
|
24
20
|
- Use workflow tools like Git to work with a team of theme developers.
|
|
25
21
|
- Upload themes to your store.
|
|
26
22
|
- Watch for local changes and upload them automatically to Shoplazza.
|
|
27
23
|
- Work on Linux, macOS, and Windows.
|
|
24
|
+
- Support customized Checkout page.
|
|
28
25
|
|
|
29
26
|
## Installation [shoplazza-cli](https://www.npmjs.com/package/shoplazza-themekit)
|
|
30
27
|
|
|
@@ -36,13 +33,80 @@ $ npm install shoplazza-cli -g
|
|
|
36
33
|
|
|
37
34
|
Before you start using Shoplazza CLI to develop themes, make sure that you do the following tasks:
|
|
38
35
|
|
|
39
|
-
- Install [Node.js](https://nodejs.org/en/) (
|
|
36
|
+
- Install [Node.js](https://nodejs.org/en/) (20.18.0).
|
|
40
37
|
- Install [Git](https://git-scm.com/downloads).
|
|
41
38
|
- Make sure that you have a account with the Manage themes permission for the store that you want to work on, or you're the owner of the store.
|
|
42
39
|
- Note the URL of the store that you want to work on.
|
|
43
40
|
- Make sure that you're connected to the internet. Most Shoplazza CLI commands need an internet connection to run.
|
|
44
41
|
|
|
45
|
-
|
|
42
|
+
|
|
43
|
+
## Checkout Develop
|
|
44
|
+
|
|
45
|
+
You can use Shoplazza CLI to develop checkout, customized checkout page as you want.
|
|
46
|
+
|
|
47
|
+
### Feature
|
|
48
|
+
|
|
49
|
+
- 支持本地开发和调试,支持热更新。
|
|
50
|
+
- 支持预览,在推送到店铺之后,通过预览链接进入可以进行预览。
|
|
51
|
+
- 支持部署extension,部署后所有用户都能看到变更。
|
|
52
|
+
- 支持下线extension,下线之后extension将不在店铺中生效。
|
|
53
|
+
|
|
54
|
+
### Get Started
|
|
55
|
+
|
|
56
|
+
#### Step 1: 创建一个项目模板
|
|
57
|
+
|
|
58
|
+
创建过程会要求你输入店铺地址和token,token可以在后台中应用->管理私有应用->创建应用 获得。创建过程还要求你输入一个extension名字,一个项目下支持存在多个extension,这是为了方便管理,它们互不影响。
|
|
59
|
+
```
|
|
60
|
+
shoplazza checkout create
|
|
61
|
+
// 安装依赖
|
|
62
|
+
npm i
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
#### Step2: 本地开发
|
|
66
|
+
extension支持本地开发,支持在线上店铺Checkout页面插入本地的extension代码,这仅在你的浏览器生效。
|
|
67
|
+
首先,先启动本地开发服务器:
|
|
68
|
+
```
|
|
69
|
+
shoplazza checkout dev
|
|
70
|
+
```
|
|
71
|
+
然后在checkout页面打开控制台切换为开发模式:
|
|
72
|
+
```
|
|
73
|
+
CheckoutAPI.extension.DEV_switchDevMode()
|
|
74
|
+
```
|
|
75
|
+
在checkout页面即可看到extension变更。
|
|
76
|
+
|
|
77
|
+
#### Step3: 预览extension
|
|
78
|
+
在完成本地开发之后,我们可以将extension推送到店铺进行预览。
|
|
79
|
+
```
|
|
80
|
+
shoplazza checkout push
|
|
81
|
+
```
|
|
82
|
+
访问预览url即可看到效果。
|
|
83
|
+
#### Step4: 部署Extension
|
|
84
|
+
在预览测试完成之后,可以在店铺发布extension,发布之后所有用户都可以看到。
|
|
85
|
+
```
|
|
86
|
+
shoplazza checkout deploy
|
|
87
|
+
```
|
|
88
|
+
或者对将已发布的extension下线:
|
|
89
|
+
```
|
|
90
|
+
shoplazza checkout undeploy
|
|
91
|
+
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Other command
|
|
95
|
+
|
|
96
|
+
#### 查看已部署的extension
|
|
97
|
+
```
|
|
98
|
+
shoplazza checkout list
|
|
99
|
+
|
|
100
|
+
// 查看所有
|
|
101
|
+
shoplazza checkout list -a
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
#### 预览extension
|
|
105
|
+
```
|
|
106
|
+
shoplazza checkout preview
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Theme Develop
|
|
46
110
|
|
|
47
111
|
### Authenticate
|
|
48
112
|
|
package/bin/shoplazza
CHANGED
|
@@ -8,6 +8,8 @@ const pkg = require('../package.json');
|
|
|
8
8
|
const report = require('../lib/report');
|
|
9
9
|
require('../lib/tracing');
|
|
10
10
|
|
|
11
|
+
const { makeCheckoutCommand } = require('../lib/checkout');
|
|
12
|
+
|
|
11
13
|
const { generateExtension, deployExtension, publishExtension, buildExtension, retry } = require('../lib/app');
|
|
12
14
|
|
|
13
15
|
Sentry.init({
|
|
@@ -29,6 +31,7 @@ updateNotifier({ pkg }).notify({
|
|
|
29
31
|
program.usage('[command] [options]');
|
|
30
32
|
|
|
31
33
|
program.command('version').description('Welcome to the Shoplazza CLI').action(require('../lib/commands/version'));
|
|
34
|
+
program.description('Welcome to the Shoplazza CLI').option('-v --version').action(require('../lib/commands/version'));
|
|
32
35
|
|
|
33
36
|
program
|
|
34
37
|
.command('login')
|
|
@@ -122,6 +125,9 @@ app
|
|
|
122
125
|
.option('-a, --app', 'Retry get and choose your app list.')
|
|
123
126
|
.action(retry);
|
|
124
127
|
|
|
128
|
+
// checkout cli
|
|
129
|
+
makeCheckoutCommand(program);
|
|
130
|
+
|
|
125
131
|
program.parse(process.argv);
|
|
126
132
|
!program.args.length && program.help();
|
|
127
133
|
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
<spz-render layout="container" manual id="navigate-render">
|
|
2
|
+
<template>
|
|
3
|
+
<div class="my-navigate-container">
|
|
4
|
+
<div
|
|
5
|
+
onclick="javascript:CheckoutAPI.step.stepNavToInformation()"
|
|
6
|
+
class="item ${data.currentStep === 'contact_information' ? 'active':''}"
|
|
7
|
+
>
|
|
8
|
+
第一页
|
|
9
|
+
</div>
|
|
10
|
+
<span>></span>
|
|
11
|
+
<div
|
|
12
|
+
onclick="javascript:CheckoutAPI.step.stepNavToShipping()"
|
|
13
|
+
class="item ${data.currentStep === 'shipping_method' ? 'active':''}"
|
|
14
|
+
>
|
|
15
|
+
<svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
|
|
16
|
+
<path
|
|
17
|
+
d="M4.1248 14.1998C5.33983 14.1998 6.3248 13.2148 6.3248 11.9998C6.3248 10.7848 5.33983 9.7998 4.1248 9.7998C2.90978 9.7998 1.9248 10.7848 1.9248 11.9998C1.9248 13.2148 2.90978 14.1998 4.1248 14.1998ZM12.0998 14.1998C13.3148 14.1998 14.2998 13.2148 14.2998 11.9998C14.2998 10.7848 13.3148 9.7998 12.0998 9.7998C10.8848 9.7998 9.8998 10.7848 9.8998 11.9998C9.8998 13.2148 10.8848 14.1998 12.0998 14.1998Z"
|
|
18
|
+
fill="currentColor"
|
|
19
|
+
></path>
|
|
20
|
+
<path
|
|
21
|
+
fill-rule="evenodd"
|
|
22
|
+
clip-rule="evenodd"
|
|
23
|
+
d="M0 11.2001V2.4001C0 1.95827 0.358172 1.6001 0.8 1.6001H7.00488C7.4467 1.6001 7.80488 1.95827 7.80488 2.4001V3.5751H7.8125V12.0001H7.18335C7.1861 11.9475 7.1875 11.8944 7.1875 11.8411C7.1875 10.1842 5.84435 8.84106 4.1875 8.84106C2.53065 8.84106 1.1875 10.1842 1.1875 11.8411C1.1875 11.8944 1.1889 11.9475 1.19165 12.0001H0.8C0.358172 12.0001 0 11.6419 0 11.2001ZM8.52496 12.0001H9.09168C9.08888 11.9475 9.08752 11.8944 9.08752 11.8411C9.08752 10.1842 10.4306 8.84106 12.0875 8.84106C13.7443 8.84106 15.0875 10.1842 15.0875 11.8411C15.0875 11.8944 15.0861 11.9475 15.0834 12.0001H15.2C15.6418 12.0001 16 11.6419 16 11.2001V8.11786C16 7.95962 15.953 7.80486 15.865 7.67326L13.3628 3.93047C13.2143 3.70841 12.9649 3.5751 12.6978 3.5751H8.52496V12.0001Z"
|
|
24
|
+
fill="currentColor"
|
|
25
|
+
></path>
|
|
26
|
+
</svg>
|
|
27
|
+
第二页
|
|
28
|
+
</div>
|
|
29
|
+
<span>></span>
|
|
30
|
+
<div
|
|
31
|
+
onclick="javascript:CheckoutAPI.step.stepNavToPayment()"
|
|
32
|
+
class="item ${data.currentStep === 'payment_method' ? 'active':''}"
|
|
33
|
+
>
|
|
34
|
+
第三页
|
|
35
|
+
</div>
|
|
36
|
+
</div>
|
|
37
|
+
</template>
|
|
38
|
+
</spz-render>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
<spz-script layout="logic" type="application/javascript">
|
|
4
|
+
(() => {
|
|
5
|
+
const render = () => {
|
|
6
|
+
const ele = document.getElementById('navigate-render');
|
|
7
|
+
console.log("ele:", ele);
|
|
8
|
+
if (ele) {
|
|
9
|
+
SPZ.whenApiDefined(ele).then((apis) => {
|
|
10
|
+
console.debug('apis:', apis);
|
|
11
|
+
apis.render(
|
|
12
|
+
{
|
|
13
|
+
currentStep: CheckoutAPI.step.getStep()
|
|
14
|
+
},
|
|
15
|
+
true
|
|
16
|
+
);
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
CheckoutAPI.step.onStepChange(() => {
|
|
22
|
+
render();
|
|
23
|
+
});
|
|
24
|
+
render();
|
|
25
|
+
})();
|
|
26
|
+
</spz-script>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<style>
|
|
2
|
+
.my-navigate-container {
|
|
3
|
+
display: flex;
|
|
4
|
+
margin-top: 20px;
|
|
5
|
+
}
|
|
6
|
+
.item:first-child {
|
|
7
|
+
margin-left: 0;
|
|
8
|
+
}
|
|
9
|
+
.item {
|
|
10
|
+
display: flex;
|
|
11
|
+
align-items: center;
|
|
12
|
+
margin: 0 10px;
|
|
13
|
+
cursor: pointer;
|
|
14
|
+
}
|
|
15
|
+
.item svg {
|
|
16
|
+
margin-right: 5px;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.item.active {
|
|
20
|
+
color: red;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
</style>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "checkout-extension",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"fs-extra": "11.1.1",
|
|
8
|
+
"@shoplazza/extension-ui": "2.0.8"
|
|
9
|
+
},
|
|
10
|
+
"devDependencies": {},
|
|
11
|
+
"scripts": {
|
|
12
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [],
|
|
15
|
+
"author": "",
|
|
16
|
+
"license": "ISC"
|
|
17
|
+
}
|
package/lib/app/constants.js
CHANGED
|
@@ -1,7 +1,24 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
const mode = 'prod';
|
|
2
|
+
let constans;
|
|
3
|
+
|
|
4
|
+
if (mode === 'dev') {
|
|
5
|
+
constans = {
|
|
6
|
+
PARNTER_URL: 'https://partners.dev.shoplazza.com',
|
|
7
|
+
LOGIN_BASE_URL: 'https://sso.dev.shoplazza.com',
|
|
8
|
+
CLIENT_ID: 'b630b285-e098-4c51-a7a4-d0240c9fc209'
|
|
9
|
+
};
|
|
10
|
+
} else if (mode === 'stg') {
|
|
11
|
+
constans = {
|
|
12
|
+
PARNTER_URL: 'https://partners.stg.shoplazza.com',
|
|
13
|
+
LOGIN_BASE_URL: 'https://sso.stg.shoplazza.com',
|
|
14
|
+
CLIENT_ID: 'b630b285-e098-4c51-a7a4-d0240c9fc209'
|
|
15
|
+
};
|
|
16
|
+
} else if (mode === 'prod') {
|
|
17
|
+
constans = {
|
|
18
|
+
PARNTER_URL: 'https://partners.shoplazza.com',
|
|
19
|
+
LOGIN_BASE_URL: 'https://sso.shoplazza.com',
|
|
20
|
+
CLIENT_ID: '807525c9-dd77-4f4e-a738-d1e9d02c593d'
|
|
21
|
+
};
|
|
22
|
+
}
|
|
6
23
|
|
|
7
24
|
module.exports = constans;
|
package/lib/app/login.js
CHANGED
|
@@ -6,7 +6,6 @@ const { fork } = require('child_process');
|
|
|
6
6
|
const path = require('path');
|
|
7
7
|
|
|
8
8
|
const { set, PARTNER_KEYS, get, empty } = require('./db/partner');
|
|
9
|
-
const { getClientId } = require('../utils');
|
|
10
9
|
const { PARNTER_URL, LOGIN_BASE_URL, CLIENT_ID } = require('./constants');
|
|
11
10
|
const { REDIRECT_URI } = require('../config');
|
|
12
11
|
const log = require('../log');
|
package/lib/auth/index.js
CHANGED
|
@@ -24,6 +24,7 @@ exports.postAccessToken = async (code, store) => {
|
|
|
24
24
|
}
|
|
25
25
|
);
|
|
26
26
|
empty();
|
|
27
|
+
|
|
27
28
|
set({
|
|
28
29
|
access_token: data.access_token,
|
|
29
30
|
session_id: data.session_id
|
|
@@ -66,6 +67,7 @@ exports.postExchangeToken = async (storeDomain, options = {}) => {
|
|
|
66
67
|
}
|
|
67
68
|
}
|
|
68
69
|
);
|
|
70
|
+
|
|
69
71
|
set({
|
|
70
72
|
store_domain: storeDomain.replace(/^https?:\/\//, ''),
|
|
71
73
|
exchange_token: data.access_token
|
|
@@ -90,3 +92,43 @@ exports.postExchangeToken = async (storeDomain, options = {}) => {
|
|
|
90
92
|
}
|
|
91
93
|
});
|
|
92
94
|
};
|
|
95
|
+
|
|
96
|
+
exports.postStoreToken = async (storeDomain, options = {}) => {
|
|
97
|
+
return new Promise(async (resolve, reject) => {
|
|
98
|
+
try {
|
|
99
|
+
const { data } = await axios.post(
|
|
100
|
+
`${getAccountUrl(storeDomain)}/api/accounts/store/session`,
|
|
101
|
+
{
|
|
102
|
+
user_id: get('user_id'),
|
|
103
|
+
domain: storeDomain
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
headers: {
|
|
107
|
+
Cookie: `awesomev2=${get('session_id')}`
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
set({
|
|
113
|
+
store_session: data.encode_session_id
|
|
114
|
+
});
|
|
115
|
+
resolve();
|
|
116
|
+
} catch (err) {
|
|
117
|
+
reject(err);
|
|
118
|
+
Sentry.captureException(err);
|
|
119
|
+
empty();
|
|
120
|
+
if (!options.ignoreLogError) {
|
|
121
|
+
if (err?.response?.status === 401) {
|
|
122
|
+
log.error(chalk.red(`\n✗ You are not authorized to edit themes on ${storeDomain}.`));
|
|
123
|
+
log.info(
|
|
124
|
+
chalk.green(
|
|
125
|
+
'Check if your user is activated, has permission to edit themes at the store, and try to re-login.'
|
|
126
|
+
)
|
|
127
|
+
);
|
|
128
|
+
} else {
|
|
129
|
+
log.error(chalk.red(`\n✗ ${storeDomain} is not a valid store.`));
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
};
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
const Axios = require('axios');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const FormData = require('form-data');
|
|
5
|
+
const loading = require('loading-cli');
|
|
6
|
+
const { openAipVersion } = require('./config');
|
|
7
|
+
const { isDebug } = require('./console');
|
|
8
|
+
const { getProjectConfig } = require('./util');
|
|
9
|
+
const chalk = require('chalk');
|
|
10
|
+
|
|
11
|
+
const FILE_SIGN_URL = '/checkout_extensions/file/sign';
|
|
12
|
+
const CREATE_URL = '/checkout_extensions/create';
|
|
13
|
+
const COMMIT_URL = '/checkout_extensions/commit';
|
|
14
|
+
const LIST_URL = '/checkout_extensions/list';
|
|
15
|
+
const VERSION_LIST_URL = '/checkout_extensions/version/list';
|
|
16
|
+
const DEPLOY_URL = '/checkout_extensions/deploy';
|
|
17
|
+
const UNDEPLOY_URL = '/checkout_extensions/undeploy';
|
|
18
|
+
const PREVIEW_URL = '/checkout_extensions/preview';
|
|
19
|
+
|
|
20
|
+
let configJson = undefined;
|
|
21
|
+
|
|
22
|
+
const request = new Axios.create();
|
|
23
|
+
|
|
24
|
+
request.interceptors.request.use((config) => {
|
|
25
|
+
if (config.data instanceof FormData) {
|
|
26
|
+
Object.assign(config.headers, config.data.getHeaders());
|
|
27
|
+
}
|
|
28
|
+
if (!configJson) {
|
|
29
|
+
configJson = getProjectConfig();
|
|
30
|
+
}
|
|
31
|
+
config.headers['Access-Token'] = configJson.token;
|
|
32
|
+
if (!config.url.startsWith('http')) {
|
|
33
|
+
config.url = path.join(configJson.store, openAipVersion, config.url);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (isDebug()) {
|
|
37
|
+
console.log(`\n==> ${config.method}: ${config.url}`);
|
|
38
|
+
}
|
|
39
|
+
return config;
|
|
40
|
+
});
|
|
41
|
+
|
|
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}`;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
request.interceptors.response.use(
|
|
51
|
+
(response) => {
|
|
52
|
+
if (isDebug()) {
|
|
53
|
+
console.log(`\n<== ${response.status}: ${response.config.url}`);
|
|
54
|
+
}
|
|
55
|
+
handleResponseError(response);
|
|
56
|
+
return response;
|
|
57
|
+
},
|
|
58
|
+
(error) => {
|
|
59
|
+
if (isDebug()) {
|
|
60
|
+
console.log(`\n<== error ${error.response.status}: ${error.response.config.url}`);
|
|
61
|
+
}
|
|
62
|
+
if (!error.response) {
|
|
63
|
+
throw chalk.red('Network error, please check your connection.');
|
|
64
|
+
}
|
|
65
|
+
if (error.response?.status == 403) {
|
|
66
|
+
return Promise.reject(new Error('Token permission failure'));
|
|
67
|
+
}
|
|
68
|
+
return Promise.reject(error);
|
|
69
|
+
}
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
async function upload(path, name) {
|
|
73
|
+
const form = new FormData();
|
|
74
|
+
await request(`${FILE_SIGN_URL}?key=${name}`)
|
|
75
|
+
.then((data) => {
|
|
76
|
+
return data.data;
|
|
77
|
+
})
|
|
78
|
+
.then((data) => {
|
|
79
|
+
const url = data.write_host;
|
|
80
|
+
form.append('policy', data.policy);
|
|
81
|
+
form.append('OSSAccessKeyId', data.access_id);
|
|
82
|
+
form.append('success_action_status', 200);
|
|
83
|
+
form.append('signature', data.sign);
|
|
84
|
+
form.append('x-oss-forbid-overwrite', 'true');
|
|
85
|
+
form.append('key', name);
|
|
86
|
+
form.append('file', fs.createReadStream(path));
|
|
87
|
+
return request.post(`https:${url}`, form, { headers: form.getHeaders() });
|
|
88
|
+
});
|
|
89
|
+
loading('succeed upload').succeed();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async function uploadDir(dirPath, files) {
|
|
93
|
+
await Promise.all(
|
|
94
|
+
files.map((file) => {
|
|
95
|
+
return upload(`${dirPath}/${file}`, `chick-extension/${file}`);
|
|
96
|
+
})
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
module.exports = {
|
|
101
|
+
upload,
|
|
102
|
+
uploadDir,
|
|
103
|
+
getExtensionList: async (params) => {
|
|
104
|
+
const load = loading('Fetch extension list').start();
|
|
105
|
+
try {
|
|
106
|
+
const res = await request(`${LIST_URL}`, {
|
|
107
|
+
params
|
|
108
|
+
});
|
|
109
|
+
load.succeed('Successfully fetched the extension list.');
|
|
110
|
+
return res;
|
|
111
|
+
} catch (error) {
|
|
112
|
+
load.fail('Failed to fetch the extension list.');
|
|
113
|
+
throw error;
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
getVersionList: async (params) => {
|
|
117
|
+
const load = loading('Fetch version list').start();
|
|
118
|
+
try {
|
|
119
|
+
const res = await request(`${VERSION_LIST_URL}`, {
|
|
120
|
+
params
|
|
121
|
+
});
|
|
122
|
+
load.succeed('Successfully fetched the version list.');
|
|
123
|
+
return res;
|
|
124
|
+
} catch (error) {
|
|
125
|
+
load.fail('Failed to fetch the version list.');
|
|
126
|
+
throw error;
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
pushExtension: async (data, isFirstPush = false) => {
|
|
130
|
+
data = {
|
|
131
|
+
extension: {
|
|
132
|
+
...data
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
const res = await request({ url: isFirstPush ? CREATE_URL : COMMIT_URL, method: 'POST', data });
|
|
136
|
+
if (res.data?.status === 3 && res.data?.message === 'INVALID_VERSION') {
|
|
137
|
+
throw 'During repeated pushes, the version number must be greater than the previous version number.';
|
|
138
|
+
}
|
|
139
|
+
return res;
|
|
140
|
+
},
|
|
141
|
+
deployExtension: async (data) => {
|
|
142
|
+
data = {
|
|
143
|
+
extension: {
|
|
144
|
+
...data
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
return request({ url: DEPLOY_URL, method: 'POST', data });
|
|
148
|
+
},
|
|
149
|
+
undeployExtension: async (data) => {
|
|
150
|
+
data = {
|
|
151
|
+
extension: {
|
|
152
|
+
...data
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
return request({ url: UNDEPLOY_URL, method: 'POST', data });
|
|
156
|
+
},
|
|
157
|
+
previewExtension: async (data) => {
|
|
158
|
+
data = {
|
|
159
|
+
extension: {
|
|
160
|
+
...data
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
const res = await request({ url: PREVIEW_URL, method: 'POST', data });
|
|
164
|
+
if (res.data?.status === 14 && res.data?.message === 'ITEM_UNAVAILABLE') {
|
|
165
|
+
throw 'Failed to generate a preview URL because your store currently has no available items.';
|
|
166
|
+
}
|
|
167
|
+
return res;
|
|
168
|
+
}
|
|
169
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const parseExtension = (str, name) => {
|
|
2
|
+
const data = str.split(/(?:import\s*(?:.*?)\s*from\s*(?:.*?)\s*;)/g);
|
|
3
|
+
const main = data[data.length - 1];
|
|
4
|
+
const id = JSON.stringify(name);
|
|
5
|
+
const importString = str.match(/(?:import\s*(?:.*?)\s*from\s*(?:.*?)\s*;)/g)?.join(' ') || '';
|
|
6
|
+
return `${importString}(function(){const __EXTENSION_ID__=${id};${main}})()`;
|
|
7
|
+
};
|
|
8
|
+
module.exports = {
|
|
9
|
+
vitePluginAddExtensionId: function () {
|
|
10
|
+
return {
|
|
11
|
+
name: 'vitePluginAddExtensionId',
|
|
12
|
+
enforce: 'pre',
|
|
13
|
+
apply: 'build',
|
|
14
|
+
transform: (code, _id) => {
|
|
15
|
+
if (/.*\/extensions\/.*\/src\/index\.js/.test(_id)) {
|
|
16
|
+
return parseExtension(code, _id.match(/extensions\/(\S*)\/src\/index\./)[1]);
|
|
17
|
+
}
|
|
18
|
+
return code;
|
|
19
|
+
},
|
|
20
|
+
buildEnd: () => {
|
|
21
|
+
console.log('end');
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
};
|