shoplazza-cli 0.0.4 → 0.0.6
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 +118 -27
- package/bin/shoplazza +19 -1
- package/lib/app/commands/build.js +66 -0
- package/lib/app/commands/deploy.js +213 -0
- package/lib/app/commands/generate.js +50 -0
- package/lib/app/commands/publish.js +52 -0
- package/lib/app/constants.js +7 -0
- package/lib/app/db/partner.js +91 -0
- package/lib/app/extensions/index.js +13 -0
- package/lib/app/extensions/theme-app.js +103 -0
- package/lib/app/index.js +37 -0
- package/lib/app/inquirers/choose-app.js +79 -0
- package/lib/app/inquirers/choose-partner.js +74 -0
- package/lib/app/inquirers/version.js +131 -0
- package/lib/app/log.js +15 -0
- package/lib/app/login.js +126 -0
- package/lib/app/logout.js +16 -0
- package/lib/auth/getCode.js +10 -6
- package/lib/auth/index.js +8 -7
- package/lib/commands/login.js +19 -7
- package/lib/commands/logout.js +14 -5
- package/lib/commands/switch.js +1 -1
- package/lib/config.js +3 -0
- package/lib/utils.js +14 -0
- package/package.json +12 -13
- package/LICENSE +0 -21
package/lib/auth/getCode.js
CHANGED
|
@@ -3,18 +3,21 @@ const { fork } = require('child_process');
|
|
|
3
3
|
const path = require('path');
|
|
4
4
|
const open = require('open');
|
|
5
5
|
const log = require('../log');
|
|
6
|
-
const {
|
|
6
|
+
const { REDIRECT_URI } = require('../config');
|
|
7
|
+
const { getSSOAuthUrl, getClientId } = require('../utils');
|
|
7
8
|
|
|
8
|
-
const openSSOPage = () => {
|
|
9
|
+
const openSSOPage = (store) => {
|
|
9
10
|
open(
|
|
10
|
-
`${
|
|
11
|
-
`${
|
|
11
|
+
`${getSSOAuthUrl(store)}/switch_account?lack=0&continue=${encodeURIComponent(
|
|
12
|
+
`${getSSOAuthUrl(store)}/api/oauth/authorize?action=login&client_id=${getClientId(
|
|
13
|
+
store
|
|
14
|
+
)}&redirect_uri=${REDIRECT_URI}&response_type=code`
|
|
12
15
|
)}`
|
|
13
16
|
);
|
|
14
17
|
log.info(`${chalk.green('✓')} Initiating authentication`);
|
|
15
18
|
};
|
|
16
19
|
|
|
17
|
-
const getCode = () => {
|
|
20
|
+
const getCode = (store) => {
|
|
18
21
|
return new Promise((resolve, reject) => {
|
|
19
22
|
const child = fork(path.join(__dirname, './child.js'), { timeout: 60 * 1000 });
|
|
20
23
|
child.on('message', function (message) {
|
|
@@ -26,9 +29,10 @@ const getCode = () => {
|
|
|
26
29
|
// Timeout
|
|
27
30
|
if (message === null) {
|
|
28
31
|
log.error(chalk.red('✗ Timed out while waiting for response from Shoplazza'));
|
|
32
|
+
reject('timeout');
|
|
29
33
|
}
|
|
30
34
|
});
|
|
31
|
-
openSSOPage();
|
|
35
|
+
openSSOPage(store);
|
|
32
36
|
});
|
|
33
37
|
};
|
|
34
38
|
|
package/lib/auth/index.js
CHANGED
|
@@ -4,14 +4,15 @@ const Sentry = require('@sentry/node');
|
|
|
4
4
|
const querystring = require('querystring');
|
|
5
5
|
const { get, set, empty } = require('../db/user');
|
|
6
6
|
const log = require('../log');
|
|
7
|
-
const {
|
|
7
|
+
const { REDIRECT_URI } = require('../config');
|
|
8
|
+
const { getAccountUrl, getClientId, getSSOAuthUrl } = require('../utils');
|
|
8
9
|
|
|
9
|
-
exports.postAccessToken = async (code) => {
|
|
10
|
+
exports.postAccessToken = async (code, store) => {
|
|
10
11
|
try {
|
|
11
12
|
const { data } = await axios.post(
|
|
12
|
-
`${
|
|
13
|
+
`${getSSOAuthUrl(store)}/api/oauth/token`,
|
|
13
14
|
querystring.stringify({
|
|
14
|
-
client_id:
|
|
15
|
+
client_id: getClientId(store),
|
|
15
16
|
code,
|
|
16
17
|
grant_type: 'authorization_code',
|
|
17
18
|
redirect_uri: REDIRECT_URI
|
|
@@ -33,9 +34,9 @@ exports.postAccessToken = async (code) => {
|
|
|
33
34
|
}
|
|
34
35
|
};
|
|
35
36
|
|
|
36
|
-
exports.getUserInfo = async () => {
|
|
37
|
+
exports.getUserInfo = async (store) => {
|
|
37
38
|
try {
|
|
38
|
-
const { data } = await axios.get(`${
|
|
39
|
+
const { data } = await axios.get(`${getSSOAuthUrl(store)}/api/sso/current/users`, {
|
|
39
40
|
headers: {
|
|
40
41
|
Cookie: `awesomev2=${get('session_id')}`
|
|
41
42
|
}
|
|
@@ -54,7 +55,7 @@ exports.postExchangeToken = async (storeDomain, options = {}) => {
|
|
|
54
55
|
return new Promise(async (resolve, reject) => {
|
|
55
56
|
try {
|
|
56
57
|
const { data } = await axios.post(
|
|
57
|
-
`${
|
|
58
|
+
`${getAccountUrl(storeDomain)}/api/accounts/store/token`,
|
|
58
59
|
{
|
|
59
60
|
user_id: get('user_id'),
|
|
60
61
|
domain: storeDomain
|
package/lib/commands/login.js
CHANGED
|
@@ -8,6 +8,8 @@ const log = require('../log');
|
|
|
8
8
|
const { getShopDetail } = require('../openAPI/api');
|
|
9
9
|
const getCode = require('../auth/getCode');
|
|
10
10
|
const { postAccessToken, getUserInfo, postExchangeToken } = require('../auth');
|
|
11
|
+
const { loginIntoPartner } = require('../app/login');
|
|
12
|
+
|
|
11
13
|
let spinner;
|
|
12
14
|
|
|
13
15
|
const checkAndLogin = async (store) => {
|
|
@@ -31,10 +33,11 @@ const checkAndLogin = async (store) => {
|
|
|
31
33
|
}
|
|
32
34
|
}
|
|
33
35
|
|
|
34
|
-
const code = await getCode();
|
|
36
|
+
const code = await getCode(store);
|
|
35
37
|
spinner = ora(`Logging in to ${chalk.green(store)}`).start();
|
|
36
|
-
|
|
37
|
-
await
|
|
38
|
+
log.info(`${chalk.green('✓')} Initiating authentication`);
|
|
39
|
+
await postAcxcessToken(code, store);
|
|
40
|
+
await getUserInfo(store);
|
|
38
41
|
await postExchangeToken(store);
|
|
39
42
|
spinner?.stop?.();
|
|
40
43
|
log.info(`${chalk.green('✓')} Finalizing authentication`);
|
|
@@ -64,10 +67,10 @@ const requestAnalyticsIfNeeded = async () => {
|
|
|
64
67
|
}
|
|
65
68
|
};
|
|
66
69
|
|
|
67
|
-
|
|
70
|
+
const loginIntoStore = async (store) => {
|
|
68
71
|
try {
|
|
69
|
-
if (
|
|
70
|
-
await checkAndLogin(
|
|
72
|
+
if (store) {
|
|
73
|
+
await checkAndLogin(store);
|
|
71
74
|
} else {
|
|
72
75
|
const answers = await inquirer.prompt([
|
|
73
76
|
{
|
|
@@ -77,7 +80,7 @@ exports.login = async (options) => {
|
|
|
77
80
|
}
|
|
78
81
|
]);
|
|
79
82
|
if (answers.store) {
|
|
80
|
-
if (
|
|
83
|
+
if (!answers.store.includes('myshoplaza.com') || !answers.store.includes('myshoplaza.com')) {
|
|
81
84
|
log.error(
|
|
82
85
|
chalk.red(
|
|
83
86
|
`✗ Invalid store provided ${answers.store}. Please provide the store in the following format: developer.myshoplaza.com`
|
|
@@ -97,3 +100,12 @@ exports.login = async (options) => {
|
|
|
97
100
|
Sentry.captureException(error);
|
|
98
101
|
}
|
|
99
102
|
};
|
|
103
|
+
|
|
104
|
+
exports.login = async (options) => {
|
|
105
|
+
if (options.partner) {
|
|
106
|
+
await loginIntoPartner();
|
|
107
|
+
return;
|
|
108
|
+
} else {
|
|
109
|
+
await loginIntoStore(options.store);
|
|
110
|
+
}
|
|
111
|
+
};
|
package/lib/commands/logout.js
CHANGED
|
@@ -1,14 +1,23 @@
|
|
|
1
1
|
const Sentry = require('@sentry/node');
|
|
2
2
|
const chalk = require('chalk');
|
|
3
|
-
const { empty } = require('../db/user');
|
|
3
|
+
const { empty: emptyUser } = require('../db/user');
|
|
4
|
+
const { logoutPartner } = require('../app/logout');
|
|
4
5
|
const log = require('../log');
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
const logoutStore = () => {
|
|
7
8
|
try {
|
|
8
|
-
|
|
9
|
-
log.info('Successfully logged out of your account');
|
|
9
|
+
emptyUser();
|
|
10
|
+
log.info('Successfully logged out of your store account');
|
|
10
11
|
} catch (error) {
|
|
11
|
-
log.error(chalk.red(`✗ Failed to logout`));
|
|
12
|
+
log.error(chalk.red(`✗ Failed to logout your store account`));
|
|
12
13
|
Sentry.captureException(error);
|
|
13
14
|
}
|
|
14
15
|
};
|
|
16
|
+
|
|
17
|
+
module.exports = (options) => {
|
|
18
|
+
if (options.partner) {
|
|
19
|
+
logoutPartner();
|
|
20
|
+
} else {
|
|
21
|
+
logoutStore();
|
|
22
|
+
}
|
|
23
|
+
};
|
package/lib/commands/switch.js
CHANGED
|
@@ -32,7 +32,7 @@ module.exports = async (options) => {
|
|
|
32
32
|
}
|
|
33
33
|
]);
|
|
34
34
|
if (answers.store) {
|
|
35
|
-
if (
|
|
35
|
+
if (!answers.store.includes('myshoplaza.com')) {
|
|
36
36
|
log.error(
|
|
37
37
|
chalk.red(
|
|
38
38
|
`✗ Invalid store provided ${answers.store}. Please provide the store in the following format: developer.myshoplaza.com`
|
package/lib/config.js
CHANGED
|
@@ -3,3 +3,6 @@ exports.ACCOUNT_URL = 'https://myaccount.shoplazza.com';
|
|
|
3
3
|
exports.CLIENT_ID = '807525c9-dd77-4f4e-a738-d1e9d02c593d';
|
|
4
4
|
exports.REDIRECT_URI = 'http://127.0.0.1:3456';
|
|
5
5
|
exports.THEME_DIRS = ['assets', 'config', 'layout', 'locales', 'sections', 'snippets', 'templates'];
|
|
6
|
+
exports.DEV_SSO_AUTH_URL = 'https://sso.dev.shoplazza.com';
|
|
7
|
+
exports.DEV_ACCOUNT_URL = 'https://myaccount.dev.shoplazza.com';
|
|
8
|
+
exports.DEV_CLIENT_ID = 'b630b285-e098-4c51-a7a4-d0240c9fc209';
|
package/lib/utils.js
CHANGED
|
@@ -3,6 +3,8 @@ const fs = require('fs-extra');
|
|
|
3
3
|
const AdmZip = require('adm-zip');
|
|
4
4
|
const chalk = require('chalk');
|
|
5
5
|
|
|
6
|
+
const { SSO_AUTH_URL, ACCOUNT_URL, CLIENT_ID, DEV_SSO_AUTH_URL, DEV_ACCOUNT_URL, DEV_CLIENT_ID } = require('./config');
|
|
7
|
+
|
|
6
8
|
exports.unzipTheme = (zipPath, outputPath) => {
|
|
7
9
|
const zip = new AdmZip(zipPath);
|
|
8
10
|
const zipEntries = zip.getEntries();
|
|
@@ -45,3 +47,15 @@ exports.formatThemeList = (themes, defaultThemeId) => {
|
|
|
45
47
|
};
|
|
46
48
|
|
|
47
49
|
exports.sleep = (time) => new Promise((resolve) => setTimeout(resolve, time));
|
|
50
|
+
|
|
51
|
+
exports.getClientId = (store) => {
|
|
52
|
+
return store.includes('dev.') ? DEV_CLIENT_ID : CLIENT_ID;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
exports.getAccountUrl = (store) => {
|
|
56
|
+
return store.includes('dev.myshoplaza.com') ? DEV_ACCOUNT_URL : ACCOUNT_URL;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
exports.getSSOAuthUrl = (store) => {
|
|
60
|
+
return store.includes('dev.myshoplaza.com') ? DEV_SSO_AUTH_URL : SSO_AUTH_URL;
|
|
61
|
+
};
|
package/package.json
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "shoplazza-cli",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"description": "Shoplazza CLI is a command-line interface tool that helps you build Shoplazza themes. It quickly generates Shoplazza themes. You can also use it to automate many common development tasks.",
|
|
3
|
+
"version": "0.0.6",
|
|
4
|
+
"description": "",
|
|
6
5
|
"main": "bin/shoplazza",
|
|
7
6
|
"engines": {
|
|
8
7
|
"node": ">=14.14.0"
|
|
@@ -14,19 +13,13 @@
|
|
|
14
13
|
"prettier": "prettier --write ./lib",
|
|
15
14
|
"test": "jest --runInBand --forceExit"
|
|
16
15
|
},
|
|
17
|
-
"homepage": "https://github.com/Shoplazza/shoplazza-cli",
|
|
18
16
|
"repository": {
|
|
19
17
|
"type": "git",
|
|
20
|
-
"url": "
|
|
18
|
+
"url": "git@gitlab.shoplazza.site:shoplaza/frontend/openapi/shoplazza-cli.git"
|
|
21
19
|
},
|
|
22
|
-
"keywords": [
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
"developer",
|
|
26
|
-
"theme"
|
|
27
|
-
],
|
|
28
|
-
"author": "Shoplazza",
|
|
29
|
-
"license": "MIT",
|
|
20
|
+
"keywords": [],
|
|
21
|
+
"author": "",
|
|
22
|
+
"license": "ISC",
|
|
30
23
|
"devDependencies": {
|
|
31
24
|
"axios-mock-adapter": "^1.20.0",
|
|
32
25
|
"jest": "^28.1.0",
|
|
@@ -36,18 +29,24 @@
|
|
|
36
29
|
"@sentry/node": "^6.19.7",
|
|
37
30
|
"@sentry/tracing": "^6.19.7",
|
|
38
31
|
"adm-zip": "^0.5.9",
|
|
32
|
+
"archiver": "^5.3.1",
|
|
39
33
|
"axios": "^0.27.1",
|
|
40
34
|
"better-sqlite3": "^7.5.1",
|
|
41
35
|
"chalk": "^4.1.2",
|
|
36
|
+
"clean-css": "^5.3.1",
|
|
42
37
|
"commander": "^9.2.0",
|
|
38
|
+
"download-git-repo": "^3.0.2",
|
|
43
39
|
"execa": "^5.1.1",
|
|
44
40
|
"form-data": "^4.0.0",
|
|
45
41
|
"fs-extra": "^10.1.0",
|
|
42
|
+
"glob": "^8.0.3",
|
|
46
43
|
"inquirer": "^8.2.3",
|
|
47
44
|
"livereload": "^0.9.3",
|
|
48
45
|
"node-watch": "^0.7.3",
|
|
49
46
|
"open": "^8.4.0",
|
|
50
47
|
"ora": "^5.4.1",
|
|
48
|
+
"spark-md5": "^3.0.2",
|
|
49
|
+
"uglify-js": "^3.17.4",
|
|
51
50
|
"update-notifier": "^5.1.0",
|
|
52
51
|
"yargs": "^17.5.0"
|
|
53
52
|
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2022 Shoplazza Opensource
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|