Comparing version 0.2.1 to 0.2.5
@@ -26,4 +26,5 @@ { | ||
"eol-last": "error", | ||
"max-len": "error" | ||
"max-len": "error", | ||
"no-unused-expressions": "error" | ||
} | ||
} |
@@ -0,0 +0,0 @@ { |
@@ -15,5 +15,7 @@ 'use strict'; | ||
outPort = outPort || 80; | ||
shell.mkdir('-p', npath.confD()); | ||
shell.mkdir('-p', npath.enabledSites()); | ||
// Creates directories if doesn't exist | ||
fs.outputFileSync((conf(npath.confD(), domain, outPort)), | ||
fs.outputFileSync((conf(npath.enabledSites(), domain, outPort)), | ||
"server {" + EOL + | ||
@@ -38,5 +40,2 @@ " listen " + outPort + ";" + EOL + | ||
// Creates directories if doesn't exist | ||
shell.ln('-sf', conf(npath.confD(), domain, outPort), | ||
conf(npath.enabledSites(), domain, outPort)); | ||
// Symlink the conf file from sites-available to sites-enabled | ||
@@ -43,0 +42,0 @@ appendToList(domain, outPort, inPort); |
@@ -16,6 +16,4 @@ 'use strict'; | ||
shell.rm('-Rf', npath() + "sites-available"); | ||
shell.rm('-Rf', npath.confD()); | ||
shell.rm('-Rf', npath.enabledSites()); | ||
shell.rm('-Rf', npath.webRoot()); | ||
shell.mkdir('-p', npath.confD()); | ||
shell.mkdir('-p', npath.enabledSites()); | ||
@@ -26,13 +24,12 @@ shell.mkdir('-p', npath.webRoot()); | ||
// Create the default.conf file | ||
console.log("All servers were killed and reverted to default."); | ||
console.log(EOL + [ | ||
"A backup of your old servers.up is " + | ||
"saved in /etc/up-serve/servers.bak.up.", | ||
"Check this if you need to." | ||
].join(EOL) + EOL); | ||
nginxReload(); | ||
console.log(EOL + "All servers were killed and reverted to default." + | ||
EOL + "A backup of your old servers.up is " + | ||
"saved in /etc/up-serve/servers.bak.up." + | ||
"Check this if you need to." + EOL | ||
); | ||
} | ||
function noKill () { | ||
console.log(EOL + "kill-all was interrupted by user."); | ||
return(EOL + "kill-all was interrupted by user."); | ||
} | ||
@@ -39,0 +36,0 @@ |
@@ -10,8 +10,7 @@ 'use strict'; | ||
const serversList = readServers(); | ||
if(serversList) console.log(EOL + prettyjson.render(serversList) + EOL); | ||
else console.log(EOL + | ||
"No servers were found! Create some using `up`!" + | ||
EOL); | ||
if(serversList) return(EOL + prettyjson.render(serversList)); | ||
else return(EOL + | ||
"No servers were found! Create some using `up`!"); | ||
} | ||
module.exports = listServers; |
@@ -1,2 +0,2 @@ | ||
# 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 | ||
@@ -3,0 +3,0 @@ AARP |
@@ -17,5 +17,5 @@ # How to contribute | ||
And that's it! Read the code available and change the part you don't like! You're change should not break the existing code and should pass the tests. We recommend using VS Code while working on this project. | ||
And that's it! Read the code available and change the part you don't like! Your change should not break any existing functionality and should work as promised. If you're having trouble with it, mention it. We recommend using VS Code while working on this project. | ||
If you're adding a new functionality, start from the branch master. It would be a better practice to create a new branch and work in there. | ||
If you're adding a new functionality, start from the branch develop. It would be a better practice to create a new branch and work in there. | ||
@@ -26,3 +26,3 @@ When you're done, submit a pull request and for one of the maintainers to check it out. We would let you know if there is any problem or any changes that should be considered. | ||
We haven't written tests yet and you can manually try commands and assure the stability of the code. If you're adding a new test please write documentation for it by creating Tests.MD. | ||
We haven't written tests yet and you can manually try commands and assure the stability of the code. If you're adding a new test please write documentation for it by creating /docs/Tests.MD. | ||
@@ -33,2 +33,2 @@ ### Documentation | ||
**__Overall, just have fun, and make sure nothing breaks. Thanks!__** | ||
**__Overall, just have fun, and make sure nothing breaks. Thanks!__** |
{ | ||
"name": "up-serve", | ||
"version": "0.2.1", | ||
"version": "0.2.5", | ||
"description": "A cli tool to quickly create and manage nginx server blocks.", | ||
"main": "index.js", | ||
"main": "lib.js", | ||
"scripts": { | ||
@@ -22,4 +22,7 @@ "test": "echo \"Error: no test specified\" && exit 1", | ||
"bin": { | ||
"up": "./index.js" | ||
"up": "./cli.js" | ||
}, | ||
"pkg": { | ||
"assets": "assets/*" | ||
}, | ||
"author": "Muthu Kumar (@MKRhere)", | ||
@@ -32,7 +35,6 @@ "license": "MIT", | ||
"dependencies": { | ||
"chalk": "^2.3.0", | ||
"commander": "^2.11.0", | ||
"chalk": "2.3.0", | ||
"commander": "2.11.0", | ||
"fs-extra": "^4.0.2", | ||
"prettyjson": "^1.2.1", | ||
"prompt": "^1.0.0", | ||
"readline-sync": "^1.4.7", | ||
@@ -39,0 +41,0 @@ "shelljs": "^0.7.8" |
@@ -11,6 +11,6 @@ <br /><br /><br /><br /><br /> | ||
> Current version: `up v.0.2.1 (Alpha)` | ||
> Current version: `up v.0.2.5 (Alpha)` | ||
> Notes: `up` is now in Alpha! 🎉 [(Changelog)](Changelog.md)\ | ||
> ⚠️ ❌ `up` is pretty useable so far. If you're testing `up` on a development server, do give us feedback. | ||
> 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. | ||
@@ -36,3 +36,4 @@ **`up`** is a command line application that creates nginx server blocks quickly with a single command. | ||
- `up static <domain> [outbound port]` - Create new static server at current folder. | ||
- `up serve <domain> [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 <domain> <inbound port> [outbound port]` - Create new proxy server listening at said port. | ||
@@ -46,12 +47,29 @@ - `up list` - List currently available servers. | ||
- `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`. | ||
## Contributors, Collaborators, and Guides | ||
## API | ||
Plenty of people gave their time guiding me and shaping this tool. | ||
```JavaScript | ||
const up = require('up-serve') | ||
I'd like to thank and give credit to [The Devs Community](https://thedevs.network), who are the primary reason this exists. | ||
console.log(up.version()) // up v. 0.2.5 | ||
I'd also personally thank the following amazing people for their valuable support and feedback: **Pouria Ezzati, Thomas Rory Gummerson, Omar Khalil, Martin, GingerPlusPlus, Faizan Akram.** | ||
let result = up.server("example.com", "path/to/project", "80") | ||
console.log(result) // Will log success or throw if error | ||
And the following people for their moral support and listening to my constant bickering: **David (The Humanoid), Иброхеем, Simon 'SitiSchu' Schürrle.** | ||
let result = up.kill("example.com", "80") | ||
console.log(result) // Will log success or throw if error | ||
``` | ||
More detailed API documentation coming soon. | ||
--- | ||
<h2 align="center">Meta</h2> | ||
<h4 align="center"><a href="/docs/Roadmap.MD">Roadmap</a></h4> | ||
<h4 align="center"><a href="Contributing.MD">Contribution Guidelines</a></h4> | ||
<h4 align="center"><a href="/docs/Contributors.md">Contributors, Collaborators, and Guides</a></h4> |
'use strict'; | ||
const { EOL } = require('os'); | ||
const fs = require('fs-extra'); | ||
@@ -20,5 +18,5 @@ | ||
if (!inPort) { | ||
domBlock.type = "static"; | ||
domBlock.type = "static/server"; | ||
} else { | ||
domBlock.type = "proxy"; | ||
domBlock.type = "proxy server"; | ||
domBlock.inPort = inPort; | ||
@@ -39,9 +37,17 @@ } | ||
let jsonFile = { "domains": [] }; | ||
const jsonBuffer = JSON.parse(fs.readFileSync(listFilePath())); | ||
jsonFile.domains = removeFromArray(jsonBuffer.domains, domain, outPort); | ||
jsonFile = JSON.stringify(jsonBuffer, null, '\t'); | ||
fs.writeFileSync(listFilePath(), jsonFile); | ||
const jsonContent = fs.readFileSync(listFilePath(), "utf-8"); | ||
const jsonBuffer = JSON.parse(jsonContent); | ||
for (let i = 0; i < (jsonBuffer.domains).length; i ++) { | ||
if(jsonBuffer.domains[i].domain == domain){ | ||
jsonFile.domains = | ||
removeFromArray(jsonBuffer.domains, domain, outPort); | ||
jsonFile = JSON.stringify(jsonFile, null, '\t'); | ||
fs.writeFileSync(listFilePath(), jsonFile); | ||
return; | ||
} | ||
} | ||
throw new Error("This domain does not exist in servers.up"); | ||
} | ||
else console.log(EOL + "No servers were created using `up` yet." + EOL); | ||
else throw new Error("No servers were created using `up` yet."); | ||
} | ||
@@ -53,6 +59,8 @@ | ||
serversList = JSON.parse(fs.readFileSync(listFilePath())); | ||
if(!serversList.domains[0]) return undefined; | ||
if(!serversList.domains[0]) { | ||
throw new Error("No domains exist in servers.up"); | ||
} | ||
} | ||
else { | ||
return "Servers were not created"; | ||
return "No servers were created using `up` yet."; | ||
} | ||
@@ -59,0 +67,0 @@ return serversList; |
@@ -6,12 +6,15 @@ 'use strict'; | ||
function nginxReload() { | ||
execSync('service nginx reload', function (error, stdout, stderr) { | ||
if (error) { | ||
console.error("exec error: " + error); | ||
console.log("stdout: " + stdout); | ||
console.log("stderr: " + stderr); | ||
process.exit(1); | ||
} | ||
}); | ||
try { | ||
execSync('service nginx reload', { | ||
stdio: 'ignore' | ||
}); | ||
execSync('service nginx start', { | ||
stdio: 'ignore' | ||
}); | ||
} catch (err) { | ||
throw new Error('nginx failed to load'); | ||
} | ||
return; | ||
} | ||
module.exports = nginxReload; |
@@ -28,3 +28,4 @@ 'use strict'; | ||
if (process.getuid() != 0) { | ||
console.log("`up` requires root privileges to work. Please use `sudo up <command>`"); | ||
shell.echo("`up` requires root privileges to work." | ||
+ "Please use `sudo up <command>`"); | ||
shell.exit(1); | ||
@@ -31,0 +32,0 @@ } |
'use strict'; | ||
const { EOL } = require('os'); | ||
const parseToInt = require('./parseToInt'); | ||
@@ -18,8 +16,8 @@ const isIP = require('./isIP'); | ||
const domainInvalidMsg = [ | ||
EOL + "Please use a domain name instead of an IP address.", | ||
EOL + "Domain is not valid. Please use a valid domain name." | ||
"Please use a domain name instead of an IP address.", | ||
"Domain is not valid. Please use a valid domain name." | ||
]; | ||
const portInvalidMsg = [ | ||
EOL + "Port should be a number.", | ||
EOL + "Port should be a number from 1 and 65535." | ||
"Port should be a number.", | ||
"Port should be a number from 1 and 65535." | ||
]; | ||
@@ -34,12 +32,5 @@ | ||
// The value of isInvalid will be returned back. | ||
// If none of the `if`s are true, the default | ||
// value `true` is returned `domain`, `inPort` and `outPort` are considered | ||
// validated. | ||
let isValid = true; | ||
// Throw if IP is given instead of domain name. | ||
if (isIP(domain)) { | ||
console.log(domainInvalidMsg[0]); | ||
return isValid = false; | ||
throw new Error(domainInvalidMsg[0]); | ||
} | ||
@@ -49,4 +40,3 @@ | ||
if (!isDomain(domain)) { | ||
console.log(domainInvalidMsg[1]); | ||
return isValid = false; | ||
throw new Error(domainInvalidMsg[1]); | ||
} | ||
@@ -58,9 +48,7 @@ | ||
if (!validOutPort) { | ||
console.log(portInvalidMsg[0]); // `outPort` is not an integer. | ||
return isValid = false; | ||
throw new Error(portInvalidMsg[0]);// `outPort` is not an integer. | ||
} | ||
if (!(validOutPort > 0 && validOutPort <= 65535)) { | ||
console.log(portInvalidMsg[1]); | ||
throw new Error(portInvalidMsg[1]); | ||
// `outPort` is not within port range. | ||
return isValid = false; | ||
} | ||
@@ -73,5 +61,4 @@ } | ||
if (!validInPort || !validOutPort) { | ||
console.log(portInvalidMsg[0]); | ||
throw new Error(portInvalidMsg[0]); | ||
// Either `inPort` or `outPort` is not an integer. | ||
return isValid = false; | ||
} | ||
@@ -83,10 +70,6 @@ if (typeof outPort !== undefined) { | ||
)) { | ||
console.log(portInvalidMsg[1]); | ||
throw new Error(portInvalidMsg[1]); | ||
// Either `inPort` or `outPort` are not within port range. | ||
return isValid = false; | ||
} | ||
} | ||
return isValid; | ||
// If any of the `if`s were true, `isInvalid = false`. | ||
// If not, `isInvalid = true`. | ||
} | ||
@@ -93,0 +76,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
399701
6
36
655
73
+ Addedchalk@2.3.0(transitive)
+ Addedcommander@2.11.0(transitive)
+ Addedhas-flag@2.0.0(transitive)
+ Addedsupports-color@4.5.0(transitive)
- Removedprompt@^1.0.0
- Removed@colors/colors@1.5.0(transitive)
- Removedasync@2.6.43.2.3(transitive)
- Removedchalk@2.4.2(transitive)
- Removedcolors@1.0.3(transitive)
- Removedcommander@2.20.3(transitive)
- Removedcycle@1.0.3(transitive)
- Removedeyes@0.1.8(transitive)
- Removedhas-flag@3.0.0(transitive)
- Removedisstream@0.1.2(transitive)
- Removedlodash@4.17.21(transitive)
- Removedmute-stream@0.0.8(transitive)
- Removedprompt@1.3.0(transitive)
- Removedread@1.0.7(transitive)
- Removedrevalidator@0.1.8(transitive)
- Removedstack-trace@0.0.10(transitive)
- Removedsupports-color@5.5.0(transitive)
- Removedwinston@2.4.7(transitive)
Updatedchalk@2.3.0
Updatedcommander@2.11.0