mango-cms 0.1.2 → 0.1.4
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
|
@@ -36,8 +36,8 @@ async function ensureSrcExists(mangoCmsRoot) {
|
|
|
36
36
|
|
|
37
37
|
// Helper function to validate and prompt for license if needed
|
|
38
38
|
async function ensureLicenseExists(configPath) {
|
|
39
|
-
let settings = {
|
|
40
|
-
|
|
39
|
+
let settings = {};
|
|
40
|
+
|
|
41
41
|
try {
|
|
42
42
|
if (fs.existsSync(configPath)) {
|
|
43
43
|
settings = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
|
@@ -60,7 +60,10 @@ async function ensureLicenseExists(configPath) {
|
|
|
60
60
|
}
|
|
61
61
|
]);
|
|
62
62
|
|
|
63
|
-
settings
|
|
63
|
+
settings = {
|
|
64
|
+
...settings,
|
|
65
|
+
license: answer.license
|
|
66
|
+
};
|
|
64
67
|
fs.mkdirSync(path.dirname(configPath), { recursive: true });
|
|
65
68
|
fs.writeFileSync(configPath, JSON.stringify(settings, null, 2));
|
|
66
69
|
}
|
|
@@ -118,16 +121,29 @@ program
|
|
|
118
121
|
|
|
119
122
|
// Create or update settings.json
|
|
120
123
|
const settingsPath = path.join(configDir, 'config/settings.json');
|
|
121
|
-
|
|
124
|
+
let settings = {};
|
|
125
|
+
|
|
126
|
+
try {
|
|
127
|
+
if (fs.existsSync(settingsPath)) {
|
|
128
|
+
settings = JSON.parse(fs.readFileSync(settingsPath, 'utf8'));
|
|
129
|
+
}
|
|
130
|
+
} catch (error) {
|
|
131
|
+
console.log('Error reading settings file:', error.message);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
settings = {
|
|
135
|
+
...settings,
|
|
122
136
|
license: answers.license
|
|
123
137
|
};
|
|
138
|
+
fs.mkdirSync(path.dirname(settingsPath), { recursive: true });
|
|
124
139
|
fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2));
|
|
125
140
|
|
|
126
141
|
console.log(`
|
|
127
142
|
✨ Project ${answers.projectName} created successfully!
|
|
128
143
|
To get started:
|
|
129
144
|
cd ${answers.projectName}
|
|
130
|
-
|
|
145
|
+
npm install
|
|
146
|
+
npm mango start
|
|
131
147
|
`);
|
|
132
148
|
} catch (error) {
|
|
133
149
|
console.error('Error creating project:', error.message);
|
package/package.json
CHANGED
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
// import CMS from '../../../mango/src/cms' (for use like {address: CMS.fields.Address()})
|
|
2
|
-
import fields from '@cms/1. build/fields'
|
|
3
|
-
import { readEntries, readEntry } from '../../../mango/src/cms/1. build/libraries/mongo'
|
|
4
|
-
|
|
5
|
-
const billing = {
|
|
6
|
-
fields: {
|
|
7
|
-
paymentId: String,
|
|
8
|
-
firstName: { type: String, search: { enabled: true, weight: 5 } },
|
|
9
|
-
lastName: { type: String, search: { enabled: true, weight: 5 } },
|
|
10
|
-
phoneNumber: String,
|
|
11
|
-
address: fields.Address(),
|
|
12
|
-
payment: {
|
|
13
|
-
fields: {
|
|
14
|
-
creditCard: {
|
|
15
|
-
fields: {
|
|
16
|
-
cardNumber: String,
|
|
17
|
-
cardType: String,
|
|
18
|
-
expirationDate: String,
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
|
-
bankAccount: {
|
|
22
|
-
fields: {
|
|
23
|
-
accountNumber: String,
|
|
24
|
-
accountType: String,
|
|
25
|
-
echeckType: String,
|
|
26
|
-
nameOnAccount: String,
|
|
27
|
-
routingNumber: String
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const Items = {
|
|
36
|
-
name: 'items',
|
|
37
|
-
singular: 'item',
|
|
38
|
-
fields: {
|
|
39
|
-
price: { type: 'Int' },
|
|
40
|
-
stock: { type: 'Int' },
|
|
41
|
-
description: fields.PlainText(),
|
|
42
|
-
},
|
|
43
|
-
hooks: {
|
|
44
|
-
sold({ item }) {
|
|
45
|
-
console.log('sold', item.title)
|
|
46
|
-
},
|
|
47
|
-
addedToCart({ item }) {
|
|
48
|
-
console.log('addedToCart', item.title)
|
|
49
|
-
},
|
|
50
|
-
removedFromCart({ item }) {
|
|
51
|
-
console.log('removedFromCart', item.title)
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const Discounts = {
|
|
57
|
-
name: 'discounts',
|
|
58
|
-
singular: 'discount',
|
|
59
|
-
permissions: {
|
|
60
|
-
public: ['create', 'read']
|
|
61
|
-
},
|
|
62
|
-
fields: {
|
|
63
|
-
type: fields.Select({ options: ['coupon', 'sale'], required: true }),
|
|
64
|
-
code: { required: true, translateInput: i => i.toLowerCase() },
|
|
65
|
-
limitations: {
|
|
66
|
-
fields: {
|
|
67
|
-
items: fields.Relationship({ collection: 'item' }),
|
|
68
|
-
perCustomer: 'Int',
|
|
69
|
-
totalUses: 'Int',
|
|
70
|
-
perOrder: 'Int',
|
|
71
|
-
quantity: 'Int',
|
|
72
|
-
// remainingUses: {
|
|
73
|
-
// computed: doc => doc.limitations.totalUses ? /* Get times used and subtract from total uses */ : null
|
|
74
|
-
// }
|
|
75
|
-
}
|
|
76
|
-
},
|
|
77
|
-
freeShipping: Boolean,
|
|
78
|
-
discount: {
|
|
79
|
-
inputExample: '$12.50 or 50% etc.',
|
|
80
|
-
inputType: String,
|
|
81
|
-
validate: input => ({ valid: (!!input.match(/\$[0-9]+/) || input.match(/[0-9]\%+/)) ? true : false, response: 'Should be formatted like `100%` or `$12.50`' }),
|
|
82
|
-
translateInput: input => ({
|
|
83
|
-
type: !!input.match(/\$[0-9]+/) ? 'fixed' : 'percentage',
|
|
84
|
-
value: !!input.match(/\$[0-9]+/) ? input.match(/\$\d+(?:\.\d+)?/)[0].replace('$', '') : input.match(/(\d+|\d+[.,]\d{1,2})(?=\s*%)/)[0].replace('%', '')
|
|
85
|
-
}),
|
|
86
|
-
fields: {
|
|
87
|
-
type: String,
|
|
88
|
-
value: 'Float'
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
const Carts = {
|
|
96
|
-
name: 'carts',
|
|
97
|
-
singular: 'cart',
|
|
98
|
-
permissions: {
|
|
99
|
-
public: ['create', 'read', 'update']
|
|
100
|
-
},
|
|
101
|
-
fields: {
|
|
102
|
-
|
|
103
|
-
title: { required: false },
|
|
104
|
-
|
|
105
|
-
transactionId: String,
|
|
106
|
-
finalized: Boolean,
|
|
107
|
-
completed: Boolean,
|
|
108
|
-
completedDate: fields.Timestamp(),
|
|
109
|
-
cartItems: [{
|
|
110
|
-
fields: {
|
|
111
|
-
quantity: 'Int',
|
|
112
|
-
discount: 'Float',
|
|
113
|
-
item: fields.Relationship({ collection: 'item', single: true }),
|
|
114
|
-
}
|
|
115
|
-
}],
|
|
116
|
-
coupons: fields.Relationship({ collection: 'discount' }),
|
|
117
|
-
|
|
118
|
-
customerId: String,
|
|
119
|
-
billing,
|
|
120
|
-
shipping: {
|
|
121
|
-
fields: {
|
|
122
|
-
method: String,
|
|
123
|
-
price: String,
|
|
124
|
-
addressId: String,
|
|
125
|
-
firstName: String,
|
|
126
|
-
lastName: String,
|
|
127
|
-
phoneNumber: String,
|
|
128
|
-
address: fields.Address(),
|
|
129
|
-
free: { type: Boolean, computed: doc => doc?.coupons?.find(c => c.freeShipping) }
|
|
130
|
-
}
|
|
131
|
-
},
|
|
132
|
-
|
|
133
|
-
price: {
|
|
134
|
-
fields: {
|
|
135
|
-
subtotal: 'Float',
|
|
136
|
-
discount: 'Float',
|
|
137
|
-
total: 'Float',
|
|
138
|
-
},
|
|
139
|
-
computed: async doc => {
|
|
140
|
-
|
|
141
|
-
let subtotal = Number(doc.cartItems?.reduce((a, i) => a + ((i.item?.price || 0) * i.quantity), 0)) || 0
|
|
142
|
-
let shipping = doc?.shipping?.price || 0
|
|
143
|
-
|
|
144
|
-
let discount = 0
|
|
145
|
-
|
|
146
|
-
if (doc?.coupons?.length) {
|
|
147
|
-
let coupon = doc?.coupons?.[0]
|
|
148
|
-
if (coupon?.limitations?.items) {
|
|
149
|
-
for (let item of doc.cartItems) {
|
|
150
|
-
if (coupon?.limitations?.items?.find(i => i.id == item.item?.id)) {
|
|
151
|
-
if (coupon.discount.type == 'fixed') {
|
|
152
|
-
discount += (item.quantity * coupon.discount.value)
|
|
153
|
-
} else {
|
|
154
|
-
discount += ((item.quantity * item.item.price) * (Number(coupon.discount.value) / 100))
|
|
155
|
-
console.log('discount', discount)
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
} else {
|
|
160
|
-
if (coupon.discount.type == 'fixed') {
|
|
161
|
-
discount = Number(coupon.discount.value > subtotal ? subtotal : coupon.discount.value)
|
|
162
|
-
} else {
|
|
163
|
-
discount = Number(subtotal * (Number(coupon.discount.value) / 100))
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
let activeSales = await readEntries({ collection: 'discounts', search: { type: 'sale', startDate: { $lt: new Date() }, endDate: { $gt: new Date() } } })
|
|
169
|
-
|
|
170
|
-
if (activeSales?.length) {
|
|
171
|
-
for (let item of doc.cartItems) {
|
|
172
|
-
for (let sale of activeSales.sort((a, b) => b.discount.value < a.discount.value ? 1 : -1)) {
|
|
173
|
-
let saleApplies = sale?.limitations?.items?.some(i => i == item.item?.id) || !sale?.limitations?.items?.length
|
|
174
|
-
if (saleApplies) {
|
|
175
|
-
if (sale.discount.type == 'fixed') {
|
|
176
|
-
item.discount = (item.quantity * sale.discount.value)
|
|
177
|
-
} else {
|
|
178
|
-
item.discount = Number((item.quantity * item.item.price) * (Number(sale.discount.value) / 100))
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
discount = Number(doc.cartItems?.reduce((a, i) => a + i.discount, 0))
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
let total = (subtotal + shipping - discount) || 0
|
|
187
|
-
|
|
188
|
-
return {
|
|
189
|
-
subtotal,
|
|
190
|
-
discount,
|
|
191
|
-
total,
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
},
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
export default {
|
|
200
|
-
name: 'mangoStand',
|
|
201
|
-
collections: [
|
|
202
|
-
Items,
|
|
203
|
-
Carts,
|
|
204
|
-
Discounts,
|
|
205
|
-
],
|
|
206
|
-
}
|