Skip to content

Commit b93646d

Browse files
committed
add conf support for command line usage
1 parent 7656e3f commit b93646d

File tree

6 files changed

+46
-32
lines changed

6 files changed

+46
-32
lines changed

README.md

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
1-
brbower
2-
=======
1+
browserify-bower
2+
================
33

4-
[![NPM](https://nodei.co/npm/brbower.png)](https://nodei.co/npm/brbower/)
4+
[![NPM](https://nodei.co/npm/browserify-bower.png)](https://nodei.co/npm/browserify-bower/)
55

6-
Let `brbower` plugin require bower components for you when building bundles, then you can `require` them as normal node modules in application codes.
7-
You can also provide external config, to guide `brbower` to external some bower components, which is useful when when building multiple bundles.
6+
Let `browserify-bower` plugin require bower components for you when building bundles, then you can `require` them as normal node modules in application codes.
7+
You can also provide external config, to guide `browserify-bower` to external some bower components, which is useful when when building multiple bundles.
88

99

1010
# install
1111

1212
With [npm](https://npmjs.org) do:
1313

1414
```
15-
npm install brbower
15+
npm install browserify-bower
1616
```
1717

1818
# usage
19+
## Programmatic API
1920
In your task runner like `gulp`, add this plugin to `browserify`:
2021
```javascript
21-
b.plugin('brbower', {
22+
b.plugin('browserify-bower', {
2223
require: ['*', 'base62/lib/base62'],
2324
external: {
2425
exclude: ['comp1', 'comp2']
@@ -46,12 +47,22 @@ var comp2 = require('alias2');
4647
</script>
4748
```
4849

50+
## Command Line
51+
Use conf file,
52+
```shell
53+
$ browserify entry.js -d -p [browserify-bower --conf conf.json] > bundle.js
54+
```
55+
Use conf json string,
56+
```shell
57+
$ browserify entry.js -d -p [browserify-bower --optjson '{"require": ["comp1", "comp2:alias2"], "external": {"exclude": ["comp1", "comp2"]}}'] > bundle.js
58+
```
59+
4960
_**p.s. feel free to use it side by other plugins/transforms, since it's a standard [`browserify`](https://github.com/substack/node-browserify) plugin, no hack, no change to your codes.**_
5061

5162
# options
52-
![brbower config](https://raw.githubusercontent.com/tminglei/brbower/master/doc/brbower-config.png)
63+
![browserify-bower config](https://raw.githubusercontent.com/tminglei/browserify-bower/master/doc/browserify-bower-config.png)
5364

54-
**action:** _string_, guide `brbower` to **require**/**external** specified bower components; available values: `require` | `external`, default `require`
65+
**action:** _string_, guide `browserify-bower` to **require**/**external** specified bower components; available values: `require` | `external`, default `require`
5566

5667
**action config:** _string array or map object_, available config items: `include` | `exclude` | `alias`, examples:
5768
a) `['name1', 'name2', ...]` _(p.s. will be treated as `{ include: [name1, name2, ...] }`)_
@@ -65,37 +76,37 @@ _Notes: `name` format: `name[:alias]`, and name can be component name or submodu
6576
- if both include/exclude and alias declared an alias for a component, declaration in alias will be used
6677

6778
# run test
68-
_You need ensure related node modules (for `brbower`) and bower components (for test codes) installed, then run `npm test`._
79+
_You need ensure related node modules (for `browserify-bower`) and bower components (for test codes) installed, then run `npm test`._
6980

7081
For first time, you can do it like this:
7182
```sh
72-
tminglei@T500 ~/repos/brbower $ npm install
83+
browserify-bower $ npm install
7384
...
74-
tminglei@T500 ~/repos/brbower $ cd test
75-
tminglei@T500 ~/repos/brbower/test $ bower install
85+
browserify-bower $ cd test
86+
browserify-bower/test $ bower install
7687
...
77-
tminglei@T500 ~/repos/brbower/test $ cd ..
78-
tminglei@T500 ~/repos/brbower $ npm test
88+
browserify-bower/test $ cd ..
89+
browserify-bower $ npm test
7990

80-
> brbower@0.2.1 test ~/repos/brbower
91+
> browserify-bower@0.4.0 test ~/repos/browserify-bower
8192
> mocha
8293

8394

8495
....
8596

8697
4 passing (580ms)
8798

88-
tminglei@T500 ~/repos/brbower $
99+
browserify-bower $
89100
```
90101
# diffenence with `debowerify`
91-
`brbower` and `debowerify` try to resolve same problem, but by different ways.
92-
_(p.s. in fact, brbower's test codes were copied and modified from `debowerify`, thanks so much ^^)_
102+
`browserify-bower` and `debowerify` try to resolve same problem, but by different ways.
103+
_(p.s. in fact, browserify-bower's test codes were copied and modified from `debowerify`, thanks so much ^^)_
93104

94105
**debowerify's way:** analyze every js files of the application, to find/replace require string for bower components with their real paths
95-
**brbower's way:** pre resolve specified bower components and require them to browserify, then when required, they're already there
106+
**browserify-bower's way:** pre resolve specified bower components and require them to browserify, then when required, they're already there
96107

97-
#### Comparison of `brbower` and `debowerify`:
98-
| | brbower | debowerify |
108+
#### Comparison of `browserify-bower` and `debowerify`:
109+
| | browserify-bower | debowerify |
99110
| --------------------------- | ----------------------------- | ---------------------------------------------- |
100111
| require submodules <br> _(in application codes)_ | support <br> _(built-in)_ | support <br> _(built-in)_ |
101112
| require ... in html/template files | OK | not OK <br> _(since it doesn't anaylze html/template files)_ |

doc/brbower-config.png

-10.9 KB
Binary file not shown.

doc/browserify-bower-config.png

14 KB
Loading

index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ var _workdir = process.cwd();
99
var brbower = module.exports = function (browserify, options) {
1010
options = options || { "require": utils.componentNames(_workdir) };
1111

12+
if (options.conf) options = require(path.join(process.cwd(), options.conf));
13+
if (options.optjson) options = JSON.parse(options.optjson);
14+
1215
_(options).forEach(function(config, action) {
1316
if (_(config).isArray()) config = { "include": config };
1417

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
2-
"name": "brbower",
3-
"version":"0.3.2",
2+
"name": "browserify-bower",
3+
"version":"0.4.0",
44
"description": "a browserify plugin, to enable you require bower components just like node modules",
55
"main": "index.js",
66
"repository": {
77
"type": "git",
8-
"url": "https://github.com/tminglei/brbower"
8+
"url": "https://github.com/tminglei/browserify-bower"
99
},
1010
"keywords": [
1111
"bower",
@@ -14,15 +14,15 @@
1414
"browserify",
1515
"browserify-plugin",
1616
"plugin",
17-
"brbower"
17+
"browserify-bower"
1818
],
1919
"author": "Minglei Tu <tmlneu@gmail.com>",
2020
"license": "MIT",
2121
"dependencies": {
2222
"lodash-node": "~2.4.1"
2323
},
2424
"devDependencies": {
25-
"browserify": "~4.1.6",
25+
"browserify": "~7.0.3",
2626
"chai": "~1.9.1",
2727
"mocha": "~1.20.0"
2828
},

test/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ var expect = require('chai').expect,
55
brbower = require('..'),
66
fs = require('fs');
77

8-
describe('brbower', function() {
8+
describe('browserify-bower', function() {
99

10-
it('should be able to brbower a basic file from dependencies', function(done) {
10+
it('should be able to browserify-bower a basic file from dependencies', function(done) {
1111
var jsPath = path.join(__dirname, 'src/index.js');
1212
var b = browserify();
1313
b.plugin(brbower.setWorkdir(__dirname));
@@ -25,7 +25,7 @@ describe('brbower', function() {
2525
});
2626
});
2727

28-
it('should be able to brbower a basic file from devDependencies', function(done) {
28+
it('should be able to browserify-bower a basic file from devDependencies', function(done) {
2929
var jsPath = path.join(__dirname, 'src/base62test.js');
3030
var b = browserify();
3131
b.plugin(brbower.setWorkdir(__dirname));
@@ -43,7 +43,7 @@ describe('brbower', function() {
4343
});
4444
});
4545

46-
it('should be able to brbower a submodule', function(done) {
46+
it('should be able to browserify-bower a submodule', function(done) {
4747
var jsPath = path.join(__dirname, 'src/by_subpath.js');
4848
var b = browserify();
4949
b.plugin(brbower.setWorkdir(__dirname), {
@@ -63,7 +63,7 @@ describe('brbower', function() {
6363
});
6464
});
6565

66-
it('should be able to brbower a module with other dependencies', function(done) {
66+
it('should be able to browserify-bower a module with other dependencies', function(done) {
6767
var b = browserify();
6868
b.plugin(brbower.setWorkdir(__dirname));
6969
b.add(path.join(__dirname, 'src/deep_dependencies_test.js'));

0 commit comments

Comments
 (0)