Permalink
Browse files

Tuning of demo script

  • Loading branch information...
davidmerfield committed Jan 10, 2019
1 parent 1b65e72 commit 9449142bebf0c456120aff1a4c4eb2796ea27c62
Showing with 18 additions and 25 deletions.
  1. +2 −10 scripts/each/blog.js
  2. +1 −1 scripts/email/_template/email.txt
  3. +15 −14 scripts/email/_template/index.js
@@ -17,14 +17,10 @@ module.exports = function (doThis, allDone, options) {

if (err || !blogIDs) throw err || 'No';

if (!options.silent) console.log();

if (options.s) {

options.s = parseInt(options.s);
console.log('Starting this script with blog which has ID', options.s);
blogIDs = blogIDs.slice(options.s - 1);

}

if (options.e) {
@@ -56,12 +52,8 @@ module.exports = function (doThis, allDone, options) {
}

console.log('Starting this for blogs with ID', blogIDs.length > 1 ? blogIDs : blogIDs[0]);

}

if (!options.silent) console.log();
if (!options.silent) console.log();

var forEach = ForEach;

if (options.p) {
@@ -77,13 +69,13 @@ module.exports = function (doThis, allDone, options) {
Blog.get({id: blogID}, function(err, blog){

if (err || !blog) {
console.log('There is no blog with ID', blogID);
return nextBlog();
}

User.getById(blog.owner, function(err, user){

if (err || !user) throw err || 'No user with uid ' + blog.owner;
if (err) throw err;
if (!user) throw new Error('No user with uid ' + blog.owner);

doThis(user, blog, nextBlog);
});
@@ -1,3 +1,3 @@
Subject line here.

Email body here.
Email body here {{email}}.
@@ -1,19 +1,20 @@
var send = require("../send");
var each = require("../../each/blog");

var emailFile = __dirname + "/email.txt";
var users = [];

each(
function(user, blog, next) {
// Use this function to filter blogs based on
// whether or not we should email their owner.
function filter(user, blog, next) {

// Add the user to the list of users to email
users.push(user);

next();
}

users.push(user);
next();
},
function() {
send(emailFile, users, function(err) {
if (err) throw err;
process.exit();
});
}
);
each(filter, function() {
send(__dirname + "/email.txt", users, function(err) {
if (err) throw err;
process.exit();
});
});

0 comments on commit 9449142

Please sign in to comment.