-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_products.js
60 lines (52 loc) · 1.5 KB
/
generate_products.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Very simple script to generate products
import crypto from "crypto";
import { join } from "path";
import fs from "fs";
const range = (n) => [...Array(n).keys()];
const pickItem = (items) => items[Math.floor(Math.random() * items.length)];
const productFamilies = ["Phone", "Watch", "Glass"];
const categoriesPerFamily = {
Phone: ["Smartphone", "2FA", "GPS"],
Watch: ["Time", "Wearable"],
Glass: ["Medical", "Wearable"],
};
const colors = [
"red",
"blue",
"teal",
"silver",
"black",
"gold",
"transparent",
];
const memoryOptions = ["16KB", "2GB", "16GB", "32GB", "512GB", "1TB"];
const batteryOptions = ["small", "medium", "big", "infinite"];
const products = range(20).flatMap((yearRaw) => {
year = yearRaw + 2001;
let currentPrice = year * 100 * 1.5;
return productFamilies.flatMap((family) =>
colors.map((color) => {
return {
ean: crypto.randomUUID(),
name: `i22 ${family} ${year}_${color}`,
releaseYear: year,
price: {
current: year * 10 * 1.5,
was:
Math.random() <= 0.75 ? Math.floor(currentPrice * 1.15) : undefined,
},
categories: categoriesPerFamily[family],
color: color,
technicalDetails: {
memory: pickItem(memoryOptions),
battery: pickItem(batteryOptions),
},
stock: (yearRaw + 1) * Math.floor(Math.random() * 10),
};
})
);
});
fs.writeFileSync(
join(__dirname, "priv/products.json"),
JSON.stringify(products, undefined, 2)
);