@shoper/cli 0.1.0-9 → 0.2.0
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/build/cli/auth/cli_auth_errors_factory.js +1 -1
- package/build/cli/auth/tokens/cli_auth_tokens_errors_factory.js +1 -1
- package/build/cli/auth/tokens/cli_auth_tokens_initalizer.js +1 -1
- package/build/cli/class/errors/file_system_errors_factory.js +1 -1
- package/build/cli/class/errors/http/http_errors_constants.js +1 -0
- package/build/cli/class/errors/{http_errors_factory.js → http/http_errors_factory.js} +3 -2
- package/build/cli/commands/auth/cli_auth_add_token_command.js +22 -19
- package/build/cli/commands/auth/cli_auth_commands_constants.js +3 -0
- package/build/cli/commands/auth/cli_auth_commands_utils.js +46 -0
- package/build/cli/commands/auth/cli_auth_list_tokens_command.js +19 -6
- package/build/cli/commands/auth/cli_auth_remove_token_command.js +36 -10
- package/build/cli/commands/auth/cli_auth_switch_token_command.js +19 -9
- package/build/cli/commands/auth/ui/invalid_token_index_error.js +11 -0
- package/build/cli/commands/auth/ui/missing_credentials_error.js +9 -0
- package/build/cli/commands/auth/ui/missing_token_index_error.js +19 -0
- package/build/cli/commands/cli_ui_dump_command.js +11 -0
- package/build/cli/commands/cli_update_command.js +13 -4
- package/build/cli/commands/commands_constants.js +2 -1
- package/build/cli/core/cli_setup.js +5 -1
- package/build/cli/features/controls/controls_constants.js +12 -0
- package/build/cli/features/controls/controls_dto_mappers.js +55 -0
- package/build/cli/features/controls/ui/controls_mappers.js +62 -0
- package/build/cli/features/controls/ui/form.js +4 -0
- package/build/cli/features/controls/ui/form_constants.js +7 -0
- package/build/cli/features/controls/validators/greater_eq_than_validator.js +5 -0
- package/build/cli/features/controls/validators/length_validator.js +6 -0
- package/build/cli/features/controls/validators/required_validator.js +5 -0
- package/build/cli/features/controls/validators/validator_constants.js +13 -0
- package/build/cli/features/execution_context/execution_context_service.js +5 -5
- package/build/cli/features/http_requester/http_requester_initializer.js +1 -1
- package/build/cli/hooks/authorization/ensure_authorization_hook.js +2 -2
- package/build/cli/hooks/authorization/ensure_authorization_hook_constants.js +8 -8
- package/build/index.js +37 -19
- package/build/theme/class/checksums/theme_checksums.js +174 -0
- package/build/theme/{features/theme/utils → class}/checksums/theme_checksums_error_factory.js +1 -1
- package/build/theme/class/checksums/theme_checksums_utils.js +17 -0
- package/build/theme/class/fetch_resources/fetch_resources.js +1 -0
- package/build/theme/class/fetch_resources/fetch_resources_errors_factory.js +1 -1
- package/build/theme/class/fetch_resources/fetch_resources_utils.js +4 -1
- package/build/theme/commands/delete/theme_delete_command.js +111 -0
- package/build/theme/commands/delete/ui/theme_deleted_successfully.js +15 -0
- package/build/theme/commands/delete/ui/theme_deletion_warning.js +10 -0
- package/build/theme/commands/info/theme_info_command.js +94 -0
- package/build/theme/commands/info/theme_info_command_utils.js +39 -0
- package/build/theme/commands/init/theme_init_command.js +97 -0
- package/build/theme/commands/init/ui/theme_created_success.js +15 -0
- package/build/theme/commands/list/theme_list_command.js +25 -0
- package/build/theme/commands/list/theme_list_command_utils.js +27 -0
- package/build/theme/commands/publish/theme_publish_command.js +92 -0
- package/build/theme/commands/pull/theme_pull_command.js +194 -0
- package/build/theme/commands/pull/ui/theme_pull_id_mismatch_error.js +7 -0
- package/build/theme/commands/pull/ui/theme_pull_unpublished_changes_warning.js +10 -0
- package/build/theme/commands/pull/ui/theme_pulled_success.js +5 -0
- package/build/theme/commands/push/theme_push_command.js +134 -0
- package/build/theme/commands/push/ui/theme_push_skip_into.js +7 -0
- package/build/theme/commands/push/ui/theme_pushed_success.js +5 -0
- package/build/theme/commands/push/ui/theme_unpermitted_actions_error.js +12 -0
- package/build/theme/commands/theme_commands_constants.js +4 -1
- package/build/theme/commands/theme_show_changes_command.js +1 -0
- package/build/theme/commands/theme_verify_command.js +8 -7
- package/build/theme/commands/ui/invalid_theme_id.js +11 -0
- package/build/theme/commands/ui/missing_theme_files.js +15 -0
- package/build/theme/commands/ui/missing_theme_id_error.js +13 -0
- package/build/theme/commands/ui/ouside_of_theme_directory_context_error.js +7 -0
- package/build/theme/commands/ui/theme_directory_context_error.js +7 -0
- package/build/theme/commands/ui/theme_work_url_mismatch.js +17 -0
- package/build/theme/commands/ui/unpermitted_command_error.js +18 -0
- package/build/theme/features/theme/actions/api/theme_actions_api.js +3 -0
- package/build/theme/features/theme/actions/service/theme_actions_service.js +15 -3
- package/build/theme/features/theme/actions/service/theme_actions_service_constants.js +1 -0
- package/build/theme/features/theme/actions/theme_actions_constants.js +3 -1
- package/build/theme/features/theme/actions/theme_actions_initializer.js +1 -1
- package/build/theme/features/theme/actions/theme_actions_utils.js +20 -7
- package/build/theme/features/theme/delete/api/theme_delete_api.js +13 -0
- package/build/theme/features/theme/delete/http/theme_delete_http_api.js +17 -0
- package/build/theme/features/theme/delete/service/theme_delete_service.js +31 -0
- package/build/theme/features/theme/delete/theme_delete_constants.js +2 -0
- package/build/theme/features/theme/delete/theme_delete_initalizer.js +20 -0
- package/build/theme/features/theme/fetch/service/theme_fetch_service.js +30 -10
- package/build/theme/features/theme/info/theme_info_utils.js +9 -0
- package/build/theme/features/theme/init/service/theme_init_service.js +9 -4
- package/build/theme/features/theme/merge/api/theme_merge_api.js +0 -12
- package/build/theme/features/theme/merge/service/theme_merge_service.js +20 -28
- package/build/theme/features/theme/push/service/theme_push_service.js +92 -69
- package/build/theme/features/theme/push/theme_push_constants.js +2 -0
- package/build/theme/features/theme/push/theme_push_errors_factory.js +7 -4
- package/build/theme/features/theme/push/theme_push_initializer.js +0 -3
- package/build/theme/features/theme/push/theme_push_utils.js +25 -0
- package/build/theme/features/theme/skinstore/api/theme_skinstore_api.js +19 -0
- package/build/theme/features/theme/skinstore/http/theme_skinstore_http_api.js +17 -0
- package/build/theme/features/theme/skinstore/service/theme_skinstore_service.js +32 -0
- package/build/theme/features/theme/skinstore/theme_publish_constants.js +4 -0
- package/build/theme/features/theme/skinstore/theme_skinstore_initialzier.js +20 -0
- package/build/theme/features/theme/utils/files_structure/theme_files_structure_utils.js +40 -0
- package/build/theme/features/theme/utils/hidden_directory/hidden_directory_utils.js +32 -0
- package/build/theme/features/theme/utils/meta_data/theme_meta_data_constants.js +1 -0
- package/build/theme/features/theme/utils/meta_data/theme_meta_data_error_factory.js +15 -0
- package/build/theme/features/theme/utils/meta_data/theme_meta_data_utils.js +39 -0
- package/build/theme/features/theme/utils/{directories → resources}/theme_resources_with_id_directory_utils.js +3 -14
- package/build/theme/features/theme/utils/theme_images_utils.js +1 -1
- package/build/theme/features/themes/list/api/themes_list_api.js +3 -0
- package/build/theme/features/themes/list/services/themes_list_service.js +13 -7
- package/build/theme/hooks/{ensure_theme_meta_data_untouched.js → ensure_theme_meta_data_untouched_hook.js} +2 -2
- package/build/theme/hooks/theme_checksums/ensure_theme_current_checksums_up_to_date_constants.js +1 -1
- package/build/theme/hooks/theme_checksums/{ensure_theme_current_checksums_up_to_date.js → ensure_theme_current_checksums_up_to_date_hook.js} +2 -5
- package/build/theme/hooks/themes_actions/ensure_themes_actions_hook.js +1 -0
- package/build/theme/hooks/themes_actions/ensure_themes_actions_hook_constants.js +1 -0
- package/build/theme/index.js +11 -5
- package/build/theme/utils/directory_validator/directory_validator_constants.js +2 -6
- package/build/theme/utils/directory_validator/directory_validator_utils.js +7 -25
- package/build/ui/box.js +2 -0
- package/build/ui/color_constants.js +30 -0
- package/build/ui/command.js +6 -0
- package/build/ui/file_name.js +6 -0
- package/build/ui/flag.js +6 -0
- package/build/ui/icons/error_icon.js +7 -0
- package/build/ui/icons/info_icon.js +7 -0
- package/build/ui/icons/success_icon.js +7 -0
- package/build/ui/icons/warning_icon.js +7 -0
- package/build/ui/link.js +8 -0
- package/build/ui/list/list.js +10 -0
- package/build/ui/list/list_constants.js +4 -0
- package/build/ui/list/list_item.js +11 -0
- package/build/ui/message_box/error.js +4 -0
- package/build/ui/message_box/info.js +4 -0
- package/build/ui/message_box/message_box.js +11 -0
- package/build/ui/message_box/message_box_constants.js +24 -0
- package/build/ui/message_box/success.js +4 -0
- package/build/ui/message_box/warning.js +4 -0
- package/build/ui/prompts/prompt_confirmation.js +11 -0
- package/build/ui/prompts/prompt_input.js +10 -0
- package/build/ui/table/t_cell.js +7 -0
- package/build/ui/table/t_header.js +9 -0
- package/build/ui/table/t_row.js +5 -0
- package/build/ui/table/table.js +18 -0
- package/build/ui/text.js +2 -0
- package/build/ui/tip.js +9 -0
- package/build/ui/ui_dump/ui_component_box.js +9 -0
- package/build/ui/ui_dump/ui_dump.js +53 -0
- package/build/ui/ui_dump/ui_dump_constants.js +21 -0
- package/build/ui/ui_utils.js +11 -0
- package/build/ui/validation_errors/validation_error_content.js +19 -0
- package/build/ui/validation_errors/validation_errors.js +21 -0
- package/build/ui/validation_errors/validation_errors_utils.js +17 -0
- package/build/utils/checksums/checksums_utils.js +9 -26
- package/build/utils/download_file/download_file_errors_factory.js +1 -1
- package/build/utils/download_file/download_file_utils.js +4 -2
- package/build/utils/fs/errors/stream_read_error.js +1 -1
- package/build/utils/fs/errors/stream_write_error.js +1 -1
- package/build/utils/fs/fs_utils.js +12 -1
- package/build/utils/path_utils.js +18 -2
- package/build/utils/platform_utils.js +3 -0
- package/build/utils/zip/create_zip_utils.js +1 -1
- package/build/utils/zip/errors/create_zip_error.js +1 -1
- package/build/utils/zip/errors/open_zip_error.js +1 -1
- package/oclif.config.js +2 -2
- package/package.json +13 -8
- package/build/theme/commands/theme_init_command.js +0 -53
- package/build/theme/commands/theme_list_command.js +0 -16
- package/build/theme/commands/theme_pull_command.js +0 -126
- package/build/theme/commands/theme_push_command.js +0 -65
- package/build/theme/features/theme/directory/theme_directory_utils.js +0 -76
- package/build/theme/features/theme/publish/theme_publish_constants.js +0 -2
- package/build/theme/features/theme/utils/checksums/theme_checksums_utils.js +0 -94
- /package/build/cli/{features → class}/caches/cache_factory.js +0 -0
- /package/build/cli/{features → class}/caches/json_cache/json_cache.js +0 -0
- /package/build/cli/{features → class}/caches/memory_cache.js +0 -0
- /package/build/cli/class/errors/{app_error → app}/app_error.js +0 -0
- /package/build/cli/class/errors/{app_error → app}/app_error_constants.js +0 -0
- /package/build/theme/features/theme/{publish → skinstore}/theme_publish_utils.js +0 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Text } from '../../../ui/text.js';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
export class ThemeInfoCommandUtils {
|
|
4
|
+
static mapThemeMetaDataToTableData(theme) {
|
|
5
|
+
return {
|
|
6
|
+
headers: [
|
|
7
|
+
{
|
|
8
|
+
content: 'Theme Info'
|
|
9
|
+
}
|
|
10
|
+
],
|
|
11
|
+
rows: [
|
|
12
|
+
[
|
|
13
|
+
React.createElement(Text, null,
|
|
14
|
+
React.createElement(Text, { bold: true }, "ID:"),
|
|
15
|
+
" ",
|
|
16
|
+
theme.skinId)
|
|
17
|
+
],
|
|
18
|
+
[
|
|
19
|
+
React.createElement(Text, null,
|
|
20
|
+
React.createElement(Text, { bold: true }, "Name:"),
|
|
21
|
+
" ",
|
|
22
|
+
theme.title)
|
|
23
|
+
],
|
|
24
|
+
[
|
|
25
|
+
React.createElement(Text, null,
|
|
26
|
+
React.createElement(Text, { bold: true }, "Description:"),
|
|
27
|
+
" ",
|
|
28
|
+
theme.description ? theme.description : '-')
|
|
29
|
+
],
|
|
30
|
+
[
|
|
31
|
+
React.createElement(Text, null,
|
|
32
|
+
React.createElement(Text, { bold: true }, "Status: "),
|
|
33
|
+
": ",
|
|
34
|
+
theme.isActive ? 'Active' : 'Inactive')
|
|
35
|
+
]
|
|
36
|
+
]
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { BaseThemeCommand } from '../../class/base_theme_command.js';
|
|
2
|
+
import { Args } from '@oclif/core';
|
|
3
|
+
import { THEME_INIT_API_NAME } from '../../features/theme/init/theme_init_constants.js';
|
|
4
|
+
import { CLI_AUTH_API_NAME } from '../../../cli/auth/cli_auth_constants.js';
|
|
5
|
+
import ora from 'ora';
|
|
6
|
+
import { EXECUTION_CONTEXT_API_NAME, EXECUTION_CONTEXTS } from '../../../cli/features/execution_context/execution_context_constants.js';
|
|
7
|
+
import { THEME_ACTION_NOT_FOUND_ERROR_CODE, THEME_ACTIONS_API_NAME, THEME_ACTIONS_TYPES } from '../../features/theme/actions/theme_actions_constants.js';
|
|
8
|
+
import { renderOnce } from '../../../ui/ui_utils.js';
|
|
9
|
+
import { ThemeDirectoryContextError } from '../ui/theme_directory_context_error.js';
|
|
10
|
+
import React from 'react';
|
|
11
|
+
import { UnpermittedCommandError } from '../ui/unpermitted_command_error.js';
|
|
12
|
+
import { MissingCredentialsError } from '../../../cli/commands/auth/ui/missing_credentials_error.js';
|
|
13
|
+
import { ThemeCreatedSuccess } from './ui/theme_created_success.js';
|
|
14
|
+
import { Text } from '../../../ui/text.js';
|
|
15
|
+
import { MissingThemeIdError } from '../ui/missing_theme_id_error.js';
|
|
16
|
+
import { Box } from '../../../ui/box.js';
|
|
17
|
+
import { ValidationErrors } from '../../../ui/validation_errors/validation_errors.js';
|
|
18
|
+
export class ThemeInitCommand extends BaseThemeCommand {
|
|
19
|
+
static summary = 'Creates a copy of an existing theme by duplicating it.';
|
|
20
|
+
static description = 'The new theme will be named after the source theme with a "Copy" suffix and an incremental number.\n\nYou must run this command from the root directory (not inside any theme folder) and provide the ID of the theme you want to duplicate.';
|
|
21
|
+
static examples = [
|
|
22
|
+
{
|
|
23
|
+
description: 'This will duplicate the theme with ID 123 (named SourceTheme Copy 3) and create a new theme named "SourceTheme Copy 4".\nUse this as a starting point for your customizations.\n',
|
|
24
|
+
command: '<%= config.bin %> <%= command.id %> 123'
|
|
25
|
+
}
|
|
26
|
+
];
|
|
27
|
+
static args = {
|
|
28
|
+
id: Args.string({
|
|
29
|
+
description: 'Theme id',
|
|
30
|
+
name: 'id',
|
|
31
|
+
required: false,
|
|
32
|
+
type: 'string'
|
|
33
|
+
})
|
|
34
|
+
};
|
|
35
|
+
async run() {
|
|
36
|
+
const data = await this.parse(ThemeInitCommand);
|
|
37
|
+
const { args } = data;
|
|
38
|
+
const themeId = args.id;
|
|
39
|
+
const cliAuthApi = this.getApi(CLI_AUTH_API_NAME);
|
|
40
|
+
const themeInitApi = this.getApi(THEME_INIT_API_NAME);
|
|
41
|
+
const themeActionsApi = this.getApi(THEME_ACTIONS_API_NAME);
|
|
42
|
+
const executionContextApi = this.getApi(EXECUTION_CONTEXT_API_NAME);
|
|
43
|
+
const credentials = cliAuthApi.getCredentials();
|
|
44
|
+
if (!credentials) {
|
|
45
|
+
renderOnce(React.createElement(MissingCredentialsError, null));
|
|
46
|
+
return;
|
|
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
|
+
}
|
|
57
|
+
let spinner;
|
|
58
|
+
try {
|
|
59
|
+
const copyAction = themeActionsApi.getThemeAction({
|
|
60
|
+
actionType: THEME_ACTIONS_TYPES.copy,
|
|
61
|
+
themeId,
|
|
62
|
+
credentials
|
|
63
|
+
});
|
|
64
|
+
if (!copyAction) {
|
|
65
|
+
renderOnce(React.createElement(UnpermittedCommandError, { themeId: themeId, commandName: "init" }));
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
spinner = ora('Creating theme...').start();
|
|
69
|
+
const { themeId: createdThemeId, themeName } = await themeInitApi.initTheme({ action: copyAction, credentials });
|
|
70
|
+
spinner.stop();
|
|
71
|
+
renderOnce(React.createElement(ThemeCreatedSuccess, { createdThemeId: createdThemeId, themeName: themeName }));
|
|
72
|
+
}
|
|
73
|
+
catch (err) {
|
|
74
|
+
spinner?.stop();
|
|
75
|
+
this._handleError(err, themeId);
|
|
76
|
+
//TODO analyze why on nodejs v22 this command does not exit properly, even all promises are resolved
|
|
77
|
+
this.exit();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
_handleError(err, themeId) {
|
|
81
|
+
if (err?.code === THEME_ACTION_NOT_FOUND_ERROR_CODE && themeId) {
|
|
82
|
+
renderOnce(React.createElement(UnpermittedCommandError, { themeId: themeId, commandName: "init" }));
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (err?.message) {
|
|
86
|
+
renderOnce(React.createElement(ValidationErrors, { errors: err.message }));
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
this.error(String(err));
|
|
90
|
+
}
|
|
91
|
+
_renderMissingThemeIdError() {
|
|
92
|
+
renderOnce(React.createElement(MissingThemeIdError, null,
|
|
93
|
+
React.createElement(Box, { flexDirection: "column", gap: 1 },
|
|
94
|
+
React.createElement(Text, null, "Usage: shoper theme init [ID]"),
|
|
95
|
+
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."))));
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Box } from '../../../../ui/box.js';
|
|
2
|
+
import { Text } from '../../../../ui/text.js';
|
|
3
|
+
import { Success } from '../../../../ui/message_box/success.js';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
export const ThemeCreatedSuccess = ({ createdThemeId, themeName }) => {
|
|
6
|
+
return (React.createElement(Success, { header: "Success: Theme was created!" },
|
|
7
|
+
React.createElement(Box, { gap: 1, flexDirection: "column" },
|
|
8
|
+
React.createElement(Text, null,
|
|
9
|
+
"Theme \"",
|
|
10
|
+
themeName,
|
|
11
|
+
"\" was created (ID: ",
|
|
12
|
+
createdThemeId,
|
|
13
|
+
")."),
|
|
14
|
+
React.createElement(Text, null, "You can now customize your new theme."))));
|
|
15
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { BaseThemeCommand } from '../../class/base_theme_command.js';
|
|
2
|
+
import { THEMES_LIST_API_NAME } from '../../features/themes/list/themes_list_constants.js';
|
|
3
|
+
import { CLI_AUTH_API_NAME } from '../../../cli/auth/cli_auth_constants.js';
|
|
4
|
+
import { renderOnce } from '../../../ui/ui_utils.js';
|
|
5
|
+
import { Info } from '../../../ui/message_box/info.js';
|
|
6
|
+
import React from 'react';
|
|
7
|
+
import { Table } from '../../../ui/table/table.js';
|
|
8
|
+
import { ThemeListCommandUtils } from './theme_list_command_utils.js';
|
|
9
|
+
export class ThemeListCommand extends BaseThemeCommand {
|
|
10
|
+
static summary = 'Displays a list of all themes available in your store, including their IDs, names, and statuses (active/inactive).';
|
|
11
|
+
static description = 'Use this to check which theme is now active in your store.';
|
|
12
|
+
async run() {
|
|
13
|
+
const ThemesListApi = this.getApi(THEMES_LIST_API_NAME);
|
|
14
|
+
const cliAuthApi = this.getApi(CLI_AUTH_API_NAME);
|
|
15
|
+
const credentials = cliAuthApi.getCredentials();
|
|
16
|
+
if (!credentials)
|
|
17
|
+
this.error('Credentials not found. Please authorize first.');
|
|
18
|
+
const themes = await ThemesListApi.getThemes(credentials);
|
|
19
|
+
if (!themes?.length) {
|
|
20
|
+
renderOnce(React.createElement(Info, { header: "No themes found for this store." }));
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
renderOnce(React.createElement(Table, { data: ThemeListCommandUtils.mapThemeListToTableData(themes) }));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Text } from '../../../ui/text.js';
|
|
3
|
+
export class ThemeListCommandUtils {
|
|
4
|
+
static mapThemeListToTableData(themes) {
|
|
5
|
+
return {
|
|
6
|
+
headers: [
|
|
7
|
+
{
|
|
8
|
+
content: 'Theme ID',
|
|
9
|
+
width: 10
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
content: 'Theme Name',
|
|
13
|
+
width: 70
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
content: 'Status',
|
|
17
|
+
width: 10
|
|
18
|
+
}
|
|
19
|
+
],
|
|
20
|
+
rows: themes.map((theme) => [
|
|
21
|
+
React.createElement(Text, null, theme.skinId),
|
|
22
|
+
React.createElement(Text, null, theme.title),
|
|
23
|
+
React.createElement(Text, null, theme.isActive ? 'active' : 'inactive')
|
|
24
|
+
])
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { Args } from '@oclif/core';
|
|
2
|
+
import { BaseThemeCommand } from '../../class/base_theme_command.js';
|
|
3
|
+
import { CLI_AUTH_API_NAME } from '../../../cli/auth/cli_auth_constants.js';
|
|
4
|
+
import { THEME_ACTION_NOT_FOUND_ERROR_CODE, THEME_ACTIONS_API_NAME, THEME_ACTIONS_TYPES } from '../../features/theme/actions/theme_actions_constants.js';
|
|
5
|
+
import { EXECUTION_CONTEXT_API_NAME, EXECUTION_CONTEXTS } from '../../../cli/features/execution_context/execution_context_constants.js';
|
|
6
|
+
import { renderOnce } from '../../../ui/ui_utils.js';
|
|
7
|
+
import { MissingCredentialsError } from '../../../cli/commands/auth/ui/missing_credentials_error.js';
|
|
8
|
+
import React from 'react';
|
|
9
|
+
import { UnpermittedCommandError } from '../ui/unpermitted_command_error.js';
|
|
10
|
+
import { Error } from '../../../ui/message_box/error.js';
|
|
11
|
+
import { Text } from '../../../ui/text.js';
|
|
12
|
+
import { MissingThemeIdError } from '../ui/missing_theme_id_error.js';
|
|
13
|
+
import { THEME_SKINSTORE_API_NAME } from '../../features/theme/skinstore/theme_publish_constants.js';
|
|
14
|
+
import { Form } from '../../../cli/features/controls/ui/form.js';
|
|
15
|
+
export class ThemePublishCommand extends BaseThemeCommand {
|
|
16
|
+
static summary = 'Permanently deletes the specified theme from your store.';
|
|
17
|
+
static description = 'This action cannot be undone, so make sure you really want to remove this theme.\n\nYou can run this command from a specific theme directory (ID not needed) or outside any theme directory (theme ID required).';
|
|
18
|
+
static examples = [
|
|
19
|
+
{
|
|
20
|
+
description: 'This will delete the theme with ID 123 permanently from your store. Make sure you have a backup if needed.',
|
|
21
|
+
command: '<%= config.bin %> <%= command.id %> 123'
|
|
22
|
+
}
|
|
23
|
+
];
|
|
24
|
+
static hidden = true;
|
|
25
|
+
static args = {
|
|
26
|
+
id: Args.string({
|
|
27
|
+
description: 'Theme id',
|
|
28
|
+
name: 'id',
|
|
29
|
+
required: false,
|
|
30
|
+
type: 'string'
|
|
31
|
+
})
|
|
32
|
+
};
|
|
33
|
+
async run() {
|
|
34
|
+
const data = await this.parse(ThemePublishCommand);
|
|
35
|
+
const { args } = data;
|
|
36
|
+
const themeId = args.id;
|
|
37
|
+
const cliAuthApi = this.getApi(CLI_AUTH_API_NAME);
|
|
38
|
+
const executionContextApi = this.getApi(EXECUTION_CONTEXT_API_NAME);
|
|
39
|
+
const credentials = cliAuthApi.getCredentials();
|
|
40
|
+
if (!credentials) {
|
|
41
|
+
renderOnce(React.createElement(MissingCredentialsError, null));
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const executionContext = await executionContextApi.getExecutionContext();
|
|
45
|
+
try {
|
|
46
|
+
let _themeId = themeId;
|
|
47
|
+
if (executionContext.type !== EXECUTION_CONTEXTS.theme && !_themeId) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (executionContext.type === EXECUTION_CONTEXTS.theme) {
|
|
51
|
+
_themeId = _themeId ?? executionContext.themeId;
|
|
52
|
+
}
|
|
53
|
+
if (!_themeId) {
|
|
54
|
+
renderOnce(React.createElement(MissingThemeIdError, null));
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const themeActionsApi = this.getApi(THEME_ACTIONS_API_NAME);
|
|
58
|
+
const themeSkinstoreApi = this.getApi(THEME_SKINSTORE_API_NAME);
|
|
59
|
+
const pushAction = themeActionsApi.getThemeAction({
|
|
60
|
+
actionType: THEME_ACTIONS_TYPES.publishForm,
|
|
61
|
+
themeId: _themeId,
|
|
62
|
+
credentials
|
|
63
|
+
});
|
|
64
|
+
const controls = await themeSkinstoreApi.getPublishFormData({
|
|
65
|
+
actionData: pushAction.data,
|
|
66
|
+
credentials
|
|
67
|
+
});
|
|
68
|
+
Form({
|
|
69
|
+
controls,
|
|
70
|
+
onSubmit: (formData) => {
|
|
71
|
+
console.log('formData', formData);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
catch (err) {
|
|
76
|
+
this._handleError(err, themeId);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
_handleError(err, themeId) {
|
|
81
|
+
if (err?.code === THEME_ACTION_NOT_FOUND_ERROR_CODE && themeId) {
|
|
82
|
+
renderOnce(React.createElement(UnpermittedCommandError, { themeId: themeId, commandName: "delete" }));
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (err?.message) {
|
|
86
|
+
renderOnce(React.createElement(Error, null,
|
|
87
|
+
React.createElement(Text, null, err.message)));
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
this.error(String(err));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { Args, Flags } from '@oclif/core';
|
|
2
|
+
import { BaseThemeCommand } from '../../class/base_theme_command.js';
|
|
3
|
+
import { THEME_FETCH_API_NAME, THEME_FETCH_TYPES } from '../../features/theme/fetch/theme_fetch_constants.js';
|
|
4
|
+
import { CLI_AUTH_API_NAME } from '../../../cli/auth/cli_auth_constants.js';
|
|
5
|
+
import { EXECUTION_CONTEXT_API_NAME, EXECUTION_CONTEXTS } from '../../../cli/features/execution_context/execution_context_constants.js';
|
|
6
|
+
import ora from 'ora';
|
|
7
|
+
import { THEME_MERGE_API_NAME } from '../../features/theme/merge/theme_merge_constants.js';
|
|
8
|
+
import tmp from 'tmp-promise';
|
|
9
|
+
import { join } from '../../../utils/path_utils.js';
|
|
10
|
+
import { THEME_ACTION_NOT_FOUND_ERROR_CODE, THEME_ACTIONS_API_NAME, THEME_ACTIONS_TYPES } from '../../features/theme/actions/theme_actions_constants.js';
|
|
11
|
+
import process from 'node:process';
|
|
12
|
+
import { ThemeResourcesWithIdDirectoryUtils } from '../../features/theme/utils/resources/theme_resources_with_id_directory_utils.js';
|
|
13
|
+
import { renderOnce } from '../../../ui/ui_utils.js';
|
|
14
|
+
import { MissingCredentialsError } from '../../../cli/commands/auth/ui/missing_credentials_error.js';
|
|
15
|
+
import React from 'react';
|
|
16
|
+
import { MissingThemeIdError } from '../ui/missing_theme_id_error.js';
|
|
17
|
+
import { Text } from '../../../ui/text.js';
|
|
18
|
+
import { UnpermittedCommandError } from '../ui/unpermitted_command_error.js';
|
|
19
|
+
import { ThemePullIdMismatchError } from './ui/theme_pull_id_mismatch_error.js';
|
|
20
|
+
import { ThemePullUnpublishedChangesWarning } from './ui/theme_pull_unpublished_changes_warning.js';
|
|
21
|
+
import { promptConfirmation } from '../../../ui/prompts/prompt_confirmation.js';
|
|
22
|
+
import { ThemePulledSuccess } from './ui/theme_pulled_success.js';
|
|
23
|
+
import { Info } from '../../../ui/message_box/info.js';
|
|
24
|
+
import { directoryExists } from '../../../utils/fs/fs_utils.js';
|
|
25
|
+
import { THEME_WORK_URL_MISMATCH_ERROR } from '../../features/theme/utils/meta_data/theme_meta_data_constants.js';
|
|
26
|
+
import { ThemeWorkUrlMismatch } from '../ui/theme_work_url_mismatch.js';
|
|
27
|
+
import { Error } from '../../../ui/message_box/error.js';
|
|
28
|
+
import { ThemeMetaDataUtils } from '../../features/theme/utils/meta_data/theme_meta_data_utils.js';
|
|
29
|
+
import { ThemeChecksums } from '../../class/checksums/theme_checksums.js';
|
|
30
|
+
//TODO jak jest error w pullu wowczas usuwamy docelowo pociagniety skin
|
|
31
|
+
export class ThemePullCommand extends BaseThemeCommand {
|
|
32
|
+
static summary = 'Downloads the current version of your theme from the store and overwrites your local theme files.';
|
|
33
|
+
static description = 'Make sure to back up any local modifications you wish to keep.\n\nYou can run this command from a specific theme directory (ID not needed) or outside any theme directory (theme ID required).\n\nThis keeps your local theme the same as the version in your store.';
|
|
34
|
+
static examples = [
|
|
35
|
+
{
|
|
36
|
+
description: 'This will update your local theme files with the current version from the store.',
|
|
37
|
+
command: '<%= config.bin %> <%= command.id %>'
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
description: 'This will download the theme with ID "2" from the store.',
|
|
41
|
+
command: '<%= config.bin %> <%= command.id %> 2'
|
|
42
|
+
}
|
|
43
|
+
];
|
|
44
|
+
static args = {
|
|
45
|
+
id: Args.string({
|
|
46
|
+
description: 'Theme id',
|
|
47
|
+
name: 'id',
|
|
48
|
+
type: 'string'
|
|
49
|
+
})
|
|
50
|
+
};
|
|
51
|
+
static flags = {
|
|
52
|
+
type: Flags.string({
|
|
53
|
+
default: THEME_FETCH_TYPES.full,
|
|
54
|
+
description: 'Type of theme to pull',
|
|
55
|
+
options: Object.values(THEME_FETCH_TYPES)
|
|
56
|
+
})
|
|
57
|
+
};
|
|
58
|
+
#spinner;
|
|
59
|
+
async run() {
|
|
60
|
+
const data = await this.parse(ThemePullCommand);
|
|
61
|
+
const { args, flags } = data;
|
|
62
|
+
const themeId = args.id;
|
|
63
|
+
const cliAuthApi = this.getApi(CLI_AUTH_API_NAME);
|
|
64
|
+
const themeFetchApi = this.getApi(THEME_FETCH_API_NAME);
|
|
65
|
+
const executionContextApi = this.getApi(EXECUTION_CONTEXT_API_NAME);
|
|
66
|
+
const themeActionsApi = this.getApi(THEME_ACTIONS_API_NAME);
|
|
67
|
+
const credentials = cliAuthApi.getCredentials();
|
|
68
|
+
if (!credentials) {
|
|
69
|
+
renderOnce(React.createElement(MissingCredentialsError, null));
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const executionContext = await executionContextApi.getExecutionContext();
|
|
73
|
+
let _themeId = themeId;
|
|
74
|
+
try {
|
|
75
|
+
if (executionContext.type !== EXECUTION_CONTEXTS.theme) {
|
|
76
|
+
await this._pullNewTheme({
|
|
77
|
+
themeId,
|
|
78
|
+
themeFetchApi,
|
|
79
|
+
themeActionsApi,
|
|
80
|
+
credentials,
|
|
81
|
+
fetchType: flags.type
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
if (executionContext.type === EXECUTION_CONTEXTS.theme) {
|
|
85
|
+
_themeId = themeId ? themeId : executionContext.themeId;
|
|
86
|
+
await this._pullThemeIntoExistingOne({
|
|
87
|
+
themeId: _themeId,
|
|
88
|
+
themeFetchApi,
|
|
89
|
+
themeActionsApi,
|
|
90
|
+
fetchType: flags.type,
|
|
91
|
+
executionContext,
|
|
92
|
+
credentials
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
catch (err) {
|
|
97
|
+
this.#spinner?.stop();
|
|
98
|
+
this._handleError(err, _themeId);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
_handleError(err, _themeId) {
|
|
102
|
+
if (err?.code === THEME_ACTION_NOT_FOUND_ERROR_CODE && _themeId) {
|
|
103
|
+
this._renderUnpermittedCommandError(_themeId);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
if (err?.code === THEME_WORK_URL_MISMATCH_ERROR) {
|
|
107
|
+
renderOnce(React.createElement(ThemeWorkUrlMismatch, { command: "pull" }));
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
if (err?.message) {
|
|
111
|
+
renderOnce(React.createElement(Error, null,
|
|
112
|
+
React.createElement(Text, null, err.message)));
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
this.error(String(err));
|
|
116
|
+
}
|
|
117
|
+
_renderUnpermittedCommandError(themeId) {
|
|
118
|
+
renderOnce(React.createElement(UnpermittedCommandError, { themeId: themeId, commandName: "pull" }));
|
|
119
|
+
}
|
|
120
|
+
async _pullNewTheme({ themeId, themeFetchApi, themeActionsApi, credentials, fetchType }) {
|
|
121
|
+
if (themeId === undefined) {
|
|
122
|
+
renderOnce(React.createElement(MissingThemeIdError, null,
|
|
123
|
+
React.createElement(Text, null, "Usage: shoper theme pull [ID]")));
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
const pullAction = themeActionsApi.getThemeAction({
|
|
127
|
+
actionType: THEME_ACTIONS_TYPES.pull,
|
|
128
|
+
themeId,
|
|
129
|
+
credentials
|
|
130
|
+
});
|
|
131
|
+
if (!pullAction) {
|
|
132
|
+
this._renderUnpermittedCommandError(themeId);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
this.#spinner = ora('Pulling theme...').start();
|
|
136
|
+
await themeFetchApi.fetchTheme({
|
|
137
|
+
credentials,
|
|
138
|
+
action: pullAction,
|
|
139
|
+
config: {
|
|
140
|
+
dist: process.cwd(),
|
|
141
|
+
fetchType
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
this.#spinner.stop();
|
|
145
|
+
renderOnce(React.createElement(ThemePulledSuccess, null));
|
|
146
|
+
}
|
|
147
|
+
async _pullThemeIntoExistingOne({ themeId, themeFetchApi, themeActionsApi, fetchType, executionContext, credentials }) {
|
|
148
|
+
//TODO move these logi somvewhere else?
|
|
149
|
+
await ThemeMetaDataUtils.ensureThemeWorkUrlMatch(executionContext.themeRootDir, credentials.shopUrl);
|
|
150
|
+
const pullAction = themeActionsApi.getThemeAction({
|
|
151
|
+
actionType: THEME_ACTIONS_TYPES.pull,
|
|
152
|
+
themeId,
|
|
153
|
+
credentials
|
|
154
|
+
});
|
|
155
|
+
if (!pullAction) {
|
|
156
|
+
this._renderUnpermittedCommandError(themeId);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
if (executionContext.themeId !== themeId) {
|
|
160
|
+
renderOnce(React.createElement(ThemePullIdMismatchError, { providedThemeId: themeId, currentThemeId: executionContext.themeId }));
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
const themeMergeApi = this.getApi(THEME_MERGE_API_NAME);
|
|
164
|
+
const { path: tmpDir } = await tmp.dir({ unsafeCleanup: true });
|
|
165
|
+
this.#spinner = ora('Pulling theme...').start();
|
|
166
|
+
const { name } = await themeFetchApi.fetchTheme({
|
|
167
|
+
credentials,
|
|
168
|
+
action: pullAction,
|
|
169
|
+
config: {
|
|
170
|
+
fetchType,
|
|
171
|
+
dist: tmpDir
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
const localModulesPath = join(executionContext.themeRootDir, 'modules');
|
|
175
|
+
const fetchedThemePath = join(tmpDir, name);
|
|
176
|
+
const fetchedModulesPath = join(fetchedThemePath, 'modules');
|
|
177
|
+
if ((await directoryExists(localModulesPath)) && (await directoryExists(fetchedModulesPath)))
|
|
178
|
+
await ThemeResourcesWithIdDirectoryUtils.updateDirectoryNamesOfResourcesWithIdAccordingToLocalThemeNames(localModulesPath, fetchedModulesPath, fetchedThemePath);
|
|
179
|
+
this.#spinner.stop();
|
|
180
|
+
const changes = await themeMergeApi.getChangesBetweenThemes(fetchedThemePath, executionContext.themeRootDir);
|
|
181
|
+
const themeChecksums = new ThemeChecksums(executionContext.themeRootDir);
|
|
182
|
+
if (changes.length && (await themeChecksums.hasThemeBeenModified())) {
|
|
183
|
+
renderOnce(React.createElement(ThemePullUnpublishedChangesWarning, { changes: changes }));
|
|
184
|
+
const { proceed } = await promptConfirmation('Do you want to continue and overwrite local changes?');
|
|
185
|
+
if (!proceed) {
|
|
186
|
+
renderOnce(React.createElement(Info, null,
|
|
187
|
+
React.createElement(Text, null, "Pull operation cancelled. Your local changes are safe.")));
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
await themeMergeApi.applyChanges(join(tmpDir, name), executionContext.themeRootDir, changes);
|
|
192
|
+
renderOnce(React.createElement(ThemePulledSuccess, null));
|
|
193
|
+
}
|
|
194
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Error } from '../../../../ui/message_box/error.js';
|
|
3
|
+
import { Text } from '../../../../ui/text.js';
|
|
4
|
+
export const ThemePullIdMismatchError = ({ providedThemeId, currentThemeId }) => {
|
|
5
|
+
return (React.createElement(Error, { header: `Error: Provided ID (${providedThemeId}) doesn't match the current theme directory (${currentThemeId}).` },
|
|
6
|
+
React.createElement(Text, null, "Please move outside the theme directory and run the command again with the correct ID.")));
|
|
7
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Warning } from '../../../../ui/message_box/warning.js';
|
|
2
|
+
import { List } from '../../../../ui/list/list.js';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
export const ThemePullUnpublishedChangesWarning = ({ changes }) => {
|
|
5
|
+
const items = changes.map(([action, path]) => ({
|
|
6
|
+
content: `${action} - ${path}`
|
|
7
|
+
}));
|
|
8
|
+
return (React.createElement(Warning, { header: "Warning: You have unpushed local changes in this theme directory. Pulling now may overwrite your local modifications." },
|
|
9
|
+
React.createElement(List, { items: items })));
|
|
10
|
+
};
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { BaseThemeCommand } from '../../class/base_theme_command.js';
|
|
2
|
+
import { CLI_AUTH_API_NAME } from '../../../cli/auth/cli_auth_constants.js';
|
|
3
|
+
import { EXECUTION_CONTEXT_API_NAME, EXECUTION_CONTEXTS } from '../../../cli/features/execution_context/execution_context_constants.js';
|
|
4
|
+
import { THEME_ACTION_NOT_FOUND_ERROR_CODE, THEME_ACTIONS_API_NAME, THEME_ACTIONS_TYPES } from '../../features/theme/actions/theme_actions_constants.js';
|
|
5
|
+
import { THEME_ARCHIVE_UPLOAD_ERROR, THEME_FILES_UPLOAD_ERROR, THEME_PUSH_API_NAME } from '../../features/theme/push/theme_push_constants.js';
|
|
6
|
+
import { ThemeMetaDataUtils } from '../../features/theme/utils/meta_data/theme_meta_data_utils.js';
|
|
7
|
+
import { mapChecksumToTree } from '../../../utils/checksums/checksums_utils.js';
|
|
8
|
+
import { mapToPermissionsTree } from '../../utils/directory_validator/directory_validator_utils.js';
|
|
9
|
+
import { renderOnce } from '../../../ui/ui_utils.js';
|
|
10
|
+
import { UnpermittedCommandError } from '../ui/unpermitted_command_error.js';
|
|
11
|
+
import React from 'react';
|
|
12
|
+
import { OutsideOfThemeDirectoryContextError } from '../ui/ouside_of_theme_directory_context_error.js';
|
|
13
|
+
import { MissingCredentialsError } from '../../../cli/commands/auth/ui/missing_credentials_error.js';
|
|
14
|
+
import { ThemePushedSuccess } from './ui/theme_pushed_success.js';
|
|
15
|
+
import ora from 'ora';
|
|
16
|
+
import { MissingThemeFiles } from '../ui/missing_theme_files.js';
|
|
17
|
+
import { SHOPER_THEME_METADATA_DIR } from '../../constants/directory_contstants.js';
|
|
18
|
+
import { THEME_FILES_STRUCTURE_FILE_NAME } from '../../features/theme/theme_constants.js';
|
|
19
|
+
import { ThemePushSkipInfo } from './ui/theme_push_skip_into.js';
|
|
20
|
+
import { ThemeUnpermittedActionsError } from './ui/theme_unpermitted_actions_error.js';
|
|
21
|
+
import { Error } from '../../../ui/message_box/error.js';
|
|
22
|
+
import { Text } from '../../../ui/text.js';
|
|
23
|
+
import { ThemeWorkUrlMismatch } from '../ui/theme_work_url_mismatch.js';
|
|
24
|
+
import { THEME_WORK_URL_MISMATCH_ERROR } from '../../features/theme/utils/meta_data/theme_meta_data_constants.js';
|
|
25
|
+
import { ThemeFilesStructureUtils } from '../../features/theme/utils/files_structure/theme_files_structure_utils.js';
|
|
26
|
+
import { ThemeInfoUtils } from '../../features/theme/info/theme_info_utils.js';
|
|
27
|
+
import { ValidationErrors } from '../../../ui/validation_errors/validation_errors.js';
|
|
28
|
+
import { ThemeChecksums } from '../../class/checksums/theme_checksums.js';
|
|
29
|
+
export class ThemePushCommand extends BaseThemeCommand {
|
|
30
|
+
static summary = 'Uploads your local theme files to the store and overwrites the current version of the theme in your store.';
|
|
31
|
+
static description = 'Check your local changes before pushing.\n\nYou must run this command from a specific theme directory (ID not needed).';
|
|
32
|
+
static examples = [
|
|
33
|
+
{
|
|
34
|
+
description: 'This will replace the store version with your local copy.',
|
|
35
|
+
command: '<%= config.bin %> <%= command.id %>'
|
|
36
|
+
}
|
|
37
|
+
];
|
|
38
|
+
async run() {
|
|
39
|
+
const cliAuthApi = this.getApi(CLI_AUTH_API_NAME);
|
|
40
|
+
const themePushApi = this.getApi(THEME_PUSH_API_NAME);
|
|
41
|
+
const themeActionsApi = this.getApi(THEME_ACTIONS_API_NAME);
|
|
42
|
+
const executionContextApi = this.getApi(EXECUTION_CONTEXT_API_NAME);
|
|
43
|
+
const credentials = cliAuthApi.getCredentials();
|
|
44
|
+
if (!credentials) {
|
|
45
|
+
renderOnce(React.createElement(MissingCredentialsError, null));
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const executionContext = await executionContextApi.getExecutionContext();
|
|
49
|
+
if (executionContext.type !== EXECUTION_CONTEXTS.theme) {
|
|
50
|
+
renderOnce(React.createElement(OutsideOfThemeDirectoryContextError, null));
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
let spinner;
|
|
54
|
+
try {
|
|
55
|
+
const themeChecksums = new ThemeChecksums(executionContext.themeRootDir);
|
|
56
|
+
await ThemeMetaDataUtils.ensureThemeWorkUrlMatch(executionContext.themeRootDir, credentials.shopUrl);
|
|
57
|
+
const pushAction = themeActionsApi.getThemeAction({
|
|
58
|
+
actionType: THEME_ACTIONS_TYPES.push,
|
|
59
|
+
themeId: executionContext.themeId,
|
|
60
|
+
credentials
|
|
61
|
+
});
|
|
62
|
+
if (!pushAction) {
|
|
63
|
+
renderOnce(React.createElement(UnpermittedCommandError, { themeId: executionContext.themeId, commandName: "push" }));
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const initialChecksums = await themeChecksums.getInitialChecksums();
|
|
67
|
+
const permissions = await ThemeFilesStructureUtils.getFilesPermissions(executionContext.themeRootDir);
|
|
68
|
+
if (!initialChecksums || !permissions)
|
|
69
|
+
this.error('Theme checksums or permissions not found. Please ensure you are in the correct theme directory.');
|
|
70
|
+
if (!(await themeChecksums.hasThemeBeenModified())) {
|
|
71
|
+
renderOnce(React.createElement(ThemePushSkipInfo, null));
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const validationResult = await ThemeFilesStructureUtils.validateThemeDirectoryStructure({
|
|
75
|
+
//TDO przeniesc do theme checksums
|
|
76
|
+
checksums: mapChecksumToTree(initialChecksums),
|
|
77
|
+
permissions: mapToPermissionsTree(permissions),
|
|
78
|
+
rootDirectory: executionContext.themeRootDir
|
|
79
|
+
});
|
|
80
|
+
//TODO jak wysyla folder z nazwa posiadajaco \ na windows, wychodzimy
|
|
81
|
+
//TODO validacja folderów przed pushem
|
|
82
|
+
if (!validationResult.isValid) {
|
|
83
|
+
renderOnce(React.createElement(ThemeUnpermittedActionsError, { unpermittedActions: validationResult.unpermittedActions }));
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const filesStructure = await ThemeFilesStructureUtils.getThemeFilesStructure(executionContext.themeRootDir);
|
|
87
|
+
if (!filesStructure) {
|
|
88
|
+
renderOnce(React.createElement(MissingThemeFiles, { files: `${SHOPER_THEME_METADATA_DIR}/${THEME_FILES_STRUCTURE_FILE_NAME}` }));
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
spinner = ora('Pushing theme...').start();
|
|
92
|
+
await themePushApi.push({
|
|
93
|
+
credentials,
|
|
94
|
+
filesStructure,
|
|
95
|
+
pushAction,
|
|
96
|
+
themeChecksums,
|
|
97
|
+
executionContext
|
|
98
|
+
});
|
|
99
|
+
spinner.stop();
|
|
100
|
+
renderOnce(React.createElement(ThemePushedSuccess, { themeName: await ThemeInfoUtils.getThemeName(executionContext.themeRootDir) }));
|
|
101
|
+
}
|
|
102
|
+
catch (err) {
|
|
103
|
+
spinner?.stop();
|
|
104
|
+
this._handleError(err, executionContext);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
_handleError(err, executionContext) {
|
|
108
|
+
if (err?.code === THEME_ACTION_NOT_FOUND_ERROR_CODE) {
|
|
109
|
+
renderOnce(React.createElement(UnpermittedCommandError, { themeId: executionContext.themeId, commandName: "push" }));
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if (err?.code === THEME_ARCHIVE_UPLOAD_ERROR) {
|
|
113
|
+
renderOnce(React.createElement(ValidationErrors, { errors: err?.details }));
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (err?.code === THEME_WORK_URL_MISMATCH_ERROR) {
|
|
117
|
+
this._renderUrlMismatchError();
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
if (err?.code === THEME_FILES_UPLOAD_ERROR) {
|
|
121
|
+
renderOnce(React.createElement(Error, { header: "Uploading theme files to the shop failed.\n" },
|
|
122
|
+
React.createElement(Text, null, "The rejected files have been removed locally. Please ensure that the files are not corrupted and that the file extensions are supported.")));
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
if (err?.message) {
|
|
126
|
+
renderOnce(React.createElement(ValidationErrors, { errors: err.message }));
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
this.error(String(err));
|
|
130
|
+
}
|
|
131
|
+
_renderUrlMismatchError() {
|
|
132
|
+
renderOnce(React.createElement(ThemeWorkUrlMismatch, { command: "push" }));
|
|
133
|
+
}
|
|
134
|
+
}
|