@shoper/cli 0.1.0-9 → 0.2.1-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.
Files changed (184) hide show
  1. package/build/cli/auth/cli_auth_errors_factory.js +1 -1
  2. package/build/cli/auth/tokens/cli_auth_tokens_errors_factory.js +1 -1
  3. package/build/cli/auth/tokens/cli_auth_tokens_initalizer.js +1 -1
  4. package/build/cli/class/base_command.js +14 -0
  5. package/build/cli/class/errors/file_system_errors_factory.js +1 -1
  6. package/build/cli/class/errors/http/http_errors_constants.js +1 -0
  7. package/build/cli/class/errors/{http_errors_factory.js → http/http_errors_factory.js} +3 -2
  8. package/build/cli/commands/auth/cli_auth_add_token_command.js +22 -19
  9. package/build/cli/commands/auth/cli_auth_commands_constants.js +3 -0
  10. package/build/cli/commands/auth/cli_auth_commands_utils.js +46 -0
  11. package/build/cli/commands/auth/cli_auth_list_tokens_command.js +19 -6
  12. package/build/cli/commands/auth/cli_auth_remove_token_command.js +37 -13
  13. package/build/cli/commands/auth/cli_auth_switch_token_command.js +20 -11
  14. package/build/cli/commands/auth/ui/invalid_token_index_error.js +11 -0
  15. package/build/cli/commands/auth/ui/missing_credentials_error.js +9 -0
  16. package/build/cli/commands/auth/ui/missing_token_index_error.js +19 -0
  17. package/build/cli/commands/cli_ui_dump_command.js +11 -0
  18. package/build/cli/commands/cli_update_command.js +13 -4
  19. package/build/cli/commands/commands_constants.js +6 -4
  20. package/build/cli/core/cli_setup.js +33 -14
  21. package/build/cli/features/controls/controls_constants.js +12 -0
  22. package/build/cli/features/controls/controls_dto_mappers.js +55 -0
  23. package/build/cli/features/controls/ui/controls_mappers.js +62 -0
  24. package/build/cli/features/controls/ui/form.js +4 -0
  25. package/build/cli/features/controls/ui/form_constants.js +7 -0
  26. package/build/cli/features/controls/validators/greater_eq_than_validator.js +5 -0
  27. package/build/cli/features/controls/validators/length_validator.js +6 -0
  28. package/build/cli/features/controls/validators/required_validator.js +5 -0
  29. package/build/cli/features/controls/validators/validator_constants.js +13 -0
  30. package/build/cli/features/execution_context/execution_context_service.js +5 -5
  31. package/build/cli/features/http_requester/http_requester_initializer.js +1 -1
  32. package/build/cli/hooks/authorization/ensure_authorization_hook.js +2 -2
  33. package/build/cli/hooks/authorization/ensure_authorization_hook_constants.js +7 -8
  34. package/build/index.js +37 -19
  35. package/build/theme/class/archive/theme_archive.js +44 -0
  36. package/build/theme/class/archive/theme_archive_errors_factory.js +11 -0
  37. package/build/theme/class/checksums/theme_checksums.js +170 -0
  38. package/build/theme/{features/theme/utils → class}/checksums/theme_checksums_error_factory.js +1 -1
  39. package/build/theme/class/checksums/theme_checksums_utils.js +17 -0
  40. package/build/theme/class/fetch_resources/fetch_resources.js +1 -0
  41. package/build/theme/class/fetch_resources/fetch_resources_errors_factory.js +1 -1
  42. package/build/theme/class/fetch_resources/fetch_resources_utils.js +4 -1
  43. package/build/theme/class/files_upload/theme_files_upload.js +61 -0
  44. package/build/theme/class/files_upload/theme_files_upload_http_api.js +23 -0
  45. package/build/theme/commands/delete/theme_delete_command.js +97 -0
  46. package/build/theme/commands/delete/ui/theme_deleted_successfully.js +15 -0
  47. package/build/theme/commands/delete/ui/theme_deletion_warning.js +10 -0
  48. package/build/theme/commands/info/theme_info_command.js +79 -0
  49. package/build/theme/commands/info/theme_info_command_utils.js +39 -0
  50. package/build/theme/commands/init/theme_init_command.js +84 -0
  51. package/build/theme/commands/init/ui/theme_created_success.js +15 -0
  52. package/build/theme/commands/list/theme_list_command.js +25 -0
  53. package/build/theme/commands/list/theme_list_command_utils.js +27 -0
  54. package/build/theme/commands/publish/theme_publish_command.js +76 -0
  55. package/build/theme/commands/pull/theme_pull_command.js +174 -0
  56. package/build/theme/commands/pull/ui/theme_pull_id_mismatch_error.js +7 -0
  57. package/build/theme/commands/pull/ui/theme_pull_unpublished_changes_warning.js +10 -0
  58. package/build/theme/commands/pull/ui/theme_pulled_success.js +5 -0
  59. package/build/theme/commands/push/theme_push_command.js +112 -0
  60. package/build/theme/commands/push/ui/theme_push_skip_into.js +7 -0
  61. package/build/theme/commands/push/ui/theme_pushed_success.js +5 -0
  62. package/build/theme/commands/push/ui/theme_unpermitted_actions_error.js +12 -0
  63. package/build/theme/commands/theme_commands_constants.js +9 -6
  64. package/build/theme/commands/theme_verify_command.js +64 -22
  65. package/build/theme/commands/ui/invalid_theme_id.js +11 -0
  66. package/build/theme/commands/ui/missing_theme_files.js +15 -0
  67. package/build/theme/commands/ui/missing_theme_id_error.js +13 -0
  68. package/build/theme/commands/ui/ouside_of_theme_directory_context_error.js +7 -0
  69. package/build/theme/commands/ui/theme_directory_context_error.js +7 -0
  70. package/build/theme/commands/ui/theme_error.js +29 -0
  71. package/build/theme/commands/ui/theme_work_url_mismatch.js +17 -0
  72. package/build/theme/commands/ui/unpermitted_command_error.js +18 -0
  73. package/build/theme/features/theme/actions/api/theme_actions_api.js +3 -0
  74. package/build/theme/features/theme/actions/service/theme_actions_service.js +15 -3
  75. package/build/theme/features/theme/actions/service/theme_actions_service_constants.js +1 -0
  76. package/build/theme/features/theme/actions/theme_actions_constants.js +5 -2
  77. package/build/theme/features/theme/actions/theme_actions_initializer.js +1 -1
  78. package/build/theme/features/theme/actions/theme_actions_utils.js +60 -7
  79. package/build/theme/features/theme/delete/api/theme_delete_api.js +13 -0
  80. package/build/theme/features/theme/delete/http/theme_delete_http_api.js +17 -0
  81. package/build/theme/features/theme/delete/service/theme_delete_service.js +31 -0
  82. package/build/theme/features/theme/delete/theme_delete_constants.js +2 -0
  83. package/build/theme/features/theme/delete/theme_delete_initalizer.js +20 -0
  84. package/build/theme/features/theme/fetch/service/theme_fetch_service.js +30 -10
  85. package/build/theme/features/theme/info/theme_info_utils.js +9 -0
  86. package/build/theme/features/theme/init/service/theme_init_service.js +9 -4
  87. package/build/theme/features/theme/init/theme_init_initializer.js +3 -3
  88. package/build/theme/features/theme/merge/api/theme_merge_api.js +0 -12
  89. package/build/theme/features/theme/merge/service/theme_merge_service.js +20 -28
  90. package/build/theme/features/theme/push/service/theme_push_service.js +67 -166
  91. package/build/theme/features/theme/push/theme_push_constants.js +2 -0
  92. package/build/theme/features/theme/push/theme_push_errors_factory.js +7 -4
  93. package/build/theme/features/theme/push/theme_push_initializer.js +1 -7
  94. package/build/theme/features/theme/push/theme_push_utils.js +25 -0
  95. package/build/theme/features/theme/skinstore/api/theme_skinstore_api.js +19 -0
  96. package/build/theme/features/theme/skinstore/http/theme_skinstore_http_api.js +17 -0
  97. package/build/theme/features/theme/skinstore/service/theme_skinstore_service.js +32 -0
  98. package/build/theme/features/theme/skinstore/theme_publish_constants.js +4 -0
  99. package/build/theme/features/theme/skinstore/theme_skinstore_initialzier.js +20 -0
  100. package/build/theme/features/theme/utils/files_structure/theme_file_structure_errors_factory.js +10 -0
  101. package/build/theme/features/theme/utils/files_structure/theme_files_structure_utils.js +76 -0
  102. package/build/theme/features/theme/utils/hidden_directory/hidden_directory_utils.js +32 -0
  103. package/build/theme/features/theme/utils/meta_data/theme_meta_data_constants.js +1 -0
  104. package/build/theme/features/theme/utils/meta_data/theme_meta_data_error_factory.js +15 -0
  105. package/build/theme/features/theme/utils/meta_data/theme_meta_data_utils.js +39 -0
  106. package/build/theme/features/theme/utils/{directories → resources}/theme_resources_with_id_directory_utils.js +3 -14
  107. package/build/theme/features/theme/utils/theme_images_utils.js +1 -19
  108. package/build/theme/features/theme/verify/api/theme_verify_api.js +13 -0
  109. package/build/theme/features/theme/verify/http/theme_verify_http_api.js +30 -0
  110. package/build/theme/features/theme/verify/theme_verify_constants.js +2 -0
  111. package/build/theme/features/theme/verify/theme_verify_initializer.js +19 -0
  112. package/build/theme/features/theme/verify/verify/theme_verify_service.js +55 -0
  113. package/build/theme/features/themes/list/api/themes_list_api.js +3 -0
  114. package/build/theme/features/themes/list/services/themes_list_service.js +13 -7
  115. package/build/theme/hooks/{ensure_theme_meta_data_untouched.js → ensure_theme_meta_data_untouched_hook.js} +2 -2
  116. package/build/theme/hooks/theme_checksums/ensure_theme_current_checksums_up_to_date_constants.js +1 -2
  117. 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
  118. package/build/theme/hooks/themes_actions/ensure_themes_actions_hook.js +1 -0
  119. package/build/theme/hooks/themes_actions/ensure_themes_actions_hook_constants.js +1 -1
  120. package/build/theme/index.js +34 -8
  121. package/build/theme/utils/directory_validator/directory_validator_constants.js +2 -6
  122. package/build/theme/utils/directory_validator/directory_validator_utils.js +7 -25
  123. package/build/ui/box.js +2 -0
  124. package/build/ui/color_constants.js +30 -0
  125. package/build/ui/command.js +6 -0
  126. package/build/ui/file_name.js +6 -0
  127. package/build/ui/flag.js +6 -0
  128. package/build/ui/icons/error_icon.js +7 -0
  129. package/build/ui/icons/info_icon.js +7 -0
  130. package/build/ui/icons/success_icon.js +7 -0
  131. package/build/ui/icons/warning_icon.js +7 -0
  132. package/build/ui/link.js +8 -0
  133. package/build/ui/list/list.js +10 -0
  134. package/build/ui/list/list_constants.js +4 -0
  135. package/build/ui/list/list_item.js +11 -0
  136. package/build/ui/message_box/error.js +4 -0
  137. package/build/ui/message_box/info.js +4 -0
  138. package/build/ui/message_box/message_box.js +11 -0
  139. package/build/ui/message_box/message_box_constants.js +24 -0
  140. package/build/ui/message_box/success.js +4 -0
  141. package/build/ui/message_box/warning.js +4 -0
  142. package/build/ui/prompts/prompt_confirmation.js +11 -0
  143. package/build/ui/prompts/prompt_input.js +10 -0
  144. package/build/ui/table/t_cell.js +7 -0
  145. package/build/ui/table/t_header.js +9 -0
  146. package/build/ui/table/t_row.js +5 -0
  147. package/build/ui/table/table.js +18 -0
  148. package/build/ui/text.js +2 -0
  149. package/build/ui/tip.js +9 -0
  150. package/build/ui/ui_dump/ui_component_box.js +9 -0
  151. package/build/ui/ui_dump/ui_dump.js +53 -0
  152. package/build/ui/ui_dump/ui_dump_constants.js +21 -0
  153. package/build/ui/ui_utils.js +11 -0
  154. package/build/ui/validation_errors/validation_error_content.js +19 -0
  155. package/build/ui/validation_errors/validation_errors.js +21 -0
  156. package/build/ui/validation_errors/validation_errors_utils.js +17 -0
  157. package/build/utils/checksums/checksums_utils.js +9 -26
  158. package/build/utils/download_file/download_file_errors_factory.js +1 -1
  159. package/build/utils/download_file/download_file_utils.js +4 -2
  160. package/build/utils/fs/errors/stream_read_error.js +1 -1
  161. package/build/utils/fs/errors/stream_write_error.js +1 -1
  162. package/build/utils/fs/fs_utils.js +12 -1
  163. package/build/utils/path_utils.js +18 -2
  164. package/build/utils/platform_utils.js +3 -0
  165. package/build/utils/zip/create_zip_utils.js +1 -1
  166. package/build/utils/zip/errors/create_zip_error.js +1 -1
  167. package/build/utils/zip/errors/open_zip_error.js +1 -1
  168. package/oclif.config.js +3 -3
  169. package/package.json +14 -9
  170. package/build/cli/commands/files_diff_command.js +0 -174
  171. package/build/theme/commands/theme_init_command.js +0 -53
  172. package/build/theme/commands/theme_list_command.js +0 -16
  173. package/build/theme/commands/theme_pull_command.js +0 -126
  174. package/build/theme/commands/theme_push_command.js +0 -65
  175. package/build/theme/commands/theme_show_changes_command.js +0 -60
  176. package/build/theme/features/theme/directory/theme_directory_utils.js +0 -76
  177. package/build/theme/features/theme/publish/theme_publish_constants.js +0 -2
  178. package/build/theme/features/theme/utils/checksums/theme_checksums_utils.js +0 -94
  179. /package/build/cli/{features → class}/caches/cache_factory.js +0 -0
  180. /package/build/cli/{features → class}/caches/json_cache/json_cache.js +0 -0
  181. /package/build/cli/{features → class}/caches/memory_cache.js +0 -0
  182. /package/build/cli/class/errors/{app_error → app}/app_error.js +0 -0
  183. /package/build/cli/class/errors/{app_error → app}/app_error_constants.js +0 -0
  184. /package/build/theme/features/theme/{publish → skinstore}/theme_publish_utils.js +0 -0
@@ -1,4 +1,4 @@
1
- import { AppError } from '../../../cli/class/errors/app_error/app_error.js';
1
+ import { AppError } from '../../../cli/class/errors/app/app_error.js';
2
2
  export class StreamWriteError extends AppError {
3
3
  constructor({ filePath, details, stack }) {
4
4
  super({
@@ -1,5 +1,5 @@
1
1
  import fsPromises from 'node:fs/promises';
2
- import fs, { createReadStream } from 'node:fs';
2
+ import fs, { createReadStream, readFileSync } from 'node:fs';
3
3
  import { isHiddenFile } from 'is-hidden-file';
4
4
  import process from 'node:process';
5
5
  import { basename, join, resolve } from '../path_utils.js';
@@ -39,6 +39,17 @@ export const readJSONFile = async (path, options = { encoding: 'utf-8', flag: 'r
39
39
  throw new Error(`Failed to parse JSON from file ${path}: ${error}`);
40
40
  }
41
41
  };
42
+ export const readJSONFileSync = (path, options = { encoding: 'utf-8', flag: 'r' }) => {
43
+ const fileContent = readFileSync(path, options);
44
+ if (typeof fileContent !== 'string')
45
+ throw new Error('File content is not a string');
46
+ try {
47
+ return JSON.parse(fileContent);
48
+ }
49
+ catch (error) {
50
+ throw new Error(`Failed to parse JSON from file ${path}: ${error}`);
51
+ }
52
+ };
42
53
  export const writeJSONFile = async (path, data) => {
43
54
  try {
44
55
  await writeFile(path, JSON.stringify(data, null, JSON_FILE_INDENT), {
@@ -1,5 +1,6 @@
1
- import { basename as pathBaseName, dirname as pathDirname, extname as pathExtname, join as pathJoin, normalize, parse as parsePath, relative as pathRelative, resolve as resolvePath, sep } from 'node:path';
1
+ import path, { basename as pathBaseName, dirname as pathDirname, extname as pathExtname, join as pathJoin, normalize, parse as parsePath, relative as pathRelative, resolve as resolvePath, sep } from 'node:path';
2
2
  import fs from 'node:fs';
3
+ import { isWindowsOs } from './platform_utils.js';
3
4
  export const resolve = (...paths) => {
4
5
  return resolvePath(...paths);
5
6
  };
@@ -32,6 +33,21 @@ export const looksLikeDirectory = (path) => {
32
33
  return isHidden || !hasExtension;
33
34
  };
34
35
  export const toUnixPath = (filePath) => {
35
- return normalize(filePath).replace(/\\/g, '/');
36
+ return normalize(filePath).split(sep).join(path.posix.sep);
37
+ };
38
+ export const toWinowsPath = (filePath) => {
39
+ return normalize(filePath).split(sep).join(path.win32.sep);
40
+ };
41
+ export const isUnixPath = (path) => {
42
+ return !path.includes('\\') && (path.startsWith('/') || path.includes('/'));
36
43
  };
37
44
  export const platformSeparator = sep;
45
+ export const mapKeysPathsToWindowPlatform = (paths) => {
46
+ return Object.entries(paths).reduce((acc, [path, value]) => {
47
+ return {
48
+ ...acc,
49
+ [toWinowsPath(path)]: value
50
+ };
51
+ }, {});
52
+ };
53
+ export const toCurrentPlatformPath = (path) => (isWindowsOs() ? toWinowsPath(path) : toUnixPath(path));
@@ -0,0 +1,3 @@
1
+ export const isWindowsOs = () => {
2
+ return process.platform === 'win32';
3
+ };
@@ -6,7 +6,7 @@ import { StreamReadError } from '../fs/errors/stream_read_error.js';
6
6
  import { CreateZipError } from './errors/create_zip_error.js';
7
7
  import { StreamWriteError } from '../fs/errors/stream_write_error.js';
8
8
  import { join } from '../path_utils.js';
9
- import { AppError } from '../../cli/class/errors/app_error/app_error.js';
9
+ import { AppError } from '../../cli/class/errors/app/app_error.js';
10
10
  export const createZip = async ({ files, dist, baseDir = process.cwd() }) => {
11
11
  const zipfile = new yazl.ZipFile();
12
12
  let hasError = false;
@@ -1,4 +1,4 @@
1
- import { AppError } from '../../../cli/class/errors/app_error/app_error.js';
1
+ import { AppError } from '../../../cli/class/errors/app/app_error.js';
2
2
  export class CreateZipError extends AppError {
3
3
  constructor({ details, stack, file }) {
4
4
  super({
@@ -1,4 +1,4 @@
1
- import { AppError } from '../../../cli/class/errors/app_error/app_error.js';
1
+ import { AppError } from '../../../cli/class/errors/app/app_error.js';
2
2
  export class OpenZipError extends AppError {
3
3
  constructor({ details, stack, file }) {
4
4
  super({
package/oclif.config.js CHANGED
@@ -2,7 +2,7 @@ export default {
2
2
  bin: 'shoper',
3
3
  scope: 'shoper',
4
4
  dirname: 'shoper_cli',
5
- plugins: ['@oclif/plugin-help', '@oclif/plugin-not-found', '@oclif/plugin-warn-if-update-available', '@oclif/plugin-version'],
5
+ plugins: ['@oclif/plugin-help', '@oclif/plugin-warn-if-update-available', '@oclif/plugin-version'],
6
6
  'warn-if-update-available': {
7
7
  frequency: 1,
8
8
  frequencyUnit: 'days',
@@ -18,8 +18,8 @@ export default {
18
18
  prerun: [
19
19
  './build/cli/hooks/authorization/ensure_authorization_hook.js',
20
20
  './build/cli/hooks/ensure_cli_initialized_hook.js',
21
- './build/theme/hooks/ensure_theme_meta_data_untouched.js',
22
- './build/theme/hooks/ensure_theme_current_checksums_up_to_date.js',
21
+ './build/theme/hooks/ensure_theme_meta_data_untouched_hook.js',
22
+ './build/theme/hooks/theme_checksums/ensure_theme_current_checksums_up_to_date_hook.js',
23
23
  './build/theme/hooks/themes_actions/ensure_themes_actions_hook.js'
24
24
  ]
25
25
  },
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@shoper/cli",
3
3
  "packageManager": "yarn@3.2.0",
4
4
  "sideEffects": false,
5
- "version": "0.1.0-9",
5
+ "version": "0.2.1-0",
6
6
  "description": "CLI tool for Shoper",
7
7
  "author": "Joanna Firek",
8
8
  "license": "MIT",
@@ -27,26 +27,26 @@
27
27
  "test": "jest --config config/jest/jest.config.mjs",
28
28
  "test:watch": "jest --config config/jest/jest.config.mjs --no-cache --watch",
29
29
  "deploy:latest": "npm run build && npm publish --tag latest --access public",
30
- "deploy:beta": "npm run build && npm publish --tag beta --access public"
30
+ "deploy:beta": "npm run build && npm version prerelease --no-git-tag-version && npm publish --tag beta --access public"
31
31
  },
32
32
  "dependencies": {
33
- "@dreamcommerce/star_core": "1.8.1",
33
+ "@dreamcommerce/star_core": "1.8.5",
34
+ "@dreamcommerce/utilities": "1.20.1",
34
35
  "@oclif/core": "4.2.10",
35
36
  "@oclif/plugin-autocomplete": "3.2.27",
36
37
  "@oclif/plugin-help": "6.2.27",
37
- "@oclif/plugin-not-found": "3.2.49",
38
38
  "@oclif/plugin-version": "2.2.27",
39
39
  "@oclif/plugin-warn-if-update-available": "3.1.38",
40
40
  "axios": "1.8.4",
41
41
  "chalk": "5.4.1",
42
42
  "conf": "13.1.0",
43
- "ink": "5.2.1",
43
+ "ink": "6.0.1",
44
44
  "inquirer": "12.5.2",
45
45
  "is-hidden-file": "1.1.2",
46
46
  "jsonwebtoken": "9.0.2",
47
47
  "memfs": "4.17.0",
48
48
  "ora": "8.2.0",
49
- "react": "18.3.1",
49
+ "react": "19.1.0",
50
50
  "reflect-metadata": "0.2.2",
51
51
  "rxjs": "7.8.2",
52
52
  "semver": "7.7.1",
@@ -59,19 +59,24 @@
59
59
  "walk-sync": "3.0.0",
60
60
  "lodash": "4.17.21",
61
61
  "uuid": "11.1.0",
62
- "fs-extra": "11.3.0"
62
+ "fs-extra": "11.3.0",
63
+ "ink-link": "4.1.0",
64
+ "log-symbols": "7.0.1",
65
+ "figures": "6.1.0",
66
+ "strip-ansi": "7.1.0",
67
+ "inquirer-select-line": "1.1.3"
63
68
  },
64
69
  "devDependencies": {
65
70
  "@babel/core": "7.27.1",
66
71
  "@babel/preset-env": "7.27.2",
67
72
  "@babel/preset-typescript": "7.27.1",
68
73
  "@oclif/test": "4.1.12",
69
- "@tsconfig/node18": "18.2.4",
74
+ "@tsconfig/node20": "20.1.6",
70
75
  "@types/jest": "29.5.14",
71
76
  "@types/fs-extra": "11.0.4",
72
77
  "@types/jsonwebtoken": "9.0.9",
73
78
  "@types/node": "18.19.84",
74
- "@types/react": "19.1.3",
79
+ "@types/react": "19.1.8",
75
80
  "@types/semver": "7.7.0",
76
81
  "@types/tmp": "0.2.6",
77
82
  "@types/yauzl": "2.10.3",
@@ -1,174 +0,0 @@
1
- //@ts-nocheck
2
- import { BaseCliCommand } from '../class/base_cli_command.js';
3
- import * as readline from 'node:readline/promises';
4
- import * as fs from 'node:fs';
5
- import { Args } from '@oclif/core';
6
- import process from 'node:process';
7
- import * as path from 'node:path';
8
- import { diffWords } from 'diff';
9
- export class CliFilesDiffCommand extends BaseCliCommand {
10
- static summary = 'Differentiate between two files';
11
- static args = {
12
- file1: Args.string({
13
- name: 'file1',
14
- required: true,
15
- description: 'First file to compare',
16
- type: 'string'
17
- }),
18
- file2: Args.string({
19
- name: 'file2',
20
- required: true,
21
- description: 'Second file to compare',
22
- type: 'string'
23
- })
24
- };
25
- async run() {
26
- const { args } = await this.parse(CliFilesDiffCommand);
27
- const inputAPath = args.file1;
28
- const inputBPath = args.file2;
29
- return new Promise((resolve, reject) => {
30
- Promise.all([readLines(inputAPath), readLines(inputBPath)]).then((result) => {
31
- const [aLines, bLines] = result;
32
- // console.log('aLines', aLines);
33
- // console.log('bLines', bLines);
34
- merge(aLines, bLines);
35
- resolve();
36
- });
37
- // aStream.on('line', (input) => {
38
- // console.log('aStream line: ', input);
39
- // });
40
- //
41
- // bStream.on('line', (input) => {
42
- // console.log('bStream line: ', input);
43
- // });
44
- });
45
- }
46
- }
47
- const readLines = async (filePath) => {
48
- return new Promise((resolve, reject) => {
49
- const lines = [];
50
- const inputStream = readline.createInterface({
51
- input: fs.createReadStream(path.resolve(process.cwd(), filePath)),
52
- crlfDelay: Infinity
53
- });
54
- inputStream.on('line', (line) => {
55
- lines.push(line);
56
- });
57
- inputStream.on('close', () => {
58
- resolve(lines);
59
- });
60
- inputStream.on('error', (err) => {
61
- reject(err);
62
- });
63
- });
64
- };
65
- const merge = (aLines, bLines) => {
66
- let hasConflict = false;
67
- const maxLength = Math.max(aLines.length, bLines.length);
68
- const outputPath = path.resolve(process.cwd(), 'merge.txt');
69
- const outStream = fs.createWriteStream(outputPath, { encoding: 'utf8' });
70
- for (let i = 0; i < maxLength; i++) {
71
- const a = aLines[i] ?? '';
72
- const b = bLines[i] ?? '';
73
- if (a === b) {
74
- outStream.write(a + '\n');
75
- }
76
- else {
77
- hasConflict = true;
78
- console.log('⚠️ Conflict detected:');
79
- console.log('a:', a);
80
- console.log('b:', b);
81
- const { aFormatted, bFormatted } = formatWordDiff(a, b);
82
- console.log('aFormatted', aFormatted);
83
- console.log('bFormatted', bFormatted);
84
- outStream.write('<<<<<<< mine\n');
85
- outStream.write(aFormatted + '\n');
86
- outStream.write('=======\n');
87
- outStream.write(bFormatted + '\n');
88
- outStream.write('>>>>>>> theirs\n');
89
- }
90
- }
91
- outStream.end();
92
- outStream.on('finish', () => {
93
- if (hasConflict) {
94
- console.log('⚠️ Conflicts detected. Check', outputPath);
95
- }
96
- else {
97
- console.log('✅ Merged with no conflicts. Output written to', outputPath);
98
- }
99
- });
100
- };
101
- function formatWordDiff(aLine, bLine) {
102
- const changes = diffWords(aLine, bLine);
103
- const aFormatted = changes.map((part) => (part.added ? '' : part.value)).join('');
104
- const bFormatted = changes.map((part) => (part.removed ? '' : part.value)).join('');
105
- return {
106
- aFormatted: aFormatted.trimEnd(),
107
- bFormatted: bFormatted.trimEnd()
108
- };
109
- }
110
- // const fs = require('fs');
111
- // const path = require('path');
112
- // const readline = require('readline');
113
- // const Diff = require('diff');
114
- //
115
- // async function mergeWithCommentsStream(fileAPath, fileBPath, outputPath) {
116
- // const textA = await fs.promises.readFile(fileAPath, 'utf8');
117
- // const textB = await fs.promises.readFile(fileBPath, 'utf8');
118
- //
119
- // const diffs = Diff.diffLines(textA, textB);
120
- // const outputStream = fs.createWriteStream(outputPath, { encoding: 'utf8' });
121
- //
122
- // let currentState = 'equal'; // 'equal' | 'added' | 'removed'
123
- //
124
- // for (const part of diffs) {
125
- // const lines = part.value.endsWith('\n') ? part.value.slice(0, -1).split('\n') : part.value.split('\n');
126
- //
127
- // if (part.added) {
128
- // if (currentState !== 'added') {
129
- // outputStream.write('added >>>>>\n');
130
- // currentState = 'added';
131
- // }
132
- // for (const line of lines) {
133
- // outputStream.write(line + '\n');
134
- // }
135
- // } else if (part.removed) {
136
- // if (currentState !== 'removed') {
137
- // outputStream.write('removed >>>>>\n');
138
- // currentState = 'removed';
139
- // }
140
- // for (const line of lines) {
141
- // outputStream.write(line + '\n');
142
- // }
143
- // } else {
144
- // // Close any previous block
145
- // if (currentState === 'added') {
146
- // outputStream.write('end-added >>>\n');
147
- // } else if (currentState === 'removed') {
148
- // outputStream.write('end-removed >>>\n');
149
- // }
150
- // currentState = 'equal';
151
- //
152
- // for (const line of lines) {
153
- // outputStream.write(line + '\n');
154
- // }
155
- // }
156
- // }
157
- //
158
- // // Final cleanup in case the last block was added/removed
159
- // if (currentState === 'added') {
160
- // outputStream.write('end-added >>>\n');
161
- // } else if (currentState === 'removed') {
162
- // outputStream.write('end-removed >>>\n');
163
- // }
164
- //
165
- // outputStream.end();
166
- // console.log(`✅ Merge complete. Output written to: ${outputPath}`);
167
- // }
168
- //
169
- // // Example usage
170
- // const fileA = path.resolve('versionA.txt');
171
- // const fileB = path.resolve('versionB.txt');
172
- // const outputFile = path.resolve('mergedWithComments.txt');
173
- //
174
- // mergeWithCommentsStream(fileA, fileB, outputFile);
@@ -1,53 +0,0 @@
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_ACTIONS_API_NAME, THEME_ACTIONS_TYPES } from '../features/theme/actions/theme_actions_constants.js';
8
- export class ThemeInitCommand extends BaseThemeCommand {
9
- static description = 'Clone a theme with provided ID from the shop';
10
- static args = {
11
- id: Args.string({
12
- description: 'Theme id',
13
- name: 'id',
14
- required: true,
15
- type: 'string'
16
- })
17
- };
18
- async run() {
19
- const data = await this.parse(ThemeInitCommand);
20
- const { args } = data;
21
- const themeId = args.id;
22
- const cliAuthApi = this.getApi(CLI_AUTH_API_NAME);
23
- const themeInitApi = this.getApi(THEME_INIT_API_NAME);
24
- const themeActionsApi = this.getApi(THEME_ACTIONS_API_NAME);
25
- const executionContextApi = this.getApi(EXECUTION_CONTEXT_API_NAME);
26
- const credentials = cliAuthApi.getCredentials();
27
- if (!credentials)
28
- this.error('Credentials not found. Please authorize first.');
29
- const copyAction = themeActionsApi.getThemeAction({
30
- actionType: THEME_ACTIONS_TYPES.copy,
31
- themeId,
32
- credentials
33
- });
34
- if (!copyAction)
35
- this.error(`You cannot init theme with id ${themeId}`);
36
- const executionContext = await executionContextApi.getExecutionContext();
37
- if (executionContext.type === EXECUTION_CONTEXTS.theme)
38
- this.error('You cannot run this command in the theme execution context');
39
- const spinner = ora('Creating theme...').start();
40
- try {
41
- await themeInitApi.initTheme({ action: copyAction, credentials });
42
- spinner.stopAndPersist({
43
- symbol: '\u2713',
44
- text: 'Theme successfully created!'
45
- });
46
- }
47
- catch (err) {
48
- // TODO handle error
49
- spinner.clear();
50
- this.error(String(err));
51
- }
52
- }
53
- }
@@ -1,16 +0,0 @@
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
- export class ThemeListCommand extends BaseThemeCommand {
5
- static description = 'List all shop themes';
6
- async run() {
7
- const ThemesListApi = this.getApi(THEMES_LIST_API_NAME);
8
- const cliAuthApi = this.getApi(CLI_AUTH_API_NAME);
9
- const credentials = cliAuthApi.getCredentials();
10
- if (!credentials)
11
- this.error('Credentials not found. Please authorize first.');
12
- const themes = await ThemesListApi.getThemes(credentials);
13
- //TODO UI
14
- this.log('themes', themes);
15
- }
16
- }
@@ -1,126 +0,0 @@
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 inquirer from 'inquirer';
7
- import ora from 'ora';
8
- import { THEME_MERGE_API_NAME } from '../features/theme/merge/theme_merge_constants.js';
9
- import tmp from 'tmp-promise';
10
- import { join } from '../../utils/path_utils.js';
11
- import { THEME_ACTIONS_API_NAME, THEME_ACTIONS_TYPES } from '../features/theme/actions/theme_actions_constants.js';
12
- import process from 'node:process';
13
- import { ThemeResourcesWithIdDirectoryUtils } from '../features/theme/utils/directories/theme_resources_with_id_directory_utils.js';
14
- export class ThemePullCommand extends BaseThemeCommand {
15
- static description = 'Pull theme from shop';
16
- static args = {
17
- id: Args.string({
18
- description: 'Theme id',
19
- name: 'id',
20
- type: 'string'
21
- })
22
- };
23
- static flags = {
24
- type: Flags.string({
25
- default: THEME_FETCH_TYPES.full,
26
- description: 'Type of theme to pull',
27
- options: Object.values(THEME_FETCH_TYPES)
28
- })
29
- };
30
- async run() {
31
- const data = await this.parse(ThemePullCommand);
32
- const { args, flags } = data;
33
- const themeId = args.id;
34
- const cliAuthApi = this.getApi(CLI_AUTH_API_NAME);
35
- const themeFetchApi = this.getApi(THEME_FETCH_API_NAME);
36
- const executionContextApi = this.getApi(EXECUTION_CONTEXT_API_NAME);
37
- const themeActionsApi = this.getApi(THEME_ACTIONS_API_NAME);
38
- const credentials = cliAuthApi.getCredentials();
39
- if (!credentials)
40
- this.error('Credentials not found. Please authorize first.');
41
- const executionContext = await executionContextApi.getExecutionContext();
42
- const spinner = ora('Pulling theme...').start();
43
- try {
44
- if (executionContext.type !== EXECUTION_CONTEXTS.theme) {
45
- if (themeId === undefined)
46
- this.error('To run this command outside theme context you must provide theme id.');
47
- const pullAction = themeActionsApi.getThemeAction({
48
- actionType: THEME_ACTIONS_TYPES.pull,
49
- themeId: themeId,
50
- credentials
51
- });
52
- await themeFetchApi.fetchTheme({
53
- credentials,
54
- action: pullAction,
55
- config: {
56
- dist: process.cwd(),
57
- fetchType: flags.type
58
- }
59
- });
60
- spinner.stopAndPersist({
61
- symbol: '\u2713',
62
- text: 'Theme successfully pulled!'
63
- });
64
- return;
65
- }
66
- const _themeId = themeId ? themeId : executionContext.themeId;
67
- const pullAction = themeActionsApi.getThemeAction({
68
- actionType: THEME_ACTIONS_TYPES.pull,
69
- themeId: _themeId,
70
- credentials
71
- });
72
- if (executionContext.themeId !== _themeId) {
73
- this.error('You cannot pull a theme in the theme execution context that is not the current theme.');
74
- }
75
- const themeMergeApi = this.getApi(THEME_MERGE_API_NAME);
76
- const { path: tmpDir } = await tmp.dir({ unsafeCleanup: true });
77
- const { name } = await themeFetchApi.fetchTheme({
78
- credentials,
79
- action: pullAction,
80
- config: {
81
- fetchType: flags.type,
82
- dist: tmpDir
83
- }
84
- });
85
- await ThemeResourcesWithIdDirectoryUtils.updateDirectoryNamesOfResourcesWithIdAccordingToLocalThemeNames(join(executionContext.themeRootDir, 'modules'), executionContext.themeRootDir, join(tmpDir, name, 'modules'), join(tmpDir, name));
86
- spinner.stopAndPersist({
87
- symbol: '\u2713',
88
- text: 'Theme successfully pulled!'
89
- });
90
- this.log('\n');
91
- const changes = await themeMergeApi.getChangesBetweenThemes(join(tmpDir, name), executionContext.themeRootDir);
92
- console.log('changes', changes);
93
- console.log('is modified', await themeMergeApi.hasThemeBeenModified(executionContext.themeRootDir));
94
- if (await themeMergeApi.hasThemeBeenModified(executionContext.themeRootDir)) {
95
- console.log('changes', changes);
96
- this.log('You have unpublished changes in your theme...\n');
97
- this.log('The following files will be changed:\n');
98
- changes.forEach(([action, name]) => {
99
- console.log(name, ' - ', action);
100
- });
101
- console.log('\n');
102
- const { proceed } = await inquirer.prompt([
103
- {
104
- type: 'confirm',
105
- name: 'proceed',
106
- message: 'Do you want to continue and overwrite local changes?',
107
- default: true
108
- }
109
- ]);
110
- if (!proceed)
111
- this.log('Pull operation cancelled. Your local changes are safe.');
112
- }
113
- try {
114
- await themeMergeApi.applyChanges(join(tmpDir, name), executionContext.themeRootDir, changes);
115
- }
116
- catch (err) {
117
- console.log('err', err);
118
- }
119
- }
120
- catch (err) {
121
- // TODO handle error
122
- spinner.clear();
123
- this.error(String(err));
124
- }
125
- }
126
- }
@@ -1,65 +0,0 @@
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_ACTIONS_API_NAME, THEME_ACTIONS_TYPES } from '../features/theme/actions/theme_actions_constants.js';
5
- import { THEME_PUSH_API_NAME } from '../features/theme/push/theme_push_constants.js';
6
- import { ThemeDirectoryUtils } from '../features/theme/directory/theme_directory_utils.js';
7
- import { mapChecksumToTree } from '../../utils/checksums/checksums_utils.js';
8
- import { mapToPermissionsTree } from '../utils/directory_validator/directory_validator_utils.js';
9
- import { ThemeChecksumsUtils } from '../features/theme/utils/checksums/theme_checksums_utils.js';
10
- export class ThemePushCommand extends BaseThemeCommand {
11
- static description = 'Upload theme files to the shop';
12
- async run() {
13
- const cliAuthApi = this.getApi(CLI_AUTH_API_NAME);
14
- const themePushApi = this.getApi(THEME_PUSH_API_NAME);
15
- const themeActionsApi = this.getApi(THEME_ACTIONS_API_NAME);
16
- const executionContextApi = this.getApi(EXECUTION_CONTEXT_API_NAME);
17
- const credentials = cliAuthApi.getCredentials();
18
- if (!credentials)
19
- this.error('Credentials not found. Please authorize first.');
20
- const executionContext = await executionContextApi.getExecutionContext();
21
- if (executionContext.type !== EXECUTION_CONTEXTS.theme)
22
- this.error('You cannot run this command outside theme context.');
23
- const pushAction = themeActionsApi.getThemeAction({
24
- actionType: THEME_ACTIONS_TYPES.push,
25
- themeId: executionContext.themeId,
26
- credentials
27
- });
28
- if (!pushAction)
29
- this.error(`You cannot push theme with id ${executionContext.themeId}`);
30
- const checksums = await ThemeChecksumsUtils.getThemeCurrentChecksums(executionContext.themeRootDir);
31
- const permissions = await ThemeDirectoryUtils.getFilesPermissions(executionContext.themeRootDir);
32
- if (!checksums || !permissions)
33
- this.error('Theme checksums or permissions not found. Please ensure you are in the correct theme directory.');
34
- try {
35
- const validationResult = await ThemeDirectoryUtils.validateThemeDirectoryStructure({
36
- checksums: mapChecksumToTree(checksums),
37
- permissions: mapToPermissionsTree(permissions),
38
- rootDirectory: executionContext.themeRootDir
39
- });
40
- //TODO jak wysyla folder z nazwa posiadajaco \ na windows, wychodzimy
41
- //TODO validacja folderów przed pushem
42
- if (!validationResult.isValid) {
43
- validationResult.unpermittedActions.forEach((unpermittedAction) => {
44
- console.log('Unpermitted action:', unpermittedAction.type, unpermittedAction.path);
45
- });
46
- return;
47
- }
48
- const filesStructure = await ThemeDirectoryUtils.getThemeFilesStructure(executionContext.themeRootDir);
49
- if (!filesStructure)
50
- this.error('Theme files structure not found. Please ensure you are in the correct theme directory.');
51
- await themePushApi.push({
52
- credentials,
53
- checksums,
54
- filesStructure,
55
- pushAction,
56
- executionContext
57
- });
58
- console.log('Theme pushed successfully!');
59
- }
60
- catch (err) {
61
- console.log(err);
62
- this.error(`Failed to push theme: ${err instanceof Error ? err.message : String(err)}`);
63
- }
64
- }
65
- }