From 98bb57a6d96ce14c4285a40f88f58e3002613e09 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Sat, 18 Jul 2015 18:29:21 -0400 Subject: [PATCH] feature(bower) philip v1.2.0 --- bower.json | 2 +- lib/client/directory.js | 4 +- modules/execon/.bower.json | 34 +++++ modules/execon/ChangeLog | 40 ++++++ modules/execon/LICENSE | 20 +++ modules/execon/README.md | 152 +++++++++++++++++++++++ modules/execon/bower.json | 25 ++++ modules/execon/lib/exec.js | 233 +++++++++++++++++++++++++++++++++++ modules/execon/package.json | 17 +++ modules/philip/.bower.json | 13 +- modules/philip/ChangeLog | 6 + modules/philip/README.md | 2 +- modules/philip/bower.json | 5 +- modules/philip/lib/philip.js | 12 +- modules/philip/package.json | 2 +- 15 files changed, 550 insertions(+), 17 deletions(-) create mode 100644 modules/execon/.bower.json create mode 100644 modules/execon/ChangeLog create mode 100644 modules/execon/LICENSE create mode 100644 modules/execon/README.md create mode 100644 modules/execon/bower.json create mode 100644 modules/execon/lib/exec.js create mode 100644 modules/execon/package.json diff --git a/bower.json b/bower.json index 15778766..d947d805 100644 --- a/bower.json +++ b/bower.json @@ -30,6 +30,6 @@ "vk-openapi": "~0.0.1", "domtokenlist-shim": "~1.1.0", "promise-polyfill": "~2.1.0", - "philip": "~1.1.2" + "philip": "~1.2.0" } } diff --git a/lib/client/directory.js b/lib/client/directory.js index 4af2aad9..67eff8a6 100644 --- a/lib/client/directory.js +++ b/lib/client/directory.js @@ -40,8 +40,8 @@ return result; }); - if (!window.fetch) - array.unshift('/modules/fetch/fetch.js'); + if (!window.exec) + array.unshift('/modules/execon/lib/exec.js'); url = CloudCmd.join(array); diff --git a/modules/execon/.bower.json b/modules/execon/.bower.json new file mode 100644 index 00000000..214f7448 --- /dev/null +++ b/modules/execon/.bower.json @@ -0,0 +1,34 @@ +{ + "name": "execon", + "homepage": "https://github.com/coderaiser/execon", + "authors": [ + "coderaiser " + ], + "description": "Patterns of function calls", + "main": "lib/exec.js", + "moduleType": [ + "globals", + "node" + ], + "keywords": [ + "exec" + ], + "license": "MIT", + "ignore": [ + "**/.*", + "node_modules", + "bower_components", + "test", + "tests" + ], + "version": "1.2.2", + "_release": "1.2.2", + "_resolution": { + "type": "version", + "tag": "v1.2.2", + "commit": "07ebb474438800f66b4b2c5b7abca58a9aa57bf7" + }, + "_source": "git://github.com/coderaiser/execon.git", + "_target": "~1.2.2", + "_originalSource": "execon" +} \ No newline at end of file diff --git a/modules/execon/ChangeLog b/modules/execon/ChangeLog new file mode 100644 index 00000000..c5250438 --- /dev/null +++ b/modules/execon/ChangeLog @@ -0,0 +1,40 @@ +2015.06.05, v1.2.2 + +feature: +- (exec) with: callback.bind -> bind.apply + + +2015.06.05, v1.2.1 + +feature: +- (exec) exec.with: arguments[0] -> slice.call(arguments) + + +2015.06.03, v1.2.0 + +feature: +- (exec) add each, eachSeries +- (exec) series: rm getType call + + +2015.01.28, v1.1.1 + +feature: +- (exec) scope -> global +- (bower) add +- (package) node-execon -> execon +- (package) v1.1.0 +- (execon) series: add callback + + +2015.01.15, v1.1.0 + +feature: +- (execon) series: add callback + + +2014.11.24, v1.0.1 + +fix: +- (package) check -> exec + diff --git a/modules/execon/LICENSE b/modules/execon/LICENSE new file mode 100644 index 00000000..7511174b --- /dev/null +++ b/modules/execon/LICENSE @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright (c) 2014-2015 coderaiser + +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. diff --git a/modules/execon/README.md b/modules/execon/README.md new file mode 100644 index 00000000..d6ffce9c --- /dev/null +++ b/modules/execon/README.md @@ -0,0 +1,152 @@ +# Execon [![License][LicenseIMGURL]][LicenseURL] [![NPM version][NPMIMGURL]][NPMURL] [![Dependency Status][DependencyStatusIMGURL]][DependencyStatusURL] +Patterns of function calls. + +## Install +![NPM_INFO][NPM_INFO_IMG] +``` +npm i execon --save +# or +bower i execon --save +``` + +## Api + +```js +var exec = require('execon'); +``` + +### exec +Check is parameter is function, if it's - executes it with given parameters + +Was: + +```js +function(callback, p1, p2, pN) { + if (typeof callback === 'function') + callback(p1, p2, pN); +} +``` + +Now + +```js +function(callback, p1, p2, pN) { + exec(callback, p1, p2, pN); +} +``` + +or just + +```js +exec.ret(callback, p1, p2, pN); +``` + +### exec.if +Conditional execution one of two functions + +Preconditions: + +```js +function one() { + console.log(1); +} + +function two(callback) { + setTimeout(callback, 1000); +} +``` + + +Before: + +```js +if (2 > 3) + one(); +else + two(one); + +``` + +After: + +```js +exec.if(2 > 3, one, two); +``` + +### exec.parallel +if a you need a couple async operation do same work, and then call callback, this function for you. + +**Node.js example**. + +```js +var fs = require('fs'), + Util = require('execon'); + +exec.parallel([ + function(callback) { + fs.readFile('file1', callback); + }, + function(callback) { + fs.readFile('file2', callback); + } +], function(error, data1, data2) { + if (error) + console.log(error) + else + console.log(data1, data2); +}); +``` +**Vanilla js example.** + +```js +var ONE_SECOND = 1000, + TWO_SECONDS = 2000, + func = function(time, str, callback) { + setTimeout(function() { + console.log(str); + callback(null, str); + }, time); + }, + + func1 = func.bind(null, TWO_SECONDS, 'first'), + func2 = func.bind(null, ONE_SECOND, 'second'); + +exec.parallel([func1, func2], function(error, str1, str2) { + console.log(str1, str2); +}); +``` + +### exec.series +executes functions one-by-one + +```js +function one(callback){ + setTimeout(function() { + console.log(1) + callback(); + }, 1000); +} + +function two(callback) { + console.log(2); + callback(); +} + +exec.series([one, two], function(error) { + console.log(error || 'done'); +}); +``` + +## License + +MIT + +[NPM_INFO_IMG]: https://nodei.co/npm/execon.png?downloads=true&&stars&&downloadRank "npm install rendy" +[NPMIMGURL]: https://img.shields.io/npm/v/execon.svg?style=flat +[DependencyStatusIMGURL]: https://img.shields.io/gemnasium/coderaiser/execon.svg?style=flat +[LicenseIMGURL]: https://img.shields.io/badge/license-MIT-317BF9.svg?style=flat +[NPMURL]: https://npmjs.org/package/execon "npm" +[BuildStatusURL]: https://travis-ci.org/coderaiser/execon "Build Status" +[DependencyStatusURL]: https://gemnasium.com/coderaiser/execon "Dependency Status" +[LicenseURL]: https://tldrlegal.com/license/mit-license "MIT License" + diff --git a/modules/execon/bower.json b/modules/execon/bower.json new file mode 100644 index 00000000..276786c0 --- /dev/null +++ b/modules/execon/bower.json @@ -0,0 +1,25 @@ +{ + "name": "execon", + "homepage": "https://github.com/coderaiser/execon", + "authors": [ + "coderaiser " + ], + "description": "Patterns of function calls", + "main": "lib/exec.js", + "moduleType": [ + "globals", + "node" + ], + "keywords": [ + "exec" + ], + "license": "MIT", + "ignore": [ + "**/.*", + "node_modules", + "bower_components", + "test", + "tests" + ], + "version": "1.2.2" +} diff --git a/modules/execon/lib/exec.js b/modules/execon/lib/exec.js new file mode 100644 index 00000000..bb4233a7 --- /dev/null +++ b/modules/execon/lib/exec.js @@ -0,0 +1,233 @@ +(function(global) { + 'use strict'; + + if (typeof module === 'object' && module.exports) + module.exports = new ExecProto(); + else + global.exec = new ExecProto(); + + function ExecProto() { + var slice = Array.prototype.slice, + /** + * function do save exec of function + * @param callback + * @param arg1 + * ... + * @param argN + */ + exec = function(callback) { + var ret, + isFunc = typeof callback === 'function', + args = slice.call(arguments, 1); + + if (isFunc) + ret = callback.apply(null, args); + + return ret; + }; + + /* + * return function that calls callback with arguments + */ + + exec.with = function(callback) { + var args = [].slice.call(arguments), + bind = Function.prototype.bind; + + args[0] = null; + + return bind.apply(callback, args); + }; + + /** + * return save exec function + * @param callback + */ + exec.ret = function() { + var result, + args = slice.call(arguments); + + args.unshift(exec); + result = exec.with.apply(null, args); + + return result; + }; + + /** + * function do conditional save exec of function + * @param condition + * @param callback + * @param func + */ + exec.if = function(condition, callback, func) { + var ret; + + if (condition) + exec(callback); + else + exec(func, callback); + + return ret; + }; + + /** + * exec function if it exist in object + * + * @param obj + * @param name + * @param arg + */ + exec.ifExist = function(obj, name, arg) { + var ret, + func = obj && obj[name]; + + if (func) + func = func.apply(obj, arg); + + return ret; + }; + + exec.parallel = function(funcs, callback) { + var ERROR = 'could not be empty!', + keys = [], + callbackWas = false, + arr = [], + obj = {}, + count = 0, + countFuncs = 0, + type = getType(funcs); + + if (!funcs) + throw(Error('funcs' + ERROR)); + + if (!callback) + throw(Error('callback' + ERROR)); + + switch(type) { + case 'array': + countFuncs = funcs.length; + + funcs.forEach(function(func, num) { + exec(func, function() { + checkFunc(num, arguments, arr); + }); + }); + break; + + case 'object': + keys = Object.keys(funcs); + countFuncs = keys.length; + + keys.forEach(function(name) { + var func = funcs[name]; + + exec(func, function() { + checkFunc(name, arguments, obj); + }); + }); + break; + } + + function checkFunc(num, data, all) { + var args = slice.call(data, 1), + isLast = false, + error = data[0], + length = args.length; + + ++count; + + isLast = count === countFuncs; + + if (!error) + if (length >= 2) + all[num] = args; + else + all[num] = args[0]; + + if (!callbackWas && (error || isLast)) { + callbackWas = true; + + if (type === 'array') + callback.apply(null, [error].concat(all)); + else + callback(error, all); + } + } + }; + + /** + * load functions thrue callbacks one-by-one + * @param funcs {Array} - array of functions + */ + exec.series = function(funcs, callback) { + var fn, + i = funcs.length, + check = function(error) { + var done; + + --i; + + if (!i || error) { + done = true; + exec(callback, error); + } + + return done; + }; + + if (!Array.isArray(funcs)) + throw(Error('funcs should be array!')); + + fn = funcs.shift(); + + exec(fn, function(error) { + if (!check(error)) + exec.series(funcs, callback); + }); + }; + + exec.each = function(array, iterator, callback) { + var listeners = array.map(function(item) { + return iterator.bind(null, item); + }); + + exec.parallel(listeners, callback); + }; + + exec.eachSeries = function(array, iterator, callback) { + var listeners = array.map(function(item) { + return iterator.bind(null, item); + }); + + exec.series(listeners, callback); + }; + + /** + * function execute param function in + * try...catch block + * + * @param callback + */ + exec.try = function(callback) { + var ret; + try { + ret = callback(); + } catch(error) { + ret = error; + } + + return ret; + }; + + function getType(variable) { + var regExp = new RegExp('\\s([a-zA-Z]+)'), + str = {}.toString.call(variable), + typeBig = str.match(regExp)[1], + result = typeBig.toLowerCase(); + + return result; + } + + return exec; + } +})(this); diff --git a/modules/execon/package.json b/modules/execon/package.json new file mode 100644 index 00000000..6b09146b --- /dev/null +++ b/modules/execon/package.json @@ -0,0 +1,17 @@ +{ + "name": "execon", + "version": "1.2.2", + "author": "coderaiser (https://github.com/coderaiser)", + "description": "Patterns of function calls", + "homepage": "http://github.com/coderaiser/execon", + "repository": { + "type": "git", + "url": "git://github.com/coderaiser/execon.git" + }, + "dependencies": {}, + "license": "MIT", + "engines": { + "node": ">=0.8" + }, + "main": "lib/exec.js" +} diff --git a/modules/philip/.bower.json b/modules/philip/.bower.json index f8403dc7..5a019783 100644 --- a/modules/philip/.bower.json +++ b/modules/philip/.bower.json @@ -1,6 +1,6 @@ { "name": "philip", - "version": "1.1.2", + "version": "1.2.0", "homepage": "https://github.com/coderaiser/domfs-philip", "authors": [ "coderaiser " @@ -23,16 +23,17 @@ ], "dependencies": { "emitify": "~1.2.0", - "findit": "~1.1.0" + "findit": "~1.1.0", + "execon": "~1.2.2" }, - "_release": "1.1.2", + "_release": "1.2.0", "_resolution": { "type": "version", - "tag": "v1.1.2", - "commit": "9784fc8c0b935b596d6135743334fa5f86d787e7" + "tag": "v1.2.0", + "commit": "f23a266be8221788974a851c6eed96060dc61f2f" }, "_source": "git://github.com/coderaiser/domfs-philip.git", - "_target": "~1.1.2", + "_target": "~1.2.0", "_originalSource": "philip", "_direct": true } \ No newline at end of file diff --git a/modules/philip/ChangeLog b/modules/philip/ChangeLog index a5249bdb..4211db03 100644 --- a/modules/philip/ChangeLog +++ b/modules/philip/ChangeLog @@ -1,3 +1,9 @@ +2015.07.18, v1.2.0 + +fix: +- (philip) not all files was processed + + 2015.07.17, v1.1.2 feature: diff --git a/modules/philip/README.md b/modules/philip/README.md index 566d7e8c..8a8980c1 100644 --- a/modules/philip/README.md +++ b/modules/philip/README.md @@ -10,7 +10,7 @@ bower i philip --save ## How to use? -Add `philip.js` [findit](https://github.com/coderaiser/domfs-findit "Find It") and [emitify](https://github.com/coderaiser/emitify "Emitify"). +Add `philip.js` [findit](https://github.com/coderaiser/domfs-findit "Find It"), [execon](https://github.com/coderaiser/execon "Patterns of function calls")(or [async](https://github.com/caolan/async "Async utilities for node and the browser" with `window.exec = window.async`) and [emitify](https://github.com/coderaiser/emitify "Emitify"). Or any other node-compitable [EventEmitter](https://iojs.org/api/events.html "Events") (set `window.Emitify = your_emitter` before using `findit`). diff --git a/modules/philip/bower.json b/modules/philip/bower.json index ecac4d5f..000114b4 100644 --- a/modules/philip/bower.json +++ b/modules/philip/bower.json @@ -1,6 +1,6 @@ { "name": "philip", - "version": "1.1.2", + "version": "1.2.0", "homepage": "https://github.com/coderaiser/domfs-philip", "authors": [ "coderaiser " @@ -23,6 +23,7 @@ ], "dependencies": { "emitify": "~1.2.0", - "findit": "~1.1.0" + "findit": "~1.1.0", + "execon": "~1.2.2" } } diff --git a/modules/philip/lib/philip.js b/modules/philip/lib/philip.js index 7aafa7eb..0ca6cde0 100644 --- a/modules/philip/lib/philip.js +++ b/modules/philip/lib/philip.js @@ -1,5 +1,6 @@ /* global Emitify */ /* global findit */ +/* global exec */ (function(global) { 'use strict'; @@ -132,10 +133,11 @@ }; Philip.prototype._find = function(entries, fn) { - [].forEach.call(entries, function(entry) { - var files = [], - dirs = [], - finder = findit(entry); + var files = [], + dirs = []; + + exec.each(entries, function(entry) { + var finder = findit(entry); finder.on('directory', function(name) { dirs.push(name); @@ -148,6 +150,8 @@ finder.on('end', function() { fn(files, dirs); }); + }, function() { + fn(files, dirs); }); }; })(this); diff --git a/modules/philip/package.json b/modules/philip/package.json index 365f5b30..8e3cffdd 100644 --- a/modules/philip/package.json +++ b/modules/philip/package.json @@ -1,7 +1,7 @@ { "name": "philip", "private": true, - "version": "1.1.2", + "version": "1.2.0", "description": "Process files and directories in DOM File System", "main": "lib/philip.js", "dependencies": {},