Browse Source

`up kill` now works!

tags/v0.2.0
Muthu Kumar 7 years ago
parent
commit
28395af4c8
  1. 20
      README.md
  2. 1
      actions/createProxyServer.js
  3. 43
      actions/createStaticServer.js
  4. 15
      actions/killServer.js
  5. 30
      index.js
  6. 68
      package.json

20
README.md

@ -8,7 +8,7 @@
# up # up
> Current version: `up v.0.1.3 (Pre-Alpha)` > Current version: `up v.0.1.4 (Pre-Alpha)`
> Notes: `up` has landed in pre-alpha! 🎉 Changelog will be added from `up v.0.2.0` [(Alpha/MVP)](Roadmap.md)\ > Notes: `up` has landed in pre-alpha! 🎉 Changelog will be added from `up v.0.2.0` [(Alpha/MVP)](Roadmap.md)\
> ⚠️ ❌ `up` is still not ready for use yet! Do not attempt to use this in development or production until alpha! > ⚠️ ❌ `up` is still not ready for use yet! Do not attempt to use this in development or production until alpha!
@ -22,19 +22,7 @@ As of now, `up` only supports Debian and Ubuntu based distros. Support for more
You will need to have [_node JS_](https://nodejs.org) and [_nginx_](https://nginx.org) installed. You will need to have [_node JS_](https://nodejs.org) and [_nginx_](https://nginx.org) installed.
If you intend to install up for development, follow these instructions: Install `up` from npm:
`git clone https://github.com/codefeathers/up-serve`
`cd up-serve`
`npm install`
`npm install -g`
> `up` is now available as a command.
Alternatively, to use `up` on to deploy servers install from npm:
`npm i -g up-serve` `npm i -g up-serve`
@ -46,7 +34,7 @@ Alternatively, to use `up` on to deploy servers install from npm:
`up proxy <domain> <port>` - Create new proxy server listening at said port. `up proxy <domain> <port>` - Create new proxy server listening at said port.
`up list` - List currently available servers. `up list` - List currently available servers. (Doesn't work yet)
`up kill <domain>` - Kill the server for this domain. `up kill <domain>` - Kill the server for this domain.
@ -56,6 +44,8 @@ Alternatively, to use `up` on to deploy servers install from npm:
`up proxy example.com 8081` will create a reverse proxy listening at port 8081. `up proxy example.com 8081` will create a reverse proxy listening at port 8081.
`up kill example.com`
## Contributors, Collaborators, and Guides ## Contributors, Collaborators, and Guides
Plenty of people gave their time guiding me and shaping this tool. Plenty of people gave their time guiding me and shaping this tool.

1
actions/createProxyServer.js

@ -1,5 +1,6 @@
var fs = require('fs-extra'); var fs = require('fs-extra');
var shell = require('shelljs'); var shell = require('shelljs');
var npath = require('../util/nginxPath'); var npath = require('../util/nginxPath');
var conf = require('../util/nginxConf'); var conf = require('../util/nginxConf');
var nginxReload = require('../util/nginxReload'); var nginxReload = require('../util/nginxReload');

43
actions/createStaticServer.js

@ -1,35 +1,36 @@
var fs = require('fs-extra'); var fs = require('fs-extra');
var shell = require('shelljs'); var shell = require('shelljs');
var path = require('path');
var npath = require('../util/nginxPath'); var npath = require('../util/nginxPath');
var conf = require('../util/nginxConf'); var conf = require('../util/nginxConf');
var path = require('path');
var nginxReload = require('../util/nginxReload'); var nginxReload = require('../util/nginxReload');
var currentPath = path.normalize(process.cwd()); var currentPath = path.normalize(process.cwd());
var { EOL } = require('os'); // \n if used on Linux, \r\n if used on Windows. var { EOL } = require('os'); // \n if used on Linux, \r\n if used on Windows.
function createStaticServer(domain, outPort = 80) { function createStaticServer(domain, outPort = 80) {
fs.outputFileSync((conf(npath.availableSites(), domain)), // Gets nginx's paths from nginxPath.js fs.outputFileSync((conf(npath.availableSites(), domain)), // Gets nginx's paths from nginxPath.js
"server {" + EOL + "server {" + EOL +
" listen " + outPort + ";" + EOL + " listen " + outPort + ";" + EOL +
" listen [::]:" + outPort + ";" + EOL + " listen [::]:" + outPort + ";" + EOL +
" root " + npath.webRoot() + domain + ";" + EOL + " root " + npath.webRoot() + domain + ";" + EOL +
" index index.html index.htm;" + EOL + " index index.html index.htm;" + EOL +
"" + EOL + "" + EOL +
" server_name " + domain + ";" + EOL + " server_name " + domain + ";" + EOL +
" location / {" + EOL + " location / {" + EOL +
" try_files $uri $uri/ =404;" + EOL + " try_files $uri $uri/ =404;" + EOL +
" }" + EOL + " }" + EOL +
"}" "}"
) )
shell.mkdir('-p', npath.enabledSites()); // Creates directory if doesn't exist shell.mkdir('-p', npath.enabledSites()); // Creates directory if doesn't exist
shell.rm('-rf', conf(npath.enabledSites(), domain)); // Removes domain from sites-enabled if exists shell.rm('-rf', conf(npath.enabledSites(), domain)); // Removes domain from sites-enabled if exists
shell.ln('-sf', conf(npath.availableSites(), domain), conf(npath.enabledSites(), domain)); // Symlink the conf file from sites-available to sites-enabled shell.ln('-sf', conf(npath.availableSites(), domain), conf(npath.enabledSites(), domain)); // Symlink the conf file from sites-available to sites-enabled
shell.rm('-rf', npath.webRoot() + domain); // Removes domain from webroot if exists shell.rm('-rf', npath.webRoot() + domain); // Removes domain from webroot if exists
shell.mkdir('-p', npath.webRoot()); // Creating the nginx www path if it doesn't exist so symlink doesn't fail shell.mkdir('-p', npath.webRoot()); // Creating the nginx www path if it doesn't exist so symlink doesn't fail
shell.ln('-sf', currentPath, npath.webRoot() + domain); // Symlink current directory to nginx's web root shell.ln('-sf', currentPath, npath.webRoot() + domain); // Symlink current directory to nginx's web root
nginxReload(); nginxReload();
}; };
module.exports = createStaticServer; module.exports = createStaticServer;

15
actions/killServer.js

@ -0,0 +1,15 @@
var shell = require('shelljs');
var npath = require('../util/nginxPath');
var conf = require('../util/nginxConf');
var nginxReload = require('../util/nginxReload');
function killServer(domain) {
shell.rm('-rf', conf(npath.enabledSites(), domain));
shell.rm('-rf', conf(npath.availableSites(), domain));
shell.rm('-rf', npath.webRoot() + domain);
nginxReload();
}
module.exports = killServer;

30
index.js

@ -13,50 +13,52 @@ var requirements = require('./util/requirements')
// Requiring Actions // Requiring Actions
var createProxyServer = require('./actions/createProxyServer'); var createProxyServer = require('./actions/createProxyServer');
var createStaticServer = require('./actions/createStaticServer'); var createStaticServer = require('./actions/createStaticServer');
var killServer = require('./actions/killServer');
// Check for requirements such as OS version and nginx install. Throw and exit if requirements not found. #Roadmap: Add ability to satisfy any possible requirements. // Check for requirements such as OS version and nginx install. Throw and exit if requirements not found. #Roadmap: Add ability to satisfy any possible requirements.
requirements(); // Comment in development and uncomment this line in production. This should check whether the OS is compatible with this version of `up` // requirements(); // Comment in development and uncomment this line in production. This should check whether the OS is compatible with this version of `up`
program program
.version('0.1.2') .version('0.1.2');
program program
.command('static <domain> [outPort]') .command('static <domain> [outPort]')
.description('Create a static server at this folder.') .description('Create a static server at this folder.')
.action(function (domain, outPort = 80) { //If outport is not given, 80 is set as default. Later, change this default to reflect nginx's settings. .action(function (domain, outPort = 80) { //If outport is not given, 80 is set as default. Later, change this default to reflect nginx's settings.
if (!validate(domain, outPort)) return //Validates domain and outport, and if invalid, throws and returns. if (!validate(domain, outPort)) return; //Validates domain and outport, and if invalid, throws and returns.
createStaticServer(domain, outPort) createStaticServer(domain, outPort);
console.log("Done! Your static server has been set up!\nPoint your domain to this server and check " + chalk.cyan(domain) + " to verify!") console.log("Done! Your static server has been set up!\nPoint your domain to this server and check " + chalk.cyan(domain) + " to verify!");
}) });
program program
.command('proxy <domain> <inPort> [outPort]') .command('proxy <domain> <inPort> [outPort]')
.description('Create a proxy server, listening at port number.') .description('Create a proxy server, listening at port number.')
.action(function (domain, inPort, outPort = "80") { //Inbound port is necessary, but outbound is set to 80 by default. Again, will change this to reflect nginx's settings. .action(function (domain, inPort, outPort = "80") { //Inbound port is necessary, but outbound is set to 80 by default. Again, will change this to reflect nginx's settings.
if (!validate(domain, inPort, outPort)) return if (!validate(domain, inPort, outPort)) return;
createProxyServer(domain, inPort, outPort) createProxyServer(domain, inPort, outPort);
console.log("Done! Your reverse proxy server has been set up!\nPoint your domain to this server and check " + chalk.cyan(domain) + " to verify!") console.log("Done! Your reverse proxy server has been set up!\nPoint your domain to this server and check " + chalk.cyan(domain) + " to verify!");
}) });
program program
.command('list') .command('list')
.description('List all available servers.') .description('List all available servers.')
.action(function () { .action(function () {
// Stuff happens here // Stuff happens here
}) });
program program
.command('kill <domain>') .command('kill <domain>')
.description('Kill a server.') .description('Kill a server.')
.action(function (domain) { .action(function (domain) {
// Stuff happens here killServer(domain);
}) console.log("Done! Your server has been killed!\n");
});
program program
.command('*') // This should pick invalid commands, but it doesn't, yet. .command('*') // This should pick invalid commands, but it doesn't, yet.
.action(function () { .action(function () {
console.log("Invalid command. Type " + chalk.cyan('up --help') + " for help.") console.log("Invalid command. Type " + chalk.cyan('up --help') + " for help.")
}) });
// Adds custom help text to the automatically generated help. // Adds custom help text to the automatically generated help.
program.on('--help', function () { program.on('--help', function () {

68
package.json

@ -1,36 +1,36 @@
{ {
"name": "up-serve", "name": "up-serve",
"version": "0.1.3", "version": "0.1.4",
"description": "A cli tool to quickly create and manage nginx server blocks.", "description": "A cli tool to quickly create and manage nginx server blocks.",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+https://github.com/codefeathers/up-serve.git" "url": "git+https://github.com/codefeathers/up-serve.git"
}, },
"keywords": [ "keywords": [
"up", "up",
"serve", "serve",
"nginx", "nginx",
"server", "server",
"block" "block"
], ],
"bin": { "bin": {
"up": "./index.js" "up": "./index.js"
}, },
"author": "Muthu Kumar (@MKRhere)", "author": "Muthu Kumar (@MKRhere)",
"license": "MIT", "license": "MIT",
"bugs": { "bugs": {
"url": "https://github.com/codefeathers/up-serve/issues" "url": "https://github.com/codefeathers/up-serve/issues"
}, },
"homepage": "https://github.com/codefeathers/up-serve#readme", "homepage": "https://github.com/codefeathers/up-serve#readme",
"dependencies": { "dependencies": {
"chalk": "^2.3.0", "chalk": "^2.3.0",
"commander": "^2.11.0", "commander": "^2.11.0",
"fs-extra": "^4.0.2", "fs-extra": "^4.0.2",
"shelljs": "^0.7.8", "shelljs": "^0.7.8",
"validator": "^9.1.1" "validator": "^9.1.1"
} }
} }

Loading…
Cancel
Save