2014-05-11 19:07:58 +00:00
|
|
|
var fs = require('fs');
|
2014-05-13 06:59:46 +00:00
|
|
|
var os = require('os');
|
2014-05-11 19:07:58 +00:00
|
|
|
var blessed = require('blessed');
|
|
|
|
var multiline = require('multiline');
|
|
|
|
|
2014-07-27 03:22:20 +00:00
|
|
|
if (os.platform() === 'win32') {
|
2014-10-18 17:38:55 +00:00
|
|
|
console.log('**************************************************************');
|
|
|
|
console.log('Hackathon Starter Generator has been disabled on Windows until');
|
2014-07-27 03:22:20 +00:00
|
|
|
console.log('https://github.com/chjj/blessed is fixed or until I find a');
|
|
|
|
console.log('better CLI module.');
|
2014-10-18 17:38:55 +00:00
|
|
|
console.log('**************************************************************');
|
2014-07-27 03:22:20 +00:00
|
|
|
process.exit();
|
|
|
|
}
|
2014-05-11 12:10:00 +00:00
|
|
|
var screen = blessed.screen({
|
2014-05-11 15:11:17 +00:00
|
|
|
autoPadding: true
|
2014-05-11 12:10:00 +00:00
|
|
|
});
|
|
|
|
|
2014-05-13 05:13:27 +00:00
|
|
|
screen.key('q', function() {
|
|
|
|
process.exit(0);
|
|
|
|
});
|
|
|
|
|
2014-05-11 15:11:17 +00:00
|
|
|
var home = blessed.list({
|
2014-05-11 12:10:00 +00:00
|
|
|
parent: screen,
|
|
|
|
padding: { top: 2 },
|
|
|
|
mouse: true,
|
|
|
|
keys: true,
|
|
|
|
fg: 'white',
|
|
|
|
bg: 'blue',
|
|
|
|
selectedFg: 'blue',
|
|
|
|
selectedBg: 'white',
|
|
|
|
items: [
|
2014-05-13 07:57:23 +00:00
|
|
|
'» REMOVE AUTHENTICATION PROVIDER',
|
2014-05-11 19:07:58 +00:00
|
|
|
'» CHANGE EMAIL SERVICE',
|
|
|
|
'» ADD NODE.JS CLUSTER SUPPORT',
|
|
|
|
'» EXIT'
|
2014-05-11 12:10:00 +00:00
|
|
|
]
|
|
|
|
});
|
|
|
|
|
2014-05-13 22:39:25 +00:00
|
|
|
var homeTitle = blessed.text({
|
|
|
|
parent: screen,
|
|
|
|
align: 'center',
|
|
|
|
fg: 'blue',
|
|
|
|
bg: 'white',
|
|
|
|
content: 'Hackathon Starter (c) 2014'
|
|
|
|
});
|
|
|
|
|
|
|
|
var footer = blessed.text({
|
|
|
|
parent: screen,
|
|
|
|
bottom: 0,
|
|
|
|
fg: 'white',
|
|
|
|
bg: 'blue',
|
|
|
|
tags: true,
|
2014-12-23 16:48:28 +00:00
|
|
|
content: ' {cyan-fg}<Up/Down>{/cyan-fg} moves |' +
|
|
|
|
' {cyan-fg}<Enter>{/cyan-fg} selects | {cyan-fg}<q>{/cyan-fg} exits'
|
2014-05-13 22:39:25 +00:00
|
|
|
});
|
|
|
|
|
2014-05-11 19:07:58 +00:00
|
|
|
var inner = blessed.form({
|
2014-05-11 16:24:16 +00:00
|
|
|
top: 'center',
|
|
|
|
left: 'center',
|
2014-05-11 19:07:58 +00:00
|
|
|
mouse: true,
|
|
|
|
keys: true,
|
2014-05-11 17:15:15 +00:00
|
|
|
width: 33,
|
|
|
|
height: 10,
|
2014-05-11 16:24:16 +00:00
|
|
|
border: {
|
|
|
|
type: 'line',
|
|
|
|
fg: 'white',
|
|
|
|
bg: 'red'
|
|
|
|
},
|
|
|
|
fg: 'white',
|
|
|
|
bg: 'red'
|
|
|
|
});
|
|
|
|
|
2014-05-11 19:07:58 +00:00
|
|
|
var success = blessed.box({
|
|
|
|
top: 'center',
|
|
|
|
left: 'center',
|
|
|
|
mouse: true,
|
|
|
|
keys: true,
|
|
|
|
tags: true,
|
|
|
|
width: '50%',
|
|
|
|
height: '40%',
|
|
|
|
border: {
|
|
|
|
type: 'line',
|
|
|
|
fg: 'white',
|
|
|
|
bg: 'green'
|
|
|
|
},
|
|
|
|
fg: 'white',
|
|
|
|
bg: 'green',
|
|
|
|
padding: 1
|
|
|
|
});
|
|
|
|
|
|
|
|
success.on('keypress', function() {
|
|
|
|
home.focus();
|
|
|
|
home.remove(success);
|
|
|
|
});
|
|
|
|
|
2014-05-11 17:15:15 +00:00
|
|
|
var clusterText = blessed.text({
|
|
|
|
top: 'top',
|
|
|
|
bg: 'red',
|
|
|
|
fg: 'white',
|
|
|
|
tags: true,
|
2014-12-23 16:48:28 +00:00
|
|
|
content: 'Take advantage of multi-core systems' +
|
|
|
|
' using built-in {underline}cluster{/underline} module.'
|
2014-05-11 17:15:15 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
var enable = blessed.button({
|
|
|
|
parent: inner,
|
|
|
|
bottom: 0,
|
|
|
|
mouse: true,
|
|
|
|
shrink: true,
|
|
|
|
name: 'enable',
|
|
|
|
content: ' ENABLE ',
|
|
|
|
border: {
|
|
|
|
type: 'line',
|
|
|
|
fg: 'white',
|
|
|
|
bg: 'red'
|
|
|
|
},
|
|
|
|
style: {
|
|
|
|
fg: 'white',
|
|
|
|
bg: 'red',
|
|
|
|
focus: {
|
2014-05-11 19:07:58 +00:00
|
|
|
fg: 'red',
|
|
|
|
bg: 'white'
|
2014-05-11 17:15:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-05-11 19:07:58 +00:00
|
|
|
|
2014-05-11 17:15:15 +00:00
|
|
|
var disable = blessed.button({
|
|
|
|
parent: inner,
|
|
|
|
bottom: 0,
|
|
|
|
left: 10,
|
|
|
|
mouse: true,
|
|
|
|
shrink: true,
|
|
|
|
name: 'disable',
|
|
|
|
content: ' DISABLE ',
|
|
|
|
border: {
|
|
|
|
type: 'line',
|
|
|
|
fg: 'white',
|
|
|
|
bg: 'red'
|
|
|
|
},
|
|
|
|
style: {
|
|
|
|
fg: 'white',
|
|
|
|
bg: 'red',
|
|
|
|
focus: {
|
2014-05-11 19:07:58 +00:00
|
|
|
fg: 'red',
|
|
|
|
bg: 'white'
|
2014-05-11 17:15:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var cancel = blessed.button({
|
|
|
|
parent: inner,
|
|
|
|
bottom: 0,
|
|
|
|
left: 21,
|
|
|
|
mouse: true,
|
|
|
|
shrink: true,
|
|
|
|
name: 'cancel',
|
|
|
|
content: ' CANCEL ',
|
|
|
|
border: {
|
|
|
|
type: 'line',
|
|
|
|
fg: 'white',
|
|
|
|
bg: 'red'
|
|
|
|
},
|
|
|
|
style: {
|
|
|
|
fg: 'white',
|
|
|
|
bg: 'red',
|
|
|
|
focus: {
|
2014-05-11 19:07:58 +00:00
|
|
|
fg: 'red',
|
|
|
|
bg: 'white'
|
2014-05-11 17:15:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2014-05-11 16:24:16 +00:00
|
|
|
|
2014-05-11 19:07:58 +00:00
|
|
|
cancel.on('press', function() {
|
|
|
|
home.focus();
|
|
|
|
home.remove(inner);
|
|
|
|
screen.render();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2014-05-13 07:57:23 +00:00
|
|
|
var authForm = blessed.form({
|
2014-05-11 15:11:17 +00:00
|
|
|
mouse: true,
|
|
|
|
keys: true,
|
|
|
|
fg: 'white',
|
|
|
|
bg: 'blue',
|
|
|
|
padding: { left: 1, right: 1 }
|
|
|
|
});
|
|
|
|
|
2014-05-13 08:40:28 +00:00
|
|
|
authForm.on('submit', function() {
|
2014-12-23 16:48:28 +00:00
|
|
|
var passportConfig = fs.readFileSync('config/passport.js')
|
|
|
|
.toString().split(os.EOL);
|
|
|
|
var loginTemplate = fs.readFileSync('views/account/login.jade')
|
|
|
|
.toString().split(os.EOL);
|
|
|
|
var profileTemplate = fs.readFileSync('views/account/profile.jade')
|
|
|
|
.toString().split(os.EOL);
|
2014-05-13 07:57:23 +00:00
|
|
|
var userModel = fs.readFileSync('models/User.js').toString().split(os.EOL);
|
|
|
|
var app = fs.readFileSync('app.js').toString().split(os.EOL);
|
|
|
|
var secrets = fs.readFileSync('config/secrets.js').toString().split(os.EOL);
|
|
|
|
|
2014-12-23 16:48:28 +00:00
|
|
|
var index = passportConfig
|
|
|
|
.indexOf('var FacebookStrategy = require("passport-facebook").Strategy;');
|
2014-05-13 08:40:28 +00:00
|
|
|
if (facebookCheckbox.checked && index !== -1) {
|
2014-05-13 07:57:23 +00:00
|
|
|
passportConfig.splice(index, 1);
|
|
|
|
index = passportConfig.indexOf('// Sign in with Facebook.');
|
|
|
|
passportConfig.splice(index, 47);
|
|
|
|
fs.writeFileSync('config/passport.js', passportConfig.join(os.EOL));
|
|
|
|
|
2014-12-23 16:48:28 +00:00
|
|
|
index = loginTemplate.indexOf(
|
|
|
|
' a.btn.btn-block.btn-facebook.btn-social(href="/auth/facebook")'
|
|
|
|
);
|
2014-05-13 07:57:23 +00:00
|
|
|
loginTemplate.splice(index, 3);
|
|
|
|
fs.writeFileSync('views/account/login.jade', loginTemplate.join(os.EOL));
|
|
|
|
|
2014-12-23 16:48:28 +00:00
|
|
|
index = profileTemplate.indexOf(' if user.facebook');
|
2014-05-13 07:57:23 +00:00
|
|
|
profileTemplate.splice(index - 1, 5);
|
2014-12-23 16:48:28 +00:00
|
|
|
fs.writeFileSync(
|
|
|
|
'views/account/profile.jade',
|
|
|
|
profileTemplate.join(os.EOL)
|
|
|
|
);
|
2014-05-13 07:57:23 +00:00
|
|
|
|
|
|
|
index = userModel.indexOf(' facebook: String,');
|
|
|
|
userModel.splice(index, 1);
|
|
|
|
fs.writeFileSync('models/User.js', userModel.join(os.EOL));
|
|
|
|
|
2014-12-23 16:48:28 +00:00
|
|
|
index = app.indexOf([
|
|
|
|
'app.get("/auth/facebook"',
|
|
|
|
'passport.authenticate("facebook",',
|
|
|
|
' { scope: ["email", "user_location"] }));'
|
|
|
|
].join(' '));
|
|
|
|
|
2014-05-13 07:57:23 +00:00
|
|
|
app.splice(index, 4);
|
|
|
|
fs.writeFileSync('app.js', app.join(os.EOL));
|
|
|
|
}
|
|
|
|
|
2014-12-23 16:48:28 +00:00
|
|
|
index = passportConfig.indexOf(
|
|
|
|
"var GitHubStrategy = require('passport-github').Strategy;"
|
|
|
|
);
|
2014-05-13 08:40:28 +00:00
|
|
|
if (githubCheckbox.checked && index !== -1) {
|
2014-05-13 09:15:28 +00:00
|
|
|
console.log(index);
|
2014-05-13 08:40:28 +00:00
|
|
|
passportConfig.splice(index, 1);
|
|
|
|
index = passportConfig.indexOf('// Sign in with GitHub.');
|
|
|
|
passportConfig.splice(index, 48);
|
|
|
|
fs.writeFileSync('config/passport.js', passportConfig.join(os.EOL));
|
|
|
|
|
2014-12-23 16:48:28 +00:00
|
|
|
index = loginTemplate.indexOf(
|
|
|
|
" a.btn.btn-block.btn-github.btn-social(href='/auth/github')"
|
|
|
|
);
|
2014-05-13 08:40:28 +00:00
|
|
|
loginTemplate.splice(index, 3);
|
|
|
|
fs.writeFileSync('views/account/login.jade', loginTemplate.join(os.EOL));
|
|
|
|
|
|
|
|
index = profileTemplate.indexOf(' if user.github');
|
|
|
|
profileTemplate.splice(index - 1, 5);
|
2014-12-23 16:48:28 +00:00
|
|
|
fs.writeFileSync(
|
|
|
|
'views/account/profile.jade',
|
|
|
|
profileTemplate.join(os.EOL)
|
|
|
|
);
|
2014-05-13 08:40:28 +00:00
|
|
|
|
|
|
|
index = userModel.indexOf(' github: String,');
|
|
|
|
userModel.splice(index, 1);
|
|
|
|
fs.writeFileSync('models/User.js', userModel.join(os.EOL));
|
|
|
|
|
2014-12-23 16:48:28 +00:00
|
|
|
index = app.indexOf(
|
|
|
|
'app.get("/auth/github", passport.authenticate("github"));'
|
|
|
|
);
|
2014-05-13 08:40:28 +00:00
|
|
|
app.splice(index, 4);
|
|
|
|
fs.writeFileSync('app.js', app.join(os.EOL));
|
|
|
|
}
|
|
|
|
|
2014-12-23 16:48:28 +00:00
|
|
|
index = passportConfig.indexOf(
|
|
|
|
'var GoogleStrategy = require("passport-google-oauth").OAuth2Strategy;'
|
|
|
|
);
|
2014-05-13 08:40:28 +00:00
|
|
|
if (googleCheckbox.checked && index !== -1) {
|
|
|
|
passportConfig.splice(index, 1);
|
|
|
|
index = passportConfig.indexOf('// Sign in with Google.');
|
|
|
|
passportConfig.splice(index, 46);
|
|
|
|
fs.writeFileSync('config/passport.js', passportConfig.join(os.EOL));
|
|
|
|
|
2014-12-23 16:48:28 +00:00
|
|
|
index = loginTemplate.indexOf(
|
|
|
|
" a.btn.btn-block.btn-google-plus.btn-social(href='/auth/google')"
|
|
|
|
);
|
2014-05-13 08:40:28 +00:00
|
|
|
loginTemplate.splice(index, 3);
|
|
|
|
fs.writeFileSync('views/account/login.jade', loginTemplate.join(os.EOL));
|
|
|
|
|
|
|
|
index = profileTemplate.indexOf(' if user.google');
|
|
|
|
profileTemplate.splice(index - 1, 5);
|
2014-12-23 16:48:28 +00:00
|
|
|
fs.writeFileSync(
|
|
|
|
'views/account/profile.jade',
|
|
|
|
profileTemplate.join(os.EOL)
|
|
|
|
);
|
2014-05-13 08:40:28 +00:00
|
|
|
|
|
|
|
index = userModel.indexOf(' google: String,');
|
|
|
|
userModel.splice(index, 1);
|
|
|
|
fs.writeFileSync('models/User.js', userModel.join(os.EOL));
|
|
|
|
|
2014-12-23 16:48:28 +00:00
|
|
|
index = app.indexOf(
|
|
|
|
'app.get("/auth/google",' +
|
|
|
|
' passport.authenticate("google", { scope: "profile email" }));'
|
|
|
|
);
|
2014-05-13 08:40:28 +00:00
|
|
|
app.splice(index, 4);
|
|
|
|
fs.writeFileSync('app.js', app.join(os.EOL));
|
|
|
|
}
|
|
|
|
|
2014-12-23 16:48:28 +00:00
|
|
|
index = passportConfig.indexOf(
|
|
|
|
'var TwitterStrategy = require("passport-twitter").Strategy;'
|
|
|
|
);
|
2014-05-13 08:40:28 +00:00
|
|
|
if (twitterCheckbox.checked && index !== -1) {
|
|
|
|
passportConfig.splice(index, 1);
|
|
|
|
index = passportConfig.indexOf('// Sign in with Twitter.');
|
|
|
|
passportConfig.splice(index, 43);
|
|
|
|
fs.writeFileSync('config/passport.js', passportConfig.join(os.EOL));
|
|
|
|
|
2014-12-23 16:48:28 +00:00
|
|
|
index = loginTemplate.indexOf(
|
|
|
|
' a.btn.btn-block.btn-twitter.btn-social(href="/auth/twitter")'
|
|
|
|
);
|
2014-05-13 08:40:28 +00:00
|
|
|
loginTemplate.splice(index, 3);
|
|
|
|
fs.writeFileSync('views/account/login.jade', loginTemplate.join(os.EOL));
|
|
|
|
|
|
|
|
index = profileTemplate.indexOf(' if user.twitter');
|
|
|
|
profileTemplate.splice(index - 1, 5);
|
2014-12-23 16:48:28 +00:00
|
|
|
fs.writeFileSync(
|
|
|
|
'views/account/profile.jade', profileTemplate.join(os.EOL)
|
|
|
|
);
|
2014-05-13 08:40:28 +00:00
|
|
|
|
|
|
|
index = userModel.indexOf(' twitter: String,');
|
|
|
|
userModel.splice(index, 1);
|
|
|
|
fs.writeFileSync('models/User.js', userModel.join(os.EOL));
|
|
|
|
|
2014-12-23 16:48:28 +00:00
|
|
|
index = app.indexOf(
|
|
|
|
"app.get('/auth/twitter', passport.authenticate('twitter'));"
|
|
|
|
);
|
2014-05-13 08:40:28 +00:00
|
|
|
app.splice(index, 4);
|
|
|
|
fs.writeFileSync('app.js', app.join(os.EOL));
|
|
|
|
}
|
|
|
|
|
2014-12-23 16:48:28 +00:00
|
|
|
index = passportConfig.indexOf(
|
|
|
|
'var LinkedInStrategy = require("passport-linkedin-oauth2").Strategy;'
|
|
|
|
);
|
2014-05-13 08:40:28 +00:00
|
|
|
if (linkedinCheckbox.checked && index !== -1) {
|
|
|
|
passportConfig.splice(index, 1);
|
|
|
|
index = passportConfig.indexOf('// Sign in with LinkedIn.');
|
2014-05-13 09:15:28 +00:00
|
|
|
passportConfig.splice(index, 47);
|
2014-05-13 08:40:28 +00:00
|
|
|
fs.writeFileSync('config/passport.js', passportConfig.join(os.EOL));
|
|
|
|
|
2014-12-23 16:48:28 +00:00
|
|
|
index = loginTemplate.indexOf(
|
|
|
|
' a.btn.btn-block.btn-linkedin.btn-social(href="/auth/linkedin")'
|
|
|
|
);
|
2014-05-13 08:40:28 +00:00
|
|
|
loginTemplate.splice(index, 3);
|
|
|
|
fs.writeFileSync('views/account/login.jade', loginTemplate.join(os.EOL));
|
|
|
|
|
|
|
|
index = profileTemplate.indexOf(' if user.linkedin');
|
|
|
|
profileTemplate.splice(index - 1, 5);
|
2014-12-23 16:48:28 +00:00
|
|
|
fs.writeFileSync(
|
|
|
|
'views/account/profile.jade',
|
|
|
|
profileTemplate.join(os.EOL)
|
|
|
|
);
|
2014-05-13 08:40:28 +00:00
|
|
|
|
|
|
|
index = userModel.indexOf(' linkedin: String,');
|
|
|
|
userModel.splice(index, 1);
|
|
|
|
fs.writeFileSync('models/User.js', userModel.join(os.EOL));
|
|
|
|
|
2014-12-23 16:48:28 +00:00
|
|
|
index = app.indexOf(
|
|
|
|
'app.get("/auth/linkedin",',
|
|
|
|
' passport.authenticate("linkedin", { state: "SOME STATE" }));'
|
|
|
|
);
|
2014-05-13 08:40:28 +00:00
|
|
|
app.splice(index, 4);
|
|
|
|
fs.writeFileSync('app.js', app.join(os.EOL));
|
|
|
|
}
|
|
|
|
|
2014-12-23 16:48:28 +00:00
|
|
|
index = passportConfig.indexOf(
|
|
|
|
'var InstagramStrategy = require("passport-instagram").Strategy;'
|
|
|
|
);
|
2014-05-13 08:40:28 +00:00
|
|
|
if (instagramCheckbox.checked && index !== -1) {
|
|
|
|
passportConfig.splice(index, 1);
|
|
|
|
index = passportConfig.indexOf('// Sign in with Instagram.');
|
2014-06-06 03:33:05 +00:00
|
|
|
passportConfig.splice(index, 43);
|
2014-12-23 16:48:28 +00:00
|
|
|
fs.writeFileSync(
|
|
|
|
'config/passport.js',
|
|
|
|
passportConfig.join(os.EOL)
|
|
|
|
);
|
|
|
|
|
|
|
|
index = loginTemplate.indexOf(
|
|
|
|
' a.btn.btn-block.btn-instagram.btn-social(href="/auth/instagram")'
|
|
|
|
);
|
2014-05-13 08:40:28 +00:00
|
|
|
loginTemplate.splice(index, 3);
|
2014-12-23 16:48:28 +00:00
|
|
|
|
|
|
|
fs.writeFileSync(
|
|
|
|
'views/account/login.jade',
|
|
|
|
loginTemplate.join(os.EOL)
|
|
|
|
);
|
2014-05-13 08:40:28 +00:00
|
|
|
|
|
|
|
index = profileTemplate.indexOf(' if user.instagram');
|
|
|
|
profileTemplate.splice(index - 1, 5);
|
2014-12-23 16:48:28 +00:00
|
|
|
fs.writeFileSync(
|
|
|
|
'views/account/profile.jade',
|
|
|
|
profileTemplate.join(os.EOL)
|
|
|
|
);
|
|
|
|
|
|
|
|
index = app.indexOf(
|
|
|
|
'app.get("/auth/instagram", passport.authenticate("instagram"));'
|
|
|
|
);
|
2014-05-13 08:40:28 +00:00
|
|
|
app.splice(index, 4);
|
|
|
|
fs.writeFileSync('app.js', app.join(os.EOL));
|
|
|
|
|
|
|
|
userModel.splice(index, 1);
|
|
|
|
fs.writeFileSync('models/User.js', userModel.join(os.EOL));
|
|
|
|
}
|
|
|
|
|
2014-05-13 07:57:23 +00:00
|
|
|
home.remove(authForm);
|
|
|
|
home.append(success);
|
2014-12-23 16:48:28 +00:00
|
|
|
success.setContent(
|
|
|
|
'Selected authentication providers have been removed' +
|
|
|
|
'from passportConfig.js, User.js, app.js, login.jade and profile.jade!'
|
|
|
|
);
|
2014-05-13 07:57:23 +00:00
|
|
|
success.focus();
|
|
|
|
screen.render();
|
|
|
|
});
|
|
|
|
|
2014-05-11 15:11:17 +00:00
|
|
|
var authText = blessed.text({
|
2014-05-13 07:57:23 +00:00
|
|
|
parent: authForm,
|
2014-12-23 16:48:28 +00:00
|
|
|
content: 'Selecting a checkbox removes an authentication provider.' +
|
|
|
|
' If authentication provider is already removed, no action will be taken.',
|
2014-05-11 15:11:17 +00:00
|
|
|
padding: 1,
|
|
|
|
bg: 'magenta',
|
|
|
|
fg: 'white'
|
|
|
|
});
|
|
|
|
|
|
|
|
var facebookCheckbox = blessed.checkbox({
|
2014-05-13 07:57:23 +00:00
|
|
|
parent: authForm,
|
2014-05-11 15:11:17 +00:00
|
|
|
top: 6,
|
|
|
|
mouse: true,
|
|
|
|
fg: 'white',
|
|
|
|
bg: 'blue',
|
|
|
|
content: 'Facebook'
|
|
|
|
});
|
|
|
|
|
|
|
|
var githubCheckbox = blessed.checkbox({
|
2014-05-13 07:57:23 +00:00
|
|
|
parent: authForm,
|
2014-05-11 15:11:17 +00:00
|
|
|
top: 7,
|
|
|
|
mouse: true,
|
|
|
|
fg: 'white',
|
|
|
|
bg: 'blue',
|
|
|
|
content: 'GitHub'
|
|
|
|
});
|
|
|
|
|
|
|
|
var googleCheckbox = blessed.checkbox({
|
2014-05-13 07:57:23 +00:00
|
|
|
parent: authForm,
|
2014-05-11 15:11:17 +00:00
|
|
|
top: 8,
|
|
|
|
mouse: true,
|
|
|
|
fg: 'white',
|
|
|
|
bg: 'blue',
|
|
|
|
content: 'Google'
|
|
|
|
});
|
|
|
|
|
|
|
|
var twitterCheckbox = blessed.checkbox({
|
2014-05-13 07:57:23 +00:00
|
|
|
parent: authForm,
|
2014-05-11 15:11:17 +00:00
|
|
|
top: 9,
|
|
|
|
mouse: true,
|
|
|
|
fg: 'white',
|
|
|
|
bg: 'blue',
|
|
|
|
content: 'Twitter'
|
|
|
|
});
|
|
|
|
|
|
|
|
var linkedinCheckbox = blessed.checkbox({
|
2014-05-13 07:57:23 +00:00
|
|
|
parent: authForm,
|
2014-05-11 15:11:17 +00:00
|
|
|
top: 10,
|
|
|
|
mouse: true,
|
|
|
|
fg: 'white',
|
|
|
|
bg: 'blue',
|
|
|
|
content: 'LinkedIn'
|
|
|
|
});
|
|
|
|
|
|
|
|
var instagramCheckbox = blessed.checkbox({
|
2014-05-13 07:57:23 +00:00
|
|
|
parent: authForm,
|
2014-05-11 15:11:17 +00:00
|
|
|
top: 11,
|
|
|
|
mouse: true,
|
|
|
|
fg: 'white',
|
|
|
|
bg: 'blue',
|
|
|
|
content: 'Instagram'
|
|
|
|
});
|
|
|
|
|
2014-05-11 19:07:58 +00:00
|
|
|
var authSubmit = blessed.button({
|
2014-05-13 07:57:23 +00:00
|
|
|
parent: authForm,
|
2014-05-11 15:11:17 +00:00
|
|
|
top: 13,
|
|
|
|
mouse: true,
|
|
|
|
shrink: true,
|
2014-05-11 19:07:58 +00:00
|
|
|
name: 'submit',
|
2014-05-11 15:11:17 +00:00
|
|
|
content: ' SUBMIT ',
|
|
|
|
style: {
|
|
|
|
fg: 'blue',
|
|
|
|
bg: 'white',
|
|
|
|
focus: {
|
|
|
|
fg: 'white',
|
|
|
|
bg: 'red'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-05-13 07:57:23 +00:00
|
|
|
authSubmit.on('press', function() {
|
|
|
|
authForm.submit();
|
|
|
|
});
|
|
|
|
|
2014-05-11 15:11:17 +00:00
|
|
|
var authCancel = blessed.button({
|
2014-05-13 07:57:23 +00:00
|
|
|
parent: authForm,
|
2014-05-11 15:11:17 +00:00
|
|
|
top: 13,
|
|
|
|
left: 9,
|
|
|
|
mouse: true,
|
|
|
|
shrink: true,
|
|
|
|
name: 'cancel',
|
|
|
|
content: ' CANCEL ',
|
|
|
|
style: {
|
|
|
|
fg: 'blue',
|
|
|
|
bg: 'white',
|
|
|
|
focus: {
|
|
|
|
fg: 'white',
|
|
|
|
bg: 'red'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-05-11 19:07:58 +00:00
|
|
|
authCancel.on('press', function() {
|
|
|
|
home.focus();
|
2014-05-13 07:57:23 +00:00
|
|
|
home.remove(authForm);
|
2014-05-11 19:07:58 +00:00
|
|
|
screen.render();
|
|
|
|
});
|
|
|
|
|
2014-05-13 06:59:46 +00:00
|
|
|
var emailForm = blessed.form({
|
2014-05-11 16:24:16 +00:00
|
|
|
mouse: true,
|
|
|
|
keys: true,
|
2014-05-11 19:07:58 +00:00
|
|
|
fg: 'white',
|
2014-05-11 16:24:16 +00:00
|
|
|
bg: 'blue',
|
|
|
|
padding: { left: 1, right: 1 }
|
|
|
|
});
|
|
|
|
|
2014-05-13 08:40:28 +00:00
|
|
|
emailForm.on('submit', function() {
|
2014-12-23 16:48:28 +00:00
|
|
|
var contactCtrl = fs.readFileSync('controllers/contact.js')
|
|
|
|
.toString().split(os.EOL);
|
|
|
|
var userCtrl = fs.readFileSync('controllers/user.js')
|
|
|
|
.toString().split(os.EOL);
|
2014-05-13 06:59:46 +00:00
|
|
|
var choice = null;
|
|
|
|
|
|
|
|
if (sendgridRadio.checked) {
|
|
|
|
choice = 'SendGrid';
|
|
|
|
} else if (mailgunRadio.checked) {
|
|
|
|
choice = 'Mailgun';
|
|
|
|
} else if (mandrillRadio.checked) {
|
|
|
|
choice = 'Mandrill';
|
|
|
|
}
|
|
|
|
|
2014-12-23 16:48:28 +00:00
|
|
|
var index = contactCtrl.indexOf(
|
|
|
|
'var transporter = nodemailer.createTransport({'
|
|
|
|
);
|
2014-05-13 06:59:46 +00:00
|
|
|
contactCtrl.splice(index + 1, 1, " service: '" + choice + "',");
|
2014-12-23 16:48:28 +00:00
|
|
|
contactCtrl.splice(
|
|
|
|
index + 3,
|
|
|
|
1,
|
|
|
|
' user: secrets.' + choice.toLowerCase() + '.user,'
|
|
|
|
);
|
|
|
|
contactCtrl.splice(
|
|
|
|
index + 4,
|
|
|
|
1,
|
|
|
|
' pass: secrets.' + choice.toLowerCase() + '.password'
|
|
|
|
);
|
2014-05-13 06:59:46 +00:00
|
|
|
fs.writeFileSync('controllers/contact.js', contactCtrl.join(os.EOL));
|
|
|
|
|
2014-12-23 16:48:28 +00:00
|
|
|
index = userCtrl.indexOf(
|
|
|
|
' var transporter = nodemailer.createTransport({'
|
|
|
|
);
|
2014-05-13 06:59:46 +00:00
|
|
|
userCtrl.splice(index + 1, 1, " service: '" + choice + "',");
|
2014-12-23 16:48:28 +00:00
|
|
|
userCtrl.splice(
|
|
|
|
index + 3,
|
|
|
|
1,
|
|
|
|
' user: secrets.' + choice.toLowerCase() + '.user,'
|
|
|
|
);
|
|
|
|
userCtrl.splice(
|
|
|
|
index + 4,
|
|
|
|
1,
|
|
|
|
' pass: secrets.' + choice.toLowerCase() + '.password'
|
|
|
|
);
|
|
|
|
|
|
|
|
index = userCtrl.indexOf(
|
|
|
|
' var transporter = nodemailer.createTransport({',
|
|
|
|
(index + 1)
|
|
|
|
);
|
|
|
|
userCtrl.splice(
|
|
|
|
index + 1,
|
|
|
|
1,
|
|
|
|
' service: "' + choice + '",'
|
|
|
|
);
|
|
|
|
|
|
|
|
userCtrl.splice(
|
|
|
|
index + 3,
|
|
|
|
1,
|
|
|
|
' user: secrets.' + choice.toLowerCase() + '.user,'
|
|
|
|
);
|
|
|
|
userCtrl.splice(
|
|
|
|
index + 4,
|
|
|
|
1,
|
|
|
|
' pass: secrets.' + choice.toLowerCase() + '.password'
|
|
|
|
);
|
2014-05-13 06:59:46 +00:00
|
|
|
fs.writeFileSync('controllers/user.js', userCtrl.join(os.EOL));
|
|
|
|
|
|
|
|
home.remove(emailForm);
|
|
|
|
home.append(success);
|
|
|
|
success.setContent('Email Service has been switched to ' + choice);
|
|
|
|
success.focus();
|
|
|
|
screen.render();
|
|
|
|
});
|
2014-05-11 19:07:58 +00:00
|
|
|
|
2014-05-11 16:24:16 +00:00
|
|
|
var emailText = blessed.text({
|
2014-05-13 06:59:46 +00:00
|
|
|
parent: emailForm,
|
2014-12-23 16:48:28 +00:00
|
|
|
content: 'Select one of the following email service providers ' +
|
|
|
|
'for {underline}contact form{/underline}' +
|
|
|
|
' and {underline}password reset{/underline}.',
|
2014-05-11 16:24:16 +00:00
|
|
|
padding: 1,
|
|
|
|
bg: 'red',
|
|
|
|
fg: 'white',
|
|
|
|
tags: true
|
|
|
|
});
|
|
|
|
|
|
|
|
var sendgridRadio = blessed.radiobutton({
|
2014-05-13 06:59:46 +00:00
|
|
|
parent: emailForm,
|
2014-05-11 16:24:16 +00:00
|
|
|
top: 5,
|
2014-05-13 06:59:46 +00:00
|
|
|
checked: true,
|
2014-05-11 16:24:16 +00:00
|
|
|
mouse: true,
|
|
|
|
fg: 'white',
|
|
|
|
bg: 'blue',
|
|
|
|
content: 'SendGrid'
|
|
|
|
});
|
|
|
|
|
|
|
|
var mailgunRadio = blessed.radiobutton({
|
2014-05-13 06:59:46 +00:00
|
|
|
parent: emailForm,
|
2014-05-11 16:24:16 +00:00
|
|
|
top: 6,
|
|
|
|
mouse: true,
|
|
|
|
fg: 'white',
|
|
|
|
bg: 'blue',
|
|
|
|
content: 'Mailgun'
|
|
|
|
});
|
|
|
|
|
|
|
|
var mandrillRadio = blessed.radiobutton({
|
2014-05-13 06:59:46 +00:00
|
|
|
parent: emailForm,
|
2014-05-11 16:24:16 +00:00
|
|
|
top: 7,
|
|
|
|
mouse: true,
|
|
|
|
fg: 'white',
|
|
|
|
bg: 'blue',
|
|
|
|
content: 'Mandrill'
|
|
|
|
});
|
|
|
|
|
2014-05-13 06:59:46 +00:00
|
|
|
var emailSubmit = blessed.button({
|
|
|
|
parent: emailForm,
|
2014-05-11 16:24:16 +00:00
|
|
|
top: 9,
|
|
|
|
mouse: true,
|
|
|
|
shrink: true,
|
2014-05-13 06:59:46 +00:00
|
|
|
name: 'submit',
|
2014-05-11 16:24:16 +00:00
|
|
|
content: ' SUBMIT ',
|
|
|
|
style: {
|
|
|
|
fg: 'blue',
|
|
|
|
bg: 'white',
|
|
|
|
focus: {
|
|
|
|
fg: 'white',
|
|
|
|
bg: 'red'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-05-13 06:59:46 +00:00
|
|
|
emailSubmit.on('press', function() {
|
|
|
|
emailForm.submit();
|
|
|
|
});
|
|
|
|
|
2014-05-11 16:24:16 +00:00
|
|
|
var emailCancel = blessed.button({
|
2014-05-13 06:59:46 +00:00
|
|
|
parent: emailForm,
|
2014-05-11 16:24:16 +00:00
|
|
|
top: 9,
|
|
|
|
left: 9,
|
|
|
|
mouse: true,
|
|
|
|
shrink: true,
|
|
|
|
name: 'cancel',
|
|
|
|
content: ' CANCEL ',
|
|
|
|
style: {
|
|
|
|
fg: 'blue',
|
|
|
|
bg: 'white',
|
|
|
|
focus: {
|
|
|
|
fg: 'white',
|
|
|
|
bg: 'red'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-05-11 19:07:58 +00:00
|
|
|
emailCancel.on('press', function() {
|
|
|
|
home.focus();
|
2014-05-13 06:59:46 +00:00
|
|
|
home.remove(emailForm);
|
2014-05-11 19:07:58 +00:00
|
|
|
screen.render();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2014-05-11 15:11:17 +00:00
|
|
|
home.on('select', function(child, index) {
|
|
|
|
switch (index) {
|
|
|
|
case 0:
|
2014-05-13 07:57:23 +00:00
|
|
|
home.append(authForm);
|
|
|
|
authForm.focus();
|
2014-05-11 19:07:58 +00:00
|
|
|
screen.render();
|
2014-05-11 15:11:17 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2014-05-13 06:59:46 +00:00
|
|
|
home.append(emailForm);
|
|
|
|
emailForm.focus();
|
2014-05-11 15:11:17 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2014-05-11 19:07:58 +00:00
|
|
|
addClusterSupport();
|
|
|
|
home.append(success);
|
2014-12-23 16:48:28 +00:00
|
|
|
success.setContent([
|
|
|
|
'New file {underline}cluster_app.js{/underline} has been created.',
|
|
|
|
'Your app is now able to use more than 1 CPU by running',
|
|
|
|
'{underline}node cluster_app.js{/underline}, which in turn',
|
|
|
|
'spawns multiple instances of {underline}app.js{/underline}'
|
|
|
|
].join(' '));
|
2014-05-11 19:07:58 +00:00
|
|
|
success.focus();
|
2014-05-11 17:15:15 +00:00
|
|
|
screen.render();
|
2014-05-11 15:11:17 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
process.exit(0);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-05-11 12:10:00 +00:00
|
|
|
screen.render();
|
|
|
|
|
2014-05-11 19:07:58 +00:00
|
|
|
|
|
|
|
function addClusterSupport() {
|
|
|
|
|
|
|
|
var fileContents = multiline(function() {
|
|
|
|
/*
|
|
|
|
var os = require('os');
|
|
|
|
var cluster = require('cluster');
|
|
|
|
|
|
|
|
cluster.setupMaster({
|
|
|
|
exec: 'app.js'
|
|
|
|
});
|
|
|
|
|
|
|
|
cluster.on('exit', function(worker) {
|
|
|
|
console.log('worker ' + worker.id + ' died');
|
|
|
|
cluster.fork();
|
|
|
|
});
|
|
|
|
|
|
|
|
for (var i = 0; i < os.cpus().length; i++) {
|
|
|
|
cluster.fork();
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
});
|
|
|
|
|
|
|
|
fs.writeFileSync('cluster_app.js', fileContents);
|
2014-08-18 23:24:27 +00:00
|
|
|
}
|