From 95145966fd631160acbf8dc59a23932e00bde179 Mon Sep 17 00:00:00 2001 From: Muthu Kumar Date: Thu, 30 Nov 2017 12:31:06 +0530 Subject: [PATCH] Bump to v. 0.2.5 * Deprecated up static in favour of up serve * Updated README, changelog and version number to 0.2.5 --- .eslintrc.json | 1 - README.md | 28 ++++++++++++++++++++++---- actions/createNewServer.js | 45 +++++++++++++++++++++++++++++++++++++++++ actions/createStaticServer.js | 47 ------------------------------------------- actions/killALL.js | 1 - assets/tlds.txt | 2 +- cli.js | 27 +++++++++++++++++-------- docs/Changelog.md | 37 ++++++++++++++++++++-------------- lib.js | 13 +++++++++--- package.json | 5 ++++- utils/listFile.js | 4 ++-- utils/nginxReload.js | 4 ++-- 12 files changed, 129 insertions(+), 85 deletions(-) create mode 100644 actions/createNewServer.js delete mode 100644 actions/createStaticServer.js diff --git a/.eslintrc.json b/.eslintrc.json index c102f6c..0af9758 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -3,7 +3,6 @@ "node": true, "es6": true }, - "parserOptions": { "ecmaVersion": 2017 }, "extends": "eslint:recommended", "rules": { "no-console": "off", diff --git a/README.md b/README.md index 17df013..6339d30 100644 --- a/README.md +++ b/README.md @@ -8,10 +8,10 @@ # up -> Current version: `up v.0.2.1 (Alpha)` +> Current version: `up v.0.2.5 (Alpha)` > Notes: `up` is now in Alpha! 🎉 [(Changelog)](/docs/Changelog.md)\ -> ⚠️ ❌ `up` is pretty useable so far. If you're testing `up` on a development server, do give us feedback. +> ⚠️ `up` is pretty useable so far. If you're testing `up` on a development server, do give us feedback. **`up`** is a command line application that creates nginx server blocks quickly with a single command. @@ -32,7 +32,8 @@ Install `up` from npm: Format: `up command [optional]` -- `up static [outbound port]` - Create new static server at current folder. +- `up serve [outbound port]` - Create new static server at current folder. + - `up static` is deprecated from `v. 0.2.5` (see [changelog](/docs/CHANGELOG.md)) - `up proxy [outbound port]` - Create new proxy server listening at said port. - `up list` - List currently available servers. - `up kill ` - Kill the server for this domain. @@ -41,10 +42,29 @@ Format: `up command [optional]` - `up static example.com` will serve a static website from current folder. - `up proxy example.com 8081` will create a reverse proxy listening at port 8081. -- `up kill example.com` +- `up kill example.com` will kill the server named example.com. +- `up list` will fetch a list of servers created with `up`. + +## API + +```JavaScript +const up = require('up-serve') + +console.log(up.version()) // up v. 0.2.5 + +let result = up.server("example.com", "path/to/project", "80") +console.log(result) // Will log success or throw if error + +let result = up.kill("example.com", "80") +console.log(result) // Will log success or throw if error +``` + +More detailed API documentation coming soon. --- +

Meta

+

Roadmap

Contribution Guidelines

diff --git a/actions/createNewServer.js b/actions/createNewServer.js new file mode 100644 index 0000000..602990b --- /dev/null +++ b/actions/createNewServer.js @@ -0,0 +1,45 @@ +'use strict'; + +const fs = require('fs-extra'); +const shell = require('shelljs'); + +const npath = require('../utils/nginxPath'); +const conf = require('../utils/nginxConf'); +const nginxReload = require('../utils/nginxReload'); +const { appendToList } = require('../utils/listFile'); + +const { EOL } = require('os'); // \n if used on Linux, \r\n if used on Windows. + +function createStaticServer(domain, path, outPort) { + outPort = outPort || 80; + + shell.mkdir('-p', npath.enabledSites()); + // Creates directories if doesn't exist + + fs.outputFileSync((conf(npath.enabledSites(), domain, outPort)), + // Gets nginx's paths from nginxPath.js + "server {" + EOL + + " listen " + outPort + ";" + EOL + + " listen [::]:" + outPort + ";" + EOL + + " root " + npath.webRoot() + domain + "." + outPort + ";" + EOL + + " index index.html index.htm;" + EOL + + "" + EOL + + " server_name " + domain + ";" + EOL + + " location / {" + EOL + + " try_files $uri $uri/ =404;" + EOL + + " }" + EOL + + "}" + ); + + shell.rm('-rf', npath.webRootDomain(domain, outPort)); + // 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', path, npath.webRootDomain(domain, outPort)); + // Symlink current directory to nginx's web root + + appendToList(domain, outPort); + nginxReload(); +} + +module.exports = createStaticServer; diff --git a/actions/createStaticServer.js b/actions/createStaticServer.js deleted file mode 100644 index 70aa67f..0000000 --- a/actions/createStaticServer.js +++ /dev/null @@ -1,47 +0,0 @@ -'use strict'; - -const fs = require('fs-extra'); -const shell = require('shelljs'); -const path = require('path'); - -const npath = require('../utils/nginxPath'); -const conf = require('../utils/nginxConf'); -const nginxReload = require('../utils/nginxReload'); -const { appendToList } = require('../utils/listFile'); - -const currentPath = path.normalize(process.cwd()); -const { EOL } = require('os'); // \n if used on Linux, \r\n if used on Windows. - -function createStaticServer(domain, outPort) { - outPort = outPort || 80; - - shell.mkdir('-p', npath.enabledSites()); - // Creates directories if doesn't exist - - fs.outputFileSync((conf(npath.enabledSites(), domain, outPort)), - // Gets nginx's paths from nginxPath.js - "server {" + EOL + - " listen " + outPort + ";" + EOL + - " listen [::]:" + outPort + ";" + EOL + - " root " + npath.webRoot() + domain + "." + outPort + ";" + EOL + - " index index.html index.htm;" + EOL + - "" + EOL + - " server_name " + domain + ";" + EOL + - " location / {" + EOL + - " try_files $uri $uri/ =404;" + EOL + - " }" + EOL + - "}" - ); - - shell.rm('-rf', npath.webRootDomain(domain, outPort)); - // 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.webRootDomain(domain, outPort)); - // Symlink current directory to nginx's web root - - appendToList(domain, outPort); - nginxReload(); -} - -module.exports = createStaticServer; diff --git a/actions/killALL.js b/actions/killALL.js index 55fd814..dfe44ba 100644 --- a/actions/killALL.js +++ b/actions/killALL.js @@ -2,7 +2,6 @@ const shell = require('shelljs'); const path = require('path'); -const fs = require('fs'); const { EOL } = require('os'); diff --git a/assets/tlds.txt b/assets/tlds.txt index 2df92a0..cab12b8 100644 --- a/assets/tlds.txt +++ b/assets/tlds.txt @@ -1,4 +1,4 @@ -# Version 2017111900, Last Updated Sun Nov 19 07:07:01 2017 UTC +# Version 2017112900, Last Updated Wed Nov 29 07:07:01 2017 UTC AAA AARP ABARTH diff --git a/cli.js b/cli.js index 89ce3f0..cf45a03 100644 --- a/cli.js +++ b/cli.js @@ -3,6 +3,7 @@ 'use strict'; const { EOL } = require('os'); +const path = require('path'); // Requiring npm modules const program = require('commander'); @@ -15,12 +16,20 @@ const killAllConfirm = require('./actions/killAllConfirm'); // Requiring utils const requirements = require('./utils/requirements'); +const currentPath = path.normalize(process.cwd()); +let cmdValue = ''; + // Check for requirements such as OS version and nginx install. // #Roadmap: Add ability to satisfy any possible requirements. requirements(); // Comment in development and uncomment this line in production. +program + .version(up.version()) + .arguments('') + .action((cmd) => cmdValue = cmd); + const tryCatch = ((test, name) => { try { const msg = test(); @@ -32,19 +41,21 @@ const tryCatch = ((test, name) => { } }); -let cmdValue = ''; - program - .version('0.2.5') - .arguments('') - .action((cmd) => cmdValue = cmd); - + .command('serve [outPort]') + .description('Create a server at this folder.') + .action((domain, outPort) => + tryCatch( + () => up.server(domain, currentPath, outPort), + 'new-server' + )); + program .command('static [outPort]') - .description('Create a static server at this folder.') + .description('DEPRECATED! Create a static server at this folder.') .action((domain, outPort) => tryCatch( - () => up.server(domain, outPort), + () => up.server(domain, currentPath, outPort), 'new-server' )); diff --git a/docs/Changelog.md b/docs/Changelog.md index b6529cf..d38c01f 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -1,15 +1,22 @@ -# Changelog / Version history - -## `up` v. 0.2.1 - -- Bug fix and patch for `up kill-all` breaking unexpectedly due to undefined default config file. - -## `up` v. 0.2.0 - -- Under the hood BREAKING changes. Working directories change. - - `/var/www/` to `/etc/up-serve/static/` - - `/etc/nginx/sites-available/` to `/etc/nginx/conf.d` -- `up static|proxy ` adds the server to `/etc/up-serve/servers.up` list. -- `up kill ` removes server from `servers.up` list. -- `up list` lists available servers from /etc/up-serve/servers.up! -- `up kill-all` destroys all servers and places a `default.conf` in `/etc/nginx/sites-enabled`. +# Changelog / Version history + +## `up` v. 0.2.5 + +- `up static` is DEPRECATED. Use `up serve` instead. +- Major refactor of code, and splitting of `index.js` to `lib.js` and `cli.js`. +- Basic API now available. +- Usage of `conf.d` is DEPRECATED. `up-serve` now only uses `sites-enabled`. Since everything is abstracted at a higher level, the need for maintaining two directories (Read sites-available here) is non-existent. + +## `up` v. 0.2.1 + +- Bug fix and patch for `up kill-all` breaking unexpectedly due to undefined default config file. + +## `up` v. 0.2.0 + +- Under the hood BREAKING changes. Working directories change. + - `/var/www/` to `/etc/up-serve/static/` + - `/etc/nginx/sites-available/` to `/etc/nginx/conf.d` +- `up static|proxy ` adds the server to `/etc/up-serve/servers.up` list. +- `up kill ` removes server from `servers.up` list. +- `up list` lists available servers from /etc/up-serve/servers.up! +- `up kill-all` destroys all servers and places a `default.conf` in `/etc/nginx/sites-enabled`. diff --git a/lib.js b/lib.js index 22f6ca1..1310ed6 100644 --- a/lib.js +++ b/lib.js @@ -6,20 +6,26 @@ const { EOL } = require('os'); const chalk = require('chalk'); // Requiring Actions +const createNewServer = require('./actions/createNewServer'); const createProxyServer = require('./actions/createProxyServer'); -const createStaticServer = require('./actions/createStaticServer'); const killServer = require('./actions/killServer'); const listServers = require('./actions/listServers'); // Requiring utils const validate = require('./utils/validate'); -function server (domain, outPort = "80") { +const pacversion = 'up-serve v. ' + require('./package.json').version; + +function version () { + return pacversion; +} + +function server (domain, path, outPort = "80") { // If outport is not given, 80 is set as default. outPort = String(outPort); validate(domain, outPort); // Validates domain and outport, and if invalid, throws and returns. - createStaticServer(domain, outPort); + createNewServer(domain, path, outPort); if (outPort != "80" || "443") domain = domain + ":" + outPort; return (EOL + [ "Done! Your static server has been set up!", @@ -56,6 +62,7 @@ function kill (domain, outPort = "80") { } module.exports = { + version, server, proxy, list, diff --git a/package.json b/package.json index acd9c84..4403865 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "up-serve", - "version": "0.2.1", + "version": "0.2.5", "description": "A cli tool to quickly create and manage nginx server blocks.", "main": "lib.js", "scripts": { @@ -21,6 +21,9 @@ "bin": { "up": "./cli.js" }, + "pkg": { + "assets": "assets/*" + }, "author": "Muthu Kumar (@MKRhere)", "license": "MIT", "bugs": { diff --git a/utils/listFile.js b/utils/listFile.js index 55e3262..9e34889 100644 --- a/utils/listFile.js +++ b/utils/listFile.js @@ -15,9 +15,9 @@ function appendToList(domain, outPort, inPort) { }; if (!inPort) { - domBlock.type = "static"; + domBlock.type = "static/server"; } else { - domBlock.type = "proxy"; + domBlock.type = "proxy server"; domBlock.inPort = inPort; } diff --git a/utils/nginxReload.js b/utils/nginxReload.js index 728e7d8..6b6f2f1 100644 --- a/utils/nginxReload.js +++ b/utils/nginxReload.js @@ -3,7 +3,7 @@ const { execSync } = require('child_process'); function nginxReload() { - /*try { + try { execSync('service nginx reload', { stdio: 'ignore' }); @@ -13,7 +13,7 @@ function nginxReload() { } catch (err) { throw new Error('nginx failed to load'); } - return;*/ + return; } module.exports = nginxReload;