diff --git a/README.md b/README.md index bf0d200..98de361 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ # 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)\ > ⚠️ ❌ `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. -If you intend to install up for development, follow these instructions: - -`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: +Install `up` from npm: `npm i -g up-serve` @@ -46,7 +34,7 @@ Alternatively, to use `up` on to deploy servers install from npm: `up proxy ` - 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 ` - 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 kill example.com` + ## Contributors, Collaborators, and Guides Plenty of people gave their time guiding me and shaping this tool. diff --git a/actions/createProxyServer.js b/actions/createProxyServer.js index 0776aa0..f0376c7 100644 --- a/actions/createProxyServer.js +++ b/actions/createProxyServer.js @@ -1,5 +1,6 @@ var fs = require('fs-extra'); var shell = require('shelljs'); + var npath = require('../util/nginxPath'); var conf = require('../util/nginxConf'); var nginxReload = require('../util/nginxReload'); diff --git a/actions/createStaticServer.js b/actions/createStaticServer.js index c1a07c4..66db50a 100644 --- a/actions/createStaticServer.js +++ b/actions/createStaticServer.js @@ -1,35 +1,36 @@ var fs = require('fs-extra'); var shell = require('shelljs'); +var path = require('path'); + var npath = require('../util/nginxPath'); var conf = require('../util/nginxConf'); -var path = require('path'); var nginxReload = require('../util/nginxReload'); var currentPath = path.normalize(process.cwd()); var { EOL } = require('os'); // \n if used on Linux, \r\n if used on Windows. function createStaticServer(domain, outPort = 80) { - fs.outputFileSync((conf(npath.availableSites(), domain)), // Gets nginx's paths from nginxPath.js - "server {" + EOL + - " listen " + outPort + ";" + EOL + - " listen [::]:" + outPort + ";" + EOL + - " root " + npath.webRoot() + domain + ";" + EOL + - " index index.html index.htm;" + EOL + - "" + EOL + - " server_name " + domain + ";" + EOL + - " location / {" + EOL + - " try_files $uri $uri/ =404;" + EOL + - " }" + EOL + - "}" - ) - 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.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.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 + fs.outputFileSync((conf(npath.availableSites(), domain)), // Gets nginx's paths from nginxPath.js + "server {" + EOL + + " listen " + outPort + ";" + EOL + + " listen [::]:" + outPort + ";" + EOL + + " root " + npath.webRoot() + domain + ";" + EOL + + " index index.html index.htm;" + EOL + + "" + EOL + + " server_name " + domain + ";" + EOL + + " location / {" + EOL + + " try_files $uri $uri/ =404;" + EOL + + " }" + EOL + + "}" + ) + 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.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.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 - nginxReload(); + nginxReload(); }; module.exports = createStaticServer; \ No newline at end of file diff --git a/actions/killServer.js b/actions/killServer.js new file mode 100644 index 0000000..3592f0f --- /dev/null +++ b/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; \ No newline at end of file diff --git a/index.js b/index.js index 4c5e626..279df4f 100644 --- a/index.js +++ b/index.js @@ -13,50 +13,52 @@ var requirements = require('./util/requirements') // Requiring Actions var createProxyServer = require('./actions/createProxyServer'); 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. -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 - .version('0.1.2') + .version('0.1.2'); program .command('static [outPort]') .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. - if (!validate(domain, outPort)) return //Validates domain and outport, and if invalid, throws and returns. - 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!") - }) + if (!validate(domain, outPort)) return; //Validates domain and outport, and if invalid, throws and returns. + 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!"); + }); program .command('proxy [outPort]') .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. - if (!validate(domain, inPort, outPort)) return - 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!") - }) + if (!validate(domain, inPort, outPort)) return; + 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!"); + }); program .command('list') .description('List all available servers.') .action(function () { // Stuff happens here - }) + }); program .command('kill ') .description('Kill a server.') .action(function (domain) { - // Stuff happens here - }) + killServer(domain); + console.log("Done! Your server has been killed!\n"); + }); program .command('*') // This should pick invalid commands, but it doesn't, yet. .action(function () { console.log("Invalid command. Type " + chalk.cyan('up --help') + " for help.") - }) + }); // Adds custom help text to the automatically generated help. program.on('--help', function () { diff --git a/package.json b/package.json index 52a3431..81e8c5d 100644 --- a/package.json +++ b/package.json @@ -1,36 +1,36 @@ { - "name": "up-serve", - "version": "0.1.3", - "description": "A cli tool to quickly create and manage nginx server blocks.", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/codefeathers/up-serve.git" - }, - "keywords": [ - "up", - "serve", - "nginx", - "server", - "block" - ], - "bin": { - "up": "./index.js" - }, - "author": "Muthu Kumar (@MKRhere)", - "license": "MIT", - "bugs": { - "url": "https://github.com/codefeathers/up-serve/issues" - }, - "homepage": "https://github.com/codefeathers/up-serve#readme", - "dependencies": { - "chalk": "^2.3.0", - "commander": "^2.11.0", - "fs-extra": "^4.0.2", - "shelljs": "^0.7.8", - "validator": "^9.1.1" - } + "name": "up-serve", + "version": "0.1.4", + "description": "A cli tool to quickly create and manage nginx server blocks.", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/codefeathers/up-serve.git" + }, + "keywords": [ + "up", + "serve", + "nginx", + "server", + "block" + ], + "bin": { + "up": "./index.js" + }, + "author": "Muthu Kumar (@MKRhere)", + "license": "MIT", + "bugs": { + "url": "https://github.com/codefeathers/up-serve/issues" + }, + "homepage": "https://github.com/codefeathers/up-serve#readme", + "dependencies": { + "chalk": "^2.3.0", + "commander": "^2.11.0", + "fs-extra": "^4.0.2", + "shelljs": "^0.7.8", + "validator": "^9.1.1" + } }