shoplazza-cli 0.0.10 → 0.1.8

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.
Files changed (61) hide show
  1. package/README.md +2 -6
  2. package/bin/shoplazza +6 -0
  3. package/examples/checkout-extension/README.md +19 -0
  4. package/examples/checkout-extension/extension.config.js +4 -0
  5. package/examples/checkout-extension/extensions/add-shipping-desc/extension.json +10 -0
  6. package/examples/checkout-extension/extensions/add-shipping-desc/src/index.js +7 -0
  7. package/examples/checkout-extension/extensions/ext-1/extension.json +10 -0
  8. package/examples/checkout-extension/extensions/ext-1/src/content.html +3 -0
  9. package/examples/checkout-extension/extensions/ext-1/src/index.html +5 -0
  10. package/examples/checkout-extension/extensions/ext-1/src/index.js +11 -0
  11. package/examples/checkout-extension/extensions/ext-1/src/script.html +3 -0
  12. package/examples/checkout-extension/extensions/ext-1/src/style.html +3 -0
  13. package/examples/checkout-extension/extensions/rewrite-navigate/extension.json +10 -0
  14. package/examples/checkout-extension/extensions/rewrite-navigate/src/content.html +38 -0
  15. package/examples/checkout-extension/extensions/rewrite-navigate/src/index.html +5 -0
  16. package/examples/checkout-extension/extensions/rewrite-navigate/src/index.js +12 -0
  17. package/examples/checkout-extension/extensions/rewrite-navigate/src/script.html +26 -0
  18. package/examples/checkout-extension/extensions/rewrite-navigate/src/style.html +23 -0
  19. package/examples/checkout-extension/package.json +17 -0
  20. package/lib/app/commands/deploy.js +0 -1
  21. package/lib/app/constants.js +22 -5
  22. package/lib/app/login.js +0 -1
  23. package/lib/auth/index.js +42 -0
  24. package/lib/checkout/api.js +156 -0
  25. package/lib/checkout/build/plugin/vite-plugin-add-extension-id.js +25 -0
  26. package/lib/checkout/build/plugin/vite-plugin-transform-extension-html.js +207 -0
  27. package/lib/checkout/build/vite.config.js +34 -0
  28. package/lib/checkout/build.js +39 -0
  29. package/lib/checkout/config.js +97 -0
  30. package/lib/checkout/console.js +32 -0
  31. package/lib/checkout/create.js +132 -0
  32. package/lib/checkout/delete.js +26 -0
  33. package/lib/checkout/deploy.js +59 -0
  34. package/lib/checkout/dev/client.js +73 -0
  35. package/lib/checkout/dev/index.js +142 -0
  36. package/lib/checkout/fields.js +29 -0
  37. package/lib/checkout/index.js +63 -0
  38. package/lib/checkout/preview.js +52 -0
  39. package/lib/checkout/pull.js +10 -0
  40. package/lib/checkout/push.js +140 -0
  41. package/lib/checkout/template/README.md +34 -0
  42. package/lib/checkout/template/_gitignore +4 -0
  43. package/lib/checkout/template/extension.config.js +4 -0
  44. package/lib/checkout/template/extensions/extension-template/extension.json +10 -0
  45. package/lib/checkout/template/extensions/extension-template/src/content.html +3 -0
  46. package/lib/checkout/template/extensions/extension-template/src/index.html +5 -0
  47. package/lib/checkout/template/extensions/extension-template/src/index.js +11 -0
  48. package/lib/checkout/template/extensions/extension-template/src/script.html +3 -0
  49. package/lib/checkout/template/extensions/extension-template/src/style.html +3 -0
  50. package/lib/checkout/template/package.json +17 -0
  51. package/lib/checkout/undeploy.js +40 -0
  52. package/lib/checkout/util.js +204 -0
  53. package/lib/checkout/verify.js +16 -0
  54. package/lib/checkout/version.js +7 -0
  55. package/lib/commands/login.js +3 -2
  56. package/lib/commands/theme/init.js +2 -2
  57. package/lib/commands/theme/pull.js +1 -1
  58. package/lib/config.js +4 -0
  59. package/lib/db/user.js +5 -2
  60. package/lib/utils.js +36 -4
  61. package/package.json +29 -3
package/README.md CHANGED
@@ -10,17 +10,13 @@
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 LifeStyle as a starting point.
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.
@@ -36,7 +32,7 @@ $ npm install shoplazza-cli -g
36
32
 
37
33
  Before you start using Shoplazza CLI to develop themes, make sure that you do the following tasks:
38
34
 
39
- - Install [Node.js](https://nodejs.org/en/) (14.14.0 or higher).
35
+ - Install [Node.js](https://nodejs.org/en/) (20.18.0).
40
36
  - Install [Git](https://git-scm.com/downloads).
41
37
  - 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
38
  - Note the URL of the store that you want to work on.
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,19 @@
1
+ # Chick Extension
2
+
3
+ ## Getting started
4
+
5
+
6
+ ## init git
7
+
8
+ ```
9
+ cd `projectDir`
10
+ git init
11
+ ```
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
@@ -0,0 +1,4 @@
1
+ module.exports = {
2
+ token: 'aadasd',
3
+ store: 'https://perry.stg.myshoplaza.com'
4
+ };
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": "1.0",
3
+ "deleteTarget": [],
4
+ "placeholder": {},
5
+ "templateName": "checkout",
6
+ "themeName": "",
7
+ "extensionId": "",
8
+ "extensionName": "add-shipping-desc",
9
+ "extensionDescription": ""
10
+ }
@@ -0,0 +1,7 @@
1
+ import { extend } from "@shoplazza/extension-ui";
2
+
3
+ extend({
4
+ extensionPoint: "Checkout::ShippingLinesTitle::RenderAfter",
5
+ component: `<p class="mb-4">所有物流方式均受到保护。</p>`,
6
+ });
7
+
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": "1.0",
3
+ "deleteTarget": [],
4
+ "placeholder": {},
5
+ "templateName": "checkout",
6
+ "themeName": "",
7
+ "extensionId": "",
8
+ "extensionName": "ext-1",
9
+ "extensionDescription": ""
10
+ }
@@ -0,0 +1,3 @@
1
+ <div>
2
+ <h2>hello world</h2>
3
+ </div>
@@ -0,0 +1,5 @@
1
+ <div>
2
+ import './style.html'
3
+ import './content.html'
4
+ import './script.html'
5
+ </div>
@@ -0,0 +1,11 @@
1
+ import { extend } from '@shoplazza/extension-ui';
2
+ import index from './index.html';
3
+
4
+ function App() {
5
+ return index;
6
+ }
7
+
8
+ extend({
9
+ extensionPoint: 'Checkout::Navigate::RenderBefore',
10
+ component: App()
11
+ });
@@ -0,0 +1,3 @@
1
+ <ljs-script layout="logic" type="application/javascript">
2
+ <!-- js代码 -->
3
+ </ljs-script>
@@ -0,0 +1,3 @@
1
+ <style>
2
+
3
+ </style>
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": "1.0",
3
+ "deleteTarget": ["navigate"],
4
+ "placeholder": {},
5
+ "templateName": "checkout",
6
+ "themeName": "",
7
+ "extensionId": "",
8
+ "extensionName": "rewrite-navigate",
9
+ "extensionDescription": ""
10
+ }
@@ -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,5 @@
1
+ <div>
2
+ import './style.html'
3
+ import './content.html'
4
+ import './script.html'
5
+ </div>
@@ -0,0 +1,12 @@
1
+ import { extend } from '@shoplazza/extension-ui';
2
+ import index from './index.html';
3
+
4
+ function App() {
5
+ return index;
6
+ }
7
+
8
+ extend({
9
+ extensionPoint: 'Checkout::Navigate::RenderBefore',
10
+ component: App()
11
+ });
12
+
@@ -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
+ }
@@ -129,7 +129,6 @@ const deployOss = async () => {
129
129
  spinner.succeed();
130
130
  return md5;
131
131
  }
132
-
133
132
  spinner.fail();
134
133
  console.log(chalk.red(e.message || e));
135
134
  }
@@ -1,7 +1,24 @@
1
- const constans = {
2
- PARNTER_URL: 'https://partners.shoplazza.com',
3
- LOGIN_BASE_URL: 'https://sso.shoplazza.com',
4
- CLIENT_ID: '807525c9-dd77-4f4e-a738-d1e9d02c593d'
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,156 @@
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
+ request.interceptors.response.use(
43
+ (response) => {
44
+ if (isDebug()) {
45
+ console.log(`\n<== ${response.status}: ${response.config.url}`);
46
+ }
47
+ return response;
48
+ },
49
+ (error) => {
50
+ if (isDebug()) {
51
+ console.log(`\n<== error ${error.response.status}: ${error.response.config.url}`);
52
+ }
53
+ if (!error.response) {
54
+ throw chalk.red('Network error, please check your connection.');
55
+ }
56
+ if (error.response?.status == 403) {
57
+ return Promise.reject(new Error('Token permission failure'));
58
+ }
59
+ return Promise.reject(error);
60
+ }
61
+ );
62
+
63
+ async function upload(path, name) {
64
+ const form = new FormData();
65
+ await request(`${FILE_SIGN_URL}?key=${name}`)
66
+ .then((data) => {
67
+ return data.data;
68
+ })
69
+ .then((data) => {
70
+ const url = data.write_host;
71
+ form.append('policy', data.policy);
72
+ form.append('OSSAccessKeyId', data.access_id);
73
+ form.append('success_action_status', 200);
74
+ form.append('signature', data.sign);
75
+ form.append('x-oss-forbid-overwrite', 'true');
76
+ form.append('key', name);
77
+ form.append('file', fs.createReadStream(path));
78
+ return request.post(`https:${url}`, form, { headers: form.getHeaders() });
79
+ });
80
+ loading('succeed upload').succeed();
81
+ }
82
+
83
+ async function uploadDir(dirPath, files) {
84
+ await Promise.all(
85
+ files.map((file) => {
86
+ return upload(`${dirPath}/${file}`, `chick-extension/${file}`);
87
+ })
88
+ );
89
+ }
90
+
91
+ module.exports = {
92
+ upload,
93
+ uploadDir,
94
+ getExtensionList: async (params) => {
95
+ const load = loading('Fetch extension list').start();
96
+ try {
97
+ const res = await request(`${LIST_URL}`, {
98
+ params
99
+ });
100
+ load.succeed('Successfully fetched the extension list.');
101
+ return res;
102
+ } catch (error) {
103
+ load.fail('Failed to fetch the extension list.');
104
+ throw error;
105
+ }
106
+ },
107
+ getVersionList: async (params) => {
108
+ const load = loading('Fetch version list').start();
109
+ try {
110
+ const res = await request(`${VERSION_LIST_URL}`, {
111
+ params
112
+ });
113
+ load.succeed('Successfully fetched the version list.');
114
+ return res;
115
+ } catch (error) {
116
+ load.fail('Failed to fetch the version list.');
117
+ throw error;
118
+ }
119
+ },
120
+ pushExtension: async (data, isFirstPush = false) => {
121
+ data = {
122
+ extension: {
123
+ ...data
124
+ }
125
+ };
126
+ const res = await request({ url: isFirstPush ? CREATE_URL : COMMIT_URL, method: 'POST', data });
127
+ if (res.data?.status === 3 && res.data?.message === 'INVALID_VERSION') {
128
+ throw 'During repeated pushes, the version number must be greater than the previous version number.';
129
+ }
130
+ return res;
131
+ },
132
+ deployExtension: async (data) => {
133
+ data = {
134
+ extension: {
135
+ ...data
136
+ }
137
+ };
138
+ return request({ url: DEPLOY_URL, method: 'POST', data });
139
+ },
140
+ undeployExtension: async (data) => {
141
+ data = {
142
+ extension: {
143
+ ...data
144
+ }
145
+ };
146
+ return request({ url: UNDEPLOY_URL, method: 'POST', data });
147
+ },
148
+ previewExtension: async (data) => {
149
+ data = {
150
+ extension: {
151
+ ...data
152
+ }
153
+ };
154
+ return request({ url: PREVIEW_URL, method: 'POST', data });
155
+ }
156
+ };
@@ -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
+ };