Add initial testdata

react_convert
Mark Moffat 2018-01-07 14:10:16 +01:00
parent f4ac5b5e21
commit c4e59e9cd0
3 changed files with 91 additions and 1 deletions

1
app.js
View File

@ -259,6 +259,7 @@ MongoClient.connect(config.databaseConnectionString, {}, (err, client) => {
// add indexing
common.runIndexing(app)
.then(common.testData(db))
.then(() => {
// lift the app
app.listen(app.get('port'), () => {

67
bin/testdata.json Normal file
View File

@ -0,0 +1,67 @@
[
{
"productPermalink": "duckworth-jacket",
"productTitle": "Duckworth Woolfill Jacket",
"productPrice": "188.00",
"productDescription": "<p style=\"margin-bottom: 25px; text-rendering: optimizeLegibility;\">Inspired by the timeless, functional style of your grandfather's work coat, the Foraker features brass buttons and 4 patch pockets. Crafted in Bristol, Tennessee, our 10oz organic duck canvas is light enough for an early summer morning, but rugged enough to handle your days work.<\/p><ul class=\"tabs-content\" style=\"margin-right: 0px; margin-bottom: 25px; margin-left: 20px; padding: 0px; text-rendering: optimizeLegibility;\"><li style=\"margin-bottom: 0px;\">100% Organic Duck Canvas.<\/li><\/ul>",
"productPublished": "true",
"productAddedDate": {
"$date": "2016-05-01T11:22:49.442Z"
},
"productTags": "organic, jacket",
"productOptions": "{\"Size\":{\"optName\":\"Size\",\"optLabel\":\"Select size\",\"optType\":\"select\",\"optOptions\":[\"S\",\"M\",\"L\",\"XL\"]},\"Colour\":{\"optName\":\"Colour\",\"optLabel\":\"Select colour\",\"optType\":\"select\",\"optOptions\":[\"Harvest\",\"Navy\"]}}",
"productImage": "/uploads/duckworth-jacket/woolfill-jacket_6c39ae23-c0c8-4821-85f4-4b5d64333c62_grande.jpg"
},
{
"productPermalink": "5-panel-cap",
"productTitle": "5 Panel Camp Cap",
"productPrice": "48",
"productDescription": "<p style=\"margin-bottom: 25px; text-rendering: optimizeLegibility;\">A classic 5 panel hat with our United By Blue logo on the front and an adjustable strap to keep fit and secure. Made with recycled polyester and organic cotton mix.<\/p><ul style=\"margin-right: 0px; margin-bottom: 25px; margin-left: 20px; padding: 0px; text-rendering: optimizeLegibility;\"><li style=\"margin-bottom: 0px;\">Made in&nbsp;New Jersey<\/li><li style=\"margin-bottom: 0px;\">7oz Eco-Twill fabric:&nbsp;35% organic cotton, 65% recycled PET&nbsp;(plastic water and soda bottles)&nbsp;<\/li><li style=\"margin-bottom: 0px;\">Embossed leather patch<\/li><\/ul><ul class=\"tabs\" style=\"margin-right: 0px; margin-bottom: 25px; margin-left: 20px; padding: 0px; text-rendering: optimizeLegibility; color: rgb(28, 29, 29); font-family: Arapey, serif; line-height: 25.008px;\"><\/ul>",
"productPublished": "true",
"productAddedDate": {
"$date": "2016-07-10T05:01:15.744Z"
},
"productTags": "panel, cap",
"productOptions": "{\"colour\":{\"optName\":\"colour\",\"optLabel\":\"Select colour\",\"optType\":\"select\",\"optOptions\":[\"Heather green\",\"Burnt orange\",\"Slate grey\",\"Navy blue\"]}}",
"productImage": "/uploads/5-panel-cap/5-panel-hat_4ee20a27-8d5a-490e-a2fc-1f9c3beb7bf5_grande.jpg"
},
{
"productPermalink": "ranger-boot",
"productTitle": "Red Wing Iron Ranger Boot",
"productPrice": "310",
"productDescription": "<p style=\"margin-bottom: 25px; text-rendering: optimizeLegibility;\">The Mesabi Iron Range lies in northern Minnesota, a rugged and remote area known for its iron mines. The local residents who work these mines are proudly known as Iron Rangers, individuals with a sense of adventure and a determined personality. Originally designed to be worn in the iron mines, Iron Ranger work boots had to be as tough as the people who wore them in demanding conditions. Iron Ranger boots are built with a double layer of leaver over the toe to provide an extra measure of safety.<\/p><ul class=\"tabs-content\" style=\"margin-right: 0px; margin-bottom: 25px; margin-left: 20px; padding: 0px; text-rendering: optimizeLegibility;\"><li style=\"margin-bottom: 0px;\">6 inch, Amber Harness leather with Nitrile Cork sole.<\/li><\/ul>",
"productPublished": "true",
"productAddedDate": {
"$date": "2016-07-10T05:29:04.941Z"
},
"productTags": "ranger, boot, leather",
"productImage": "/uploads/ranger-boot/boot_grande.jpg",
"productOptions": "{\"size\":{\"optName\":\"size\",\"optLabel\":\"Select size\",\"optType\":\"select\",\"optOptions\":[\"7.5\",\"8\",\"8.5\",\"9\",\"9.5\",\"10\",\"10.5\",\"11\"]}}"
},
{
"productPermalink": "whitney-pullover",
"productTitle": "Whitney pullover",
"productPrice": "138",
"productDescription": "<p style=\"margin-bottom: 25px; text-rendering: optimizeLegibility;\">Buttons are fussy. Sometimes you just want to roll out of bed, put on the pull over and get to the days work.&nbsp;Julie is 5'8\" and wearing a size small.<\/p><ul class=\"tabs-content\" style=\"margin-right: 0px; margin-bottom: 25px; margin-left: 20px; padding: 0px; text-rendering: optimizeLegibility;\"><li style=\"margin-bottom: 0px;\">100% Wool, Heavy 4 gauge thickness<\/li><li style=\"margin-bottom: 0px;\">Handmade in Nepal.<\/li><\/ul>",
"productPublished": "true",
"productAddedDate": {
"$date": "2016-05-01T11:23:08.374Z"
},
"productImage": "/uploads/whitney-pullover/WhitneyPullover_Full_58e7b8d6-b939-4701-9e1d-9d853dff60ed_grande.jpeg",
"productTags": "whitney, pullover",
"productOptions": "{\"size\":{\"optName\":\"size\",\"optLabel\":\"Select size\",\"optType\":\"select\",\"optOptions\":[\"S\",\"M\",\"L\",\"XL\"]}}"
},
{
"productPermalink": "scout-backpack",
"productTitle": "Scout Backpack",
"productPrice": "128.00",
"productDescription": "<p><span style=\"line-height: 1.42857;\">This durable backpack is ready for any adventure, large or small. Features adjustable and padded shoulder pads for comfort. Designed with a storm flap and a secured by two snap-button closure. Made with a waxed downpour proof exterior canvas and a soft cotton interior lining. Finished with brass hardware and genuine leather trimmings.<\/span><\/p><ul><li><span style=\"line-height: 1.42857;\">100% organic waxed 18 oz canvas<\/span><\/li><li><span style=\"line-height: 1.42857;\">Full grain genuine leather accents<\/span><\/li><li>Adjustable shoulder straps<\/li><li>Lifetime&amp;nbsp;Guarantee<\/li><\/ul>",
"productPublished": "true",
"productTags": "backpack, organic",
"productAddedDate": {
"$date": "2016-07-10T05:46:26.974Z"
},
"productImage": "/uploads/scout-backpack/scout-backpack_a035275d-8975-4a05-8456-5e1ec35f020f_grande.jpg",
"productOptions": "{\"colour\":{\"optName\":\"colour\",\"optLabel\":\"Select colour\",\"optType\":\"select\",\"optOptions\":[\"Navy\",\"Moss\",\"Nutmeg\",\"Khaki\"]}}"
}
]

View File

@ -2,6 +2,7 @@ const _ = require('lodash');
const uglifycss = require('uglifycss');
const colors = require('colors');
const lunr = require('lunr');
const fs = require('fs');
const escape = require('html-entities').AllHtmlEntities;
// common functions
@ -112,8 +113,9 @@ exports.getImages = function (dir, req, res, callback){
if(err){
console.error(colors.red('Error getting images', err));
}
// loop files in /public/uploads/
glob('public/uploads/' + dir + '/**', {nosort: true}, (er, files) => {
glob('public/uploads/' + product.productPermalink + '/**', {nosort: true}, (er, files) => {
// sort array
files.sort();
@ -493,3 +495,23 @@ exports.runIndexing = (app) => {
process.exit(2);
});
};
exports.testData = (db) => {
db.products.count({})
.then((products) => {
if(products > 0){
return Promise.resolve();
}
console.info(colors.cyan('No products, inserting test data'));
const testdata = fs.readFileSync('./bin/testdata.json', 'utf-8');
return Promise.all([
db.products.insertMany(JSON.parse(testdata))
])
.catch((err) => {
console.info(colors.red('Error inserting test data. Check `/bin/testdata.json` is correctly formatted.', err));
process.exit(2);
});
});
};