@magentrix-corp/magentrix-cli 1.1.4 → 1.2.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.
package/README.md CHANGED
@@ -24,7 +24,7 @@ Before you start, make sure you have:
24
24
  - Verify installation: `node --version`
25
25
 
26
26
  2. **Access to a Magentrix instance**
27
- - You need the URL (e.g., `https://yourcompany.magentrixcloud.com`)
27
+ - You need the URL (e.g., `https://yourcompany.magentrix.com`)
28
28
 
29
29
  3. **API Key from Magentrix**
30
30
  - Get this from your Magentrix administrator or system settings
@@ -111,6 +111,57 @@ Your configuration and local files are preserved during updates. You don't need
111
111
 
112
112
  ---
113
113
 
114
+ ## Multi-Instance Setup
115
+
116
+ ### Working with Multiple Magentrix Instances
117
+
118
+ MagentrixCLI supports managing multiple Magentrix instances simultaneously by storing credentials per-folder. This means you can have different folders for different instances, and the CLI will automatically use the correct credentials based on which folder you're in.
119
+
120
+ #### How It Works
121
+
122
+ The CLI uses a folder hash to associate credentials with each project directory. When you run `magentrix setup` in a folder, the API key and instance URL are stored globally but linked to that specific folder location.
123
+
124
+ #### Setting Up Multiple Instances
125
+
126
+ **Example**: Managing both Production and Development instances
127
+
128
+ ```bash
129
+ # Set up Production instance
130
+ mkdir ~/magentrix-production
131
+ cd ~/magentrix-production
132
+ magentrix setup
133
+ # Enter production API key and URL
134
+ magentrix pull
135
+
136
+ # Set up Development instance
137
+ mkdir ~/magentrix-development
138
+ cd ~/magentrix-development
139
+ magentrix setup
140
+ # Enter development API key and URL
141
+ magentrix pull
142
+ ```
143
+
144
+ Now you can work on both instances independently:
145
+
146
+ ```bash
147
+ # Work on production
148
+ cd ~/magentrix-production
149
+ magentrix publish # Publishes to production instance
150
+
151
+ # Work on development
152
+ cd ~/magentrix-development
153
+ magentrix publish # Publishes to development instance
154
+ ```
155
+
156
+ #### Important Notes
157
+
158
+ - Each folder maintains its own independent configuration
159
+ - Credentials are stored securely in your system's config directory
160
+ - Moving or renaming project folders will require running `magentrix setup` again
161
+ - You can verify which instance you're connected to by running `magentrix` or `magentrix config`
162
+
163
+ ---
164
+
114
165
  ## First Time Setup
115
166
 
116
167
  ### Step 1: Configure Your Credentials
@@ -124,13 +175,13 @@ magentrix setup
124
175
 
125
176
  You'll be prompted for:
126
177
  - **API Key**: Paste your Magentrix API key
127
- - **Instance URL**: Enter your Magentrix URL (like `https://yourcompany.magentrixcloud.com`)
178
+ - **Instance URL**: Enter your Magentrix instance URL (like `https://yourcompany.magentrix.com` or any custom domain)
128
179
 
129
180
  #### Non-Interactive Setup
130
181
  For automation or CI/CD, you can provide credentials via command-line flags:
131
182
 
132
183
  ```bash
133
- magentrix setup --api-key YOUR_API_KEY --instance-url https://yourcompany.magentrixcloud.com
184
+ magentrix setup --api-key YOUR_API_KEY --instance-url https://yourcompany.magentrix.com
134
185
  ```
135
186
 
136
187
  **Available flags:**
@@ -170,16 +221,31 @@ magentrix
170
221
  **What it does**: Displays your current connection status, API key (masked), and Magentrix instance URL.
171
222
  **When to use**: Quick check to verify you're properly authenticated and connected to the right instance.
172
223
 
224
+ ### Configure CLI Settings
225
+ ```bash
226
+ magentrix config
227
+ ```
228
+ **What it does**: Opens an interactive configuration wizard where you can manage CLI settings such as:
229
+ - **Log File Settings**: Enable or disable detailed operation logs
230
+ - **View All Settings**: See your current configuration including API key (masked) and instance URL
231
+
232
+ **When to use**:
233
+ - To enable or disable operation logs for debugging
234
+ - To verify your current settings and credentials
235
+ - To manage CLI preferences without re-running setup
236
+
173
237
  ### Download Latest Files from Server
174
238
  ```bash
175
239
  magentrix pull
176
240
  ```
177
- **What it does**: Downloads all ActiveClass and ActivePage records from your Magentrix server to your local `src/` folder. Detects conflicts if files have been changed both locally and remotely, and prompts you to resolve them.
241
+ **What it does**: Downloads all ActiveClass and ActivePage records from your Magentrix server to your local `src/` folder. Detects conflicts if files have been changed both locally and remotely, and prompts you to resolve them. Progress tracking shows separate steps for code entities and static assets.
178
242
  **When to use**:
179
243
  - Start of your workday to get latest changes
180
244
  - Before making major changes to avoid conflicts
181
245
  - When teammates have made server changes you need
182
246
 
247
+ **Note**: If this is your first time running `magentrix pull` in a project with many files, you may be prompted about saving operation logs. This is a one-time setup that helps with debugging.
248
+
183
249
  ### Check Status and Conflicts
184
250
  ```bash
185
251
  magentrix status
@@ -194,12 +260,14 @@ magentrix status
194
260
  ```bash
195
261
  magentrix publish
196
262
  ```
197
- **What it does**: Sends all unpublished changes from your local machine to the Magentrix server and compiles them. Shows you exactly what will be created, updated, or deleted before doing it. Processes all changes in parallel for speed. Works with both code files and static assets.
263
+ **What it does**: Sends all unpublished changes from your local machine to the Magentrix server and compiles them. Shows you exactly what will be created, updated, or deleted before doing it. Processes all changes in parallel for speed. Works with both code files and static assets. Features comprehensive progress tracking with timing diagnostics for large projects.
198
264
  **When to use**:
199
265
  - After you've finished making changes and want to deploy them
200
266
  - At the end of your work session
201
267
  - When you want to share your changes with teammates
202
268
 
269
+ **Performance Note**: The CLI uses optimized algorithms for large projects. Even with 20,000+ files, initial scanning completes in under 2 seconds.
270
+
203
271
  ### Real-Time Development Mode
204
272
  ```bash
205
273
  magentrix autopublish
@@ -528,6 +596,72 @@ This separation gives you the best of both worlds - robust version control AND s
528
596
 
529
597
  ---
530
598
 
599
+ ## Operation Logs
600
+
601
+ ### About Logs
602
+
603
+ MagentrixCLI can save detailed operation logs to help with debugging and troubleshooting. This is particularly useful when dealing with large projects or investigating sync issues.
604
+
605
+ ### Enabling/Disabling Logs
606
+
607
+ #### First Time Prompt
608
+ The first time you run an operation like `magentrix pull` or `magentrix publish`, you'll be asked:
609
+
610
+ ```
611
+ 📋 Log File Settings
612
+ Magentrix CLI can save detailed operation logs for debugging.
613
+
614
+ ? Would you like to save operation logs to files? (Y/n)
615
+ ```
616
+
617
+ Your choice is saved globally and applies to all future operations.
618
+
619
+ #### Change Settings Later
620
+ You can change your logging preference at any time:
621
+
622
+ ```bash
623
+ magentrix config
624
+ ```
625
+
626
+ Then select "Log File Settings" from the menu to enable or disable logs.
627
+
628
+ ### Log File Location
629
+
630
+ When enabled, logs are saved to `.magentrix/logs/` in your project folder:
631
+
632
+ ```
633
+ .magentrix/
634
+ └── logs/
635
+ ├── pull-2025-01-15T14-30-45.log
636
+ ├── publish-2025-01-15T15-12-30.log
637
+ └── autopublish-2025-01-15T16-00-00.log
638
+ ```
639
+
640
+ ### What Gets Logged
641
+
642
+ Operation logs include:
643
+ - Detailed timestamps for each operation
644
+ - Warnings about unknown file types or edge cases
645
+ - Errors with full stack traces
646
+ - Information about files being processed
647
+ - API calls and responses
648
+
649
+ ### Viewing Logs
650
+
651
+ To view a log file:
652
+
653
+ ```bash
654
+ cat .magentrix/logs/pull-2025-01-15T14-30-45.log
655
+ ```
656
+
657
+ Or open it in your text editor.
658
+
659
+ ### Log Cleanup
660
+
661
+ The CLI automatically keeps only the 10 most recent log files per operation type to prevent disk space issues. Older logs are automatically deleted.
662
+
663
+ ---
664
+
531
665
  ## Troubleshooting
532
666
 
533
667
  ### "Authentication failed"
@@ -553,6 +687,12 @@ This separation gives you the best of both worlds - robust version control AND s
553
687
  - Run `magentrix publish` to upload any remaining changes
554
688
  - Restart with `magentrix autopublish`
555
689
 
690
+ ### Need More Debugging Information
691
+ - Enable operation logs via `magentrix config`
692
+ - Run the failing operation again
693
+ - Check `.magentrix/logs/` for detailed error information
694
+ - Share log files with your team or support for help
695
+
556
696
  ---
557
697
 
558
698
  ## Tips & Best Practices
@@ -583,13 +723,19 @@ The tool creates these configuration files (you normally don't need to edit them
583
723
 
584
724
  ### Global Settings
585
725
  - **Location**: `~/.config/magentrix/` (Mac/Linux) or `%APPDATA%/magentrix/` (Windows)
586
- - **Contains**: Your API credentials and connection settings
726
+ - **Contains**:
727
+ - API credentials and connection settings (namespaced by folder hash)
728
+ - Global preferences like log settings
729
+ - Multiple instance credentials (each folder has its own credentials)
587
730
 
588
731
  ### Project Settings
589
732
  - **Location**: `.magentrix/` folder in your project
590
- - **Contains**: File mappings, sync status, and local cache
733
+ - **Contains**:
734
+ - File mappings and sync status
735
+ - Local cache and operation logs (if enabled)
736
+ - Base file snapshots for conflict detection
591
737
 
592
- **Note**: These folders are created automatically. Don't delete them unless you want to reconfigure everything.
738
+ **Note**: These folders are created automatically. Don't delete them unless you want to reconfigure everything. The global config supports multiple instances by storing credentials per-project folder.
593
739
 
594
740
  ---
595
741
 
@@ -609,11 +755,13 @@ magentrix status # Shows sync status
609
755
 
610
756
  ### Common Commands Summary
611
757
  - `magentrix setup` - Configure credentials
758
+ - `magentrix config` - Manage CLI settings
612
759
  - `magentrix pull` - Download files from server
613
760
  - `magentrix publish` - Upload local changes
614
761
  - `magentrix create` - Create new files
615
762
  - `magentrix status` - Check sync status
616
763
  - `magentrix autopublish` - Auto-sync mode
764
+ - `magentrix update` - Update to latest version
617
765
 
618
766
  ---
619
767
 
@@ -0,0 +1,182 @@
1
+ import chalk from 'chalk';
2
+ import inquirer from 'inquirer';
3
+ import Config from '../utils/config.js';
4
+ import { HASHED_CWD } from '../vars/global.js';
5
+
6
+ const config = new Config();
7
+
8
+ /**
9
+ * Interactive configuration wizard
10
+ */
11
+ export const configWizard = async () => {
12
+ console.clear();
13
+ console.log(chalk.cyan.bold('\n⚙️ Magentrix CLI Configuration'));
14
+ console.log(chalk.gray('─'.repeat(50)));
15
+ console.log('');
16
+
17
+ while (true) {
18
+ const { action } = await inquirer.prompt([
19
+ {
20
+ type: 'list',
21
+ name: 'action',
22
+ message: 'What would you like to do?',
23
+ pageSize: 10,
24
+ loop: false,
25
+ choices: [
26
+ {
27
+ name: ' 📋 Log File Settings',
28
+ value: 'logs',
29
+ short: 'Log Settings'
30
+ },
31
+ {
32
+ name: ' 🔧 View All Settings',
33
+ value: 'view',
34
+ short: 'View Settings'
35
+ },
36
+ new inquirer.Separator(),
37
+ {
38
+ name: chalk.gray(' Exit'),
39
+ value: 'exit',
40
+ short: 'Exit'
41
+ }
42
+ ]
43
+ }
44
+ ]);
45
+
46
+ if (action === 'exit') {
47
+ console.log('');
48
+ console.log(chalk.green('✓ Configuration saved'));
49
+ console.log('');
50
+ break;
51
+ }
52
+
53
+ console.clear();
54
+ console.log(chalk.cyan.bold('\n⚙️ Magentrix CLI Configuration'));
55
+ console.log(chalk.gray('─'.repeat(50)));
56
+
57
+ switch (action) {
58
+ case 'logs':
59
+ await configureLogSettings();
60
+ break;
61
+ case 'view':
62
+ await viewAllSettings();
63
+ break;
64
+ }
65
+
66
+ console.clear();
67
+ console.log(chalk.cyan.bold('\n⚙️ Magentrix CLI Configuration'));
68
+ console.log(chalk.gray('─'.repeat(50)));
69
+ console.log('');
70
+ }
71
+ };
72
+
73
+ /**
74
+ * Configure log file settings
75
+ */
76
+ async function configureLogSettings() {
77
+ const currentSetting = config.read('saveLogs', { global: true });
78
+
79
+ console.log('');
80
+ console.log(chalk.cyan.bold('📋 Log File Settings'));
81
+ console.log(chalk.gray('Detailed operation logs can be saved to .magentrix/logs/ for debugging.'));
82
+ console.log('');
83
+
84
+ // Show current status with better formatting
85
+ const currentStatus = currentSetting === true || currentSetting === 'true'
86
+ ? chalk.green('● ENABLED') + chalk.gray(' - Logs are being saved')
87
+ : currentSetting === false || currentSetting === 'false'
88
+ ? chalk.yellow('○ DISABLED') + chalk.gray(' - No log files created')
89
+ : chalk.gray('○ Not set') + chalk.gray(' - Will prompt on first use');
90
+
91
+ console.log(chalk.bold('Current Status: ') + currentStatus);
92
+ console.log('');
93
+
94
+ const { setting } = await inquirer.prompt([
95
+ {
96
+ type: 'list',
97
+ name: 'setting',
98
+ message: 'Choose preference:',
99
+ pageSize: 10,
100
+ loop: false,
101
+ choices: [
102
+ {
103
+ name: ' ' + chalk.green('● Enable logs'),
104
+ value: true,
105
+ short: 'Enable'
106
+ },
107
+ {
108
+ name: ' ' + chalk.yellow('○ Disable logs'),
109
+ value: false,
110
+ short: 'Disable'
111
+ },
112
+ new inquirer.Separator(),
113
+ {
114
+ name: chalk.gray(' ← Back'),
115
+ value: 'back',
116
+ short: 'Back'
117
+ }
118
+ ],
119
+ default: currentSetting === true || currentSetting === 'true' ? 0 : (currentSetting === false || currentSetting === 'false' ? 1 : 0)
120
+ }
121
+ ]);
122
+
123
+ if (setting === 'back') return;
124
+
125
+ config.save('saveLogs', setting, { global: true });
126
+
127
+ console.log('');
128
+ if (setting) {
129
+ console.log(chalk.green('✓ Logs enabled'));
130
+ console.log(chalk.gray(' → Logs will be saved to .magentrix/logs/'));
131
+ } else {
132
+ console.log(chalk.yellow('✓ Logs disabled'));
133
+ console.log(chalk.gray(' → No log files will be created'));
134
+ }
135
+
136
+ console.log('');
137
+ console.log(chalk.gray('Press Enter to continue...'));
138
+ await inquirer.prompt([{ type: 'input', name: 'continue', message: '' }]);
139
+ }
140
+
141
+ /**
142
+ * View all current settings
143
+ */
144
+ async function viewAllSettings() {
145
+ console.log('');
146
+ console.log(chalk.cyan.bold('🔧 All Settings'));
147
+ console.log('');
148
+
149
+ // Log settings
150
+ const saveLogs = config.read('saveLogs', { global: true });
151
+ const logsStatus = saveLogs === true || saveLogs === 'true'
152
+ ? chalk.green('● Enabled')
153
+ : saveLogs === false || saveLogs === 'false'
154
+ ? chalk.yellow('○ Disabled')
155
+ : chalk.gray('○ Not set');
156
+ console.log(chalk.bold(' Log Files'));
157
+ console.log(` ${logsStatus}`);
158
+ console.log('');
159
+
160
+ // API Key (masked) - read with pathHash like setup command does
161
+ const apiKey = config.read('apiKey', { global: true, pathHash: HASHED_CWD });
162
+ const keyStatus = apiKey
163
+ ? chalk.green('****' + String(apiKey).slice(-4))
164
+ : chalk.gray('Not configured');
165
+ console.log(chalk.bold(' API Key'));
166
+ console.log(` ${keyStatus}`);
167
+ console.log('');
168
+
169
+ // Instance URL - read with pathHash like setup command does
170
+ const instanceUrl = config.read('instanceUrl', { global: true, pathHash: HASHED_CWD });
171
+ const urlStatus = instanceUrl
172
+ ? chalk.cyan(instanceUrl)
173
+ : chalk.gray('Not configured');
174
+ console.log(chalk.bold(' Instance URL'));
175
+ console.log(` ${urlStatus}`);
176
+ console.log('');
177
+
178
+ console.log(chalk.gray('─'.repeat(50)));
179
+ console.log('');
180
+ console.log(chalk.gray('Press Enter to continue...'));
181
+ await inquirer.prompt([{ type: 'input', name: 'continue', message: '' }]);
182
+ }
package/actions/create.js CHANGED
@@ -400,14 +400,27 @@ export const create = async (cliOptions = {}) => {
400
400
  console.log();
401
401
 
402
402
  // Uncomment to perform creation via API:
403
- const creationResponse = await withSpinner('Creating file...', async () => {
403
+ const creationResponse = await withSpinner('Creating file...', async () => {
404
404
  return await createEntity(
405
- credentials.instanceUrl,
406
- credentials.token.value,
407
- entityType,
405
+ credentials.instanceUrl,
406
+ credentials.token.value,
407
+ entityType,
408
408
  formattedData
409
409
  ).catch(err => {
410
- return { ...err?.response, hasErrors: true };
410
+ // The error object structure from fetchMagentrix:
411
+ // - err.type: 'network' | 'http' | 'api'
412
+ // - err.message: formatted error message
413
+ // - err.response: the API response data (if available)
414
+ // - err.status: HTTP status code (for http errors)
415
+ return {
416
+ hasErrors: true,
417
+ errorType: err.type,
418
+ errorMessage: err.message,
419
+ status: err.status,
420
+ statusText: err.statusText,
421
+ errors: err.response?.errors || err.response?.Errors || [],
422
+ rawResponse: err.response
423
+ };
411
424
  });
412
425
  });
413
426
 
@@ -415,17 +428,25 @@ export const create = async (cliOptions = {}) => {
415
428
  console.log();
416
429
  console.log(chalk.bgRed.bold.white(' ✖ Creation Failed '));
417
430
  console.log(chalk.redBright('─'.repeat(48)));
431
+
432
+ // Display HTTP status if available
433
+ if (creationResponse.status) {
434
+ console.log(chalk.yellow(` Status: ${creationResponse.status} ${creationResponse.statusText || ''}`));
435
+ }
436
+
418
437
  const errors = creationResponse.errors || [];
419
438
 
420
439
  if (errors.length > 0) {
421
440
  errors.forEach((err) => {
422
441
  const code = err.code ? chalk.gray(`[${err.code}] `) : '';
423
- const status = err.status ? chalk.yellow(`[${err.status}] `) : '';
424
- const msg = chalk.whiteBright(err.message);
425
- console.log(`${chalk.redBright(' •')} ${status}${code}${msg}`);
442
+ const msg = chalk.whiteBright(err.message || err);
443
+ console.log(`${chalk.redBright(' •')} ${code}${msg}`);
426
444
  });
445
+ } else if (creationResponse.errorMessage) {
446
+ // Show the formatted error message from fetchMagentrix
447
+ console.log(chalk.red(creationResponse.errorMessage));
427
448
  } else {
428
- console.log(chalk.red('An unknown error occurred during deletion.'));
449
+ console.log(chalk.red('An unknown error occurred during creation.'));
429
450
  }
430
451
 
431
452
  return;