A cli tool to quickly create and manage nginx server blocks. https://up.js.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
2.3 KiB

#!/usr/bin/env node
'use strict';
const { EOL } = require('os');
// Requiring npm modules
const program = require('commander');
const chalk = require('chalk');
// Require API
const up = require('./api');
// Requiring utils
const requirements = require('./utils/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`
let cmdValue;
program
.version('0.2.1')
.arguments('<cmd>')
7 years ago
.action((cmd) => cmdValue = cmd);
program
.command('static <domain> [outPort]')
.description('Create a static server at this folder.')
7 years ago
.action((domain, outPort) => up.server(domain, outPort));
program
.command('proxy <domain> <inPort> [outPort]')
.description('Create a proxy server, listening at port number.')
7 years ago
.action((domain, inPort, outPort) => up.proxy(domain, inPort, outPort));
program
.command('list')
.description('List all available servers.')
7 years ago
.action(() => up.list());
program
.command('kill <domain> [ourPort]')
.description('Kill a server.')
7 years ago
.action((domain, outPort) => up.kill(domain, outPort));
program
.command('kill-all')
.description('Warning! Will completely kill all servers and reset nginx')
7 years ago
.action(() => up.reset());
program
.command('*') // This should pick invalid commands, but it doesn't, yet.
7 years ago
.action(() => {
console.log(EOL + "Invalid command. Type " +
chalk.cyan('up --help') + " for help." + EOL);
});
// Adds custom help text to the automatically generated help.
7 years ago
program.on('--help', () => {
console.log(EOL
+ ' Usage:'
+ EOL
+ EOL
+ ' ' + chalk.yellow('$ up ')
+ chalk.cyan('static')
+ chalk.blue('[domain-name]')
+ EOL
+ ' Set up a static server at domain-name'
+ EOL
+ EOL
+ ' ' + chalk.yellow('$ up ')
+ chalk.cyan('proxy')
+ chalk.blue('[domain-name] <port-number>')
+ EOL
+ ' Set up a proxy server listening at port-number'
+ EOL);
});
// Parses commands passed to `up` and chooses one of the above commands.
program.parse(process.argv);
if (typeof cmdValue === 'undefined') {
console.log(EOL + "No command was given. `up --help` for help info.");
process.exit(1);
}