File tree Expand file tree Collapse file tree 4 files changed +57
-3
lines changed Expand file tree Collapse file tree 4 files changed +57
-3
lines changed Original file line number Diff line number Diff line change 11"use strict" ;
22
3- var info = require ( "./cli-info" ) ;
3+ var path = require ( "path" ) ;
4+ var fs = require ( "fs" ) ;
5+ var _ = require ( "lodash" ) ;
6+ var utils = require ( "../utils" ) ;
47
58/**
69 * $ browser-sync start <options>
@@ -13,11 +16,31 @@ var info = require("./cli-info");
1316 */
1417module . exports = function ( opts ) {
1518
16- var flags = stripUndefined ( opts . cli . flags ) ;
19+ var flags = stripUndefined ( opts . cli . flags ) ;
20+ var maybepkg = path . resolve ( process . cwd ( ) , "package.json" ) ;
21+ var input = flags ;
22+
23+ if ( flags . config ) {
24+ var maybeconf = path . resolve ( process . cwd ( ) , flags . config ) ;
25+ if ( fs . existsSync ( maybeconf ) ) {
26+ var conf = require ( maybeconf ) ;
27+ input = _ . merge ( { } , conf , flags ) ;
28+ } else {
29+ utils . fail ( true , new Error ( "Configuration file '" + flags . config + "' not found" ) , opts . cb ) ;
30+ }
31+ } else {
32+ if ( fs . existsSync ( maybepkg ) ) {
33+ var pkg = require ( maybepkg ) ;
34+ if ( pkg [ "browser-sync" ] ) {
35+ console . log ( "> Configuration obtained from package.json" ) ;
36+ input = _ . merge ( { } , pkg [ "browser-sync" ] , flags ) ;
37+ }
38+ }
39+ }
1740
1841 return require ( "../../" )
1942 . create ( "cli" )
20- . init ( flags , opts . cb ) ;
43+ . init ( input , opts . cb ) ;
2144} ;
2245
2346/**
Original file line number Diff line number Diff line change 6868 },
6969 "config" : {
7070 "type" : " string" ,
71+ "alias" : " c" ,
7172 "desc" : " Specify a path to a configuration file"
7273 },
7374 "host" : {
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ module.exports = {
22 files : [ "test/fixtures/**/*.css" , "test/fixtures/**/*.html" ] ,
33 testConfig : true ,
44 logLevel : "debug" ,
5+ open : false ,
56 server : {
67 baseDir : "test/fixtures"
78 }
Original file line number Diff line number Diff line change 1+ "use strict" ;
2+
3+ var path = require ( "path" ) ;
4+ var browserSync = require ( path . resolve ( "./" ) ) ;
5+ var pkg = require ( path . resolve ( "package.json" ) ) ;
6+ var assert = require ( "chai" ) . assert ;
7+ var sinon = require ( "sinon" ) ;
8+ var fs = require ( "fs" ) ;
9+ var cli = require ( path . resolve ( pkg . bin ) ) ;
10+
11+ // describe("CLI: merging package.json property with cli args", function () {
12+ // it("accepts key `browser-sync` from package.json", function (done) {
13+ // browserSync.reset();
14+ // cli({
15+ // cli: {
16+ // input: ["start"],
17+ // flags: {
18+ // logLevel: "silent",
19+ // open: false
20+ // }
21+ // },
22+ // cb: function (err, bs) {
23+ // assert.equal(bs.options.getIn(["server", "baseDir"]), "test/fixtures");
24+ // bs.cleanup();
25+ // done();
26+ // }
27+ // });
28+ // });
29+ // });
You can’t perform that action at this time.
0 commit comments