mango-cms 0.2.47 → 0.2.48

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/cli.js CHANGED
@@ -675,6 +675,60 @@ program
675
675
  }
676
676
  });
677
677
 
678
+ program
679
+ .command('pull')
680
+ .description('Pull the remote database to your local machine')
681
+ .action(async () => {
682
+ try {
683
+ const configPath = path.join(process.cwd(), 'mango/config/settings.json');
684
+
685
+ if (!fs.existsSync(configPath)) {
686
+ console.error('Error: settings.json not found at', configPath);
687
+ process.exit(1);
688
+ }
689
+
690
+ const settings = JSON.parse(fs.readFileSync(configPath, 'utf8'));
691
+ const serverIp = settings.serverIp;
692
+ const database = settings.database;
693
+
694
+ if (!serverIp) {
695
+ console.error('Error: serverIp is not configured in settings.json');
696
+ process.exit(1);
697
+ }
698
+
699
+ if (!database) {
700
+ console.error('Error: database is not configured in settings.json');
701
+ process.exit(1);
702
+ }
703
+
704
+ console.log(`Using server IP: ${serverIp}`);
705
+ console.log(`Using database: ${database}`);
706
+
707
+ const downloadsDir = path.join(require('os').homedir(), 'Downloads');
708
+ const dumpZip = path.join(downloadsDir, 'dump.zip');
709
+ const dumpDir = path.join(downloadsDir, 'dump');
710
+
711
+ console.log('Dumping remote database...');
712
+ execSync(`ssh root@${serverIp} "rm -rf dump dump.zip; mongodump --db ${database}; zip -r dump.zip dump/${database}"`, { stdio: 'inherit' });
713
+
714
+ console.log('Downloading dump...');
715
+ execSync(`rsync root@${serverIp}:~/dump.zip ${dumpZip}`, { stdio: 'inherit' });
716
+
717
+ console.log('Restoring locally...');
718
+ execSync(`unzip -o ${dumpZip}`, { cwd: downloadsDir, stdio: 'inherit' });
719
+ execSync(`mongorestore --drop --db ${database} ${path.join(dumpDir, database)}`, { stdio: 'inherit' });
720
+
721
+ // Clean up
722
+ fs.removeSync(dumpDir);
723
+ fs.removeSync(dumpZip);
724
+
725
+ console.log(`\n✨ Database "${database}" pulled and restored successfully!`);
726
+ } catch (error) {
727
+ console.error('Error pulling database:', error.message);
728
+ process.exit(1);
729
+ }
730
+ });
731
+
678
732
  program
679
733
  .command('update')
680
734
  .description('Update Mango CMS source files to the latest version')
@@ -33,9 +33,9 @@ echo "Using server IP: $SERVER_IP"
33
33
  echo "Using database: $DATABASE"
34
34
 
35
35
  cd ~/Downloads;
36
- ssh root@$SERVER_IP "rm -rf dump.zip; mongodump --db $DATABASE; zip -r dump.zip dump"
36
+ ssh root@$SERVER_IP "rm -rf dump dump.zip; mongodump --db $DATABASE; zip -r dump.zip dump/$DATABASE"
37
37
  rsync root@$SERVER_IP:~/dump.zip ~/Downloads/dump.zip;
38
38
  unzip -o dump.zip;
39
- mongorestore --drop dump;
39
+ mongorestore --drop --db $DATABASE dump/$DATABASE;
40
40
  rm -rf dump;
41
41
  rm -rf dump.zip;
@@ -25,7 +25,7 @@
25
25
  "dayjs": "^1.10.7",
26
26
  "express": "^4.18.1",
27
27
  "google-maps": "^4.3.3",
28
- "mango-cms": "^0.2.46",
28
+ "mango-cms": "^0.2.48",
29
29
  "mapbox-gl": "^2.7.0",
30
30
  "sweetalert2": "^11.4.0",
31
31
  "vite": "^6.2.2",
@@ -356,6 +356,11 @@ const Mango = collections.reduce((a, c) => {
356
356
  a[c.singular]['local']['delete'] = localDB.delete
357
357
  a[c.name]['sync'] = sync
358
358
 
359
+ a[c.name]['count'] = ({ search } = {}) => {
360
+ return runQuery({ search, fields: ['id'], verbose: true })
361
+ .then(data => data?.count || 0)
362
+ }
363
+
359
364
  a[c.name]['search'] = search
360
365
  a[c.name]['search']['init'] = (search, query, algoliaFilters) => {
361
366
  let loading = ref(true)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mango-cms",
3
- "version": "0.2.47",
3
+ "version": "0.2.48",
4
4
  "main": "./index.js",
5
5
  "exports": {
6
6
  ".": "./index.js",