@shoper/cli 0.1.0-22 → 0.1.0-23
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.
|
@@ -8,11 +8,12 @@ import { THEME_ACTION_NOT_FOUND_ERROR_CODE, THEME_ACTIONS_API_NAME, THEME_ACTION
|
|
|
8
8
|
import { renderOnce } from '../../../ui/ui_utils.js';
|
|
9
9
|
import { ThemeDirectoryContextError } from '../ui/theme_directory_context_error.js';
|
|
10
10
|
import React from 'react';
|
|
11
|
-
import { MissingThemeIdError } from '../ui/missing_theme_id_error.js';
|
|
12
11
|
import { UnpermittedCommandError } from '../ui/unpermitted_command_error.js';
|
|
13
12
|
import { MissingCredentialsError } from '../../../cli/commands/auth/ui/missing_credentials_error.js';
|
|
14
13
|
import { ThemeCreatedSuccess } from './ui/theme_created_success.js';
|
|
15
14
|
import { Text } from '../../../ui/text.js';
|
|
15
|
+
import { Error } from '../../../ui/message_box/error.js';
|
|
16
|
+
import { MissingThemeIdError } from '../ui/missing_theme_id_error.js';
|
|
16
17
|
import { Box } from '../../../ui/box.js';
|
|
17
18
|
export class ThemeInitCommand extends BaseThemeCommand {
|
|
18
19
|
static summary = 'Creates a copy of an existing theme by duplicating it.';
|
|
@@ -35,13 +36,6 @@ export class ThemeInitCommand extends BaseThemeCommand {
|
|
|
35
36
|
const data = await this.parse(ThemeInitCommand);
|
|
36
37
|
const { args } = data;
|
|
37
38
|
const themeId = args.id;
|
|
38
|
-
if (!themeId) {
|
|
39
|
-
renderOnce(React.createElement(MissingThemeIdError, null,
|
|
40
|
-
React.createElement(Box, { flexDirection: "column", gap: 1 },
|
|
41
|
-
React.createElement(Text, null, "Usage: shoper theme init [ID]"),
|
|
42
|
-
React.createElement(Text, null, "This command creates a copy of an existing theme based on its ID.To proceed, you must provide the ID of the theme you want to duplicate."))));
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
39
|
const cliAuthApi = this.getApi(CLI_AUTH_API_NAME);
|
|
46
40
|
const themeInitApi = this.getApi(THEME_INIT_API_NAME);
|
|
47
41
|
const themeActionsApi = this.getApi(THEME_ACTIONS_API_NAME);
|
|
@@ -51,6 +45,15 @@ export class ThemeInitCommand extends BaseThemeCommand {
|
|
|
51
45
|
renderOnce(React.createElement(MissingCredentialsError, null));
|
|
52
46
|
return;
|
|
53
47
|
}
|
|
48
|
+
const executionContext = await executionContextApi.getExecutionContext();
|
|
49
|
+
if (executionContext.type === EXECUTION_CONTEXTS.theme) {
|
|
50
|
+
renderOnce(React.createElement(ThemeDirectoryContextError, null));
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (!themeId) {
|
|
54
|
+
this._renderMissingThemeIdError();
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
54
57
|
let spinner;
|
|
55
58
|
try {
|
|
56
59
|
const copyAction = themeActionsApi.getThemeAction({
|
|
@@ -62,11 +65,6 @@ export class ThemeInitCommand extends BaseThemeCommand {
|
|
|
62
65
|
renderOnce(React.createElement(UnpermittedCommandError, { themeId: themeId, commandName: "init" }));
|
|
63
66
|
return;
|
|
64
67
|
}
|
|
65
|
-
const executionContext = await executionContextApi.getExecutionContext();
|
|
66
|
-
if (executionContext.type === EXECUTION_CONTEXTS.theme) {
|
|
67
|
-
renderOnce(React.createElement(ThemeDirectoryContextError, null));
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
68
|
spinner = ora('Creating theme...').start();
|
|
71
69
|
const { themeId: createdThemeId, themeName } = await themeInitApi.initTheme({ action: copyAction, credentials });
|
|
72
70
|
spinner.stop();
|
|
@@ -74,9 +72,24 @@ export class ThemeInitCommand extends BaseThemeCommand {
|
|
|
74
72
|
}
|
|
75
73
|
catch (err) {
|
|
76
74
|
spinner?.stop();
|
|
77
|
-
|
|
78
|
-
renderOnce(React.createElement(UnpermittedCommandError, { themeId: themeId, commandName: "init" }));
|
|
79
|
-
}
|
|
75
|
+
this._handleError(err, themeId);
|
|
80
76
|
}
|
|
81
77
|
}
|
|
78
|
+
_handleError(err, themeId) {
|
|
79
|
+
if (err?.code === THEME_ACTION_NOT_FOUND_ERROR_CODE && themeId) {
|
|
80
|
+
renderOnce(React.createElement(UnpermittedCommandError, { themeId: themeId, commandName: "init" }));
|
|
81
|
+
}
|
|
82
|
+
if (err?.message) {
|
|
83
|
+
renderOnce(React.createElement(Error, null,
|
|
84
|
+
React.createElement(Text, null, err.message)));
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
this.error(String(err));
|
|
88
|
+
}
|
|
89
|
+
_renderMissingThemeIdError() {
|
|
90
|
+
renderOnce(React.createElement(MissingThemeIdError, null,
|
|
91
|
+
React.createElement(Box, { flexDirection: "column", gap: 1 },
|
|
92
|
+
React.createElement(Text, null, "Usage: shoper theme init [ID]"),
|
|
93
|
+
React.createElement(Text, null, "This command creates a copy of an existing theme based on its ID.To proceed, you must provide the ID of the theme you want to duplicate."))));
|
|
94
|
+
}
|
|
82
95
|
}
|
|
@@ -14,7 +14,7 @@ export class ThemeMetaDataUtils {
|
|
|
14
14
|
const filePath = this.getThemeMetadataFilePath(themeDirectory);
|
|
15
15
|
const metadataFileContent = await readJSONFile(filePath);
|
|
16
16
|
return {
|
|
17
|
-
themeId: String(metadataFileContent.
|
|
17
|
+
themeId: String(metadataFileContent.skin_id)
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
20
|
static async updateThemeMetadata(themeDirectory, data) {
|