-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
68d9248
commit 88f2da9
Showing
5 changed files
with
155 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
const User = require("models/user"); | ||
const Blog = require("models/blog"); | ||
const config = require("config"); | ||
const format = require("url").format; | ||
|
||
const email = "[email protected]"; | ||
const password = "password"; | ||
|
||
function establishTestUser () { | ||
return new Promise((resolve, reject) => { | ||
User.getByEmail(email, function (err, user) { | ||
if (err) return reject(err); | ||
if (user) return resolve(user); | ||
User.hashPassword(password, function (err, passwordHash) { | ||
if (err) return reject(err); | ||
User.create(email, passwordHash, {}, {}, function (err, newUser) { | ||
if (err) return reject(err); | ||
resolve(newUser); | ||
}); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
function establishTestBlog(user) { | ||
return new Promise((resolve, reject) => { | ||
if (user.blogs.length > 0) return resolve(user); | ||
|
||
Blog.create(user.uid, { handle: "example" }, (err, blog) => { | ||
if (err) return reject(err); | ||
user.blogs.push(blog.id); | ||
resolve(user); | ||
}); | ||
}); | ||
} | ||
|
||
const configureBlog = (blogID) => { | ||
return new Promise((resolve, reject) => { | ||
Blog.get({ id: blogID }, (err, blog) => { | ||
if (err) return reject(err); | ||
Blog.set(blogID, { forceSSL: false, client: "local" }, (err) => { | ||
if (err) return reject(err); | ||
resolve(blog); | ||
}); | ||
}); | ||
}); | ||
}; | ||
|
||
function configureBlogs(user) { | ||
return new Promise((resolve, reject) => { | ||
|
||
|
||
const configureAllBlogs = async () => { | ||
|
||
let blog; | ||
|
||
for (const blogID of user.blogs) { | ||
blog = await configureBlog(blogID); | ||
} | ||
|
||
return blog; | ||
}; | ||
|
||
configureAllBlogs() | ||
.then((blog) => { | ||
User.generateAccessToken({ uid: user.uid }, (err, token) => { | ||
if (err) return reject(err); | ||
|
||
const url = format({ | ||
protocol: "https", | ||
host: config.host, | ||
pathname: "/sites/log-in", | ||
query: { token: token } | ||
}); | ||
|
||
console.log("Local server capabilities:"); | ||
console.log("- twitter embeds " + !!config.twitter.consumer_secret); | ||
console.log("- markdown with pandoc " + !!config.pandoc.bin); | ||
console.log("- .docx conversion " + !!config.pandoc.bin); | ||
console.log("- .odt conversion " + !!config.pandoc.bin); | ||
console.log("- dropbox client " + !!config.dropbox.app.key); | ||
console.log("- persistent dashboard sessions " + !!config.session.secret); | ||
|
||
console.log(); | ||
console.log(`Visit your dashboard:`); | ||
console.log(url); | ||
console.log(); | ||
|
||
console.log(`Visit your blog:`); | ||
console.log(`https://${blog.handle}.${config.host}`); | ||
console.log(); | ||
|
||
console.log(`Open your blog's folder:`); | ||
console.log("./data/blogs/" + blog.id); | ||
console.log(); | ||
|
||
resolve(user); | ||
}); | ||
}) | ||
.catch(reject); | ||
}); | ||
} | ||
|
||
const main = async function (){ | ||
const user = await establishTestUser(); | ||
await establishTestBlog(user); | ||
await configureBlogs(user); | ||
} | ||
|
||
module.exports = config.environment === "development" ? main : () => {}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters