[Pkg-javascript-commits] [node-base] 01/04: New upstream version 1.0.1
Praveen Arimbrathodiyil
praveen at moszumanska.debian.org
Sat Jan 13 08:11:50 UTC 2018
This is an automated email from the git hooks/post-receive script.
praveen pushed a commit to branch master
in repository node-base.
commit d8ca05a6ae1b8c02fa4b96f0cb82283e47b5186b
Author: Pirate Praveen <praveen at debian.org>
Date: Wed Jan 10 12:40:19 2018 +0530
New upstream version 1.0.1
---
.editorconfig | 18 +-
.eslintrc.json | 10 +-
.gitignore | 31 +++-
.travis.yml | 17 +-
.verb.md | 135 ++++++++++----
LICENSE | 2 +-
README.md | 322 ++++++++++++++++----------------
changelog.md | 50 +++++
docs/logo.png | Bin 83366 -> 86176 bytes
docs/plugins.md | 41 +++++
gulpfile.js | 30 ---
index.js | 563 ++++++++++++++++++++------------------------------------
package.json | 64 ++++---
test.js | 318 ++++----------------------------
utils.js | 25 ---
verbfile.js | 14 +-
16 files changed, 658 insertions(+), 982 deletions(-)
diff --git a/.editorconfig b/.editorconfig
index 991900b..449f0da 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -1,22 +1,14 @@
-# http://editorconfig.org
+# http://editorconfig.org/
root = true
[*]
-indent_style = space
-end_of_line = lf
charset = utf-8
+end_of_line = lf
indent_size = 2
-trim_trailing_whitespace = true
+indent_style = space
insert_final_newline = true
+trim_trailing_whitespace = true
-[*.md]
-trim_trailing_whitespace = false
-insert_final_newline = false
-
-[test/**]
-trim_trailing_whitespace = false
-insert_final_newline = false
-
-[templates/**]
+[{**/{actual,fixtures,expected,templates}/**,*.md}]
trim_trailing_whitespace = false
insert_final_newline = false
diff --git a/.eslintrc.json b/.eslintrc.json
index bb28232..61e8895 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -1,9 +1,4 @@
{
- "ecmaFeatures": {
- "modules": true,
- "experimentalObjectRestSpread": true
- },
-
"env": {
"browser": false,
"es6": true,
@@ -33,8 +28,8 @@
"generator-star-spacing": [2, { "before": true, "after": true }],
"handle-callback-err": [2, "^(err|error)$" ],
"indent": [2, 2, { "SwitchCase": 1 }],
- "keyword-spacing": [2, {"before": true, "after": true}],
"key-spacing": [2, { "beforeColon": false, "afterColon": true }],
+ "keyword-spacing": [2, { "before": true, "after": true }],
"new-cap": [2, { "newIsCap": true, "capIsNew": false }],
"new-parens": 2,
"no-array-constructor": 2,
@@ -50,7 +45,6 @@
"no-dupe-keys": 2,
"no-duplicate-case": 2,
"no-empty-character-class": 2,
- "no-labels": 2,
"no-eval": 2,
"no-ex-assign": 2,
"no-extend-native": 2,
@@ -72,7 +66,7 @@
"no-multi-spaces": 2,
"no-multi-str": 2,
"no-multiple-empty-lines": [2, { "max": 1 }],
- "no-native-reassign": 2,
+ "no-native-reassign": 0,
"no-negated-in-lhs": 2,
"no-new": 2,
"no-new-func": 2,
diff --git a/.gitignore b/.gitignore
index 80a228c..f969a2c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,15 +1,30 @@
+# always ignore files
*.DS_Store
+.idea
+.vscode
*.sublime-*
-_gh_pages
-bower_components
+
+# test related, or directories generated by tests
+test/actual
+actual
+coverage
+.nyc*
+
+# npm
node_modules
npm-debug.log
-actual
-test/actual
+
+# yarn
+yarn.lock
+yarn-error.log
+
+# misc
+_gh_pages
+_draft
+_drafts
+bower_components
+vendor
temp
tmp
TODO.md
-vendor
-.idea
-benchmark
-coverage
+package-lock.json
\ No newline at end of file
diff --git a/.travis.yml b/.travis.yml
index 09768f0..1fd107d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,12 +1,11 @@
sudo: false
+os:
+ - linux
+ - osx
language: node_js
node_js:
- - "stable"
- - "5"
- - "4"
- - "0.12"
- - "0.10"
-matrix:
- fast_finish: true
- allow_failures:
- - node_js: "0.10"
+ - node
+ - '9'
+ - '8'
+ - '7'
+ - '6'
diff --git a/.verb.md b/.verb.md
index f260034..62bdc2b 100644
--- a/.verb.md
+++ b/.verb.md
@@ -1,23 +1,45 @@
-{{#block "logo"}}
<p align="center">
- <a href="{%= homepage %}">
+ <a href="https://github.com/node-base/base">
<img height="250" width="250" src="https://raw.githubusercontent.com/node-base/base/master/docs/logo.png">
</a>
</p>
-{{/block}}
-{{#block "about"}}
-## What is Base?
+# {%= name %}
-Base is a framework for rapidly creating high quality node.js applications, using plugins like building blocks.
+{%= badge("npm") %} {%= badge('downloads') %} {%= ifExists(["test", "test.js"], badge('travis')) %} {%= badge('gitter') %}
+
+## Table of contents
+<details>
+<summary><strong>Table of contents</strong></summary>
+
+<!-- toc -->
+
+</details>
+
+<details>
+<summary><strong>About</strong></summary>
+
+## Why use Base?
+
+Base is a foundation for creating modular, unit testable and highly pluggable server-side node.js APIs.
+
+* Go from zero to working application within minutes
+* Use [community plugins](https://www.npmjs.com/browse/keyword/baseplugin) to add feature-functionality to your application
+* Create your own custom plugins to add features
+* Like building blocks, plugins are stackable. Allowing you to build [sophisticated applications](#toolkit-suite) from simple plugins. Moreover, those applications can also be used as plugins themselves.
+
+Most importantly, once you learn Base, you will be familiar with the core API of all applications built on Base. This means you will not only benefit as a developer, but as a user as well.
### Guiding principles
The core team follows these principles to help guide API decisions:
- **Compact API surface**: The smaller the API surface, the easier the library will be to learn and use.
-- **Easy to extend**: Implementors can use any npm package, and write plugins in pure JavaScript. If you're building complex apps, Base simplifies inheritance.
+- **Easy to extend**: Implementors can use any npm package, and write plugins in pure JavaScript. If you're building complex apps, Base dramatically simplifies inheritance.
- **Easy to test**: No special setup should be required to unit test `Base` or base plugins
+- **100% Node.js core style**
+ * No API sugar (left for higher level projects)
+ * Written in readable vanilla JavaScript
### Minimal API surface
@@ -59,6 +81,8 @@ function plugin(base) {
base.use(plugin);
```
+Add "smart plugin" functionality with the [base-plugins][] plugin.
+
**Inheritance**
Easily inherit Base using `.extend`:
@@ -91,52 +115,101 @@ app.set('foo', 'bar');
console.log(app.cache.foo);
//=> 'bar'
```
+</details>
-{{/block}}
+## Install
+**NPM**
-## API
+## Install
+
+{%= include("install-npm", {save: true}) %}
+
+**yarn**
-**Usage**
+Install with [yarn](yarnpkg.com):
+
+```sh
+$ yarn add base && yarn upgrade
+```
+
+## Usage
```js
var Base = require('base');
var app = new Base();
+
+// set a value
app.set('foo', 'bar');
console.log(app.foo);
//=> 'bar'
+
+// register a plugin
+app.use(function() {
+ // do stuff (see API docs for ".use")
+});
```
+## API
{%= apidocs("index.js") %}
-## In the wild
+## Toolkit suite
-The following node.js applications were built with `Base`:
+Base is used as the foundation for all of the applications in the [toolkit suite](https://github.com/node-toolkit/getting-started) (except for [enquirer][]):
-- [assemble][]
-- [verb][]
-- [generate][]
-- [scaffold][]
-- [boilerplate][]
+**Building blocks**
-## Test coverage
+- [base][]: (you are here!) framework for rapidly creating high quality node.js applications, using plugins like building blocks.
+- [templates][]: API for managing template collections and rendering templates with any node.js template engine. Can be used as the basis for creating a static site generator, blog framework, documentaton system, and so on.
+- [enquirer][]: composable, plugin-based prompt system (Base is used in [prompt-base][], the core prompt module that powers all prompt plugins)
-```
-{%= coverage('coverage/summary.txt') %}
-```
+**Lifecycle**
+
+Developer frameworks and command line tools that address common phases of the software development lifecycle. Each of these tools can be used entirely standalone, but they work even better together.
+
+- [generate][]: create projects
+- [assemble][]: build projects
+- [verb][]: document projects
+- [update][]: maintain projects
+
+## About
+### Related projects
+{%= related(verb.related.list) %}
+
+### Tests
+{%= include("tests") %}
+
+### Contributing
+{%= include("contributing") %}
+
+If Base doesn't do what you need, [please let us know](../../issues).
+
+### Release History
+{%= increaseHeadings(increaseHeadings(changelog('changelog.md', {
+ changelogFooter: true,
+ stripHeading: true,
+ repo: repo
+}))) %}
+
+### Authors
+
+**Jon Schlinkert**
+
+* [github/jonschlinkert](https://github.com/jonschlinkert)
+* [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
+
+**Brian Woodward**
-## History
+* [github/doowb](https://github.com/doowb)
+* [twitter/doowb](http://twitter.com/doowb)
-**v0.11.0 - major breaking changes!**
+### License
+{%= copyright() %}
+{%= license %}
-- Static `.use` and `.run` methods are now non-enumerable
+***
-**v0.9.0 - major breaking changes!**
+{%= include("footer") %}
-- `.is` no longer takes a function, a string must be passed
-- all remaining `.debug` code has been removed
-- `app._namespace` was removed (related to `debug`)
-- `.plugin`, `.use`, and `.define` no longer emit events
-- `.assertPlugin` was removed
-- `.lazy` was removed
\ No newline at end of file
+{%= reflinks(verb.reflinks) %}
diff --git a/LICENSE b/LICENSE
index 1e49edf..e33d14b 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
The MIT License (MIT)
-Copyright (c) 2015-2016, Jon Schlinkert.
+Copyright (c) 2015-2017, Jon Schlinkert.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/README.md b/README.md
index 7bd5310..fbdbf96 100644
--- a/README.md
+++ b/README.md
@@ -1,22 +1,61 @@
-# base [![NPM version](https://img.shields.io/npm/v/base.svg?style=flat)](https://www.npmjs.com/package/base) [![NPM downloads](https://img.shields.io/npm/dm/base.svg?style=flat)](https://npmjs.org/package/base) [![Build Status](https://img.shields.io/travis/node-base/base.svg?style=flat)](https://travis-ci.org/node-base/base)
-
<p align="center">
+
<a href="https://github.com/node-base/base">
<img height="250" width="250" src="https://raw.githubusercontent.com/node-base/base/master/docs/logo.png">
</a>
</p>
-## What is Base?
+# base
+
+[![NPM version](https://img.shields.io/npm/v/base.svg?style=flat)](https://www.npmjs.com/package/base) [![NPM monthly downloads](https://img.shields.io/npm/dm/base.svg?style=flat)](https://npmjs.org/package/base) [![Build Status](https://img.shields.io/travis/node-base/base.svg?style=flat)](https://travis-ci.org/node-base/base) [![Gitter](https://badges.gitter.im/join_chat.svg)](https://gitter.im/node-base/base)
+
+<details>
+<summary><strong>Table of contents</strong></summary>
+
+- [Why use Base?](#why-use-base)
+ * [Guiding principles](#guiding-principles)
+ * [Minimal API surface](#minimal-api-surface)
+ * [Composability](#composability)
+- [Install](#install)
+- [Install](#install-1)
+- [Usage](#usage)
+- [API](#api)
+- [Toolkit suite](#toolkit-suite)
+- [About](#about)
+ * [Related projects](#related-projects)
+ * [Tests](#tests)
+ * [Contributing](#contributing)
+ * [Release History](#release-history)
+ * [Authors](#authors)
+ * [License](#license)
+
+</details>
+
+<details>
+<summary><strong>About</strong></summary>
-Base is a framework for rapidly creating high quality node.js applications, using plugins like building blocks.
+## Why use Base?
+
+Base is a foundation for creating modular, unit testable and highly pluggable server-side node.js APIs.
+
+* Go from zero to working application within minutes
+* Use [community plugins](https://www.npmjs.com/browse/keyword/baseplugin) to add feature-functionality to your application
+* Create your own custom plugins to add features
+* Like building blocks, plugins are stackable. Allowing you to build [sophisticated applications](#toolkit-suite) from simple plugins. Moreover, those applications can also be used as plugins themselves.
+
+Most importantly, once you learn Base, you will be familiar with the core API of all applications built on Base. This means you will not only benefit as a developer, but as a user as well.
### Guiding principles
The core team follows these principles to help guide API decisions:
* **Compact API surface**: The smaller the API surface, the easier the library will be to learn and use.
-* **Easy to extend**: Implementors can use any npm package, and write plugins in pure JavaScript. If you're building complex apps, Base simplifies inheritance.
+* **Easy to extend**: Implementors can use any npm package, and write plugins in pure JavaScript. If you're building complex apps, Base dramatically simplifies inheritance.
* **Easy to test**: No special setup should be required to unit test `Base` or base plugins
+* **100% Node.js core style**
+
+ - No API sugar (left for higher level projects)
+ - Written in readable vanilla JavaScript
### Minimal API surface
@@ -58,6 +97,8 @@ function plugin(base) {
base.use(plugin);
```
+Add "smart plugin" functionality with the [base-plugins](https://github.com/node-base/base-plugins) plugin.
+
**Inheritance**
Easily inherit Base using `.extend`:
@@ -90,6 +131,11 @@ app.set('foo', 'bar');
console.log(app.cache.foo);
//=> 'bar'
```
+</details>
+
+## Install
+
+**NPM**
## Install
@@ -99,32 +145,47 @@ Install with [npm](https://www.npmjs.com/):
$ npm install --save base
```
-## API
+**yarn**
-**Usage**
+Install with [yarn](yarnpkg.com):
+
+```sh
+$ yarn add base && yarn upgrade
+```
+
+## Usage
```js
var Base = require('base');
var app = new Base();
+
+// set a value
app.set('foo', 'bar');
console.log(app.foo);
//=> 'bar'
+
+// register a plugin
+app.use(function() {
+ // do stuff (see API docs for ".use")
+});
```
-### [Base](index.js#L38)
+## API
+
+### [Base](index.js#L42)
Create an instance of `Base` with the given `config` and `options`.
**Params**
-* `config` **{Object}**: If supplied, this object is passed to [cache-base](https://github.com/jonschlinkert/cache-base) to merge onto the the instance upon instantiation.
+* `cache` **{Object}**: If supplied, this object is passed to [cache-base](https://github.com/jonschlinkert/cache-base) to merge onto the the instance.
* `options` **{Object}**: If supplied, this object is used to initialize the `base.options` object.
**Example**
```js
// initialize with `config` and `options`
-var app = new Base({isApp: true}, {abc: true});
+const app = new Base({isApp: true}, {abc: true});
app.set('foo', 'bar');
// values defined with the given `config` object will be on the root of the instance
@@ -138,7 +199,7 @@ console.log(app.get('foo')); //=> 'bar'
console.log(app.options.abc); //=> true
```
-### [.is](index.js#L101)
+### [.is](index.js#L69)
Set the given `name` on `app._name` and `app.is*` properties. Used for doing lookups in plugins.
@@ -150,21 +211,14 @@ Set the given `name` on `app._name` and `app.is*` properties. Used for doing loo
**Example**
```js
-app.is('foo');
-console.log(app._name);
-//=> 'foo'
-console.log(app.isFoo);
+app.is('collection');
+console.log(app.type);
+//=> 'collection'
+console.log(app.isCollection);
//=> true
-app.is('bar');
-console.log(app.isFoo);
-//=> true
-console.log(app.isBar);
-//=> true
-console.log(app._name);
-//=> 'bar'
```
-### [.isRegistered](index.js#L139)
+### [.isRegistered](index.js#L104)
Returns true if a plugin has already been registered on an instance.
@@ -185,7 +239,7 @@ instance.
**Example**
```js
-var base = new Base();
+const base = new Base();
base.use(function(app) {
if (app.isRegistered('myPlugin')) return;
// do stuff to `app`
@@ -198,12 +252,9 @@ base.use(function(app) {
});
```
-### [.use](index.js#L169)
-
-Define a plugin function to be called immediately upon init. Plugins are chainable and expose the following arguments to the plugin function:
+### [.use](index.js#L131)
-* `app`: the current instance of `Base`
-* `base`: the [first ancestor instance](#base) of `Base`
+Define a plugin function to be called immediately upon init.
**Params**
@@ -213,13 +264,13 @@ Define a plugin function to be called immediately upon init. Plugins are chainab
**Example**
```js
-var app = new Base()
+const app = new Base()
.use(foo)
.use(bar)
.use(baz)
```
-### [.define](index.js#L191)
+### [.define](index.js#L154)
The `.define` method is used for adding non-enumerable property on the instance. Dot-notation is **not supported** with `define`.
@@ -238,25 +289,7 @@ app.define('render', function(str, locals) {
});
```
-### [.mixin](index.js#L216)
-
-Mix property `key` onto the Base prototype. If base is inherited using `Base.extend` this method will be overridden by a new `mixin` method that will only add properties to the prototype of the inheriting application.
-
-**Params**
-
-* `key` **{String}**
-* `val` **{Object|Array}**
-* `returns` **{Object}**: Returns the `base` instance for chaining.
-
-**Example**
-
-```js
-app.mixin('foo', function() {
- // do stuff
-});
-```
-
-### [.base](index.js#L262)
+### [.base](index.js#L196)
Getter/setter used when creating nested instances of `Base`, for storing a reference to the first ancestor instance. This works by setting an instance of `Base` on the `parent` property of a "child" instance. The `base` property defaults to the current instance if no `parent` property is defined.
@@ -264,16 +297,16 @@ Getter/setter used when creating nested instances of `Base`, for storing a refer
```js
// create an instance of `Base`, this is our first ("base") instance
-var first = new Base();
+const first = new Base();
first.foo = 'bar'; // arbitrary property, to make it easier to see what's happening later
// create another instance
-var second = new Base();
+const second = new Base();
// create a reference to the first instance (`first`)
second.parent = first;
// create another instance
-var third = new Base();
+const third = new Base();
// create a reference to the previous instance (`second`)
// repeat this pattern every time a "child" instance is created
third.parent = second;
@@ -285,10 +318,9 @@ console.log(second.base.foo);
//=> 'bar'
console.log(third.base.foo);
//=> 'bar'
-// and now you know how to get to third base ;)
```
-### [#use](index.js#L287)
+### [Base.use](index.js#L218)
Static method for adding global plugin functions that will be added to an instance when created.
@@ -303,111 +335,100 @@ Static method for adding global plugin functions that will be added to an instan
Base.use(function(app) {
app.foo = 'bar';
});
-var app = new Base();
+const app = new Base();
console.log(app.foo);
//=> 'bar'
```
-### [#extend](index.js#L331)
+## Toolkit suite
-Static method for inheriting the prototype and static methods of the `Base` class. This method greatly simplifies the process of creating inheritance-based applications. See [static-extend](https://github.com/jonschlinkert/static-extend) for more details.
+Base is used as the foundation for all of the applications in the [toolkit suite](https://github.com/node-toolkit/getting-started) (except for [enquirer](http://enquirer.io)):
-**Params**
+**Building blocks**
-* `Ctor` **{Function}**: constructor to extend
-* `methods` **{Object}**: Optional prototype properties to mix in.
-* `returns` **{Object}**: Returns the `Base` constructor for chaining
+* [base](https://github.com/node-base/base): (you are here!) framework for rapidly creating high quality node.js applications, using plugins like building blocks.
+* [templates](https://github.com/jonschlinkert/templates): API for managing template collections and rendering templates with any node.js template engine. Can be used as the basis for creating a static site generator, blog framework, documentaton system, and so on.
+* [enquirer](http://enquirer.io): composable, plugin-based prompt system (Base is used in [prompt-base](https://github.com/enquirer/prompt-base), the core prompt module that powers all prompt plugins)
-**Example**
+**Lifecycle**
-```js
-var extend = cu.extend(Parent);
-Parent.extend(Child);
+Developer frameworks and command line tools that address common phases of the software development lifecycle. Each of these tools can be used entirely standalone, but they work even better together.
-// optional methods
-Parent.extend(Child, {
- foo: function() {},
- bar: function() {}
-});
-```
+* [generate](https://github.com/generate/generate): create projects
+* [assemble](https://github.com/assemble/assemble): build projects
+* [verb](https://github.com/verbose/verb): document projects
+* [update](https://github.com/update/update): maintain projects
-### [#mixin](index.js#L373)
+## About
-Used for adding methods to the `Base` prototype, and/or to the prototype of child instances. When a mixin function returns a function, the returned function is pushed onto the `.mixins` array, making it available to be used on inheriting classes whenever `Base.mixins()` is called (e.g. `Base.mixins(Child)`).
+### Related projects
-**Params**
+* [base-cwd](https://www.npmjs.com/package/base-cwd): Base plugin that adds a getter/setter for the current working directory. | [homepage](https://github.com/node-base/base-cwd "Base plugin that adds a getter/setter for the current working directory.")
+* [base-data](https://www.npmjs.com/package/base-data): adds a `data` method to base-methods. | [homepage](https://github.com/node-base/base-data "adds a `data` method to base-methods.")
+* [base-fs](https://www.npmjs.com/package/base-fs): base-methods plugin that adds vinyl-fs methods to your 'base' application for working with the file… [more](https://github.com/node-base/base-fs) | [homepage](https://github.com/node-base/base-fs "base-methods plugin that adds vinyl-fs methods to your 'base' application for working with the file system, like src, dest, copy and symlink.")
+* [base-generators](https://www.npmjs.com/package/base-generators): Adds project-generator support to your `base` application. | [homepage](https://github.com/node-base/base-generators "Adds project-generator support to your `base` application.")
+* [base-option](https://www.npmjs.com/package/base-option): Adds a few options methods to base, like `option`, `enable` and `disable`. See the readme… [more](https://github.com/node-base/base-option) | [homepage](https://github.com/node-base/base-option "Adds a few options methods to base, like `option`, `enable` and `disable`. See the readme for the full API.")
+* [base-pipeline](https://www.npmjs.com/package/base-pipeline): base-methods plugin that adds pipeline and plugin methods for dynamically composing streaming plugin pipelines. | [homepage](https://github.com/node-base/base-pipeline "base-methods plugin that adds pipeline and plugin methods for dynamically composing streaming plugin pipelines.")
+* [base-pkg](https://www.npmjs.com/package/base-pkg): Plugin for adding a `pkg` method that exposes pkg-store to your base application. | [homepage](https://github.com/node-base/base-pkg "Plugin for adding a `pkg` method that exposes pkg-store to your base application.")
+* [base-plugins](https://www.npmjs.com/package/base-plugins): Adds 'smart plugin' support to your base application. | [homepage](https://github.com/node-base/base-plugins "Adds 'smart plugin' support to your base application.")
+* [base-questions](https://www.npmjs.com/package/base-questions): Plugin for base-methods that adds methods for prompting the user and storing the answers on… [more](https://github.com/node-base/base-questions) | [homepage](https://github.com/node-base/base-questions "Plugin for base-methods that adds methods for prompting the user and storing the answers on a project-by-project basis.")
+* [base-store](https://www.npmjs.com/package/base-store): Plugin for getting and persisting config values with your base-methods application. Adds a 'store' object… [more](https://github.com/node-base/base-store) | [homepage](https://github.com/node-base/base-store "Plugin for getting and persisting config values with your base-methods application. Adds a 'store' object that exposes all of the methods from the data-store library. Also now supports sub-stores!")
+* [base-task](https://www.npmjs.com/package/base-task): base plugin that provides a very thin wrapper around [https://github.com/doowb/composer](https://github.com/doowb/composer) for adding task methods to… [more](https://github.com/node-base/base-task) | [homepage](https://github.com/node-base/base-task "base plugin that provides a very thin wrapper around <https://github.com/doowb/composer> for adding task methods to your application.")
-* `fn` **{Function}**: Function to call
-* `returns` **{Object}**: Returns the `Base` constructor for chaining
+### Tests
-**Example**
+Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
-```js
-Base.mixin(function(proto) {
- proto.foo = function(msg) {
- return 'foo ' + msg;
- };
-});
+```sh
+$ npm install && npm test
```
-### [#mixins](index.js#L395)
+### Contributing
-Static method for running global mixin functions against a child constructor. Mixins must be registered before calling this method.
+Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
-**Params**
+If Base doesn't do what you need, [please let us know](../../issues).
-* `Child` **{Function}**: Constructor function of a child class
-* `returns` **{Object}**: Returns the `Base` constructor for chaining
+### Release History
-**Example**
+#### key
-```js
-Base.extend(Child);
-Base.mixins(Child);
-```
+Changelog entries are classified using the following labels from [keep-a-changelog](https://github.com/olivierlacan/keep-a-changelog):
-### [#inherit](index.js#L414)
+* `added`: for new features
+* `changed`: for changes in existing functionality
+* `deprecated`: for once-stable features removed in upcoming releases
+* `removed`: for deprecated features removed in this release
+* `fixed`: for any bug fixes
-Similar to `util.inherit`, but copies all static properties, prototype properties, and getters/setters from `Provider` to `Receiver`. See [class-utils](https://github.com/jonschlinkert/class-utils#inherit) for more details.
+Custom labels used in this changelog:
-**Params**
+* `dependencies`: bumps dependencies
+* `housekeeping`: code re-organization, minor edits, or other changes that don't fit in one of the other categories.
-* `Receiver` **{Function}**: Receiving (child) constructor
-* `Provider` **{Function}**: Providing (parent) constructor
-* `returns` **{Object}**: Returns the `Base` constructor for chaining
+**Heads up!**
-**Example**
+Please [let us know](../../issues) if any of the following heading links are broken. Thanks!
-```js
-Base.inherit(Foo, Bar);
-```
+#### [0.12.0](https://github.com/node-base/base/compare/0.11.0...0.12.0)
-## In the wild
+**Fixed**
-The following node.js applications were built with `Base`:
+* ensure `__callbacks` and `super_` are non-enumberable
-* [assemble](https://github.com/assemble/assemble)
-* [verb](https://github.com/verbose/verb)
-* [generate](https://github.com/generate/generate)
-* [scaffold](https://github.com/jonschlinkert/scaffold)
-* [boilerplate](https://github.com/jonschlinkert/boilerplate)
+**Added**
-## Test coverage
+* Now sets `app.type` when `app.is('foo')` is called. This allows Base instances to be used more like AST nodes, which is especially helpful with [smart plugins](https://github.com/node-base/base-plugins)
-```
-Statements : 98.95% ( 94/95 )
-Branches : 92.31% ( 24/26 )
-Functions : 100% ( 17/17 )
-Lines : 98.94% ( 93/94 )
-```
-
-## History
+#### [0.11.0](https://github.com/node-base/base/compare/0.9.0...0.11.0)
-**v0.11.0 - major breaking changes!**
+**Major breaking changes!**
* Static `.use` and `.run` methods are now non-enumerable
-**v0.9.0 - major breaking changes!**
+#### [0.9.0](https://github.com/node-base/base/compare/0.8.0...0.9.0)
+
+**Major breaking changes!**
* `.is` no longer takes a function, a string must be passed
* all remaining `.debug` code has been removed
@@ -416,60 +437,25 @@ Lines : 98.94% ( 93/94 )
* `.assertPlugin` was removed
* `.lazy` was removed
-## Related projects
-
-There are a number of different plugins available for extending base. Let us know if you create your own!
-
-* [base-cwd](https://www.npmjs.com/package/base-cwd): Base plugin that adds a getter/setter for the current working directory. | [homepage](https://github.com/node-base/base-cwd "Base plugin that adds a getter/setter for the current working directory.")
-* [base-data](https://www.npmjs.com/package/base-data): adds a `data` method to base-methods. | [homepage](https://github.com/node-base/base-data "adds a `data` method to base-methods.")
-* [base-fs](https://www.npmjs.com/package/base-fs): base-methods plugin that adds vinyl-fs methods to your 'base' application for working with the file… [more](https://github.com/node-base/base-fs) | [homepage](https://github.com/node-base/base-fs "base-methods plugin that adds vinyl-fs methods to your 'base' application for working with the file system, like src, dest, copy and symlink.")
-* [base-generators](https://www.npmjs.com/package/base-generators): Adds project-generator support to your `base` application. | [homepage](https://github.com/node-base/base-generators "Adds project-generator support to your `base` application.")
-* [base-option](https://www.npmjs.com/package/base-option): Adds a few options methods to base, like `option`, `enable` and `disable`. See the readme… [more](https://github.com/node-base/base-option) | [homepage](https://github.com/node-base/base-option "Adds a few options methods to base, like `option`, `enable` and `disable`. See the readme for the full API.")
-* [base-pipeline](https://www.npmjs.com/package/base-pipeline): base-methods plugin that adds pipeline and plugin methods for dynamically composing streaming plugin pipelines. | [homepage](https://github.com/node-base/base-pipeline "base-methods plugin that adds pipeline and plugin methods for dynamically composing streaming plugin pipelines.")
-* [base-pkg](https://www.npmjs.com/package/base-pkg): Plugin for adding a `pkg` method that exposes pkg-store to your base application. | [homepage](https://github.com/node-base/base-pkg "Plugin for adding a `pkg` method that exposes pkg-store to your base application.")
-* [base-plugins](https://www.npmjs.com/package/base-plugins): Upgrade's plugin support in base applications to allow plugins to be called any time after… [more](https://github.com/node-base/base-plugins) | [homepage](https://github.com/node-base/base-plugins "Upgrade's plugin support in base applications to allow plugins to be called any time after init.")
-* [base-questions](https://www.npmjs.com/package/base-questions): Plugin for base-methods that adds methods for prompting the user and storing the answers on… [more](https://github.com/node-base/base-questions) | [homepage](https://github.com/node-base/base-questions "Plugin for base-methods that adds methods for prompting the user and storing the answers on a project-by-project basis.")
-* [base-store](https://www.npmjs.com/package/base-store): Plugin for getting and persisting config values with your base-methods application. Adds a 'store' object… [more](https://github.com/node-base/base-store) | [homepage](https://github.com/node-base/base-store "Plugin for getting and persisting config values with your base-methods application. Adds a 'store' object that exposes all of the methods from the data-store library. Also now supports sub-stores!")
-* [base-task](https://www.npmjs.com/package/base-task): base plugin that provides a very thin wrapper around [https://github.com/doowb/composer](https://github.com/doowb/composer) for adding task methods to… [more](https://github.com/node-base/base-task) | [homepage](https://github.com/node-base/base-task "base plugin that provides a very thin wrapper around <https://github.com/doowb/composer> for adding task methods to your application.")
-
-## Contributing
-
-This document was generated by [verb-readme-generator](https://github.com/verbose/verb-readme-generator) (a [verb](https://github.com/verbose/verb) generator), please don't edit directly. Any changes to the readme must be made in [.verb.md](.verb.md). See [Building Docs](#building-docs).
-
-Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
-
-Or visit the [verb-readme-generator](https://github.com/verbose/verb-readme-generator) project to submit bug reports or pull requests for the readme layout template.
+_(Changelog generated by [helper-changelog](https://github.com/helpers/helper-changelog))_
-## Building docs
-
-_(This document was generated by [verb-readme-generator](https://github.com/verbose/verb-readme-generator) (a [verb](https://github.com/verbose/verb) generator), please don't edit the readme directly. Any changes to the readme must be made in [.verb.md](.verb.md).)_
-
-Generate readme and API documentation with [verb](https://github.com/verbose/verb):
-
-```sh
-$ npm install -g verb verb-readme-generator && verb
-```
-
-## Running tests
-
-Install dev dependencies:
-
-```sh
-$ npm install -d && npm test
-```
-
-## Author
+### Authors
**Jon Schlinkert**
* [github/jonschlinkert](https://github.com/jonschlinkert)
* [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
-## License
+**Brian Woodward**
+
+* [github/doowb](https://github.com/doowb)
+* [twitter/doowb](http://twitter.com/doowb)
+
+### License
-Copyright © 2016, [Jon Schlinkert](https://github.com/jonschlinkert).
-Released under the [MIT license](https://github.com/node-base/base/blob/master/LICENSE).
+Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert).
+MIT
***
-_This file was generated by [verb](https://github.com/verbose/verb), v0.9.0, on June 23, 2016._
\ No newline at end of file
+_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on December 21, 2017._
\ No newline at end of file
diff --git a/changelog.md b/changelog.md
new file mode 100644
index 0000000..31938fd
--- /dev/null
+++ b/changelog.md
@@ -0,0 +1,50 @@
+# Release History
+
+## key
+
+Changelog entries are classified using the following labels from [keep-a-changelog][]:
+
+* `added`: for new features
+* `changed`: for changes in existing functionality
+* `deprecated`: for once-stable features removed in upcoming releases
+* `removed`: for deprecated features removed in this release
+* `fixed`: for any bug fixes
+
+Custom labels used in this changelog:
+
+* `dependencies`: bumps dependencies
+* `housekeeping`: code re-organization, minor edits, or other changes that don't fit in one of the other categories.
+
+**Heads up!**
+
+Please [let us know](../../issues) if any of the following heading links are broken. Thanks!
+
+## [0.12.0]
+
+**Fixed**
+
+- ensure `__callbacks` and `super_` are non-enumberable
+
+**Added**
+
+- Now sets `app.type` when `app.is('foo')` is called. This allows Base instances to be used more like AST nodes, which is especially helpful with [smart plugins](https://github.com/node-base/base-plugins)
+
+## [0.11.0]
+
+**Major breaking changes!**
+
+- Static `.use` and `.run` methods are now non-enumerable
+
+## [0.9.0](https://github.com/node-base/base/compare/0.8.0...0.9.0)
+
+**Major breaking changes!**
+
+- `.is` no longer takes a function, a string must be passed
+- all remaining `.debug` code has been removed
+- `app._namespace` was removed (related to `debug`)
+- `.plugin`, `.use`, and `.define` no longer emit events
+- `.assertPlugin` was removed
+- `.lazy` was removed
+
+
+[keep-a-changelog]: https://github.com/olivierlacan/keep-a-changelog
diff --git a/docs/logo.png b/docs/logo.png
index f218612..70bb361 100755
Binary files a/docs/logo.png and b/docs/logo.png differ
diff --git a/docs/plugins.md b/docs/plugins.md
new file mode 100644
index 0000000..b626027
--- /dev/null
+++ b/docs/plugins.md
@@ -0,0 +1,41 @@
+**DRAFT / PLACEHOLDER**
+
+```js
+function plugin(app) {
+ // do stuff to "app"
+}
+
+
+function plugin(app) {
+ // do stuff to "app"
+ return function(collection) {
+ // do stuff to "collection"
+ };
+}
+
+
+function plugin(app) {
+ // do stuff to "app"
+ return function(collection) {
+ // do stuff to "collection"
+ return function(view) {
+ // do stuff to "view"
+ };
+ };
+}
+
+
+function plugin(view) {
+ if (!view.isView) return plugin;
+ // do stuff to "view"
+}
+
+var i = 0;
+function plugin(obj) {
+ obj.foo = i++;
+}
+
+app.use(plugin);
+console.log(app.foo);
+//=> 1
+```
diff --git a/gulpfile.js b/gulpfile.js
deleted file mode 100644
index aef2b75..0000000
--- a/gulpfile.js
+++ /dev/null
@@ -1,30 +0,0 @@
-'use strict';
-
-var gulp = require('gulp');
-var mocha = require('gulp-mocha');
-var istanbul = require('gulp-istanbul');
-var eslint = require('gulp-eslint');
-
-gulp.task('coverage', function() {
- return gulp.src(['index.js', 'utils.js'])
- .pipe(istanbul({includeUntested: true}))
- .pipe(istanbul.hookRequire());
-});
-
-gulp.task('mocha', ['coverage'], function() {
- return gulp.src('test.js')
- .pipe(mocha())
- .pipe(istanbul.writeReports())
- .pipe(istanbul.writeReports({
- reporters: [ 'text', 'text-summary' ],
- reportOpts: {dir: 'coverage', file: 'summary.txt'}
- }));
-});
-
-gulp.task('eslint', function() {
- return gulp.src('*.js')
- .pipe(eslint())
- .pipe(eslint.format());
-});
-
-gulp.task('default', ['mocha', 'eslint']);
diff --git a/index.js b/index.js
index 47fcd9a..aa8713e 100644
--- a/index.js
+++ b/index.js
@@ -1,22 +1,25 @@
'use strict';
-var util = require('util');
-var utils = require('./utils');
+const assert = require('assert');
+const define = require('define-property');
+const isObject = require('isobject');
+const pascal = require('pascalcase');
+const merge = require('mixin-deep');
+const Cache = require('cache-base');
/**
* Optionally define a custom `cache` namespace to use.
*/
function namespace(name) {
- var Cache = name ? utils.Cache.namespace(name) : utils.Cache;
- var fns = [];
+ const fns = [];
/**
* Create an instance of `Base` with the given `config` and `options`.
*
* ```js
* // initialize with `config` and `options`
- * var app = new Base({isApp: true}, {abc: true});
+ * const app = new Base({isApp: true}, {abc: true});
* app.set('foo', 'bar');
*
* // values defined with the given `config` object will be on the root of the instance
@@ -30,389 +33,223 @@ function namespace(name) {
* console.log(app.options.abc); //=> true
* ```
*
- * @param {Object} `config` If supplied, this object is passed to [cache-base][] to merge onto the the instance upon instantiation.
+ * @name Base
+ * @param {Object} `cache` If supplied, this object is passed to [cache-base][] to merge onto the the instance.
* @param {Object} `options` If supplied, this object is used to initialize the `base.options` object.
* @api public
*/
- function Base(config, options) {
- if (!(this instanceof Base)) {
- return new Base(config, options);
+ class Base extends Cache {
+ constructor(cache, options) {
+ super(name, cache);
+ this.is('base');
+ this.is('app');
+ this.options = merge({}, this.options, options);
+ this.cache = this.cache || {};
+ this.define('registered', {});
+ this.constructor.run(this, 'use', fns);
}
- Cache.call(this, config);
- this.is('base');
- this.initBase(config, options);
- }
-
- /**
- * Inherit cache-base
- */
-
- util.inherits(Base, Cache);
-
- /**
- * Add static emitter methods
- */
- utils.Emitter(Base);
-
- /**
- * Initialize `Base` defaults with the given `config` object
- */
-
- Base.prototype.initBase = function(config, options) {
- this.options = utils.merge({}, this.options, options);
- this.cache = this.cache || {};
- this.define('registered', {});
- if (name) this[name] = {};
-
- // make `app._callbacks` non-enumerable
- this.define('_callbacks', this._callbacks);
- if (utils.isObject(config)) {
- this.visit('set', config);
+ /**
+ * Set the given `name` on `app._name` and `app.is*` properties. Used for doing
+ * lookups in plugins.
+ *
+ * ```js
+ * app.is('collection');
+ * console.log(app.type);
+ * //=> 'collection'
+ * console.log(app.isCollection);
+ * //=> true
+ * ```
+ * @name .is
+ * @param {String} `name`
+ * @return {Boolean}
+ * @api public
+ */
+
+ is(type) {
+ assert.equal(typeof type, 'string', 'expected type to be a string');
+ if (type !== 'app') delete this.isApp;
+ this.define('type', type.toLowerCase());
+ this.define('is' + pascal(type), true);
+ return this;
}
- Base.run(this, 'use', fns);
- };
- /**
- * Set the given `name` on `app._name` and `app.is*` properties. Used for doing
- * lookups in plugins.
- *
- * ```js
- * app.is('foo');
- * console.log(app._name);
- * //=> 'foo'
- * console.log(app.isFoo);
- * //=> true
- * app.is('bar');
- * console.log(app.isFoo);
- * //=> true
- * console.log(app.isBar);
- * //=> true
- * console.log(app._name);
- * //=> 'bar'
- * ```
- * @name .is
- * @param {String} `name`
- * @return {Boolean}
- * @api public
- */
-
- Base.prototype.is = function(name) {
- if (typeof name !== 'string') {
- throw new TypeError('expected name to be a string');
+ /**
+ * Returns true if a plugin has already been registered on an instance.
+ *
+ * Plugin implementors are encouraged to use this first thing in a plugin
+ * to prevent the plugin from being called more than once on the same
+ * instance.
+ *
+ * ```js
+ * const base = new Base();
+ * base.use(function(app) {
+ * if (app.isRegistered('myPlugin')) return;
+ * // do stuff to `app`
+ * });
+ *
+ * // to also record the plugin as being registered
+ * base.use(function(app) {
+ * if (app.isRegistered('myPlugin', true)) return;
+ * // do stuff to `app`
+ * });
+ * ```
+ * @name .isRegistered
+ * @emits `plugin` Emits the name of the plugin being registered. Useful for unit tests, to ensure plugins are only registered once.
+ * @param {String} `name` The plugin name.
+ * @param {Boolean} `register` If the plugin if not already registered, to record it as being registered pass `true` as the second argument.
+ * @return {Boolean} Returns true if a plugin is already registered.
+ * @api public
+ */
+
+ isRegistered(name, register) {
+ assert.equal(typeof name, 'string', 'expected name to be a string');
+ if (this.registered.hasOwnProperty(name)) {
+ return true;
+ }
+ if (register !== false) {
+ this.registered[name] = true;
+ this.emit('plugin', name);
+ }
+ return false;
}
- this.define('is' + utils.pascal(name), true);
- this.define('_name', name);
- this.define('_appname', name);
- return this;
- };
- /**
- * Returns true if a plugin has already been registered on an instance.
- *
- * Plugin implementors are encouraged to use this first thing in a plugin
- * to prevent the plugin from being called more than once on the same
- * instance.
- *
- * ```js
- * var base = new Base();
- * base.use(function(app) {
- * if (app.isRegistered('myPlugin')) return;
- * // do stuff to `app`
- * });
- *
- * // to also record the plugin as being registered
- * base.use(function(app) {
- * if (app.isRegistered('myPlugin', true)) return;
- * // do stuff to `app`
- * });
- * ```
- * @name .isRegistered
- * @emits `plugin` Emits the name of the plugin being registered. Useful for unit tests, to ensure plugins are only registered once.
- * @param {String} `name` The plugin name.
- * @param {Boolean} `register` If the plugin if not already registered, to record it as being registered pass `true` as the second argument.
- * @return {Boolean} Returns true if a plugin is already registered.
- * @api public
- */
-
- Base.prototype.isRegistered = function(name, register) {
- if (this.registered.hasOwnProperty(name)) {
- return true;
- }
- if (register !== false) {
- this.registered[name] = true;
- this.emit('plugin', name);
+ /**
+ * Define a plugin function to be called immediately upon init.
+ *
+ * ```js
+ * const app = new Base()
+ * .use(foo)
+ * .use(bar)
+ * .use(baz)
+ * ```
+ * @name .use
+ * @param {Function} `fn` plugin function to call
+ * @return {Object} Returns the item instance for chaining.
+ * @api public
+ */
+
+ use(fn) {
+ assert.equal(typeof fn, 'function', 'expected plugin to be a function');
+ fn.call(this, this);
+ return this;
}
- return false;
- };
-
- /**
- * Define a plugin function to be called immediately upon init. Plugins are chainable
- * and expose the following arguments to the plugin function:
- *
- * - `app`: the current instance of `Base`
- * - `base`: the [first ancestor instance](#base) of `Base`
- *
- * ```js
- * var app = new Base()
- * .use(foo)
- * .use(bar)
- * .use(baz)
- * ```
- * @name .use
- * @param {Function} `fn` plugin function to call
- * @return {Object} Returns the item instance for chaining.
- * @api public
- */
-
- Base.prototype.use = function(fn) {
- fn.call(this, this);
- return this;
- };
-
- /**
- * The `.define` method is used for adding non-enumerable property on the instance.
- * Dot-notation is **not supported** with `define`.
- *
- * ```js
- * // arbitrary `render` function using lodash `template`
- * app.define('render', function(str, locals) {
- * return _.template(str)(locals);
- * });
- * ```
- * @name .define
- * @param {String} `key` The name of the property to define.
- * @param {any} `value`
- * @return {Object} Returns the instance for chaining.
- * @api public
- */
- Base.prototype.define = function(key, val) {
- if (utils.isObject(key)) {
- return this.visit('define', key);
+ /**
+ * The `.define` method is used for adding non-enumerable property on the instance.
+ * Dot-notation is **not supported** with `define`.
+ *
+ * ```js
+ * // arbitrary `render` function using lodash `template`
+ * app.define('render', function(str, locals) {
+ * return _.template(str)(locals);
+ * });
+ * ```
+ * @name .define
+ * @param {String} `key` The name of the property to define.
+ * @param {any} `value`
+ * @return {Object} Returns the instance for chaining.
+ * @api public
+ */
+
+ define(key, val) {
+ if (isObject(key)) {
+ return this.visit('define', key);
+ }
+ define(this, key, val);
+ return this;
}
- utils.define(this, key, val);
- return this;
- };
- /**
- * Mix property `key` onto the Base prototype. If base is inherited using
- * `Base.extend` this method will be overridden by a new `mixin` method that will
- * only add properties to the prototype of the inheriting application.
- *
- * ```js
- * app.mixin('foo', function() {
- * // do stuff
- * });
- * ```
- * @name .mixin
- * @param {String} `key`
- * @param {Object|Array} `val`
- * @return {Object} Returns the `base` instance for chaining.
- * @api public
- */
-
- Base.prototype.mixin = function(key, val) {
- Base.prototype[key] = val;
- return this;
- };
-
- /**
- * Non-enumberable mixin array, used by the static [Base.mixin]() method.
- */
-
- Base.prototype.mixins = Base.prototype.mixins || [];
-
- /**
- * Getter/setter used when creating nested instances of `Base`, for storing a reference
- * to the first ancestor instance. This works by setting an instance of `Base` on the `parent`
- * property of a "child" instance. The `base` property defaults to the current instance if
- * no `parent` property is defined.
- *
- * ```js
- * // create an instance of `Base`, this is our first ("base") instance
- * var first = new Base();
- * first.foo = 'bar'; // arbitrary property, to make it easier to see what's happening later
- *
- * // create another instance
- * var second = new Base();
- * // create a reference to the first instance (`first`)
- * second.parent = first;
- *
- * // create another instance
- * var third = new Base();
- * // create a reference to the previous instance (`second`)
- * // repeat this pattern every time a "child" instance is created
- * third.parent = second;
- *
- * // we can always access the first instance using the `base` property
- * console.log(first.base.foo);
- * //=> 'bar'
- * console.log(second.base.foo);
- * //=> 'bar'
- * console.log(third.base.foo);
- * //=> 'bar'
- * // and now you know how to get to third base ;)
- * ```
- * @name .base
- * @api public
- */
-
- Object.defineProperty(Base.prototype, 'base', {
- configurable: true,
- get: function() {
+ /**
+ * Getter/setter used when creating nested instances of `Base`, for storing a reference
+ * to the first ancestor instance. This works by setting an instance of `Base` on the `parent`
+ * property of a "child" instance. The `base` property defaults to the current instance if
+ * no `parent` property is defined.
+ *
+ * ```js
+ * // create an instance of `Base`, this is our first ("base") instance
+ * const first = new Base();
+ * first.foo = 'bar'; // arbitrary property, to make it easier to see what's happening later
+ *
+ * // create another instance
+ * const second = new Base();
+ * // create a reference to the first instance (`first`)
+ * second.parent = first;
+ *
+ * // create another instance
+ * const third = new Base();
+ * // create a reference to the previous instance (`second`)
+ * // repeat this pattern every time a "child" instance is created
+ * third.parent = second;
+ *
+ * // we can always access the first instance using the `base` property
+ * console.log(first.base.foo);
+ * //=> 'bar'
+ * console.log(second.base.foo);
+ * //=> 'bar'
+ * console.log(third.base.foo);
+ * //=> 'bar'
+ * ```
+ * @name .base
+ * @api public
+ */
+
+ get base() {
return this.parent ? this.parent.base : this;
}
- });
-
- /**
- * Static method for adding global plugin functions that will
- * be added to an instance when created.
- *
- * ```js
- * Base.use(function(app) {
- * app.foo = 'bar';
- * });
- * var app = new Base();
- * console.log(app.foo);
- * //=> 'bar'
- * ```
- * @name #use
- * @param {Function} `fn` Plugin function to use on each instance.
- * @return {Object} Returns the `Base` constructor for chaining
- * @api public
- */
-
- utils.define(Base, 'use', function(fn) {
- fns.push(fn);
- return Base;
- });
- /**
- * Run an array of functions by passing each function
- * to a method on the given object specified by the given property.
- *
- * @param {Object} `obj` Object containing method to use.
- * @param {String} `prop` Name of the method on the object to use.
- * @param {Array} `arr` Array of functions to pass to the method.
- */
-
- utils.define(Base, 'run', function(obj, prop, arr) {
- var len = arr.length, i = 0;
- while (len--) {
- obj[prop](arr[i++]);
+ /**
+ * Static method for adding global plugin functions that will
+ * be added to an instance when created.
+ *
+ * ```js
+ * Base.use(function(app) {
+ * app.foo = 'bar';
+ * });
+ * const app = new Base();
+ * console.log(app.foo);
+ * //=> 'bar'
+ * ```
+ * @name #use
+ * @param {Function} `fn` Plugin function to use on each instance.
+ * @return {Object} Returns the `Base` constructor for chaining
+ * @api public
+ */
+
+ static use(fn) {
+ assert.equal(typeof fn, 'function', 'expected plugin to be a function');
+ fns.push(fn);
+ return this;
}
- return Base;
- });
-
- /**
- * Static method for inheriting the prototype and static methods of the `Base` class.
- * This method greatly simplifies the process of creating inheritance-based applications.
- * See [static-extend][] for more details.
- *
- * ```js
- * var extend = cu.extend(Parent);
- * Parent.extend(Child);
- *
- * // optional methods
- * Parent.extend(Child, {
- * foo: function() {},
- * bar: function() {}
- * });
- * ```
- * @name #extend
- * @param {Function} `Ctor` constructor to extend
- * @param {Object} `methods` Optional prototype properties to mix in.
- * @return {Object} Returns the `Base` constructor for chaining
- * @api public
- */
- utils.define(Base, 'extend', utils.cu.extend(Base, function(Ctor, Parent) {
- Ctor.prototype.mixins = Ctor.prototype.mixins || [];
-
- utils.define(Ctor, 'mixin', function(fn) {
- var mixin = fn(Ctor.prototype, Ctor);
- if (typeof mixin === 'function') {
- Ctor.prototype.mixins.push(mixin);
+ /**
+ * Run an array of functions by passing each function
+ * to a method on the given object specified by the given property.
+ *
+ * @param {Object} `target` Object containing method to use.
+ * @param {String} `key` Name of the method to call
+ * @param {Array} `arr` Array of functions to pass to the method.
+ */
+
+ static run(target, key, arr) {
+ assert.equal(typeof key, 'string', 'expected key to be a string');
+ let len = arr.length, i = 0;
+ while (len--) {
+ target[key](arr[i++]);
}
- return Ctor;
- });
-
- utils.define(Ctor, 'mixins', function(Child) {
- Base.run(Child, 'mixin', Ctor.prototype.mixins);
- return Ctor;
- });
-
- Ctor.prototype.mixin = function(key, value) {
- Ctor.prototype[key] = value;
return this;
- };
- return Base;
- }));
-
- /**
- * Used for adding methods to the `Base` prototype, and/or to the prototype of child instances.
- * When a mixin function returns a function, the returned function is pushed onto the `.mixins`
- * array, making it available to be used on inheriting classes whenever `Base.mixins()` is
- * called (e.g. `Base.mixins(Child)`).
- *
- * ```js
- * Base.mixin(function(proto) {
- * proto.foo = function(msg) {
- * return 'foo ' + msg;
- * };
- * });
- * ```
- * @name #mixin
- * @param {Function} `fn` Function to call
- * @return {Object} Returns the `Base` constructor for chaining
- * @api public
- */
-
- utils.define(Base, 'mixin', function(fn) {
- var mixin = fn(Base.prototype, Base);
- if (typeof mixin === 'function') {
- Base.prototype.mixins.push(mixin);
}
- return Base;
- });
- /**
- * Static method for running global mixin functions against a child constructor.
- * Mixins must be registered before calling this method.
- *
- * ```js
- * Base.extend(Child);
- * Base.mixins(Child);
- * ```
- * @name #mixins
- * @param {Function} `Child` Constructor function of a child class
- * @return {Object} Returns the `Base` constructor for chaining
- * @api public
- */
+ /**
+ * Remove static mixin method from emitter
+ */
- utils.define(Base, 'mixins', function(Child) {
- Base.run(Child, 'mixin', Base.prototype.mixins);
- return Base;
- });
-
- /**
- * Similar to `util.inherit`, but copies all static properties, prototype properties, and
- * getters/setters from `Provider` to `Receiver`. See [class-utils][]{#inherit} for more details.
- *
- * ```js
- * Base.inherit(Foo, Bar);
- * ```
- * @name #inherit
- * @param {Function} `Receiver` Receiving (child) constructor
- * @param {Function} `Provider` Providing (parent) constructor
- * @return {Object} Returns the `Base` constructor for chaining
- * @api public
- */
+ static get mixin() {
+ return undefined;
+ }
+ }
- utils.define(Base, 'inherit', utils.cu.inherit);
- utils.define(Base, 'bubble', utils.cu.bubble);
return Base;
}
diff --git a/package.json b/package.json
index 77f00c2..249db36 100644
--- a/package.json
+++ b/package.json
@@ -1,56 +1,51 @@
{
"name": "base",
- "description": "base is the foundation for creating modular, unit testable and highly pluggable node.js applications, starting with a handful of common methods, like `set`, `get`, `del` and `use`.",
- "version": "0.11.1",
+ "description": "Framework for rapidly creating high quality, server-side node.js applications, using plugins like building blocks",
+ "version": "1.0.1",
"homepage": "https://github.com/node-base/base",
"author": "Jon Schlinkert (https://github.com/jonschlinkert)",
- "contributors": [
- "Brian Woodward (https://github.com/doowb)"
- ],
"maintainers": [
"Brian Woodward (https://github.com/doowb)",
"Jon Schlinkert (https://github.com/jonschlinkert)"
],
+ "contributors": [
+ "Brian Woodward (https://twitter.com/doowb)",
+ "John O'Donnell (https://github.com/criticalmash)",
+ "Jon Schlinkert (http://twitter.com/jonschlinkert)",
+ "Olsten Larck (https://i.am.charlike.online)",
+ "(https://github.com/wtgtybhertgeghgtwtg)"
+ ],
"repository": "node-base/base",
"bugs": {
"url": "https://github.com/node-base/base/issues"
},
"license": "MIT",
"files": [
- "index.js",
- "utils.js"
+ "index.js"
],
"main": "index.js",
"engines": {
- "node": ">=0.10.0"
+ "node": ">=6"
},
"scripts": {
"test": "mocha"
},
"dependencies": {
- "arr-union": "^3.1.0",
- "cache-base": "^0.8.4",
- "class-utils": "^0.3.4",
- "component-emitter": "^1.2.1",
- "define-property": "^0.2.5",
- "isobject": "^2.1.0",
- "lazy-cache": "^2.0.1",
- "mixin-deep": "^1.1.3",
+ "cache-base": "^2.0.2",
+ "define-property": "^1.0.0",
+ "isobject": "^3.0.1",
+ "mixin-deep": "^1.2.0",
"pascalcase": "^0.1.1"
},
"devDependencies": {
- "gulp": "^3.9.1",
- "gulp-eslint": "^2.0.0",
- "gulp-format-md": "^0.1.9",
- "gulp-istanbul": "^0.10.4",
- "gulp-mocha": "^2.2.0",
- "helper-coverage": "^0.1.3",
- "mocha": "^2.5.3",
- "should": "^9.0.1",
- "through2": "^2.0.1",
- "verb-readme-generator": "^0.1.13"
+ "gulp-format-md": "^1.0.0",
+ "helper-changelog": "^0.3.0",
+ "mocha": "^3.5.3",
+ "through2": "^2.0.3",
+ "verb-generate-readme": "^0.6.0"
},
"keywords": [
+ "base",
"boilerplate",
"cache",
"del",
@@ -64,8 +59,7 @@
],
"verb": {
"run": true,
- "toc": false,
- "layout": "default",
+ "toc": "collapsible",
"tasks": [
"readme"
],
@@ -73,7 +67,7 @@
"gulp-format-md"
],
"helpers": [
- "helper-coverage"
+ "helper-changelog"
],
"related": {
"description": "There are a number of different plugins available for extending base. Let us know if you create your own!",
@@ -94,14 +88,18 @@
},
"reflinks": [
"assemble",
- "boilerplate",
+ "base",
+ "base-plugins",
"cache-base",
"class-utils",
+ "enquirer",
"generate",
- "scaffold",
- "verb",
+ "helper-changelog",
+ "prompt-base",
"static-extend",
- "verb-readme-generator"
+ "templates",
+ "update",
+ "verb"
],
"lint": {
"reflinks": true
diff --git a/test.js b/test.js
index 90a6404..e835d93 100644
--- a/test.js
+++ b/test.js
@@ -1,9 +1,7 @@
'use strict';
require('mocha');
-require('should');
var assert = require('assert');
-var utils = require('./utils');
var Base = require('./');
var base;
@@ -13,11 +11,6 @@ describe('constructor', function() {
assert(base instanceof Base);
});
- it('should return an instance of Base without new:', function() {
- base = Base();
- assert(base instanceof Base);
- });
-
it('should "visit" over an object to extend the instance', function() {
base = new Base({foo: 'bar'});
assert.equal(base.foo, 'bar');
@@ -39,16 +32,14 @@ describe('constructor', function() {
});
it('should merge options throughout the inheritance chain', function() {
- function Foo(options) {
- Base.call(this, null, options);
- this.options.x = 'y';
+ class Foo extends Base {
+ constructor(options) {
+ super(null, options);
+ this.options.x = 'y';
+ }
}
- Base.extend(Foo);
- function Bar(options) {
- Foo.call(this, options);
- }
- Foo.extend(Bar);
+ class Bar extends Foo {}
var bar = new Bar({a: 'b'});
@@ -57,9 +48,7 @@ describe('constructor', function() {
});
it('should add foo', function() {
- base = new Base({
- foo: 'bar'
- });
+ base = new Base({foo: 'bar'});
assert.equal(base.foo, 'bar');
});
@@ -67,6 +56,11 @@ describe('constructor', function() {
base = new Base();
assert.equal(base.isBase, true);
});
+
+ it('should set isApp on the instance', function() {
+ base = new Base();
+ assert.equal(base.isApp, true);
+ });
});
describe('static properties', function() {
@@ -78,46 +72,19 @@ describe('static properties', function() {
assert.equal(typeof Base.use, 'function');
});
- it('should expose `.extend` method', function() {
- assert.equal(typeof Base.extend, 'function');
- });
-
- it('should extend the given Ctor with static methods:', function() {
- function Ctor() {
- Base.call(this);
- }
- Base.extend(Ctor);
- assert.equal(typeof Ctor.extend, 'function');
-
- function foo() {}
- Ctor.extend(foo);
- assert.equal(typeof foo.extend, 'function');
- });
-
- describe('.extend', function() {
- it('should set the extend method on the given object:', function() {
- function Ctor() {}
- Base.extend(Ctor);
- assert.equal(typeof Ctor.extend, 'function');
- });
+ it('should extend static properties:', function() {
+ class Ctor extends Base {}
+ assert.equal(typeof Ctor.use, 'function');
+ assert.equal(typeof Ctor.run, 'function');
});
describe('.use', function() {
- it('should set the use method on the given object:', function() {
- function Ctor() {}
- Base.extend(Ctor);
- assert.equal(typeof Ctor.use, 'function');
- });
-
it('should use a globally loaded plugin through the static use method:', function() {
- function Ctor() {
- Base.call(this);
- }
- Base.extend(Ctor);
+ class Ctor extends Base {}
Ctor.use(function(app) {
app.foo = 'bar';
});
- var inst = new Ctor();
+ const inst = new Ctor();
assert.equal(inst.foo, 'bar');
});
@@ -156,80 +123,18 @@ describe('static properties', function() {
assert.equal(typeof bar.bar.bar, 'undefined');
});
});
-
- describe('.mixin', function() {
- it('should set the mixin method on the given object:', function() {
- function Ctor() {}
- Base.extend(Ctor);
- assert.equal(typeof Base.mixin, 'function');
- assert.equal(typeof Ctor.mixin, 'function');
- });
-
- it('should use a globally loaded mixin through the static mixin method:', function() {
- function Ctor() {
- Base.call(this);
- }
- Base.extend(Ctor);
- Base.mixin(function(proto) {
- proto.foo = 'bar';
- });
-
- var inst = new Ctor();
- Ctor.mixin(function(proto) {
- proto.bar = 'baz';
- });
-
- assert.equal(Base.prototype.foo, 'bar');
- assert.equal(Ctor.prototype.bar, 'baz');
- assert.equal(inst.foo, 'bar');
- assert.equal(inst.bar, 'baz');
- });
- });
-
- describe('.mixins', function() {
- it('should set the mixins method on the given object:', function() {
- function Ctor() {}
- Base.extend(Ctor);
- assert.equal(typeof Ctor.mixins, 'function');
- });
-
- it('should use a globally loaded mixin through the static mixins method:', function() {
-
- function Ctor() {
- Base.call(this);
- }
- Base.extend(Ctor);
- Base.mixin(function fn(proto) {
- proto.bar = 'bar';
- return fn;
- });
-
- function Child() {
- Ctor.call(this);
- }
- Base.extend(Child);
- Base.mixins(Child);
- Ctor.mixins(Child);
-
- var inst = new Child();
- assert.equal(Child.prototype.bar, 'bar');
- assert.equal(inst.bar, 'bar');
- });
- });
});
describe('extend prototype methods', function() {
beforeEach(function() {
- var Ctor = require('./');
+ const Ctor = require('./');
Base = Ctor.namespace();
});
it('should extend the prototype of the given Ctor:', function() {
- function Ctor() {
- Base.call(this);
- }
- Base.extend(Ctor);
- assert.equal(typeof Ctor.extend, 'function');
+ class Ctor extends Base {}
+ assert.equal(typeof Ctor.use, 'function');
+ assert.equal(typeof Ctor.run, 'function');
var ctor = new Ctor();
assert.equal(typeof ctor.set, 'function');
@@ -256,25 +161,13 @@ describe('extend prototype methods', function() {
assert.equal(typeof Base.prototype.define, 'function');
});
- it('should expose `prototype.mixin` method', function() {
- assert.equal(typeof Base.prototype.mixin, 'function');
- });
-
it('should add prototype methods to the given Ctor:', function() {
- function Ctor() {
- Base.call(this);
- }
- Base.extend(Ctor);
+ class Ctor extends Base {}
assert.equal(typeof Ctor.prototype.set, 'function');
assert.equal(typeof Ctor.prototype.get, 'function');
assert.equal(typeof Ctor.prototype.del, 'function');
assert.equal(typeof Ctor.prototype.visit, 'function');
assert.equal(typeof Ctor.prototype.define, 'function');
- assert.equal(typeof Ctor.prototype.mixin, 'function');
-
- function foo() {}
- Ctor.extend(foo);
- assert.equal(typeof foo.prototype.set, 'function');
});
});
@@ -525,151 +418,6 @@ describe('prototype methods', function() {
});
});
-describe('.mixin', function() {
- beforeEach(function() {
- var Ctor = require('./');
- Base = Ctor.namespace();
- base = new Base();
- });
-
- it('should add a property to the base prototype:', function() {
- base.mixin('a', function() {});
- assert.equal(typeof base.a, 'function');
- assert.equal(typeof Base.prototype.a, 'function');
- });
-
- it('should add to the prototype of an inheriting app:', function() {
- function Foo() {
- Base.call(this);
- }
- Base.extend(Foo);
- var foo = new Foo();
- foo.mixin('a', function() {});
- assert.equal(typeof Foo.prototype.a, 'function');
- assert.equal(typeof foo.a, 'function');
- });
-
- it('should add to inheriting app prototype:', function() {
- function Foo() {
- Base.call(this);
- }
- Base.extend(Foo);
-
- var base = new Base();
- var foo = new Foo();
-
- base.mixin('abc', function() {});
- foo.mixin('xyz', function() {});
-
- assert.equal(typeof Base.prototype.abc, 'function');
- assert.equal(typeof Foo.prototype.abc, 'function');
- assert.equal(typeof base.abc, 'function');
- assert.equal(typeof foo.abc, 'function');
-
- assert(typeof Base.prototype.xyz !== 'function');
- assert.equal(typeof Foo.prototype.xyz, 'function');
- assert.equal(typeof foo.xyz, 'function');
- assert(typeof base.xyz !== 'function');
- });
-
- it('should chain calls to mixin:', function() {
- function Foo() {
- Base.call(this);
- }
- Base.extend(Foo);
-
- var base = new Base();
- var foo = new Foo();
-
- base.mixin('abc', function() {})
- .mixin('def', function() {});
-
- foo.mixin('xyz', function() {})
- .mixin('uvw', function() {});
-
- assert.equal(typeof Base.prototype.abc, 'function');
- assert.equal(typeof Base.prototype.def, 'function');
- assert.equal(typeof Foo.prototype.abc, 'function');
- assert.equal(typeof Foo.prototype.def, 'function');
- assert.equal(typeof base.abc, 'function');
- assert.equal(typeof base.def, 'function');
- assert.equal(typeof foo.abc, 'function');
- assert.equal(typeof foo.def, 'function');
-
- assert(typeof Base.prototype.xyz !== 'function');
- assert(typeof Base.prototype.uvw !== 'function');
- assert.equal(typeof Foo.prototype.xyz, 'function');
- assert.equal(typeof Foo.prototype.uvw, 'function');
- assert.equal(typeof foo.xyz, 'function');
- assert.equal(typeof foo.uvw, 'function');
- assert(typeof base.xyz !== 'function');
- assert(typeof base.uvw !== 'function');
- });
-
- it('should not add to Base.prototype from an inheriting app:', function() {
- function Foo() {
- Base.call(this);
- }
- Base.extend(Foo);
-
- var foo = new Foo();
- var base = new Base();
-
- foo.mixin('a', function() {});
-
- // yes
- assert.equal(typeof Foo.prototype.a, 'function');
- assert.equal(typeof foo.a, 'function');
-
- // no
- assert(typeof Base.prototype.a !== 'function');
- assert(typeof base.a !== 'function');
- });
-
- it('should NOT mixin from one inheriting prototype to another:', function() {
- function Foo() { Base.call(this); }
- Base.extend(Foo);
-
- function Bar() { Base.call(this); }
- Base.extend(Bar);
-
- var foo = new Foo();
- var bar = new Bar();
-
- foo.mixin('a', function() {});
-
- // yes
- assert.equal(typeof Foo.prototype.a, 'function');
- assert.equal(typeof foo.a, 'function');
-
- // no
- assert(typeof Bar.prototype.a !== 'function');
- assert(typeof bar.a !== 'function');
- });
-
- it('should mixin from Base.prototype to all others:', function() {
- function Foo() { Base.call(this); }
- Base.extend(Foo);
-
- function Bar() { Base.call(this); }
- Base.extend(Bar);
-
- var base = new Base();
- var foo = new Foo();
- var bar = new Bar();
-
- base.mixin('xyz', function() {});
-
- assert.equal(typeof Base.prototype.xyz, 'function');
- assert.equal(typeof Foo.prototype.xyz, 'function');
- assert.equal(typeof Bar.prototype.xyz, 'function');
-
- assert.equal(typeof base.xyz, 'function');
- assert.equal(typeof foo.xyz, 'function');
- assert.equal(typeof bar.xyz, 'function');
- });
-});
-
describe('namespaces', function() {
beforeEach(function() {
Base = require('./');
@@ -682,16 +430,9 @@ describe('namespaces', function() {
it('should extend the given Ctor with static methods:', function() {
var Foo = Base.namespace('cache');
-
- function Ctor() {
- Foo.call(this);
- }
- Foo.extend(Ctor);
- assert.equal(typeof Ctor.extend, 'function');
-
- function foo() {}
- Ctor.extend(foo);
- assert.equal(typeof foo.extend, 'function');
+ class Ctor extends Foo {}
+ assert.equal(typeof Ctor.use, 'function');
+ assert.equal(typeof Ctor.run, 'function');
});
});
@@ -803,8 +544,15 @@ describe('.is', function() {
it('should set a name prefixed with `is` on the instance:', function() {
base.is('Foo');
assert(base.isFoo);
+ assert.equal(base.type, 'foo');
assert.equal(base.isFoo, true);
});
+
+ it('should remove isApp when another type is set', function() {
+ base.is('Foo');
+ assert(base.isFoo);
+ assert.equal(base.isApp, undefined);
+ });
});
describe('events', function() {
diff --git a/utils.js b/utils.js
deleted file mode 100644
index b4dd5cc..0000000
--- a/utils.js
+++ /dev/null
@@ -1,25 +0,0 @@
-'use strict';
-
-var utils = require('lazy-cache')(require);
-var fn = require;
-require = utils; // eslint-disable-line
-
-/**
- * Lazily required module dependencies
- */
-
-require('arr-union', 'union');
-require('cache-base', 'Cache');
-require('define-property', 'define');
-require('component-emitter', 'Emitter');
-require('class-utils', 'cu');
-require('isobject', 'isObject');
-require('mixin-deep', 'merge');
-require('pascalcase', 'pascal');
-require = fn; // eslint-disable-line
-
-/**
- * Expose `utils` modules
- */
-
-module.exports = utils;
diff --git a/verbfile.js b/verbfile.js
index 863263c..6f54f70 100644
--- a/verbfile.js
+++ b/verbfile.js
@@ -2,18 +2,16 @@
var through = require('through2');
-module.exports = function(verb) {
- verb.use(require('verb-readme-generator'));
- verb.task('default', ['readme'], function(cb) {
- return verb.src('README.md')
+module.exports = function(app) {
+ app.use(require('verb-generate-readme'));
+ app.task('default', ['readme'], function(cb) {
+ return app.src('README.md')
.pipe(through.obj(function(file, enc, next) {
var str = file.contents.toString();
- str = str.replace(/^(#+ \[)\.#/gm, '$1Base.');
+ str = str.replace(/^(#+ \[)#/gm, '$1Base.');
file.contents = new Buffer(str);
next(null, file);
}))
- .pipe(verb.dest('.'));
+ .pipe(app.dest('.'));
});
};
-
-
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-base.git
More information about the Pkg-javascript-commits
mailing list