Browse Source

Merge branch 'develop'

pull/14/head
Muthu Kumar 7 years ago
parent
commit
ba4ec879ff
  1. 4
      .eslintrc.json
  2. 3
      .gitignore
  3. 10
      README.md
  4. 3
      actions/listServers.js
  5. 30
      cli.js
  6. 5
      docs/Changelog.md
  7. 9
      lib.js
  8. 20
      package-lock.json
  9. 2
      package.json
  10. 12
      utils/listFile.js
  11. 9
      utils/validate.js

4
.eslintrc.json

@ -18,7 +18,9 @@
"error",
"always"
],
"prefer-const": "error",
"prefer-const": ["error", {
"destructuring": "all"
}],
"prefer-destructuring": "error",
"no-var": "error",
"strict": "error",

3
.gitignore

@ -1,3 +1,4 @@
node_modules
test
test.txt
test.txt
binaries

10
README.md

@ -10,7 +10,7 @@
![A quick demo](assets/demo.gif)
> Current version: `up v.0.2.5 (Alpha)`
> Current version: `up v.0.3.0 (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.
@ -42,7 +42,7 @@ Format: `up command <required> [optional]`
## Examples
- `up static example.com` will serve a static website from current folder.
- `up serve 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` will kill the server named example.com.
- `up list` will fetch a list of servers created with `up`.
@ -52,12 +52,12 @@ Format: `up command <required> [optional]`
```JavaScript
const up = require('up-serve')
console.log(up.version()) // up v. 0.2.5
console.log(up.version()) // up v. 0.3.0
let result = up.server("example.com", "path/to/project", "80")
let result = up.server({ domain: "example.com", path: "path/to/project", outPort: "80" })
console.log(result) // Will log success or throw if error
let result = up.kill("example.com", "80")
let result = up.kill({ domain: "example.com", outPort: "80" })
console.log(result) // Will log success or throw if error
```

3
actions/listServers.js

@ -8,8 +8,7 @@ const { EOL } = require('os');
function listServers() {
const serversList = readServers();
if(serversList) return(EOL + prettyjson.render(serversList));
else return(EOL +
"No servers were found! Create some using `up`!");
else throw new Error("No servers were found! Create some using `up`!");
}
module.exports = listServers;

30
cli.js

@ -22,7 +22,7 @@ let cmdValue = '';
// Check for requirements such as OS version and nginx install.
// #Roadmap: Add ability to satisfy any possible requirements.
requirements();
//requirements();
// Comment in development and uncomment this line in production.
program
@ -46,16 +46,25 @@ program
.description('Create a server at this folder.')
.action((domain, outPort) =>
tryCatch(
() => up.server(domain, currentPath, outPort),
() => up.server({
domain: domain,
path: currentPath,
outPort: outPort
}),
'new-server'
));
program
.command('static <domain> [outPort]')
.description('DEPRECATED! Create a static server at this folder.')
.description(`DEPRECATED! Use 'up serve' instead!
Create a static server at this folder.`)
.action((domain, outPort) =>
tryCatch(
() => up.server(domain, currentPath, outPort),
() => up.server({
domain: domain,
path: currentPath,
outPort: outPort
}),
'new-server'
));
@ -64,7 +73,11 @@ program
.description('Create a proxy server, listening at port number.')
.action((domain, inPort, outPort) =>
tryCatch(
() => up.proxy(domain, inPort, outPort),
() => up.proxy({
domain: domain,
inPort: inPort,
outPort: outPort
}),
'new-proxy'
));
@ -82,7 +95,10 @@ program
.description('Kill a server.')
.action((domain, outPort) =>
tryCatch (
() => up.kill(domain, outPort),
() => up.kill({
domain: domain,
outPort: outPort
}),
'kill-server'
));

5
docs/Changelog.md

@ -1,5 +1,9 @@
# Changelog / Version history
## `up` v. 0.3.0
- BREAKING API changes. Functions will now accept an object instead of a list of arguments. This allows for named parameters that don't have to follow a precise order. Check [README](../README.md) for details.
## `up` v. 0.2.5
- `up static` is DEPRECATED. Use `up serve` instead.
@ -13,6 +17,7 @@
## `up` v. 0.2.0
- Added CHANGELOG from here.
- Under the hood BREAKING changes. Working directories change.
- `/var/www/` to `/etc/up-serve/static/`
- `/etc/nginx/sites-available/` to `/etc/nginx/conf.d`

9
lib.js

@ -20,7 +20,8 @@ function version () {
return pacversion;
}
function server (domain, path, outPort = "80") {
function server (options) {
let { domain, path, outPort = "80" } = options;
// If outport is not given, 80 is set as default.
outPort = String(outPort);
validate(domain, outPort);
@ -35,7 +36,8 @@ function server (domain, path, outPort = "80") {
].join(EOL));
}
function proxy (domain, inPort, outPort = "80") {
function proxy (options) {
let { domain, inPort, outPort = "80" } = options;
// Inbound port is necessary, but outbound is set to 80 by default.
outPort = String(outPort);
inPort = String(inPort);
@ -54,7 +56,8 @@ function list () {
return listServers();
}
function kill (domain, outPort = "80") {
function kill (options) {
let { domain, outPort = "80" } = options;
outPort = String(outPort);
// This is a string because regex needs to validate it.
killServer(domain, outPort);

20
package-lock.json

@ -1,6 +1,6 @@
{
"name": "up-serve",
"version": "0.2.1",
"version": "0.2.5",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@ -1063,15 +1063,6 @@
"integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=",
"dev": true
},
"string_decoder": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz",
"integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==",
"dev": true,
"requires": {
"safe-buffer": "5.1.1"
}
},
"string-width": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz",
@ -1082,6 +1073,15 @@
"strip-ansi": "4.0.0"
}
},
"string_decoder": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz",
"integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==",
"dev": true,
"requires": {
"safe-buffer": "5.1.1"
}
},
"strip-ansi": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz",

2
package.json

@ -1,6 +1,6 @@
{
"name": "up-serve",
"version": "0.2.5",
"version": "0.3.0",
"description": "A cli tool to quickly create and manage nginx server blocks.",
"main": "lib.js",
"scripts": {

12
utils/listFile.js

@ -9,23 +9,23 @@ function appendToList(domain, outPort, inPort) {
inPort = inPort || undefined;
let jsonFile = { "domains": [] };
const domBlock = {
const domainBlock = {
"domain": domain,
"outPort": outPort
};
if (!inPort) {
domBlock.type = "static/server";
domainBlock.type = "static/server";
} else {
domBlock.type = "proxy server";
domBlock.inPort = inPort;
domainBlock.type = "proxy server";
domainBlock.inPort = inPort;
}
if (fs.existsSync(listFilePath())) {
const jsonBuffer = JSON.parse(fs.readFileSync(listFilePath()));
jsonFile.domains = removeFromArray(jsonBuffer.domains, domain, outPort);
}
jsonFile.domains.push(domBlock);
jsonFile.domains.push(domainBlock);
jsonFile = JSON.stringify(jsonFile, null, '\t');
fs.writeFileSync(listFilePath(), jsonFile);
}
@ -59,7 +59,7 @@ function readServers () {
}
}
else {
return "No servers were created using `up` yet.";
throw new Error("No servers were created using `up` yet.");
}
return serversList;
}

9
utils/validate.js

@ -3,14 +3,11 @@
const parseToInt = require('./parseToInt');
const isIP = require('./isIP');
// Using Validator
// Validate fully qualified domain names
const isDomain = require('./isFQDN');
function validate(domain, inPort, outPort) {
//
inPort = inPort || undefined;
outPort = outPort || 80;
function validate(domain, inPort = undefined, outPort = 80) {
// Error messages
const domainInvalidMsg = [
"Please use a domain name instead of an IP address.",

Loading…
Cancel
Save