File tree Expand file tree Collapse file tree
packages/contentstack-utilities/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11fileignoreconfig:
22 - filename: pnpm-lock.yaml
33 checksum: 3679e7796d7b2b35b3485f4d56a52778557e94a079900bb65ecd41785b234383
4- version: '1.0'
4+ - filename: packages/contentstack-utilities/src/message-handler.ts
5+ checksum: e7221e8413005b9efe3a230cd91aff130850976addc41c0acb10745a56ec3245
6+ version: '1.0'
Original file line number Diff line number Diff line change 11import fs from 'fs' ;
22import CLIError from './cli-error' ;
33
4+ const STORE_KEY = '__cs_messages__' ;
5+
46/**
57 * Message handler
68 */
79class Messages {
8- private messages : object ;
9- messageFilePath : any ;
10-
11- constructor ( ) {
12- this . messages = { } ;
13- }
14-
1510 init ( context ) {
1611 if ( ! context . messageFilePath ) {
1712 return ;
1813 }
1914 try {
20- this . messages = JSON . parse ( fs . readFileSync ( context . messageFilePath , 'utf-8' ) ) ;
15+ const loaded = JSON . parse ( fs . readFileSync ( context . messageFilePath , 'utf-8' ) ) ;
16+ ( globalThis as any ) [ STORE_KEY ] = { ...( globalThis as any ) [ STORE_KEY ] , ...loaded } ;
2117 } catch ( error ) {
22- // create empty messages object if message file is not exist
23- if ( error . code === 'ENOENT' ) {
24- this . messages = { } ;
25- } else {
18+ if ( error . code !== 'ENOENT' ) {
2619 throw new CLIError ( `Error: ${ error . message } ` ) ;
2720 }
2821 }
2922 }
3023
3124 parse ( messageKey : string , ...substitutions : Array < any > ) : string {
32- const msg = this . messages [ messageKey ] ;
25+ const store = ( globalThis as any ) [ STORE_KEY ] || { } ;
26+ const msg = store [ messageKey ] ;
3327 if ( ! msg ) {
3428 return messageKey ;
3529 }
You can’t perform that action at this time.
0 commit comments