@shoper/cli 0.5.1-0 → 0.5.1-1

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.
@@ -14,7 +14,6 @@ import { MissingCredentialsError } from '../../../cli/commands/auth/ui/missing_c
14
14
  import { ThemePushedSuccess } from './ui/theme_pushed_success.js';
15
15
  import ora from 'ora';
16
16
  import { ThemePushSkipInfo } from './ui/theme_push_skip_into.js';
17
- import { ThemeUnpermittedActionsError } from './ui/theme_unpermitted_actions_error.js';
18
17
  import { ThemeFilesStructureUtils } from '../../features/theme/utils/files_structure/theme_files_structure_utils.js';
19
18
  import { ThemeInfoUtils } from '../../features/theme/info/theme_info_utils.js';
20
19
  import { ThemeChecksums } from '../../class/checksums/theme_checksums.js';
@@ -25,6 +24,7 @@ import { MissingThemeFiles } from '../ui/missing_theme_files.js';
25
24
  import { SHOPER_THEME_METADATA_DIR } from '../../constants/directory_contstants.js';
26
25
  import { THEME_FILES_STRUCTURE_FILE_NAME } from '../../features/theme/theme_constants.js';
27
26
  import { ThemeError } from '../ui/theme_error.js';
27
+ import { ThemeUnpermittedActionsError } from './ui/theme_unpermitted_actions_error.js';
28
28
  export class ThemePushCommand extends BaseThemeCommand {
29
29
  static summary = 'Uploads your local theme files to the store and overwrites the current version of the theme in your store.';
30
30
  static description = 'Check your local changes before pushing.\n\nYou must run this command from a specific theme directory (ID not needed).';
@@ -3,19 +3,14 @@ import { THEME_FETCH_TYPES } from '../theme_fetch_constants.js';
3
3
  import { downloadFile } from '../../../../../utils/download_file/download_file_utils.js';
4
4
  import { extractZip } from '../../../../../utils/zip/extract_zip_utils.js';
5
5
  import { join } from '../../../../../utils/path_utils.js';
6
- import { SHOPER_THEME_METADATA_DIR } from '../../../../constants/directory_contstants.js';
7
6
  import { getResources, mapResourcesToTree, removeOldResources } from '../../../../class/fetch_resources/fetch_resources_utils.js';
8
7
  import { FetchResources } from '../../../../class/fetch_resources/fetch_resources.js';
9
8
  import { jsonIndentTransform } from '../../../../../utils/stream_transforms/json_indent_transform.js';
10
- import { THEME_CURRENT_CHECKSUMS_FILE_NAME, THEME_CURRENT_CHECKSUMS_VERITY_FILE_NAME, THEME_INITIAL_CHECKSUMS_FILE_NAME, THEME_INITIAL_CHECKSUMS_VERITY_FILE_NAME } from '../../theme_constants.js';
11
- import { THEME_FILES_LIST_FILE_NAME } from '../../push/theme_push_constants.js';
12
9
  import { JSON_FILE_INDENT } from '../../../../../cli/cli_constants.js';
13
- import { createWriteStream } from 'node:fs';
14
10
  import { AppError } from '../../../../../cli/class/errors/app/app_error.js';
15
- import { THEME_ACTIONS_TYPES } from '../../actions/theme_actions_constants.js';
16
11
  import { ThemeFilesStructureUtils } from '../../utils/files_structure/theme_files_structure_utils.js';
17
- import { ThemeMetaDataUtils } from '../../utils/meta_data/theme_meta_data_utils.js';
18
12
  import { ThemeChecksums } from '../../../../class/checksums/theme_checksums.js';
13
+ import { ThemeMetaDataUtils } from '../../utils/meta_data/theme_meta_data_utils.js';
19
14
  export class ThemeFetchService {
20
15
  #themeHttpApi;
21
16
  #httpApi;
@@ -44,7 +39,7 @@ export class ThemeFetchService {
44
39
  await this.fetchResources(shopUrl, themeDir, resources);
45
40
  }
46
41
  try {
47
- await this._updateFilesStructure(themeDir);
42
+ await ThemeFilesStructureUtils.updateFilesStructure(themeDir);
48
43
  }
49
44
  catch (err) {
50
45
  throw new AppError({
@@ -53,8 +48,8 @@ export class ThemeFetchService {
53
48
  stack: err.stack
54
49
  });
55
50
  }
56
- await this._createGitIgnoreFile(themeDir);
57
- await this._updateMetadataFileWithWorkUrl(themeDir, credentials.shopUrl);
51
+ await ThemeMetaDataUtils.createGitIgnoreFile(themeDir);
52
+ await ThemeMetaDataUtils.updateMetadataFileWithWorkUrl(themeDir, credentials.shopUrl);
58
53
  /**
59
54
  * moze to nie powinno lezec tutaj :?
60
55
  */
@@ -63,49 +58,6 @@ export class ThemeFetchService {
63
58
  name: basename
64
59
  };
65
60
  }
66
- async _updateFilesStructure(themeDir) {
67
- const fileStructure = await ThemeFilesStructureUtils.getThemeFilesStructure(themeDir);
68
- const checksumsFiles = [
69
- `${SHOPER_THEME_METADATA_DIR}/${THEME_INITIAL_CHECKSUMS_FILE_NAME}`,
70
- `${SHOPER_THEME_METADATA_DIR}/${THEME_INITIAL_CHECKSUMS_VERITY_FILE_NAME}`,
71
- `${SHOPER_THEME_METADATA_DIR}/${THEME_CURRENT_CHECKSUMS_FILE_NAME}`,
72
- `${SHOPER_THEME_METADATA_DIR}/${THEME_CURRENT_CHECKSUMS_VERITY_FILE_NAME}`
73
- ];
74
- checksumsFiles.forEach((file) => {
75
- fileStructure[file] = {
76
- permissions: {
77
- canAdd: true,
78
- canEdit: true,
79
- canDelete: false
80
- }
81
- };
82
- });
83
- fileStructure[THEME_FILES_LIST_FILE_NAME] = {
84
- permissions: {
85
- canAdd: true,
86
- canEdit: true,
87
- canDelete: true
88
- },
89
- _links: { [THEME_ACTIONS_TYPES.push]: '*' }
90
- };
91
- ['.gitignore'].forEach((fileName) => {
92
- fileStructure[fileName] = {
93
- permissions: {
94
- canAdd: true,
95
- canEdit: true,
96
- canDelete: true
97
- }
98
- };
99
- });
100
- await ThemeFilesStructureUtils.writeThemeFilesStructure(themeDir, fileStructure);
101
- }
102
- async _updateMetadataFileWithWorkUrl(themeDir, workUrl) {
103
- const shopMetadata = await ThemeMetaDataUtils.getThemeMetadata(themeDir);
104
- await ThemeMetaDataUtils.updateThemeMetadata(themeDir, {
105
- ...shopMetadata,
106
- workUrl
107
- });
108
- }
109
61
  async fetchResources(shopUrl, dist, resources) {
110
62
  await removeOldResources(dist, resources);
111
63
  const resourcesTree = mapResourcesToTree(resources);
@@ -116,18 +68,4 @@ export class ThemeFetchService {
116
68
  shopUrl
117
69
  })));
118
70
  }
119
- _createGitIgnoreFile(themeDir) {
120
- return new Promise((resolve, reject) => {
121
- const gitIgnoreContent = `styles/src/`;
122
- const writeStream = createWriteStream(join(themeDir, '.gitignore'));
123
- writeStream.write(gitIgnoreContent);
124
- writeStream.end();
125
- writeStream.on('error', (err) => {
126
- reject(err);
127
- });
128
- writeStream.on('finish', () => {
129
- resolve();
130
- });
131
- });
132
- }
133
71
  }
@@ -5,7 +5,9 @@ import { downloadFile } from '../../../../../utils/download_file/download_file_u
5
5
  import { extractZip } from '../../../../../utils/zip/extract_zip_utils.js';
6
6
  import { ThemeMetaDataUtils } from '../../utils/meta_data/theme_meta_data_utils.js';
7
7
  import { ThemeInfoUtils } from '../../info/theme_info_utils.js';
8
- import { ThemeChecksums } from '../../../../../theme/class/checksums/theme_checksums.js';
8
+ import { ThemeChecksums } from '../../../../class/checksums/theme_checksums.js';
9
+ import { ThemeFilesStructureUtils } from '../../utils/files_structure/theme_files_structure_utils.js';
10
+ import { AppError } from '../../../../../cli/class/errors/app/app_error.js';
9
11
  export class ThemeInitService {
10
12
  #httpApi;
11
13
  constructor({ httpApi }) {
@@ -18,16 +20,28 @@ export class ThemeInitService {
18
20
  dist: tmpDir,
19
21
  request: this.#httpApi.initTheme(credentials.shopUrl, action.data).response
20
22
  });
21
- const distDir = join(process.cwd(), basename);
23
+ const themeDir = join(process.cwd(), basename);
22
24
  await extractZip({
23
25
  source: join(tmpDir, filename),
24
- dist: distDir
26
+ dist: themeDir
25
27
  });
26
- new ThemeChecksums(distDir).updateAllChecksums();
27
- const themeMetaData = await ThemeMetaDataUtils.getThemeMetadata(distDir);
28
+ try {
29
+ await ThemeFilesStructureUtils.updateFilesStructure(themeDir);
30
+ }
31
+ catch (err) {
32
+ throw new AppError({
33
+ message: `Failed to update files structure in theme directory: ${themeDir}`,
34
+ code: 'theme_files_structure_update_error',
35
+ stack: err.stack
36
+ });
37
+ }
38
+ await ThemeMetaDataUtils.createGitIgnoreFile(themeDir);
39
+ await ThemeMetaDataUtils.updateMetadataFileWithWorkUrl(themeDir, credentials.shopUrl);
40
+ await new ThemeChecksums(themeDir).updateAllChecksums();
41
+ const themeMetaData = await ThemeMetaDataUtils.getThemeMetadata(themeDir);
28
42
  return {
29
43
  themeId: themeMetaData.themeId,
30
- themeName: await ThemeInfoUtils.getThemeName(distDir)
44
+ themeName: await ThemeInfoUtils.getThemeName(themeDir)
31
45
  };
32
46
  }
33
47
  }
@@ -1,11 +1,12 @@
1
1
  import { readJSONFile, removeFile, writeJSONFile } from '../../../../../utils/fs/fs_utils.js';
2
2
  import { join, looksLikeDirectory, mapKeysPathsToWindowPlatform, toUnixPath } from '../../../../../utils/path_utils.js';
3
3
  import { SHOPER_THEME_METADATA_DIR } from '../../../../constants/directory_contstants.js';
4
- import { THEME_FILES_STRUCTURE_FILE_NAME } from '../../theme_constants.js';
4
+ import { THEME_CURRENT_CHECKSUMS_FILE_NAME, THEME_CURRENT_CHECKSUMS_VERITY_FILE_NAME, THEME_FILES_STRUCTURE_FILE_NAME, THEME_INITIAL_CHECKSUMS_FILE_NAME, THEME_INITIAL_CHECKSUMS_VERITY_FILE_NAME } from '../../theme_constants.js';
5
5
  import { isWindowsOs } from '../../../../../utils/platform_utils.js';
6
6
  import { validateDirectory } from '../../../../utils/directory_validator/directory_validator_utils.js';
7
7
  import path from 'node:path';
8
8
  import { THEME_FILES_LIST_FILE_NAME } from '../../push/theme_push_constants.js';
9
+ import { THEME_ACTIONS_TYPES } from '../../actions/theme_actions_constants.js';
9
10
  export class ThemeFilesStructureUtils {
10
11
  static async getThemeFilesStructure(themeDirectory) {
11
12
  const filesStructure = await readJSONFile(join(themeDirectory, SHOPER_THEME_METADATA_DIR, THEME_FILES_STRUCTURE_FILE_NAME));
@@ -80,4 +81,40 @@ export class ThemeFilesStructureUtils {
80
81
  static async removeAFilesListFile(themeRootDir) {
81
82
  await removeFile(join(themeRootDir, THEME_FILES_LIST_FILE_NAME));
82
83
  }
84
+ static async updateFilesStructure(themeDir) {
85
+ const fileStructure = await ThemeFilesStructureUtils.getThemeFilesStructure(themeDir);
86
+ const checksumsFiles = [
87
+ `${SHOPER_THEME_METADATA_DIR}/${THEME_INITIAL_CHECKSUMS_FILE_NAME}`,
88
+ `${SHOPER_THEME_METADATA_DIR}/${THEME_INITIAL_CHECKSUMS_VERITY_FILE_NAME}`,
89
+ `${SHOPER_THEME_METADATA_DIR}/${THEME_CURRENT_CHECKSUMS_FILE_NAME}`,
90
+ `${SHOPER_THEME_METADATA_DIR}/${THEME_CURRENT_CHECKSUMS_VERITY_FILE_NAME}`
91
+ ];
92
+ checksumsFiles.forEach((file) => {
93
+ fileStructure[file] = {
94
+ permissions: {
95
+ canAdd: true,
96
+ canEdit: true,
97
+ canDelete: false
98
+ }
99
+ };
100
+ });
101
+ fileStructure[THEME_FILES_LIST_FILE_NAME] = {
102
+ permissions: {
103
+ canAdd: true,
104
+ canEdit: true,
105
+ canDelete: true
106
+ },
107
+ _links: { [THEME_ACTIONS_TYPES.push]: '*' }
108
+ };
109
+ ['.gitignore'].forEach((fileName) => {
110
+ fileStructure[fileName] = {
111
+ permissions: {
112
+ canAdd: true,
113
+ canEdit: true,
114
+ canDelete: true
115
+ }
116
+ };
117
+ });
118
+ await ThemeFilesStructureUtils.writeThemeFilesStructure(themeDir, fileStructure);
119
+ }
83
120
  }
@@ -3,6 +3,7 @@ import { SHOPER_THEME_METADATA_DIR } from '../../../../constants/directory_conts
3
3
  import { join } from '../../../../../utils/path_utils.js';
4
4
  import { HiddenDirectoryUtils } from '../hidden_directory/hidden_directory_utils.js';
5
5
  import { ThemeMetaDataErrorFactory } from './theme_meta_data_error_factory.js';
6
+ import { createWriteStream } from 'node:fs';
6
7
  export class ThemeMetaDataUtils {
7
8
  static async closestThemeRootDirectory(path) {
8
9
  return closestFile(SHOPER_THEME_METADATA_DIR, path);
@@ -36,4 +37,25 @@ export class ThemeMetaDataUtils {
36
37
  if (metadataWorkUrl !== executionWorkUrl)
37
38
  throw ThemeMetaDataErrorFactory.createThemeWorkUrlMismatchError(executionWorkUrl, metadataWorkUrl);
38
39
  }
40
+ static async updateMetadataFileWithWorkUrl(themeDir, workUrl) {
41
+ const shopMetadata = await ThemeMetaDataUtils.getThemeMetadata(themeDir);
42
+ await ThemeMetaDataUtils.updateThemeMetadata(themeDir, {
43
+ ...shopMetadata,
44
+ workUrl
45
+ });
46
+ }
47
+ static async createGitIgnoreFile(themeDir) {
48
+ return new Promise((resolve, reject) => {
49
+ const gitIgnoreContent = `styles/src/`;
50
+ const writeStream = createWriteStream(join(themeDir, '.gitignore'));
51
+ writeStream.write(gitIgnoreContent);
52
+ writeStream.end();
53
+ writeStream.on('error', (err) => {
54
+ reject(err);
55
+ });
56
+ writeStream.on('finish', () => {
57
+ resolve();
58
+ });
59
+ });
60
+ }
39
61
  }
@@ -1,7 +1,7 @@
1
1
  import { EXECUTION_CONTEXT_API_NAME, EXECUTION_CONTEXTS } from '../../../cli/features/execution_context/execution_context_constants.js';
2
2
  import { useApi } from '../../../cli/hooks/ensure_cli_initialized_hook.js';
3
3
  import { THEME_COMMANDS_THAT_REQUIRES_UP_TO_DATE_CHECKSUMS } from './ensure_theme_current_checksums_up_to_date_constants.js';
4
- import { ThemeChecksums } from '../../../theme/class/checksums/theme_checksums.js';
4
+ import { ThemeChecksums } from '../../class/checksums/theme_checksums.js';
5
5
  export const ensureThemeChecksumsUpToDate = async ({ Command }) => {
6
6
  if (!THEME_COMMANDS_THAT_REQUIRES_UP_TO_DATE_CHECKSUMS.includes(Command.id))
7
7
  return;
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.5.1-0",
5
+ "version": "0.5.1-1",
6
6
  "description": "CLI tool for Shoper",
7
7
  "author": "Joanna Firek",
8
8
  "license": "MIT",