Removed cluster_app.js, moved to the new generator
This commit is contained in:
@ -1,15 +0,0 @@
|
|||||||
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();
|
|
||||||
}
|
|
147
setup.js
147
setup.js
@ -1,4 +1,7 @@
|
|||||||
var blessed = require('blessed')
|
var fs = require('fs');
|
||||||
|
var blessed = require('blessed');
|
||||||
|
var multiline = require('multiline');
|
||||||
|
|
||||||
var screen = blessed.screen({
|
var screen = blessed.screen({
|
||||||
autoPadding: true
|
autoPadding: true
|
||||||
});
|
});
|
||||||
@ -13,17 +16,19 @@ var home = blessed.list({
|
|||||||
selectedFg: 'blue',
|
selectedFg: 'blue',
|
||||||
selectedBg: 'white',
|
selectedBg: 'white',
|
||||||
items: [
|
items: [
|
||||||
'» Authentication',
|
'» REMOVE AUTHENTICATION',
|
||||||
'» Email Service',
|
'» CHANGE EMAIL SERVICE',
|
||||||
'» Socket.IO',
|
'» ENABLE SOCKET.IO',
|
||||||
'» Node.js Cluster',
|
'» ADD NODE.JS CLUSTER SUPPORT',
|
||||||
'» Exit'
|
'» EXIT'
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
var inner = blessed.box({
|
var inner = blessed.form({
|
||||||
top: 'center',
|
top: 'center',
|
||||||
left: 'center',
|
left: 'center',
|
||||||
|
mouse: true,
|
||||||
|
keys: true,
|
||||||
width: 33,
|
width: 33,
|
||||||
height: 10,
|
height: 10,
|
||||||
border: {
|
border: {
|
||||||
@ -35,6 +40,29 @@ var inner = blessed.box({
|
|||||||
bg: 'red'
|
bg: 'red'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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);
|
||||||
|
});
|
||||||
|
|
||||||
var socketText = blessed.text({
|
var socketText = blessed.text({
|
||||||
top: 'top',
|
top: 'top',
|
||||||
bg: 'red',
|
bg: 'red',
|
||||||
@ -68,12 +96,13 @@ var enable = blessed.button({
|
|||||||
fg: 'white',
|
fg: 'white',
|
||||||
bg: 'red',
|
bg: 'red',
|
||||||
focus: {
|
focus: {
|
||||||
fg: 'white',
|
fg: 'red',
|
||||||
bg: 'red'
|
bg: 'white'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
var disable = blessed.button({
|
var disable = blessed.button({
|
||||||
parent: inner,
|
parent: inner,
|
||||||
bottom: 0,
|
bottom: 0,
|
||||||
@ -91,8 +120,8 @@ var disable = blessed.button({
|
|||||||
fg: 'white',
|
fg: 'white',
|
||||||
bg: 'red',
|
bg: 'red',
|
||||||
focus: {
|
focus: {
|
||||||
fg: 'white',
|
fg: 'red',
|
||||||
bg: 'red'
|
bg: 'white'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -114,13 +143,20 @@ var cancel = blessed.button({
|
|||||||
fg: 'white',
|
fg: 'white',
|
||||||
bg: 'red',
|
bg: 'red',
|
||||||
focus: {
|
focus: {
|
||||||
fg: 'white',
|
fg: 'red',
|
||||||
bg: 'red'
|
bg: 'white'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var authentication = blessed.form({
|
cancel.on('press', function() {
|
||||||
|
home.focus();
|
||||||
|
home.remove(inner);
|
||||||
|
screen.render();
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
var auth = blessed.form({
|
||||||
mouse: true,
|
mouse: true,
|
||||||
keys: true,
|
keys: true,
|
||||||
fg: 'white',
|
fg: 'white',
|
||||||
@ -129,7 +165,7 @@ var authentication = blessed.form({
|
|||||||
});
|
});
|
||||||
|
|
||||||
var authText = blessed.text({
|
var authText = blessed.text({
|
||||||
parent: authentication,
|
parent: auth,
|
||||||
content: 'Selecting a checkbox adds an authentication provider. Unselecting a checkbox removes it. If authentication provider is already present, no action will be taken.',
|
content: 'Selecting a checkbox adds an authentication provider. Unselecting a checkbox removes it. If authentication provider is already present, no action will be taken.',
|
||||||
padding: 1,
|
padding: 1,
|
||||||
bg: 'magenta',
|
bg: 'magenta',
|
||||||
@ -137,7 +173,7 @@ var authText = blessed.text({
|
|||||||
});
|
});
|
||||||
|
|
||||||
var facebookCheckbox = blessed.checkbox({
|
var facebookCheckbox = blessed.checkbox({
|
||||||
parent: authentication,
|
parent: auth,
|
||||||
top: 6,
|
top: 6,
|
||||||
checked: true,
|
checked: true,
|
||||||
mouse: true,
|
mouse: true,
|
||||||
@ -147,7 +183,7 @@ var facebookCheckbox = blessed.checkbox({
|
|||||||
});
|
});
|
||||||
|
|
||||||
var githubCheckbox = blessed.checkbox({
|
var githubCheckbox = blessed.checkbox({
|
||||||
parent: authentication,
|
parent: auth,
|
||||||
top: 7,
|
top: 7,
|
||||||
checked: true,
|
checked: true,
|
||||||
mouse: true,
|
mouse: true,
|
||||||
@ -157,7 +193,7 @@ var githubCheckbox = blessed.checkbox({
|
|||||||
});
|
});
|
||||||
|
|
||||||
var googleCheckbox = blessed.checkbox({
|
var googleCheckbox = blessed.checkbox({
|
||||||
parent: authentication,
|
parent: auth,
|
||||||
top: 8,
|
top: 8,
|
||||||
checked: true,
|
checked: true,
|
||||||
mouse: true,
|
mouse: true,
|
||||||
@ -167,7 +203,7 @@ var googleCheckbox = blessed.checkbox({
|
|||||||
});
|
});
|
||||||
|
|
||||||
var twitterCheckbox = blessed.checkbox({
|
var twitterCheckbox = blessed.checkbox({
|
||||||
parent: authentication,
|
parent: auth,
|
||||||
top: 9,
|
top: 9,
|
||||||
checked: true,
|
checked: true,
|
||||||
mouse: true,
|
mouse: true,
|
||||||
@ -177,7 +213,7 @@ var twitterCheckbox = blessed.checkbox({
|
|||||||
});
|
});
|
||||||
|
|
||||||
var linkedinCheckbox = blessed.checkbox({
|
var linkedinCheckbox = blessed.checkbox({
|
||||||
parent: authentication,
|
parent: auth,
|
||||||
top: 10,
|
top: 10,
|
||||||
checked: true,
|
checked: true,
|
||||||
mouse: true,
|
mouse: true,
|
||||||
@ -187,7 +223,7 @@ var linkedinCheckbox = blessed.checkbox({
|
|||||||
});
|
});
|
||||||
|
|
||||||
var instagramCheckbox = blessed.checkbox({
|
var instagramCheckbox = blessed.checkbox({
|
||||||
parent: authentication,
|
parent: auth,
|
||||||
top: 11,
|
top: 11,
|
||||||
checked: true,
|
checked: true,
|
||||||
mouse: true,
|
mouse: true,
|
||||||
@ -196,12 +232,12 @@ var instagramCheckbox = blessed.checkbox({
|
|||||||
content: 'Instagram'
|
content: 'Instagram'
|
||||||
});
|
});
|
||||||
|
|
||||||
var authOk = blessed.button({
|
var authSubmit = blessed.button({
|
||||||
parent: authentication,
|
parent: auth,
|
||||||
top: 13,
|
top: 13,
|
||||||
mouse: true,
|
mouse: true,
|
||||||
shrink: true,
|
shrink: true,
|
||||||
name: 'ok',
|
name: 'submit',
|
||||||
content: ' SUBMIT ',
|
content: ' SUBMIT ',
|
||||||
style: {
|
style: {
|
||||||
fg: 'blue',
|
fg: 'blue',
|
||||||
@ -214,7 +250,7 @@ var authOk = blessed.button({
|
|||||||
});
|
});
|
||||||
|
|
||||||
var authCancel = blessed.button({
|
var authCancel = blessed.button({
|
||||||
parent: authentication,
|
parent: auth,
|
||||||
top: 13,
|
top: 13,
|
||||||
left: 9,
|
left: 9,
|
||||||
mouse: true,
|
mouse: true,
|
||||||
@ -231,14 +267,21 @@ var authCancel = blessed.button({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
authCancel.on('press', function() {
|
||||||
|
home.focus();
|
||||||
|
home.remove(auth);
|
||||||
|
screen.render();
|
||||||
|
});
|
||||||
|
|
||||||
var email = blessed.form({
|
var email = blessed.form({
|
||||||
mouse: true,
|
mouse: true,
|
||||||
keys: true,
|
keys: true,
|
||||||
fg: 'whiqte',
|
fg: 'white',
|
||||||
bg: 'blue',
|
bg: 'blue',
|
||||||
padding: { left: 1, right: 1 }
|
padding: { left: 1, right: 1 }
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
var emailText = blessed.text({
|
var emailText = blessed.text({
|
||||||
parent: email,
|
parent: email,
|
||||||
content: 'Select one of the following email service providers for {underline}contact form{/underline} and {underline}password reset{/underline}.',
|
content: 'Select one of the following email service providers for {underline}contact form{/underline} and {underline}password reset{/underline}.',
|
||||||
@ -310,6 +353,13 @@ var emailCancel = blessed.button({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
emailCancel.on('press', function() {
|
||||||
|
home.focus();
|
||||||
|
home.remove(email);
|
||||||
|
screen.render();
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
var title = blessed.text({
|
var title = blessed.text({
|
||||||
parent: screen,
|
parent: screen,
|
||||||
align: 'center',
|
align: 'center',
|
||||||
@ -323,14 +373,16 @@ var footer = blessed.text({
|
|||||||
bottom: 0,
|
bottom: 0,
|
||||||
fg: 'white',
|
fg: 'white',
|
||||||
bg: 'blue',
|
bg: 'blue',
|
||||||
content: ' <Up/Down> moves | <Enter> selects | <q> exits'
|
tags: true,
|
||||||
|
content: ' {cyan-fg}<Up/Down>{/cyan-fg} moves | {cyan-fg}<Enter>{/cyan-fg} selects | {cyan-fg}<q>{/cyan-fg} exits'
|
||||||
});
|
});
|
||||||
|
|
||||||
home.on('select', function(child, index) {
|
home.on('select', function(child, index) {
|
||||||
switch (index) {
|
switch (index) {
|
||||||
case 0:
|
case 0:
|
||||||
home.append(authentication);
|
home.append(auth);
|
||||||
authentication.focus();
|
auth.focus();
|
||||||
|
screen.render();
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
home.append(email);
|
home.append(email);
|
||||||
@ -343,10 +395,13 @@ home.on('select', function(child, index) {
|
|||||||
screen.render();
|
screen.render();
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
home.append(inner);
|
// Cluster
|
||||||
inner.append(clusterText);
|
addClusterSupport();
|
||||||
inner.focus();
|
home.append(success);
|
||||||
|
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 node {underline}cluster_app.js{/underline}, which in turn spawns multiple instances of {underline}app.js{/underline}');
|
||||||
|
success.focus();
|
||||||
screen.render();
|
screen.render();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
@ -354,11 +409,35 @@ home.on('select', function(child, index) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
screen.key('q', function() {
|
screen.key('q', function() {
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
|
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user