@shoper/cli 0.1.0-33 → 0.1.0-34

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.
@@ -15,6 +15,7 @@ import { ThemeMergeInitializer } from '../../theme/features/theme/merge/theme_me
15
15
  import { ThemeActionsInitializer } from '../../theme/features/theme/actions/theme_actions_initializer.js';
16
16
  import { ThemePushInitializer } from '../../theme/features/theme/push/theme_push_initializer.js';
17
17
  import { ThemeDeleteInitializer } from '../../theme/features/theme/delete/theme_delete_initalizer.js';
18
+ import { ThemeSkinstoreInitializer } from '../../theme/features/theme/skinstore/theme_skinstore_initialzier.js';
18
19
  tmp.setGracefulCleanup();
19
20
  export const cliSetup = async () => {
20
21
  //TODO jakis ładny komuniakt błedu
@@ -36,7 +37,8 @@ export const cliSetup = async () => {
36
37
  ThemeMergeInitializer,
37
38
  ThemeFetchInitializer,
38
39
  ThemePushInitializer,
39
- ThemeDeleteInitializer
40
+ ThemeDeleteInitializer,
41
+ ThemeSkinstoreInitializer
40
42
  ],
41
43
  options: {
42
44
  featuresTracking: false,
@@ -0,0 +1,77 @@
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 } 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
+ export class ThemePublishCommand extends BaseThemeCommand {
15
+ static summary = 'Permanently deletes the specified theme from your store.';
16
+ 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).';
17
+ static examples = [
18
+ {
19
+ description: 'This will delete the theme with ID 123 permanently from your store. Make sure you have a backup if needed.',
20
+ command: '<%= config.bin %> <%= command.id %> 123'
21
+ }
22
+ ];
23
+ static hidden = true;
24
+ static args = {
25
+ id: Args.string({
26
+ description: 'Theme id',
27
+ name: 'id',
28
+ required: false,
29
+ type: 'string'
30
+ })
31
+ };
32
+ async run() {
33
+ const data = await this.parse(ThemePublishCommand);
34
+ const { args } = data;
35
+ const themeId = args.id;
36
+ const cliAuthApi = this.getApi(CLI_AUTH_API_NAME);
37
+ const executionContextApi = this.getApi(EXECUTION_CONTEXT_API_NAME);
38
+ const credentials = cliAuthApi.getCredentials();
39
+ if (!credentials) {
40
+ renderOnce(React.createElement(MissingCredentialsError, null));
41
+ return;
42
+ }
43
+ const executionContext = await executionContextApi.getExecutionContext();
44
+ try {
45
+ let _themeId = themeId;
46
+ if (executionContext.type !== EXECUTION_CONTEXTS.theme && !_themeId) {
47
+ return;
48
+ }
49
+ if (executionContext.type === EXECUTION_CONTEXTS.theme) {
50
+ _themeId = _themeId ?? executionContext.themeId;
51
+ }
52
+ if (!_themeId) {
53
+ renderOnce(React.createElement(MissingThemeIdError, null));
54
+ return;
55
+ }
56
+ const themeSkinstoreApi = this.getApi(THEME_SKINSTORE_API_NAME);
57
+ const formData = await themeSkinstoreApi.getPublishFormData();
58
+ console.log('formData', formData);
59
+ }
60
+ catch (err) {
61
+ this._handleError(err, themeId);
62
+ return;
63
+ }
64
+ }
65
+ _handleError(err, themeId) {
66
+ if (err?.code === THEME_ACTION_NOT_FOUND_ERROR_CODE && themeId) {
67
+ renderOnce(React.createElement(UnpermittedCommandError, { themeId: themeId, commandName: "delete" }));
68
+ return;
69
+ }
70
+ if (err?.message) {
71
+ renderOnce(React.createElement(Error, null,
72
+ React.createElement(Text, null, err.message)));
73
+ return;
74
+ }
75
+ this.error(String(err));
76
+ }
77
+ }
@@ -171,11 +171,13 @@ export class ThemePullCommand extends BaseThemeCommand {
171
171
  dist: tmpDir
172
172
  }
173
173
  });
174
- const themeModulesPath = join(executionContext.themeRootDir, 'modules');
175
- if (await directoryExists(themeModulesPath))
176
- await ThemeResourcesWithIdDirectoryUtils.updateDirectoryNamesOfResourcesWithIdAccordingToLocalThemeNames(themeModulesPath, join(tmpDir, name, 'modules'), join(tmpDir, name));
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);
177
179
  this.#spinner.stop();
178
- const changes = await themeMergeApi.getChangesBetweenThemes(join(tmpDir, name), executionContext.themeRootDir);
180
+ const changes = await themeMergeApi.getChangesBetweenThemes(fetchedThemePath, executionContext.themeRootDir);
179
181
  const themeChecksums = new ThemeChecksums(executionContext.themeRootDir);
180
182
  if (changes.length && (await themeChecksums.hasThemeBeenModified())) {
181
183
  renderOnce(React.createElement(ThemePullUnpublishedChangesWarning, { changes: changes }));
@@ -6,5 +6,6 @@ export const THEME_COMMANDS_NAME = {
6
6
  showChanges: 'theme:show-changes',
7
7
  verify: 'theme:verify',
8
8
  info: 'theme:info',
9
- delete: 'theme:delete'
9
+ delete: 'theme:delete',
10
+ publish: 'theme:publish'
10
11
  };
@@ -1,8 +1,10 @@
1
1
  import FSTree from 'fs-tree-diff';
2
2
  import { copyFileSync, getAllDirectoriesNamesInside } from '../../../../../utils/fs/fs_utils.js';
3
3
  import walkSync from 'walk-sync';
4
- import { SHOPER_THEME_METADATA_DIR } from '../../../../constants/directory_contstants.js';
5
4
  import { ThemeChecksums } from '../../../../class/checksums/theme_checksums.js';
5
+ import { ThemeFilesStructureUtils } from '../../utils/files_structure/theme_files_structure_utils.js';
6
+ import { SHOPER_THEME_METADATA_DIR } from '../../../../constants/directory_contstants.js';
7
+ import { join, platformSeparator } from '../../../../../utils/path_utils.js';
6
8
  export class ThemeMergeService {
7
9
  async applyChanges(fromTheme, toTheme, changes) {
8
10
  FSTree.applyPatch(fromTheme, toTheme, changes, {
@@ -24,10 +26,7 @@ export class ThemeMergeService {
24
26
  });
25
27
  const theme1Checksums = new ThemeChecksums(theme1);
26
28
  const theme2Checksums = new ThemeChecksums(theme2);
27
- const rootDirectories = await getAllDirectoriesNamesInside(theme1, {
28
- recursive: false,
29
- hidden: true
30
- });
29
+ const userDirectories = await this._getUserRootDirectories(theme2);
31
30
  return theme2Tree
32
31
  .calculatePatch(theme1Tree, (entryA, entryB) => {
33
32
  if (entryA.isDirectory() && entryB.isDirectory())
@@ -36,7 +35,14 @@ export class ThemeMergeService {
36
35
  theme2Checksums.getCurrentChecksumFromPathSync(entryB.relativePath));
37
36
  })
38
37
  .filter(([_, name]) => {
39
- return !name.startsWith(SHOPER_THEME_METADATA_DIR) && rootDirectories.some((rootDir) => name.startsWith(rootDir));
38
+ return !name.startsWith(SHOPER_THEME_METADATA_DIR) && !userDirectories.some((userDir) => name.startsWith(userDir));
40
39
  });
41
40
  }
41
+ async _getUserRootDirectories(themeDir) {
42
+ const filesStructure = await ThemeFilesStructureUtils.getThemeRootDirectories(themeDir);
43
+ return (await getAllDirectoriesNamesInside(themeDir, {
44
+ recursive: false,
45
+ hidden: true
46
+ })).filter((directory) => !filesStructure.includes(join(directory, platformSeparator)));
47
+ }
42
48
  }
@@ -1,5 +1,7 @@
1
1
  import { FeatureApi } from '@dreamcommerce/star_core';
2
+ import { THEME_SKINSTORE_API_NAME } from '../theme_publish_constants.js';
2
3
  export class ThemeSkinstoreApi extends FeatureApi {
4
+ moduleName = THEME_SKINSTORE_API_NAME;
3
5
  #service;
4
6
  constructor(service) {
5
7
  super();
@@ -1,2 +1,4 @@
1
1
  export const THEME_SKINSTORE_LOCATION = 'skinstore';
2
2
  export const THEME_SKINSTORE_SETTINGS_FILE_NAME = 'settings.json';
3
+ export const THEME_SKINSTORE_API_NAME = 'ThemeSkinstoreApi';
4
+ export const THEME_SKINSTORE_FEATURE_NAME = 'ThemeSkinstore';
@@ -0,0 +1,20 @@
1
+ import { FEATURE_CORES_TYPES, HTTP_REQUESTER_API_NAME, SyncFeatureInitializer } from '@dreamcommerce/star_core';
2
+ import { THEME_SKINSTORE_FEATURE_NAME } from './theme_publish_constants.js';
3
+ import { ThemeSkinstoreService } from './service/theme_skinstore_service.js';
4
+ import { ThemeSkinstoreHttpApi } from './http/theme_skinstore_http_api.js';
5
+ import { ThemeSkinstoreApi } from './api/theme_skinstore_api.js';
6
+ export class ThemeSkinstoreInitializer extends SyncFeatureInitializer {
7
+ static featureName = THEME_SKINSTORE_FEATURE_NAME;
8
+ init() {
9
+ const httpApi = this.getApiSync(HTTP_REQUESTER_API_NAME);
10
+ const service = new ThemeSkinstoreService(new ThemeSkinstoreHttpApi(httpApi));
11
+ return {
12
+ cores: [
13
+ {
14
+ type: FEATURE_CORES_TYPES.api,
15
+ instance: new ThemeSkinstoreApi(service)
16
+ }
17
+ ]
18
+ };
19
+ }
20
+ }
@@ -1,5 +1,5 @@
1
1
  import { readJSONFile, writeJSONFile } from '../../../../../utils/fs/fs_utils.js';
2
- import { join, mapKeysPathsToWindowPlatform } from '../../../../../utils/path_utils.js';
2
+ import { join, looksLikeDirectory, mapKeysPathsToWindowPlatform } from '../../../../../utils/path_utils.js';
3
3
  import { SHOPER_THEME_METADATA_DIR } from '../../../../constants/directory_contstants.js';
4
4
  import { THEME_FILES_STRUCTURE_FILE_NAME } from '../../theme_constants.js';
5
5
  import { isWindowsOs } from '../../../../../utils/platform_utils.js';
@@ -31,4 +31,10 @@ export class ThemeFilesStructureUtils {
31
31
  rootDirectory
32
32
  });
33
33
  }
34
+ static async getThemeRootDirectories(themeDirectory) {
35
+ const filesStructure = await ThemeFilesStructureUtils.getThemeFilesStructure(themeDirectory);
36
+ return Object.keys(filesStructure).filter((path) => {
37
+ return looksLikeDirectory(path);
38
+ });
39
+ }
34
40
  }
@@ -3,7 +3,7 @@ import walkSync from 'walk-sync';
3
3
  import { THEME_FILES_OPERATIONS } from '../../merge/theme_merge_constants.js';
4
4
  import { fileExists, readJSONFile, renameFile } from '../../../../../utils/fs/fs_utils.js';
5
5
  import { join } from '../../../../../utils/path_utils.js';
6
- import { ThemeChecksums } from '../../../../../theme/class/checksums/theme_checksums.js';
6
+ import { ThemeChecksums } from '../../../../class/checksums/theme_checksums.js';
7
7
  export class ThemeResourcesWithIdDirectoryUtils {
8
8
  static async updateDirectoryNamesOfResourcesWithIdAccordingToLocalThemeNames(localResourcesDir, remoteResourcesDir, remoteThemeDir) {
9
9
  const localThemeTree = new FSTree({
@@ -7,6 +7,7 @@ import { ThemeShowChangesCommand } from './commands/theme_show_changes_command.j
7
7
  import { ThemeVerifyCommand } from './commands/theme_verify_command.js';
8
8
  import { ThemeInfoCommand } from './commands/info/theme_info_command.js';
9
9
  import { ThemeDeleteCommand } from './commands/delete/theme_delete_command.js';
10
+ import { ThemePublishCommand } from './commands/publish/theme_publish_command.js';
10
11
  export const COMMANDS = {
11
12
  [THEME_COMMANDS_NAME.list]: ThemeListCommand,
12
13
  [THEME_COMMANDS_NAME.pull]: ThemePullCommand,
@@ -15,5 +16,6 @@ export const COMMANDS = {
15
16
  [THEME_COMMANDS_NAME.showChanges]: ThemeShowChangesCommand,
16
17
  [THEME_COMMANDS_NAME.verify]: ThemeVerifyCommand,
17
18
  [THEME_COMMANDS_NAME.info]: ThemeInfoCommand,
18
- [THEME_COMMANDS_NAME.delete]: ThemeDeleteCommand
19
+ [THEME_COMMANDS_NAME.delete]: ThemeDeleteCommand,
20
+ [THEME_COMMANDS_NAME.publish]: ThemePublishCommand
19
21
  };
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-33",
5
+ "version": "0.1.0-34",
6
6
  "description": "CLI tool for Shoper",
7
7
  "author": "Joanna Firek",
8
8
  "license": "MIT",
@@ -30,7 +30,7 @@
30
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.2-3",
33
+ "@dreamcommerce/star_core": "1.8.5",
34
34
  "@oclif/core": "4.2.10",
35
35
  "@oclif/plugin-autocomplete": "3.2.27",
36
36
  "@oclif/plugin-help": "6.2.27",