@shoper/cli 0.5.2-8 → 0.6.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.
@@ -0,0 +1,11 @@
1
+ import { FeatureApi } from '@dreamcommerce/star_core';
2
+ export class ThemeWatchApi extends FeatureApi {
3
+ #service;
4
+ constructor(service) {
5
+ super();
6
+ this.#service = service;
7
+ }
8
+ async watchTheme(props) {
9
+ return this.#service.watchTheme(props);
10
+ }
11
+ }
@@ -0,0 +1,48 @@
1
+ // import chokidar from 'chokidar';
2
+ import { relative } from '../../../../../utils/path_utils.js';
3
+ export class ThemeWatchService {
4
+ #themePushApi;
5
+ constructor({ themePushApi }) {
6
+ this.#themePushApi = themePushApi;
7
+ }
8
+ async watchTheme({ themeChecksums, executionContext, onChange, credentials, themeFilesUploadApi, filesStructure, action }) {
9
+ const themePath = executionContext.themeRootDir;
10
+ console.log(`[watch] Watching for changes in: ${themePath}`);
11
+ // const watcher = chokidar.watch(themePath, {
12
+ // ignored: /(^|[\/\\])\../, // ignore dotfiles
13
+ // persistent: true,
14
+ // ignoreInitial: true // Don't trigger on initial scan
15
+ // });
16
+ const handleFileChange = async (filePath) => {
17
+ const relativePath = relative(themePath, filePath);
18
+ console.log(`[watch] Detected change in: ${relativePath}. Pushing theme...`);
19
+ try {
20
+ // Assuming pushTheme handles the logic of pushing the entire theme
21
+ return;
22
+ //@ts-ignore
23
+ await this.#themePushApi.partialPush({
24
+ credentials,
25
+ filesStructure,
26
+ action,
27
+ executionContext,
28
+ themeChecksums,
29
+ themeFilesUploadApi
30
+ });
31
+ console.log(`[watch] Theme pushed successfully.`);
32
+ }
33
+ catch (error) {
34
+ console.error(`[watch] Error pushing theme:`, error);
35
+ }
36
+ };
37
+ //
38
+ // watcher
39
+ // .on('add', handleFileChange)
40
+ // .on('change', handleFileChange)
41
+ // .on('unlink', handleFileChange)
42
+ // //@ts-ignore
43
+ // .on('error', (error) => console.error(`[watch] Watcher error: ${error}`))
44
+ // .on('ready', () => console.log('[watch] Initial scan complete. Ready for changes.'));
45
+ // Keep the process alive while watching
46
+ return new Promise(() => { });
47
+ }
48
+ }
@@ -0,0 +1,2 @@
1
+ export const THEME_WATCH_FEATURE_NAME = 'ThemeWatch';
2
+ export const THEME_WATCH_API_NAME = 'ThemeWatchApi';
@@ -0,0 +1,20 @@
1
+ import { FEATURE_CORES_TYPES, SyncFeatureInitializer } from '@dreamcommerce/star_core';
2
+ import { THEME_WATCH_FEATURE_NAME } from './theme_watch_constants.js';
3
+ import { ThemeWatchService } from './service/theme_watch_service.js';
4
+ import { THEME_PUSH_API_NAME } from '../push/theme_push_constants.js';
5
+ import { ThemeWatchApi } from './api/theme_watch_api.js';
6
+ export class ThemeWatchInitializer extends SyncFeatureInitializer {
7
+ static featureName = THEME_WATCH_FEATURE_NAME;
8
+ init() {
9
+ const themePushApi = this.getApiSync(THEME_PUSH_API_NAME);
10
+ const service = new ThemeWatchService({ themePushApi });
11
+ return {
12
+ cores: [
13
+ {
14
+ type: FEATURE_CORES_TYPES.api,
15
+ instance: new ThemeWatchApi(service)
16
+ }
17
+ ]
18
+ };
19
+ }
20
+ }
@@ -12,9 +12,14 @@ export const jsonIndentTransform = (space = JSON_FILE_INDENT) => {
12
12
  if (!data) {
13
13
  return callback();
14
14
  }
15
- const json = JSON.parse(data);
15
+ // 1. Escape backslashes to preserve literal '\u' during parsing
16
+ const escapedJsonString = data.replace(/\\u/g, '\\\\u');
17
+ const json = JSON.parse(escapedJsonString);
18
+ // 2. Stringify the object, which will re-escape the backslashes (e.g., '\\u' -> '\\\\u')
16
19
  const pretty = JSON.stringify(json, null, space);
17
- this.push(pretty);
20
+ // 3. Un-escape the double backslashes to get the desired literal '\u'
21
+ const finalString = pretty.replace(/\\\\u/g, '\\u');
22
+ this.push(finalString);
18
23
  callback();
19
24
  }
20
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.5.2-8",
5
+ "version": "0.6.0",
6
6
  "description": "CLI tool for Shoper",
7
7
  "author": "Joanna Firek",
8
8
  "license": "MIT",