mango-cms 0.2.46 → 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 +61 -0
- package/default/gitignore +5 -0
- package/default/mango/config/globalFields.js +1 -1
- package/default/mango/config/settings.json +1 -0
- package/default/mango/helpers/syncDbWithLocal.sh +2 -2
- package/default/package.json +1 -1
- package/default/src/helpers/mango.js +23 -0
- package/default/vite.config.js +1 -0
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -168,6 +168,13 @@ program
|
|
|
168
168
|
fs.mkdirSync(projectDir);
|
|
169
169
|
fs.copySync(templateDir, projectDir, { filter: (src, dest) => true });
|
|
170
170
|
|
|
171
|
+
// Copy gitignore file (npm excludes .gitignore, so we store it as gitignore)
|
|
172
|
+
const gitignoreSource = path.join(templateDir, 'gitignore');
|
|
173
|
+
const gitignoreDest = path.join(projectDir, '.gitignore');
|
|
174
|
+
if (fs.existsSync(gitignoreSource)) {
|
|
175
|
+
fs.copySync(gitignoreSource, gitignoreDest);
|
|
176
|
+
}
|
|
177
|
+
|
|
171
178
|
// Create config directory if it doesn't exist
|
|
172
179
|
const configDir = path.join(projectDir, 'mango');
|
|
173
180
|
|
|
@@ -668,6 +675,60 @@ program
|
|
|
668
675
|
}
|
|
669
676
|
});
|
|
670
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
|
+
|
|
671
732
|
program
|
|
672
733
|
.command('update')
|
|
673
734
|
.description('Update Mango CMS source files to the latest version')
|
|
@@ -4,7 +4,7 @@ let { PlainText, Select, Timestamp, Relationship } = fields
|
|
|
4
4
|
export default {
|
|
5
5
|
|
|
6
6
|
// title: PlainText({ required: true }),
|
|
7
|
-
author: Relationship({ collection: 'member', single: true,
|
|
7
|
+
author: Relationship({ collection: 'member', single: true, default: (doc, req) => req?.member?.id || null }),
|
|
8
8
|
editId: { computed: (doc, req) => req?.member?.id || null },
|
|
9
9
|
created: { computed: doc => doc.created || new Date, type: 'Float' },
|
|
10
10
|
updated: { computed: doc => doc.updated ? new Date : doc.created, type: 'Float' },
|
|
@@ -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;
|
package/default/package.json
CHANGED
|
@@ -87,6 +87,14 @@ const processFields = (fields, collectionName) => {
|
|
|
87
87
|
return result
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
+
// Function for setting cookies
|
|
91
|
+
let setCookie = function (cname, cvalue) {
|
|
92
|
+
var d = new Date();
|
|
93
|
+
d.setTime(d.getTime() + (365 * 24 * 60 * 60 * 1000));
|
|
94
|
+
var expires = "expires=" + d.toUTCString();
|
|
95
|
+
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
|
|
96
|
+
}
|
|
97
|
+
|
|
90
98
|
const Mango = collections.reduce((a, c) => {
|
|
91
99
|
let localDB = new LocalDB(c.name, api)
|
|
92
100
|
|
|
@@ -348,6 +356,11 @@ const Mango = collections.reduce((a, c) => {
|
|
|
348
356
|
a[c.singular]['local']['delete'] = localDB.delete
|
|
349
357
|
a[c.name]['sync'] = sync
|
|
350
358
|
|
|
359
|
+
a[c.name]['count'] = ({ search } = {}) => {
|
|
360
|
+
return runQuery({ search, fields: ['id'], verbose: true })
|
|
361
|
+
.then(data => data?.count || 0)
|
|
362
|
+
}
|
|
363
|
+
|
|
351
364
|
a[c.name]['search'] = search
|
|
352
365
|
a[c.name]['search']['init'] = (search, query, algoliaFilters) => {
|
|
353
366
|
let loading = ref(true)
|
|
@@ -487,12 +500,22 @@ Mango.login = ({ email, password }) => {
|
|
|
487
500
|
window.localStorage.setItem('token', response.data.token)
|
|
488
501
|
window.localStorage.setItem('user', response.data.memberId)
|
|
489
502
|
window.localStorage.setItem('email', email)
|
|
503
|
+
setCookie(`Authorization`, `${response.data.token}`)
|
|
490
504
|
resolve(response.data)
|
|
491
505
|
})
|
|
492
506
|
.catch((e) => reject(e))
|
|
493
507
|
})
|
|
494
508
|
}
|
|
495
509
|
|
|
510
|
+
Mango.logout = (axios) => {
|
|
511
|
+
window.localStorage.removeItem('token')
|
|
512
|
+
window.localStorage.removeItem('user')
|
|
513
|
+
window.localStorage.removeItem('email')
|
|
514
|
+
setCookie(`Authorization`, ``)
|
|
515
|
+
if (axios) delete axios.defaults.headers.common['Authorization']
|
|
516
|
+
return true
|
|
517
|
+
}
|
|
518
|
+
|
|
496
519
|
// Build endpoints from the generated .endpoints.json
|
|
497
520
|
Mango.endpoints = Object.keys(endpointsData).reduce((acc, path) => {
|
|
498
521
|
const methods = endpointsData[path]
|
package/default/vite.config.js
CHANGED