Skip to content
Browse files

autocompute functiona arguments by default

  • Loading branch information...
1 parent 967d758 commit 24636e37db0035618f20f2e5894f2938cf27e1e5 @weepy committed
Showing with 13,747 additions and 16 deletions.
  1. +10 −0 History.md
  2. +20 −11 README.md
  3. +1 −2 component.json
  4. +13 −3 index.js
  5. +1 −0 node_modules/.bin/component
  6. +1 −0 node_modules/.bin/component-build
  7. +1 −0 node_modules/.bin/component-changes
  8. +1 −0 node_modules/.bin/component-convert
  9. +1 −0 node_modules/.bin/component-create
  10. +1 −0 node_modules/.bin/component-docs
  11. +1 −0 node_modules/.bin/component-help
  12. +1 −0 node_modules/.bin/component-info
  13. +1 −0 node_modules/.bin/component-install
  14. +1 −0 node_modules/.bin/component-ls
  15. +1 −0 node_modules/.bin/component-open
  16. +1 −0 node_modules/.bin/component-search
  17. +1 −0 node_modules/.bin/component-wiki
  18. +5 −0 node_modules/component/.npmignore
  19. +170 −0 node_modules/component/History.md
  20. +13 −0 node_modules/component/Makefile
  21. +242 −0 node_modules/component/Readme.md
  22. +76 −0 node_modules/component/bin/component
  23. +111 −0 node_modules/component/bin/component-build
  24. +68 −0 node_modules/component/bin/component-changes
  25. +50 −0 node_modules/component/bin/component-convert
  26. +188 −0 node_modules/component/bin/component-create
  27. +67 −0 node_modules/component/bin/component-docs
  28. +23 −0 node_modules/component/bin/component-help
  29. +61 −0 node_modules/component/bin/component-info
  30. +232 −0 node_modules/component/bin/component-install
  31. +25 −0 node_modules/component/bin/component-ls
  32. +21 −0 node_modules/component/bin/component-open
  33. +124 −0 node_modules/component/bin/component-search
  34. +11 −0 node_modules/component/bin/component-wiki
  35. +1 −0 node_modules/component/component.json
  36. +1 −0 node_modules/component/index.js
  37. +342 −0 node_modules/component/lib/Package.js
  38. +210 −0 node_modules/component/lib/component.js
  39. +57 −0 node_modules/component/lib/utils.js
  40. +1 −0 node_modules/component/node_modules/.bin/jog
  41. +4 −0 node_modules/component/node_modules/batch/.npmignore
  42. +30 −0 node_modules/component/node_modules/batch/History.md
  43. +6 −0 node_modules/component/node_modules/batch/Makefile
  44. +72 −0 node_modules/component/node_modules/batch/Readme.md
  45. +2 −0 node_modules/component/node_modules/batch/index.js
  46. +90 −0 node_modules/component/node_modules/batch/lib/batch.js
  47. +1 −0 node_modules/component/node_modules/batch/node_modules/.bin/_mocha
  48. +1 −0 node_modules/component/node_modules/batch/node_modules/.bin/mocha
  49. +6 −0 node_modules/component/node_modules/batch/node_modules/mocha/.npmignore
  50. +5 −0 node_modules/component/node_modules/batch/node_modules/mocha/.travis.yml
  51. +478 −0 node_modules/component/node_modules/batch/node_modules/mocha/History.md
  52. +22 −0 node_modules/component/node_modules/batch/node_modules/mocha/LICENSE
  53. +126 −0 node_modules/component/node_modules/batch/node_modules/mocha/Makefile
  54. +36 −0 node_modules/component/node_modules/batch/node_modules/mocha/Readme.md
  55. +4,906 −0 node_modules/component/node_modules/batch/node_modules/mocha/_mocha.js
  56. +422 −0 node_modules/component/node_modules/batch/node_modules/mocha/bin/_mocha
  57. +47 −0 node_modules/component/node_modules/batch/node_modules/mocha/bin/mocha
  58. BIN node_modules/component/node_modules/batch/node_modules/mocha/images/error.png
  59. BIN node_modules/component/node_modules/batch/node_modules/mocha/images/ok.png
  60. +4 −0 node_modules/component/node_modules/batch/node_modules/mocha/index.js
  61. +6 −0 node_modules/component/node_modules/batch/node_modules/mocha/lib/browser/debug.js
  62. 0 node_modules/component/node_modules/batch/node_modules/mocha/lib/browser/diff.js
  63. +178 −0 node_modules/component/node_modules/batch/node_modules/mocha/lib/browser/events.js
  64. 0 node_modules/component/node_modules/batch/node_modules/mocha/lib/browser/fs.js
  65. 0 node_modules/component/node_modules/batch/node_modules/mocha/lib/browser/path.js
  66. +125 −0 node_modules/component/node_modules/batch/node_modules/mocha/lib/browser/progress.js
  67. +8 −0 node_modules/component/node_modules/batch/node_modules/mocha/lib/browser/tty.js
  68. +69 −0 node_modules/component/node_modules/batch/node_modules/mocha/lib/context.js
  69. +50 −0 node_modules/component/node_modules/batch/node_modules/mocha/lib/hook.js
  70. +133 −0 node_modules/component/node_modules/batch/node_modules/mocha/lib/interfaces/bdd.js
  71. +60 −0 node_modules/component/node_modules/batch/node_modules/mocha/lib/interfaces/exports.js
  72. +5 −0 node_modules/component/node_modules/batch/node_modules/mocha/lib/interfaces/index.js
  73. +91 −0 node_modules/component/node_modules/batch/node_modules/mocha/lib/interfaces/qunit.js
  74. +123 −0 node_modules/component/node_modules/batch/node_modules/mocha/lib/interfaces/tdd.js
  75. +301 −0 node_modules/component/node_modules/batch/node_modules/mocha/lib/mocha.js
  76. +81 −0 node_modules/component/node_modules/batch/node_modules/mocha/lib/ms.js
  77. +381 −0 node_modules/component/node_modules/batch/node_modules/mocha/lib/reporters/base.js
  78. +56 −0 node_modules/component/node_modules/batch/node_modules/mocha/lib/reporters/doc.js
  79. +62 −0 node_modules/component/node_modules/batch/node_modules/mocha/lib/reporters/dot.js
  80. +51 −0 node_modules/component/node_modules/batch/node_modules/mocha/lib/reporters/html-cov.js
  81. +255 −0 node_modules/component/node_modules/batch/node_modules/mocha/lib/reporters/html.js
  82. +19 −0 node_modules/component/node_modules/batch/node_modules/mocha/lib/reporters/index.js
  83. +153 −0 node_modules/component/node_modules/batch/node_modules/mocha/lib/reporters/json-cov.js
  84. +71 −0 node_modules/component/node_modules/batch/node_modules/mocha/lib/reporters/json-stream.js
  85. +80 −0 node_modules/component/node_modules/batch/node_modules/mocha/lib/reporters/json.js
  86. +97 −0 node_modules/component/node_modules/batch/node_modules/mocha/lib/reporters/landing.js
  87. +64 −0 node_modules/component/node_modules/batch/node_modules/mocha/lib/reporters/list.js
  88. +92 −0 node_modules/component/node_modules/batch/node_modules/mocha/lib/reporters/markdown.js
  89. +38 −0 node_modules/component/node_modules/batch/node_modules/mocha/lib/reporters/min.js
  90. +259 −0 node_modules/component/node_modules/batch/node_modules/mocha/lib/reporters/nyan.js
  91. +86 −0 node_modules/component/node_modules/batch/node_modules/mocha/lib/reporters/progress.js
  92. +87 −0 node_modules/component/node_modules/batch/node_modules/mocha/lib/reporters/spec.js
  93. +63 −0 node_modules/component/node_modules/batch/node_modules/mocha/lib/reporters/tap.js
  94. +65 −0 node_modules/component/node_modules/batch/node_modules/mocha/lib/reporters/teamcity.js
  95. +50 −0 node_modules/component/node_modules/batch/node_modules/mocha/lib/reporters/templates/coverage.jade
  96. +13 −0 node_modules/component/node_modules/batch/node_modules/mocha/lib/reporters/templates/menu.jade
  97. +34 −0 node_modules/component/node_modules/batch/node_modules/mocha/lib/reporters/templates/script.html
  98. +307 −0 node_modules/component/node_modules/batch/node_modules/mocha/lib/reporters/templates/style.html
  99. +115 −0 node_modules/component/node_modules/batch/node_modules/mocha/lib/reporters/xunit.js
  100. +219 −0 node_modules/component/node_modules/batch/node_modules/mocha/lib/runnable.js
  101. +532 −0 node_modules/component/node_modules/batch/node_modules/mocha/lib/runner.js
  102. +296 −0 node_modules/component/node_modules/batch/node_modules/mocha/lib/suite.js
  103. +17 −0 node_modules/component/node_modules/batch/node_modules/mocha/lib/template.html
  104. +32 −0 node_modules/component/node_modules/batch/node_modules/mocha/lib/test.js
  105. +282 −0 node_modules/component/node_modules/batch/node_modules/mocha/lib/utils.js
  106. +227 −0 node_modules/component/node_modules/batch/node_modules/mocha/mocha.css
Sorry, we could not display the entire diff because too many files (777) changed.
View
10 History.md
@@ -0,0 +1,10 @@
+0.0.2
+=====
+
+* Attr's with function arguments are assumed to be computed by default
+
+
+0.0.1
+=====
+
+* Intial Release
View
31 README.md
@@ -70,17 +70,10 @@ name.on('change', function(new_name, old_name) {
## Computed properties
- These have the same API, except no setter and a function is passed in and is run to determine the initial value
-
-### attr.computed(fn, dependencies)
-
- Creates a computed attr.
- Dependencies are automatically calculated unless set explicitly.
+ Has the same API, except function is passed in and is run to determine the initial value. (has no setter)
```javascript
-var cattr = require('attr').computed
-
-fullName = cattr(function() {
+fullName = attr(function() {
return firstName() + ' ' + surName()
})
@@ -89,11 +82,27 @@ fullName() // => 'Homer Simpson'
fullName.dependencies // => [ firstName, surName ]
```
+Dependencies on other simple (non-computed) are automatically calculated unless set explicitly via a second argument as in:
-### attr.dependencies(fn)
+```
+fullName = attr(function() {
+ return firstName() + ' ' + surName()
+}, [firstName])
- Calculates a list of the simple attributes called by running this function
+fullName.dependencies // => [ firstName ]
+``
+
+### attr.autocompute
+
+ By default function values are assumed to be computed. This behaviour can be turned off by setting autocompute.
+
+### attr.computed(fn, dependencies)
+
+ Explicitly creates a computed property - this is only useful if autocompute is turned off
+
+### attr.dependencies(fn)
+ Calculates a list of the simple (non-computed) attributes called by running this function
# Testing
View
3 component.json
@@ -2,10 +2,9 @@
"name": "attr",
"repo": "weepy/attr",
"description": "Simple property with get/set and events",
- "version": "0.0.1",
+ "version": "0.0.2",
"keywords": [],
"dependencies": {
- "component/assert": "*",
"component/emitter": "*"
},
"development": {
View
16 index.js
@@ -34,10 +34,10 @@ function extend(a, b) {
var watcher = false
-function Attr(arg) {
+function Attr(arg, dependencies) {
- // IDEA: autocreate computed attr for function values
- // if(typeof arg =='function') return Attr.computed(arg)
+ // autocreate computed attr for function values
+ if(Attr.autocompute && typeof arg =='function') return Attr.computed(arg, dependencies)
function attr(v) {
if(arguments.length) {
@@ -61,6 +61,12 @@ function Attr(arg) {
return attr
}
+/*
+ * Autocompute functions
+ */
+
+Attr.autocompute = true
+
var lastValue = null
@@ -76,6 +82,8 @@ Attr.dependencies = function(fn) {
}
+
+
/*
* computed attribute
*/
@@ -111,6 +119,8 @@ Attr.computed = function(fn, dependencies) {
attr.change()
}
+ attr.computed = true
+
return attr
}
View
1 node_modules/.bin/component
View
1 node_modules/.bin/component-build
View
1 node_modules/.bin/component-changes
View
1 node_modules/.bin/component-convert
View
1 node_modules/.bin/component-create
View
1 node_modules/.bin/component-docs
View
1 node_modules/.bin/component-help
View
1 node_modules/.bin/component-info
View
1 node_modules/.bin/component-install
View
1 node_modules/.bin/component-ls
View
1 node_modules/.bin/component-open
View
1 node_modules/.bin/component-search
View
1 node_modules/.bin/component-wiki
View
5 node_modules/component/.npmignore
@@ -0,0 +1,5 @@
+support
+test
+examples
+*.sock
+components
View
170 node_modules/component/History.md
@@ -0,0 +1,170 @@
+
+0.9.0 / 2012-11-06
+==================
+
+ * add `-l, --local` to `component-create(1)`. Closes #119
+ * add module check to `component-build(1)` --standalone dance
+ * add `.paths` lookup path array support. Closes #137
+ * update builder for root main alias fix
+ * remove __COMPONENT_PATH__ support. Closes #137
+
+0.8.0 / 2012-11-04
+==================
+
+ * add `-p, --prefix <str>` support
+ * add asset copying and url rewriting. Closes #52
+ * add `.images` and `.fonts` support for installation
+
+0.7.1 / 2012-11-02
+==================
+
+ * add error-handling for getFiles(). Closes #121
+ * add error(res, url) helper
+
+0.7.0 / 2012-10-31
+==================
+
+ * add implicit `--save` to `component-install(1)`. Closes #103
+ * add recursive `.local` support to `component-install(1)`
+ * add better local dep failure message
+ * add `-l, --license` to `component-search(1)`. Closes #107
+ * add `component.lookup(pkg)` function
+ * add `component.dependenciesOf(pkg)` function
+ * add History.md to `component-create(1)`. Closes #101
+ * add default .license of "MIT" to `component-create(1)`
+ * update builder
+
+0.6.4 / 2012-10-26
+==================
+
+ * fix a component-install(1) bug where a 404 would not display an error [damian]
+
+0.6.3 / 2012-10-24
+==================
+
+ * update builder for main alias fix
+
+0.6.2 / 2012-10-22
+==================
+
+ * add component-create(1) support for existing dirs and files. Closes #58
+ * add local sub-command resolution
+ * improve some error handling
+ * fix annoying node warning for existsSync()
+ * fix utils.error() stderr
+
+0.6.1 / 2012-10-22
+==================
+
+ * change "bundled" to "local"
+
+0.6.0 / 2012-10-22
+==================
+
+ * add __COMPONENT_PATH__ support. Closes #30
+ * add `component.paths()` helper function
+ * update builder
+
+0.5.0 / 2012-10-19
+==================
+
+ * add "main" support
+ * fix `component-search(1)` when description is missing. Closes #83 [Tim Oxley]
+
+0.4.2 / 2012-10-17
+==================
+
+ * fix silly component-install(1) bug attempting to read ./component.json. Closes #81
+
+0.4.1 / 2012-10-16
+==================
+
+ * update builder
+
+0.4.0 / 2012-10-15
+==================
+
+ * add `.remotes` support. Closes #6
+ * add --name option to specify the base name of built files.
+ * change --standalone name to be required. Closes #71
+ * update builder dep, remove --dev cascading. Closes #69
+
+0.3.0 / 2012-10-10
+==================
+
+ * add readme template for `component-create(1)` with more boilerplate
+ * add default of `{}` for conf for direct installs
+ * add `auth` support for basic authentication [Dan Williams]
+
+0.2.0 / 2012-10-06
+==================
+
+ * add `component-search(1)` `--open` flag to view in browser. Closes #39
+ * add `component-wiki(1)`. Closes #55
+ * add "y" as "yes" support
+ * add `component-install(1)` `--save` support
+ * fix < 0.8.x support
+
+0.1.1 / 2012-09-19
+==================
+
+ * add new "stdio" child process inherit option. Closes #45
+ * update component(1) --help docs
+ * remove special-casing of 127 exit status
+ * remove component-register(1) from package.json
+ * fix subcommand execution on windows [ForbesLindesay]
+
+0.1.0 / 2012-09-18
+==================
+
+ * add remote search
+ * add ★ to search output
+ * add sorting by stars
+ * add --json to `component-search(1)`
+ * remove `component-register(1)`
+ * change `component-search(1)` to use only verbose output
+
+0.0.7 / 2012-09-14
+==================
+
+ * add `--standalone [name]` support to component-build(1). Closes #34
+ * add memoized mkdir
+ * add empty .development `{}` to component-create(1)
+ * update component-builder
+ * remove "which" dependency
+ * remove logging from component-convert(1)
+ * remove "component.json" dep of component target in component-create(1) makefile
+ * rename devDependencies to development
+
+0.0.6 / 2012-09-05
+==================
+
+ * add `--dev` to `component-create(1)` build command
+ * add `component-build(1)` --dev flag. Closes #25
+ * rename `devDependencies` to `development`
+ * fix `component-create(1)` undefined.css. Closes#24
+
+0.0.5 / 2012-09-04
+==================
+
+ * add `--standalone` to `component-build(1)`
+
+0.0.4 / 2012-09-01
+==================
+
+ * add `.repo` to `component-create(1)`
+ * add `.files` support. Closes #11
+ * fix installation of files nested in dirs
+ * change `component-register(1)` to use .repo prop
+ * change `component-search(1)` query to be optional
+ * change `component-search(1)` to join args
+
+0.0.3 / 2012-08-30
+==================
+
+ * add missing commands to package.json
+
+0.0.2 / 2012-08-30
+==================
+
+ * update commander.js for pull-request fail
View
13 node_modules/component/Makefile
@@ -0,0 +1,13 @@
+
+templates/readme.js: templates/readme.md
+ ./node_modules/.bin/minstache < $< > $@
+
+test:
+ @./node_modules/.bin/mocha \
+ --require should \
+ --timeout 10s \
+ --slow 3s \
+ --bail \
+ --reporter spec
+
+.PHONY: test
View
242 node_modules/component/Readme.md
@@ -0,0 +1,242 @@
+
+ ![web component logo](http://i49.tinypic.com/e7nj9v.png)
+
+ Component package manager for building a better web.
+
+## Installation
+
+ $ npm install -g component
+
+## Installing packages
+
+ To install one or more packages, simply pass their github
+ repo names as arguments to `component install`. Dependencies
+ are resolved and the component contents are downloaded into
+ `./components` by default. View `component help install` for details.
+
+```
+$ component install component/tip
+
+ install : component/tip@master
+ dep : component/emitter@master
+ install : component/emitter@master
+ dep : component/jquery@master
+ install : component/jquery@master
+ fetch : component/tip:index.js
+ fetch : component/tip:tip.css
+ fetch : component/tip:tip.html
+ fetch : component/emitter:index.js
+ fetch : component/jquery:index.js
+ complete : component/emitter
+ complete : component/jquery
+ complete : component/tip
+```
+
+## Searching for components
+
+ By adding your component to the [Components List](https://github.com/component/component/wiki/Components) wiki page it will become automatically available to `component-search(1)`. When invoked with no query all components are displayed, otherwise a filtered search, ordered by the number of github "stars":
+
+```
+$ component search ui
+
+ component/dialog
+ url: https://github.com/component/dialog
+ desc: Dialog component
+ ★ 12
+
+ component/notification
+ url: https://github.com/component/notification
+ desc: Notification component
+ ★ 10
+
+ component/overlay
+ url: https://github.com/component/overlay
+ desc: Overlay component
+ ★ 7
+
+```
+
+## Usage
+
+ Via `--help`:
+
+```
+
+Usage: component <command> [options]
+
+Options:
+
+ -h, --help output usage information
+ -V, --version output the version number
+
+Commands:
+
+ install [name ...] install one or more components
+ create [dir] create a component skeleton
+ search [query] search with the given query
+ convert <file ...> convert html files to js modules
+ info <name> [prop] output json component information
+ changes <name> output changelog contents
+ docs <name> output readme contents
+ open <name> open component github repo
+ wiki open the components list wiki page
+ build build the component
+ ls list installed components
+
+```
+
+## Features
+
+ - write modular commonjs components
+ - write components that include their own styles, images, scripts, or any combo
+ - no registry publishing or account required, uses github repositories
+ - extensible sub-commands via `component-YOURCOMMAND` git-style
+ - component skeleton creation command
+ - installs dependencies from the command-line or ./component.json
+ - avoid name squatting through github's naming conventions
+ - build your components with `--standalone` to share them with non-component(1) users
+ - view documentation from the command line
+ - simple private registry set up (all you need is a file server)
+ - very fast
+
+## Using Github as a registry
+
+ By using GitHub as the registry, `component(1)` is automatically
+ available to you without further explicit knowledge or work
+ creating a registry account etc.
+
+ A nice side-effect of this namespaced world is that dependencies
+ are explicit and self-documenting. No longer do you need to query
+ the registry for a "repo" property that may not exist, it's simply
+ built in to the package name, for example ["visionmedia/page.js"](https://github.com/visionmedia/page.js) rather
+ than the unclear "page".
+
+ Another benefit of this is that there are zero name collisions, for example
+ you may use "component/tip" for a dependency of "foo", and "someuser/tip"
+ as a dependency of "bar", providing `require('tip')` in each. This prevents
+ obscure or irrelevant naming such as "progress", "progress2", "progress-bar",
+ "progress-component" found in npm.
+
+## Creating a component
+
+ The `component-create(1)` command can create a component
+ project skeleton for you by filling out the prompts. Once
+ this repo is published to Github, you're all done!
+
+```
+name: popover
+description: Popover UI component
+does this component have js? yes
+does this component have css? yes
+does this component have html? yes
+
+ create : popover
+ create : popover/index.js
+ create : popover/template.html
+ create : popover/popover.css
+ create : popover/Makefile
+ create : popover/Readme.md
+ create : popover/.gitignore
+ create : popover/component.json
+
+```
+
+ A `Makefile` is created for you in order to create a build of the component,
+ complete with installed dependencies simply execute `make`.
+
+## Templates
+
+ Because `component(1)` has no notion of a "template", even simple HTML files
+ should be converted to a `require()`-able module. It is recommended that public
+ components shared within the community use regular HTML templates, and regular
+ CSS stylesheets to maximize contributions, however if you wish to use alternate
+ technologies just make sure to compile them before publishing them to Github.
+
+ For the recommended use-case of regular HTML, the `component-convert(1)` command
+ will translate a regular HTML file to its `require()`-able JavaScript counterpart.
+
+## Developing component(1) sub-commands
+
+ `component(1)` and sub-commands are structured much like `git(1)`,
+ in that sub-commands are simply separate executables. For example
+ `$ component info pkg` and `$ component-info pkg` are equivalent.
+
+ Because of this you'll likely want `PATH="./bin:$PATH"` in your
+ profile or session while developing component, otherwise `./bin/component`
+ will have a hard time finding the sub-commands.
+
+## Running tests
+
+Make sure dependencies are installed:
+
+```
+$ npm install
+```
+
+Then run:
+
+```
+$ make test
+```
+
+## Shout-outs
+
+ The concept of components themselves are nothing new, Drupal
+ for example has been doing this for years, however it seemed the concept was never
+ really translated to the client. My hope is that other communities will re-implement this
+ simple tool in their language of choice so that we can all consume components
+ easily.
+
+## Screencasts
+
+ - [App integration introduction](https://vimeo.com/48054442)
+
+## Links
+
+ - [List](https://github.com/component/component/wiki/Components) of all available components
+ - [Wiki](https://github.com/component/component/wiki)
+ - [Mailing List](https://groups.google.com/group/componentjs)
+ - component ["spec"](https://github.com/component/component/wiki/Spec)
+ - join `#components` on freenode
+ - follow [@component_js](http://twitter.com/component_js) on twitter
+ - [Building better components](https://github.com/component/component/wiki/Building-better-components) tips
+ - [F.A.Q](https://github.com/component/component/wiki/F.A.Q)
+
+## Contributors
+
+ - TJ Holowaychuk
+ - Guillermo Rauch
+ - Garrett Johnson
+ - Amir Abu Shareb
+ - Adam Sanderson
+ - Matt Mueller
+ - Forbes Lindesay
+ - Arpad Borsos
+ - Dan Williams
+ - Damián Suárez
+ - Tim Oxley
+
+## License
+
+(The MIT License)
+
+Copyright (c) 2012 TJ Holowaychuk &lt;tj@vision-media.ca&gt;
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
76 node_modules/component/bin/component
@@ -0,0 +1,76 @@
+#!/usr/bin/env node
+
+/**
+ * Module dependencies.
+ */
+
+var program = require('commander')
+ , utils = require('../lib/utils')
+ , spawn = require('win-spawn')
+ , path = require('path')
+ , fs = require('fs')
+ , join = path.join
+ , exists = fs.existsSync;
+
+// usage
+
+program
+ .version(require('../package').version)
+ .usage('<command> [options]');
+
+// sub-command help
+
+program.on('--help', function(){
+ console.log(' Commands:');
+ console.log();
+ console.log(' install [name ...] install one or more components');
+ console.log(' create [dir] create a component skeleton');
+ console.log(' search [query] search with the given query');
+ console.log(' convert <file ...> convert html files to js modules');
+ console.log(' info <name> [prop] output json component information');
+ console.log(' changes <name> output changelog contents');
+ console.log(' docs <name> output readme contents');
+ console.log(' open <name> open component github repo');
+ console.log(' wiki open the components list wiki page');
+ console.log(' build build the component');
+ console.log(' ls list installed components');
+ console.log();
+ process.exit();
+});
+
+// parse argv
+
+program.parse(process.argv);
+
+// args void of cmd
+
+var args = process.argv.slice(3);
+
+// command
+
+var cmd = program.args[0];
+
+// alias "install" as "add"
+
+if ('add' == cmd) cmd = 'install';
+
+// display help
+
+if (!cmd) {
+ process.stdout.write(program.helpInformation());
+ program.emit('--help');
+ process.exit();
+}
+
+// executable
+
+var bin = 'component-' + cmd;
+
+// local
+
+var local = join(__dirname, bin);
+if (exists(local)) bin = local;
+
+// spawn
+
+var proc = spawn(bin, args, { stdio: 'inherit', customFds: [0, 1, 2] });
View
111 node_modules/component/bin/component-build
@@ -0,0 +1,111 @@
+#!/usr/bin/env node
+
+/**
+ * Module dependencies.
+ */
+
+var program = require('commander')
+ , Builder = require('component-builder')
+ , component = require('..')
+ , utils = component.utils
+ , log = component.utils.log
+ , path = require('path')
+ , fs = require('fs')
+ , mkdir = require('mkdirp');
+
+// options
+
+program
+ .option('-d, --dev', 'build development dependencies')
+ .option('-s, --standalone <name>', 'build a stand-alone version of the component')
+ .option('-o, --out <dir>', 'output directory defaulting to ./build', 'build')
+ .option('-n, --name <file>', 'base name for build files defaulting to build', 'build')
+ .option('-v, --verbose', 'output verbose build information')
+ .option('-p, --prefix <str>', 'prefix css asset urls with <str>')
+
+// examples
+
+program.on('--help', function(){
+ console.log(' Examples:');
+ console.log();
+ console.log(' # build to ./build');
+ console.log(' $ component build');
+ console.log();
+ console.log(' # build to ./dist as assets.js, assets.css');
+ console.log(' $ component build -o dist -n assets');
+ console.log();
+ console.log(' # build standalone as window.$');
+ console.log(' $ component build --standalone $');
+ console.log();
+ console.log(' # add lookup paths');
+ console.log(' $ COMPONENT_PATH=lib');
+ console.log(' $ component build');
+ console.log();
+});
+
+// parse argv
+
+program.parse(process.argv);
+
+// load json
+
+var conf = require(path.resolve('component.json'));
+
+// standalone
+
+var standalone = program.standalone;
+
+// mkdir -p
+
+mkdir.sync(program.out);
+
+// output streams
+
+var js = fs.createWriteStream(path.join(program.out, program.name + '.js'));
+var css = fs.createWriteStream(path.join(program.out, program.name + '.css'));
+
+// build
+
+var builder = new Builder(process.cwd());
+builder.copyAssetsTo(program.out);
+if (program.dev) builder.prefixUrls('./');
+if (program.prefix) builder.prefixUrls(program.prefix);
+
+// lookup paths
+
+if (conf.paths) builder.addLookup(conf.paths);
+
+var start = new Date;
+
+// --dev
+
+if (program.dev) builder.development();
+
+if (program.verbose) console.log();
+builder.build(function(err, obj){
+ if (err) utils.fatal(err.message);
+
+ var name = 'string' == typeof standalone
+ ? standalone
+ : conf.name;
+
+ css.write(obj.css);
+ if (standalone) js.write(';(function(){\n');
+ js.write(obj.require);
+ js.write(obj.js);
+ if (standalone) js.write(' if ("undefined" == typeof module) {\n');
+ if (standalone) js.write(' window.' + name + ' = require("' + conf.name + '");\n');
+ if (standalone) js.write(' } else {\n');
+ if (standalone) js.write(' module.exports = require("' + conf.name + '");\n');
+ if (standalone) js.write(' }\n');
+ if (standalone) js.write('})();');
+
+ if (!program.verbose) return;
+ var duration = new Date - start;
+ log('write', js.path);
+ log('write', css.path);
+ log('js', (obj.js.length / 1024 | 0) + 'kb');
+ log('css', (obj.css.length / 1024 | 0) + 'kb');
+ log('duration', duration + 'ms');
+ console.log();
+});
View
68 node_modules/component/bin/component-changes
@@ -0,0 +1,68 @@
+#!/usr/bin/env node
+
+/**
+ * Module dependencies.
+ */
+
+var program = require('commander')
+ , component = require('..')
+ , utils = component.utils;
+
+// usage
+
+program.usage('<name>');
+
+// parse argv
+
+program.parse(process.argv);
+
+// package
+
+var pkg = program.args.shift();
+
+// required
+
+if (!pkg) utils.fatal("<name> required");
+
+// lookup docs
+
+component.changes(pkg, function(err, docs){
+ // TODO: handle non-markdown
+ if (err) throw err;
+ if (!docs) utils.fatal('failed to lookup changelog for "' + pkg + '"');
+ var readme = new Buffer(docs.content, 'base64').toString('utf8');
+ process.stdout.write(indent(markdown(readme)));
+ process.stdout.write('\n\n');
+});
+
+/**
+ * Convert `str` of markdown for terminal display.
+ */
+
+function markdown(str) {
+ // TODO: move this stuff to npm
+ return str
+ .replace(/^([^\n]+)\n\s*===+/gm, '\033[1m$1\033[0m')
+ .replace(/^#+ *(.+)/gm, '\033[1m$1\033[0m')
+ .replace(/`{3}\w*((?:.|\n)+?)`{3}/g, code)
+ .replace(/`(.*?)`/g, '\033[36m$1\033[0m')
+ .replace(/__(.*?)__/g, '\033[1m$1\033[0m')
+ .replace(/!?\[(.*?)\]\((.*?)\)/g, '$1:(\033[36;4m$2\033[m)');
+}
+
+/**
+ * Code formatting.
+ */
+
+function code(_, code) {
+ code = indent(code.trim());
+ return '\033[90m' + code + '\033[0m';
+}
+
+/**
+ * Indent the given `str`.
+ */
+
+function indent(str) {
+ return str.replace(/^/gm, ' ');
+}
View
50 node_modules/component/bin/component-convert
@@ -0,0 +1,50 @@
+#!/usr/bin/env node
+
+/**
+ * Module dependencies.
+ */
+
+var program = require('commander')
+ , str2js = require('string-to-js')
+ , component = require('..')
+ , utils = component.utils
+ , path = require('path')
+ , fs = require('fs')
+ , join = path.join
+ , read = fs.readFileSync;
+
+// usage
+
+program.usage('<file>');
+
+// examples
+
+program.on('--help', function(){
+ console.log(' Examples:');
+ console.log();
+ console.log(' # convert template.html to js');
+ console.log(' $ component convert template.html');
+ console.log();
+});
+
+// parse
+
+program.parse(process.argv);
+
+// config
+
+var conf = {};
+
+// file
+
+var file = program.args[0];
+
+// require file
+
+if (!file) utils.fatal('<file> required');
+
+// convert
+
+var html = read(file, 'utf8');
+var out = path.join(path.dirname(file), path.basename(file, '.html') + '.js');
+fs.writeFileSync(out, str2js(html));
View
188 node_modules/component/bin/component-create
@@ -0,0 +1,188 @@
+#!/usr/bin/env node
+
+/**
+ * Module dependencies.
+ */
+
+var program = require('commander')
+ , component = require('..')
+ , utils = component.utils
+ , path = require('path')
+ , fs = require('fs')
+ , join = path.join
+ , read = fs.readFileSync
+ , readdir = fs.readdirSync
+ , exists = fs.existsSync
+ , mkdir = require('mkdirp').sync
+ , readme = require('../templates/readme');
+
+// usage
+
+program.usage('[dir]');
+
+// options
+
+program
+ .option('-l, --local', 'create a local private component')
+ .parse(process.argv);
+
+// config
+
+var conf = {};
+
+// dest
+
+var dir = program.args[0] || '.';
+
+// --local
+
+var local = program.local;
+
+// already a component
+
+if (exists(join(dir, 'component.json'))) {
+ utils.fatal(dir + ' is already a component');
+}
+
+/**
+ * Verbose write.
+ */
+
+function write(path, str) {
+ if (exists(path)) {
+ utils.warn('exists', path);
+ } else {
+ utils.log('create', path);
+ fs.writeFileSync(path, str);
+ }
+}
+
+// private / public prompts
+
+if (local) {
+ var prompt = {
+ name: 'name: ',
+ desc: 'description: ',
+ js: 'does this component have js? ',
+ css: 'does this component have css? ',
+ html: 'does this component have html? '
+ };
+} else {
+ var prompt = {
+ repo: 'repo (username/project): ',
+ desc: 'description: ',
+ js: 'does this component have js? ',
+ css: 'does this component have css? ',
+ html: 'does this component have html? '
+ };
+}
+
+// prompt
+
+program.prompt(prompt, function(obj){
+ if (local) {
+ var name = obj.name;
+ } else {
+ // repo
+ var repo = obj.repo.split('/');
+ if (2 != repo.length) throw new Error('repo must be <username>/<project>');
+
+ // name
+ var name = repo[1];
+ }
+
+ // populate json
+ conf.name = obj.name = name;
+ if (!local) conf.repo = repo.join('/');
+ conf.description = obj.desc;
+ if (!local) conf.version = "0.0.1";
+ if (!local) conf.keywords = [];
+ conf.dependencies = {};
+ conf.development = {};
+ if (!local) conf.license = "MIT";
+
+ // dir
+ console.log();
+ utils.log('create', dir);
+ mkdir(dir);
+
+ // js
+ if (bool(obj.js)) {
+ conf.scripts = ["index.js"];
+ write(join(dir, 'index.js'), '');
+ }
+
+ // html
+ if (bool(obj.html)) {
+ conf.scripts = conf.scripts || [];
+ conf.scripts.push('template.js');
+ write(join(dir, 'template.html'), '');
+ }
+
+ // css
+ if (bool(obj.css)) {
+ conf.styles = [name + '.css'];
+ write(join(dir, name + '.css'), '');
+ }
+
+ // makefile
+ write(join(dir, 'Makefile'), createMakefile(obj));
+
+ // readme
+ if (!local) write(join(dir, 'Readme.md'), readme(obj));
+
+ // changelog
+ if (!local) write(join(dir, 'History.md'), '');
+
+ // .gitignore
+ write(join(dir, '.gitignore'), 'components\nbuild\n');
+
+ // write component.json
+ write(join(dir, 'component.json'), JSON.stringify(conf, null, 2));
+
+ console.log();
+ process.exit();
+});
+
+/**
+ * Boolean from `str`.
+ */
+
+function bool(str) {
+ return 'yes' == str
+ || 'y' == str;
+}
+
+/**
+ * Create a makefile.
+ */
+
+function createMakefile(obj) {
+ var buf = '\n';
+
+ // build target
+ buf += 'build: components';
+ if (bool(obj.js)) buf += ' index.js';
+ if (bool(obj.css)) buf += ' ' + obj.name + '.css';
+ if (bool(obj.html)) buf += ' template.js';
+ buf += '\n\t@component build --dev\n\n';
+
+ // template.js target
+ if (bool(obj.html)) {
+ buf += 'template.js: template.html\n';
+ buf += '\t@component convert $<\n\n';
+ }
+
+ // components target
+ buf += 'components: component.json\n';
+ buf += '\t@component install --dev\n\n';
+
+ // clean phony
+ buf += 'clean:\n';
+ buf += '\trm -fr build components template.js\n\n';
+
+ // PHONY
+ buf += '.PHONY: clean\n';
+
+ return buf;
+}
View
67 node_modules/component/bin/component-docs
@@ -0,0 +1,67 @@
+#!/usr/bin/env node
+
+/**
+ * Module dependencies.
+ */
+
+var program = require('commander')
+ , component = require('..')
+ , utils = component.utils;
+
+// usage
+
+program.usage('<name>');
+
+// parse argv
+
+program.parse(process.argv);
+
+// package
+
+var pkg = program.args.shift();
+
+// required
+
+if (!pkg) utils.fatal("<name> required");
+
+// lookup docs
+
+component.docs(pkg, function(err, docs){
+ // TODO: handle non-markdown
+ if (err) throw err;
+ if (!docs) utils.fatal('failed to lookup docs for "' + pkg + '"');
+ var readme = new Buffer(docs.content, 'base64').toString('utf8');
+ process.stdout.write(indent(markdown(readme)));
+ process.stdout.write('\n\n');
+});
+
+/**
+ * Convert `str` of markdown for terminal display.
+ */
+
+function markdown(str) {
+ // TODO: move this stuff to npm
+ return str
+ .replace(/^#+ *(.+)/gm, '\033[1m$1\033[0m')
+ .replace(/`{3}\w*((?:.|\n)+?)`{3}/g, code)
+ .replace(/`(.*?)`/g, '\033[36m$1\033[0m')
+ .replace(/__(.*?)__/g, '\033[1m$1\033[0m')
+ .replace(/!?\[(.*?)\]\((.*?)\)/g, '$1:(\033[36;4m$2\033[m)');
+}
+
+/**
+ * Code formatting.
+ */
+
+function code(_, code) {
+ code = indent(code.trim());
+ return '\033[90m' + code + '\033[0m';
+}
+
+/**
+ * Indent the given `str`.
+ */
+
+function indent(str) {
+ return str.replace(/^/gm, ' ');
+}
View
23 node_modules/component/bin/component-help
@@ -0,0 +1,23 @@
+#!/usr/bin/env node
+
+/**
+ * Module dependencies.
+ */
+
+var program = require('commander')
+ , exec = require('child_process').exec;
+
+// parse argv
+
+program.parse(process.argv);
+
+// output --help
+
+var cmd = program.args[0]
+ ? 'component ' + program.args[0] + ' --help'
+ : 'component --help';
+
+exec(cmd, function(err, stdout){
+ if (err) throw err;
+ process.stdout.write(stdout);
+});
View
61 node_modules/component/bin/component-info
@@ -0,0 +1,61 @@
+#!/usr/bin/env node
+
+/**
+ * Module dependencies.
+ */
+
+var program = require('commander')
+ , component = require('..');
+
+// usage
+
+program.usage('<name> [prop]');
+
+// examples
+
+program.on('--help', function(){
+ console.log(' Examples:');
+ console.log();
+ console.log(' # output remote component.json');
+ console.log(' $ component info component/tip');
+ console.log();
+ console.log(' # output version only');
+ console.log(' $ component info component/tip keywords');
+ console.log();
+});
+
+// parse argv
+
+program.parse(process.argv);
+
+// package
+
+var pkg = program.args.shift();
+
+// props
+
+var props = program.args.shift();
+
+// lookup info
+
+var parts = pkg.split('@');
+pkg = parts.shift();
+var version = parts.shift() || 'master';
+component.info(pkg, version, function(err, json){
+ if (err) throw err;
+
+ // reduce props
+ if (props) {
+ props.split('.').forEach(function(prop){
+ json = json[prop];
+ });
+ }
+
+ // output
+ if ('string' == typeof json) {
+ process.stdout.write(json);
+ } else {
+ process.stdout.write(JSON.stringify(json, null, 2));
+ }
+});
+
View
232 node_modules/component/bin/component-install
@@ -0,0 +1,232 @@
+#!/usr/bin/env node
+
+/**
+ * Module dependencies.
+ */
+
+var program = require('commander')
+ , component = require('..')
+ , fs = require('fs')
+ , exists = fs.existsSync
+ , utils = component.utils
+ , log = utils.log
+ , error = utils.error
+ , url = require('url')
+ , path = require('path')
+ , resolve = path.resolve
+
+// options
+
+program
+ .usage('[name ...]')
+ .option('-d, --dev', 'install development dependencies')
+ .option('-o, --out <dir>', 'output components to the given <dir>')
+ .option('-f, --force', 'force installation even if previously installed')
+
+// examples
+
+program.on('--help', function(){
+ console.log(' Examples:');
+ console.log();
+ console.log(' # install deps in ./component.json');
+ console.log(' $ component install');
+ console.log();
+ console.log(' # install a single component');
+ console.log(' $ component install component/tip');
+ console.log();
+ console.log(' # install several components');
+ console.log(' $ component install component/tip component/popover');
+ console.log();
+ console.log(' # shell brace expansion ftw');
+ console.log(' $ component install component/{tip,popover,dialog}');
+ console.log();
+ console.log(' # install a specific tag / sha');
+ console.log(' $ component install component/tip@8bf1ffc3f');
+ console.log();
+ console.log(' # install regular & development deps in .');
+ console.log(' $ component install -d');
+ console.log();
+});
+
+// parse argv
+
+program.parse(process.argv);
+
+// pkgs
+
+var pkgs = program.args;
+
+// install from ./component.json
+
+var local = 0 == pkgs.length;
+
+// read json
+
+var conf = loadConfig();
+
+// install from ./component.json
+
+if (local) {
+ if (conf.dependencies) {
+ pkgs = normalize(conf.dependencies);
+ }
+
+ if (conf.development && program.dev) {
+ pkgs = pkgs.concat(normalize(conf.development));
+ }
+
+ if (conf.local) {
+ conf.local.forEach(function(pkg){
+ try {
+ var deps = component.dependenciesOf(pkg, conf.paths);
+ deps.map(normalize).forEach(function(deps){
+ pkgs = pkgs.concat(deps);
+ });
+ } catch (err) {
+ utils.fatal(err.message);
+ }
+ });
+ }
+}
+
+// save to ./component.json
+
+if (!local) {
+ conf.dependencies = conf.dependencies || {};
+ pkgs.forEach(function(pkg){
+ conf.dependencies[pkg] = '*';
+ });
+ saveConfig();
+}
+
+// implicit remotes
+
+conf.remotes = conf.remotes || [];
+conf.remotes.push('https://raw.github.com');
+
+// install
+
+console.log();
+pkgs.forEach(function(pkg){
+ var parts = pkg.split('@');
+ var name = parts.shift();
+ var version = parts.shift() || 'master';
+ install(name, version);
+});
+
+// map deps to args
+
+function normalize(deps) {
+ return Object.keys(deps).map(function(name){
+ return name + '@' + deps[name];
+ });
+}
+
+// reporter
+
+function report(pkg, options) {
+ options = options || {};
+ log('install', pkg.name + '@' + pkg.version);
+
+ pkg.on('error', function(err){
+ if (404 != err.status) utils.fatal(err.stack);
+
+ if (options.error) {
+ error(err.message);
+ process.exit(1);
+ }
+ });
+
+ pkg.on('dep', function(dep){
+ log('dep', dep.name + '@' + dep.version);
+ report(dep, options);
+ });
+
+ pkg.on('exists', function(dep){
+ log('exists', dep.name + '@' + dep.version);
+ });
+
+ pkg.on('file', function(file){
+ log('fetch', pkg.name + ':' + file);
+ });
+
+ pkg.on('end', function(){
+ log('complete', pkg.name);
+ });
+}
+
+// padding
+
+process.on('exit', function(){
+ console.log();
+});
+
+/**
+ * Install package `name` at the given `version`
+ * from all specified remotes.
+ *
+ * @param {String} name
+ * @param {String} version
+ * @api private
+ */
+
+function install(name, version) {
+ var i = 0;
+
+ next();
+
+ function next() {
+ var remote = conf.remotes[i++];
+ if (!remote) return;
+
+ // parse remote
+ var last = i == conf.remotes.length - 1;
+ remote = url.parse(remote);
+
+ // strip trailing /
+ remote.href = remote.href.slice(0, -1);
+
+ // kick of installation
+ var pkg = component.install(name, version, {
+ dest: program.out,
+ force: program.force,
+ dev: program.dev,
+ remote: remote.href
+ });
+
+ // only error on the last remote otherwise
+ // we assume it may be fetchable
+ pkg.once('error', next);
+ report(pkg, { error: !last });
+
+ // TODO: add callback
+ pkg.install();
+ }
+}
+
+/**
+ * Read / create ./component.json.
+ *
+ * @return {Object}
+ * @api private
+ */
+
+function loadConfig() {
+ var path = resolve('component.json');
+ if (exists('component.json')) {
+ return require(path);
+ } else {
+ return {};
+ }
+}
+
+/**
+ * Save configuration.
+ *
+ * @api private
+ */
+
+function saveConfig() {
+ var path = resolve('component.json');
+ fs.writeFileSync(path, JSON.stringify(conf, null, 2));
+}
View
25 node_modules/component/bin/component-ls
@@ -0,0 +1,25 @@
+#!/usr/bin/env node
+
+/**
+ * Module dependencies.
+ */
+
+var program = require('commander')
+ , component = require('..')
+ , log = component.utils.log
+ , path = require('path')
+ , fs = require('fs');
+
+// parse argv
+
+program.parse(process.argv);
+
+// list
+
+console.log();
+fs.readdirSync('components').forEach(function(pkg){
+ var json = path.resolve('components', pkg, 'component.json');
+ var obj = require(json);
+ log(obj.name, obj.version);
+});
+console.log();
View
21 node_modules/component/bin/component-open
@@ -0,0 +1,21 @@
+#!/usr/bin/env node
+
+/**
+ * Module dependencies.
+ */
+
+var program = require('commander')
+ , component = require('..')
+ , exec = require('child_process').exec;
+
+// parse argv
+
+program
+ .usage('<name>')
+ .parse(process.argv);
+
+// open
+
+var pkg = program.args[0];
+if (!pkg) component.utils.fatal("<name> required");
+exec('open http://github.com/' + pkg);
View
124 node_modules/component/bin/component-search
@@ -0,0 +1,124 @@
+#!/usr/bin/env node
+
+/**
+ * Module dependencies.
+ */
+
+var program = require('commander')
+ , exec = require('child_process').exec
+ , component = require('..')
+ , utils = component.utils
+ , cols = process.stdout.columns || 80;
+
+// parse argv
+
+program
+ .usage('[query]')
+ .option('-j, --json', 'json component output')
+ .option('-o, --open', 'open matches in your default browser')
+ .option('-l, --license', 'output the package license')
+ .parse(process.argv);
+
+// --open
+
+if (program.open) program.json = true;
+
+// query
+
+var query = program.args.join(' ');
+
+// search
+
+component.search(query, function(err, pkgs){
+ if (err) utils.fatal(err.message);
+ if (!pkgs.length) return;
+ if (program.open) return open(pkgs);
+ if (program.json) json(pkgs)
+ else verbose(pkgs);
+});
+
+/**
+ * Truncate the string if necessary.
+ */
+
+function truncate(str, repo) {
+ var pad = 30 + repo.length;
+ if (str.length < cols - pad) return str;
+ return str.slice(0, cols - pad) + '';
+}
+
+/**
+ * Wrap description `str`.
+ */
+
+function description(str) {
+ if (!str) return '';
+ var space;
+ var width = cols - 20;
+ for (var i = 0; i < str.length; ++i) {
+ if (i && i % width == 0) {
+ space = str.indexOf(' ', i);
+ str = str.slice(0, space) + '\n ' + str.slice(space);
+ }
+ }
+ return str;
+}
+
+/**
+ * Filter blanks. TODO: remove... shouldn't be necessary
+ */
+
+function blanks(pkg) {
+ return pkg;
+}
+
+/**
+ * Sort by stars descending.
+ */
+
+function stars(a, b) {
+ return b.stars - a.stars;
+}
+
+/**
+ * Open `pkgs` in the default browser.
+ */
+
+function open(pkgs) {
+ var max = 5;
+ pkgs.slice(0, max).forEach(function(pkg){
+ if (!pkg.repo) return console.warn('%s missing "repo"', pkg.name);
+ exec('open https://github.com/' + pkg.repo);
+ });
+}
+
+/**
+ * Verbose output.
+ */
+
+function verbose(pkgs) {
+ console.log();
+ pkgs.filter(blanks).sort(stars).forEach(function(pkg){
+ console.log(' \033[36m%s\033[m', pkg.repo.toLowerCase());
+ console.log(' url: \033[90mhttps://github.com/%s\033[m', pkg.repo);
+ console.log(' desc: \033[90m%s\033[m', description(pkg.description));
+ if (program.license) console.log(' license: \033[90m%s\033[m', pkg.license || 'none');
+ console.log('\033[90m%s\033[m', pkg.stars);
+ console.log();
+ });
+ console.log();
+}
+
+/**
+ * JSON output.
+ */
+
+function json(pkgs) {
+ var len = pkgs.length;
+ console.log('[');
+ pkgs.filter(blanks).sort(stars).forEach(function(pkg, i){
+ process.stdout.write(JSON.stringify(pkg, null, 2));
+ if (i < len - 1) process.stdout.write(',\n');
+ });
+ console.log(']');
+}
View
11 node_modules/component/bin/component-wiki
@@ -0,0 +1,11 @@
+#!/usr/bin/env node
+
+/**
+ * Module dependencies.
+ */
+
+var exec = require('child_process').exec;
+
+// open
+
+exec('open https://github.com/component/component/wiki/Components');
View
1 node_modules/component/component.json
@@ -0,0 +1 @@
+{"dependencies":{"component/tip":"*","component/popover":"*"},"development":{"component/inherit":"*"}}
View
1 node_modules/component/index.js
@@ -0,0 +1 @@
+module.exports = require('./lib/component');
View
342 node_modules/component/lib/Package.js
@@ -0,0 +1,342 @@
+
+/**
+ * Module dependencies.
+ */
+
+var Emitter = require('events').EventEmitter
+ , path = require('path')
+ , dirname = path.dirname
+ , basename = path.basename
+ , extname = path.extname
+ , join = path.join
+ , mkdir = require('mkdirp').mkdirp
+ , request = require('superagent')
+ , debug = require('debug')('component:installer')
+ , Batch = require('batch')
+ , http = require('http')
+ , fs = require('fs');
+
+/**
+ * Expose installer.
+ */
+
+module.exports = Package;
+
+/**
+ * Initialize a new `Package` with
+ * the given `pkg` name and `version`.
+ *
+ * Options:
+ *
+ * - `dest` destination directory
+ * - `force` installation when previously installed
+ * - `remote` remote url defaulting to "https://raw.github.com"
+ *
+ * @param {String} pkg
+ * @param {String} version
+ * @param {Object} options
+ * @api private
+ */
+
+function Package(pkg, version, options) {
+ options = options || {};
+ if ('*' == version) version = 'master';
+ debug('installing %s@%s %j', pkg, version, options);
+ if (!pkg) throw new Error('pkg required');
+ if (!version) throw new Error('version required');
+ this.name = pkg;
+ this.dest = options.dest || 'components';
+ this.remote = options.remote || 'https://raw.github.com';
+ this.auth = options.auth;
+ this.force = !! options.force;
+ this.version = version;
+}
+
+/**
+ * Inherit from `Emitter.prototype`.
+ */
+
+Package.prototype.__proto__ = Emitter.prototype;
+
+/**
+ * Return dirname for this package.
+ * For example "component/dialog"
+ * becomes "component-dialog".
+ *
+ * @return {String}
+ * @api private
+ */
+
+Package.prototype.dirname = function(){
+ return join(this.dest, this.name.split('/').join('-'));
+};
+
+/**
+ * Join `path` to this package's dirname.
+ *
+ * @param {String} path
+ * @return {String}
+ * @api private
+ */
+
+Package.prototype.join = function(path){
+ return join(this.dirname(), path);
+};
+
+/**
+ * Return URL to `file`.
+ *
+ * @param {String} file
+ * @return {String}
+ * @api private
+ */
+
+Package.prototype.url = function(file){
+ return this.remote + '/' + this.name + '/' + this.version + '/' + file;
+};
+
+/**
+ * Conditionaly mkdir `dir` unless we've
+ * already done so previously.
+ *
+ * @param {String} dir
+ * @param {Function} fn
+ * @api private
+ */
+
+Package.prototype.mkdir = function(dir, fn){
+ this.dirs = this.dirs || {};
+ if (this.dirs[dir]) return fn();
+ mkdir(dir, fn);
+};
+
+/**
+ * Get local json if the component is installed
+ * and callback `fn(err, obj)`.
+ *
+ * @param {Function} fn
+ * @api private
+ */
+
+Package.prototype.getLocalJSON = function(fn){
+ fs.readFile(this.join('component.json'), 'utf8', function(err, json){
+ if (err) return fn(err);
+ try {
+ json = JSON.parse(json);
+ } catch (err) {
+ return fn(err);
+ }
+ fn(null, json);
+ });
+};
+
+/**
+ * Get component.json and callback `fn(err, obj)`.
+ *
+ * @param {Function} fn
+ * @api private
+ */
+
+Package.prototype.getJSON = function(fn){
+ var self = this;
+ var url = this.url('component.json');
+
+ debug('fetching %s', url);
+ var req = request.get(url);
+
+ req.end(function(res){
+ if (res.ok) {
+ debug('got %s', url);
+ try {
+ var json = JSON.parse(res.text);
+ } catch (err) {
+ return fn(err);
+ }
+ fn(null, json);
+ } else {
+ fn(error(res, url));
+ }
+ });
+
+ req.on('error', function(err){
+ if ('getaddrinfo' == err.syscall) err.message = 'dns lookup failed';
+ fn(err);
+ });
+};
+
+/**
+ * Fetch `files` and write them to disk and callback `fn(err)`.
+ *
+ * @param {Array} files
+ * @param {Function} fn
+ * @api private
+ */
+
+Package.prototype.getFiles = function(files, fn){
+ var self = this;
+ var batch = new Batch;
+
+ files.forEach(function(file){
+ batch.push(function(done){
+ var url = self.url(file);
+ debug('fetching %s', url);
+ self.emit('file', file, url);
+ var dst = self.join(file);
+
+ // mkdir
+ self.mkdir(dirname(dst), function(err){
+ if (err) return fn(err);
+
+ // pipe file
+ var req = request.get(url).buffer(false);
+
+ if (self.auth) req.auth(self.auth.user, self.auth.pass);
+
+ req.end(function(res){
+ if (res.error) return done(error(res, url));
+ res.pipe(fs.createWriteStream(dst));
+ res.on('error', done);
+ res.on('end', done);
+ });
+ });
+ });
+ });
+
+ batch.end(fn);
+};
+
+/**
+ * Write `file` with `str` contents to disk and callback `fn(err)`.
+ *
+ * @param {String} file
+ * @param {String} str
+ * @param {Function} fn
+ * @api private
+ */
+
+Package.prototype.writeFile = function(file, str, fn){
+ file = this.join(file);
+ debug('write %s', file);
+ fs.writeFile(file, str, fn);
+};
+
+/**
+ * Install `deps` and callback `fn()`.
+ *
+ * @param {Array} deps
+ * @param {Function} fn
+ * @api private
+ */
+
+Package.prototype.getDependencies = function(deps, fn){
+ var self = this;
+ var batch = new Batch;
+
+ Object.keys(deps).forEach(function(name){
+ var version = deps[name];
+ debug('dep %s@%s', name, version);
+ batch.push(function(done){
+ var pkg = new Package(name, version, {
+ dest: self.dest,
+ force: self.force
+ });
+ self.emit('dep', pkg);
+ pkg.on('end', done);
+ pkg.on('exists', function() { done(); });
+ pkg.install();
+ });
+ });
+
+ batch.end(fn);
+};
+
+/**
+ * Check if the component exists already,
+ * otherwise install it for realllll.
+ *
+ * @api public
+ */
+
+Package.prototype.install = function(){
+ var self = this;
+ var name = this.name;
+
+ if (!~name.indexOf('/')) {
+ return this.emit('error', new Error('invalid component name "' + name + '"'));
+ }
+
+ this.getLocalJSON(function(err, json){
+ if (err && err.code == 'ENOENT') {
+ self.reallyInstall();
+ } else if (err) {
+ self.emit('error', err);
+ } else if (!self.force) {
+ self.emit('exists', self);
+ } else {
+ self.reallyInstall();
+ }
+ });
+};
+
+/**
+ * Really install the component.
+ *
+ * @api public
+ */
+
+Package.prototype.reallyInstall = function(){
+ var self = this;
+ var batch = new Batch;
+ this.getJSON(function(err, json){
+ if (err) return self.emit('error', err);
+
+ var files = [];
+ if (json.scripts) files = files.concat(json.scripts);
+ if (json.styles) files = files.concat(json.styles);
+ if (json.templates) files = files.concat(json.templates);
+ if (json.files) files = files.concat(json.files);
+ if (json.images) files = files.concat(json.images);
+ if (json.fonts) files = files.concat(json.fonts);
+ json.repo = json.repo || self.remote + '/' + self.name;
+
+ if (json.dependencies) {
+ batch.push(function(done){
+ self.getDependencies(json.dependencies, done);
+ });
+ }
+
+ batch.push(function(done){
+ self.mkdir(self.dirname(), function(err){
+ json = JSON.stringify(json, null, 2);
+ self.writeFile('component.json', json, done);
+ });
+ });
+
+ batch.push(function(done){
+ self.mkdir(self.dirname(), function(err){
+ self.getFiles(files, done);
+ });
+ });
+
+ batch.end(function(err){
+ if (err) return self.emit('error', err);
+ self.emit('end');
+ });
+ });
+};
+
+/**
+ * Return an error for `res` / `url`.
+ *
+ * @param {Response} res
+ * @param {String} url
+ * @return {Error}
+ * @api private
+ */
+
+function error(res, url) {
+ var name = http.STATUS_CODES[res.status];
+ var err = new Error('failed to fetch ' + url + ', got ' + res.status + ' "' + name + '"');
+ err.status = res.status;
+ return err;
+}
View
210 node_modules/component/lib/component.js
@@ -0,0 +1,210 @@
+
+/**
+ * Module dependencies.
+ */
+
+var Package = require('./Package')
+ , debug = require('debug')('component')
+ , mkdir = require('mkdirp')
+ , utils = require('./utils')
+ , fs = require('fs')
+ , path = require('path')
+ , join = path.join
+ , resolve = path.resolve