#!/usr/bin/env node 'use strict' const path = require('path') const minimist = require('minimist') const findUp = require('find-up') const pkg = require('./../package') const alias = { i: 'ignore', p: 'polling', v: 'verbose', V: 'version' } const getRosid = function() { const routesPath = findUp.sync([ 'rosidfile.js', 'rosidfile.json' ]) const Rosid = require('./../src/index') const routes = require(routesPath) return Rosid(routes) } const serve = function(srcPath, opts) { srcPath = path.resolve(srcPath || '') getRosid().serve(srcPath, { polling : opts.polling, verbose : opts.verbose }) } const compile = function(srcPath, distPath, opts) { srcPath = path.resolve(srcPath || '') distPath = path.resolve(distPath || 'dist/') getRosid().compile(srcPath, distPath, { ignore : opts.ignore, verbose : opts.verbose }) } const version = function() { console.log(pkg.version) } const help = function() { console.log(` Usage: rosid [command] [options] Commands: serve [srcPath] [options] serve current or specified folder compile [srcPath] [distPath] [options] compile current or specified folder to static files Options: -p, --polling use polling to watch files over a network or in other non-standard situations -v, --verbose increase verbosity -V, --version output the version number -h, --help output usage information `.replace(/\t/g, ' ')) } const parse = function(argv) { // Output the version number if (argv.version===true) return version() // Output usage information if (argv.help===true) return help() // Ignore must be an array of strings argv.ignore = (typeof argv.ignore==='string' ? [ argv.ignore ] : argv.ignore) // Serve current or specified folder if (argv._[0]==='serve') return serve(argv._[1], { polling : argv.polling, verbose : argv.verbose }) // Compile current or specified folder to static files if (argv._[0]==='compile') return compile(argv._[1], argv._[2], { ignore : argv.ignore, verbose : argv.verbose }) // Show usage information when no known arg was found help() } parse(minimist(process.argv.slice(2), { alias }))