Skip to content

Commit

Permalink
cli: Add plugins option to cli
Browse files Browse the repository at this point in the history
  • Loading branch information
shakyShane committed Apr 6, 2016
1 parent a40dcff commit 1b316ee
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 156 deletions.
148 changes: 14 additions & 134 deletions bin/browser-sync.js
Original file line number Diff line number Diff line change
@@ -1,83 +1,53 @@
// var bs = require("./").create();
//
// /**
// * Start the Browsersync server and
// * load the express app as middleware
// */
// bs.init({
// https: true,
// scriptPath: function (path, port, options) {
// return options.get('absolute').replace('HOST', 'localhost');
// }
// });

var input = [
'--server.baseDir', '.',
'--server.index', 'index.htm',
'--server.extensions', '.html', '.css',
'--proxy.ws', 'true',
'--index',
'--serveStatic', '.', 'another',
'--ss', '.tmp', 'app',
'--open',
'--browser', 'chrome', 'firefox',
'--files', '*.css', '*.html',
'--plugins', 'bs-html-injector?files[]=*.html&files[]=*.css'
];

var qs = require('qs');
var startOpts = require('../lib/cli/opts.start.json');
var reloadOpts = require('../lib/cli/opts.reload.json');
var recipeOpts = require('../lib/cli/opts.recipe.json');
var pkg = require('../package.json');

var commands = {
"start": {
command: 'start [options]',
description: 'Start Browsersync',
builder: startOpts,
handler: function (argv) {
console.log('From start', argv);
console.log('From start');
console.log(argv);
}
},
"reload": {
command: 'reload [options]',
description: 'Send a reload event over HTTP protocol',
builder: reloadOpts,
handler: function (argv) {
console.log('From reload', argv);
console.log('From reload');
console.log(argv);
}
},
"init": {
command: 'init',
description: 'Creates a default config file',
builder: {},
handler: function (argv) {
console.log('From init', argv);
}
},
"recipe-ls": {
command: 'recipe ls [options]',
description: 'list all recipes',
builder: {},
handler: function (argv) {
console.log('From recipe ls', argv);
console.log('From init');
console.log(argv);
}
},
"recipe": {
command: 'recipe <recipe-name> [options]',
description: 'Generate the files for a recipe',
builder: recipeOpts,
handler: function (argv) {
console.log('From recipe', argv);
console.log('From recipe');
console.log(argv);
}
}
};

var yargs = attachCommands(require('yargs'), commands)
.demand(1)
.epilogue(`For help running a certain command, type <command> --help
eg: browser-sync start --help`);

.version(function () {
return pkg.version;
})
.epilogue('For help running a certain command, type <command> --help\neg: browser-sync start --help');

var argv = yargs.argv;
var command = argv._[0];
Expand All @@ -103,94 +73,4 @@ function handleIncoming(obj) {
})
.help()
.argv;
}


// console.log(
// yargs
// .options(startOpts)
// .argv);

// var out = yargs
// .command('start [options]', 'Start the Browsersync server', {
// builder: startOpts,
// handler: function (argv) {
// console.log('From start');
// // console.log(argv.version);
// }
// })
// .version(function() {
// return require('./package.json').version;
// })
// .help()
// .argv;

// var out2 = yargs
// .command('reload [options]', 'Send a reload command over http', {
// builder: reloadOpts,
// handler: function (argv) {
//
// console.log('From reload', argv);
// // console.log(argv.version);
// }
// })
// .version(function() {
// return require('./package.json').version;
// })
// .help()
// .argv;


// console.log(out);

// var out = Object.keys(ops).reduce(function (acc, key) {
// acc[key] = {
// desc: ops[key]
// }
// return acc;
// }, {});
// console.log(JSON.stringify(out, null, 4));
// var opts = {
// "browser": {
// alias: "b",
// type: "array",
// desc: "Choose which browser should be auto-opened"
// },
// "files": {
// alias: "f",
// type: "array",
// desc: "File paths to watch"
// },
// "server": {
// desc: "Run a Local server from a directory",
// },
// "serveStatic": {
// type: "array",
// desc: "Directories to serve static files from"
// },
// "index": {
// type: "string",
// desc: "Specify which file should be used as the index page"
// },
// "extensions": {
// desc: "Specify file extension fallbacks"
// }
// }
//
// var out = yargs
// .option('server')
// .options(opts);
// // .array('files')
// // // server
// // .alias('ss', 'serveStatic')
// // .string('index')
// // .array('serveStatic')
// // .array('server.extensions')
// // .boolean('open')
// // .alias('ws', 'proxy.ws')
// // .alias('s', 'server')
// // .array('plugins');
//
// console.log(out.argv);

// console.log(qs.parse(out.argv.plugins[0].split('?')[1]));
}
22 changes: 0 additions & 22 deletions lib/cli/help.txt
Original file line number Diff line number Diff line change
@@ -1,25 +1,3 @@
{bold:Usage:}
{gray:---------}

{gray:$} browser-sync <command> [options]

{bold:Commands:}
{gray:---------}

{bold:init} Creates a default config file
{bold:start} Start Browser Sync
{bold:reload} Send a reload event over HTTP protocol

{bold:`start` Options:}
{gray:--------}

%startflags%

{bold:`reload` Options:}
{gray:--------}

%reloadflags%

{cyan:Server Example:}
{gray:---------------}
Use current directory as root & watch CSS files
Expand Down
5 changes: 5 additions & 0 deletions lib/cli/opts.start.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"desc": "File paths to watch"
},
"server": {
"alias": "s",
"desc": "Run a Local server (uses your cwd as the web root)"
},
"serveStatic": {
Expand All @@ -25,6 +26,10 @@
"type": "string",
"desc": "Specify which file should be used as the index page"
},
"plugins": {
"type": "array",
"desc": "Load Browsersync plugins"
},
"extensions": {
"type": "array",
"desc": "Specify file extension fallbacks"
Expand Down

0 comments on commit 1b316ee

Please sign in to comment.