Skip to content

Commit

Permalink
Elimino best-promise para qa-control
Browse files Browse the repository at this point in the history
  • Loading branch information
diegoefe committed Nov 15, 2016
1 parent 94cd1a0 commit e085769
Show file tree
Hide file tree
Showing 8 changed files with 4,323 additions and 4,207 deletions.
7 changes: 3 additions & 4 deletions bin/txt-to-sql-run.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
var program = require('commander');
var fast = require('./fast.js');
var txtToSql = require('../lib/txt-to-sql.js');
var Promises = require('best-promise');
var fs = require('fs-promise');
var changing = require('best-globals').changing;
var fs = require('fs-promise');
Expand Down Expand Up @@ -56,7 +55,7 @@ function writeConfigYaml(params, inputYaml) {
}

function getOutputDir(inFile) {
return Promises.start(function() {
return Promise.resolve().then(function() {
if(!inFile) { throw new Error("null file"); }
return fs.exists(inFile);
}).then(function(exists) {
Expand All @@ -71,7 +70,7 @@ function getOutputDir(inFile) {

function collectExistentFiles(files) {
var existentFiles = [];
return Promises.all(files.map(function(file) {
return Promise.all(files.map(function(file) {
return fs.exists(file).then(function(exists) {
if(exists) { existentFiles.push(file); }
});
Expand Down Expand Up @@ -121,7 +120,7 @@ var localDefaultYaml = Path.resolve(Path.resolve('.'),'txt-to-sql-defaults.yaml'
var inputName = Path.basename(cmdParams.input, '.txt');
var params = {};

Promises.start(function() {
Promise.resolve().then(function() {
if(cmdParams.exportDefaults) {
process.stdout.write("Generating '"+localDefaultYaml+"'...");
return fs.writeFile(localDefaultYaml, jsYaml.safeDump({opts:txtToSql.defaultOpts}), {encoding:'utf8'}).then(function() {
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"js-yaml": "~3.7.0",

"best-globals": "~0.5.0",
"best-promise": "~0.2.4",
"mini-tools": "~0.3.3"
},
"devDependencies": {
Expand Down
17 changes: 7 additions & 10 deletions tools/web.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
"use strict";

var Promises = require('best-promise');
require('fs-extra');
var fs = require('fs-promise');
var Path = require('path');
var pug = require('pug');
var stylus = require('stylus');

function doStylus(str) {
return Promises.make(function(resolve, reject) {
return new Promise(function(resolve, reject) {
stylus(str).render(function(err, css) {
if(err) { return reject(err); }
return resolve(css);
Expand All @@ -17,12 +16,12 @@ function doStylus(str) {
}

function processDirectory(srcDir, destDir, only) {
return Promises.start(function() {
return Promise.resolve().then(function() {
return fs.readdir(srcDir)
}).then(function(files) {
return Promises.all(files.map(function(file) {
return Promise.all(files.map(function(file) {
var fullName = Path.join(srcDir, file);
return Promises.start(function() {
return Promise.resolve().then(function() {
return fs.readFile(fullName, {encoding:'utf8'});
}).then(function(content) {
var ext = Path.extname(file).substring(1);
Expand All @@ -35,8 +34,8 @@ function processDirectory(srcDir, destDir, only) {
//console.log("error", err)
});
})).then(function(files) {
return Promises.all(files.map(function (file) {
return Promises.start(function() {
return Promise.all(files.map(function (file) {
return Promise.resolve().then(function() {
//console.log("file", file.ext)
if(!file || (only && only.indexOf(file.ext)==-1)) { return {skip:true}; }
switch(file.ext) {
Expand All @@ -63,7 +62,7 @@ function processDirectory(srcDir, destDir, only) {
}

function bundlePromise(browserifyObject) {
return Promises.make(function(resolve, reject) {
return new Promise(function(resolve, reject) {
browserifyObject.bundle(function(err, buf) {
if(err) { return reject(err); }
return resolve(buf);
Expand All @@ -78,8 +77,6 @@ function generateWeb() {
return processDirectory('./lib', desDir, ['js']);
}).then(function() {
return fs.copy('./node_modules/best-globals/best-globals.js', desDir+'/best-globals.js');
//}).then(function() {
// return processDirectory('./node_modules/best-promise', desDir, ['js']);
}).then(function() {
return processDirectory('./node_modules/require-bro/lib', desDir);
}).then(function() {
Expand Down
57 changes: 52 additions & 5 deletions web/best-globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,13 +302,19 @@ bestGlobals.setGlobals = function setGlobals(theGlobalObj){
/*jshint forin:true */
};

bestGlobals.functionName = function functionName(fun) {
if(typeof fun !== "function"){
throw new Error("non function in functionName");
}
return fun.name||fun.toString().replace(/^\s*function\s*([^(]*)\((.|\s)*$/i,'$1')||'anonymous';
};

bestGlobals.constructorName = function constructorName(obj) {
if(obj){
var cn = obj.constructor.name;
if(!cn){
return obj.constructor.toString().replace(/^\s*function\s*([^(]*)\((.|\s)*$/i,'$1');
}
return cn;
return bestGlobals.functionName(obj.constructor);
}else{
console.log('deprecate use of constructorName with non-object for',obj);
console.log('it will throw Error in future releases');
}
};

Expand Down Expand Up @@ -361,6 +367,47 @@ bestGlobals.forOrder = function forOrder(text){
return main.join('')+signs.join('')+' '+text;
};

bestGlobals.forOrder.Native = function forOrderNative(a){
return a;
};

bestGlobals.nullsOrder = 1; // 1=last -1=first;

bestGlobals.compareForOrder = function compareForOrder(sortColumns){
var thisModule = this;
return function forOrderComparator(row1,row2){
var column;
var i=0;
do{
var order = bestGlobals.coalesce(sortColumns[i].order, 1);
column=sortColumns[i].column;
if(row1[column]==null){
if(row2[column]!=null){
return thisModule.nullsOrder;
}
}else if(row2[column]==null){
return -thisModule.nullsOrder;
}else{
var a=(sortColumns[i].func||thisModule.forOrder)(row1[column]);
var b=(sortColumns[i].func||thisModule.forOrder)(row2[column]);
if(a>b){
return 1*order;
}else if(a<b){
return -1*order;
}
}
i++;
}while(i<sortColumns.length);
return 0;
};
};

bestGlobals.sleep = function sleep(milliseconds){
return new Promise(function(resolve){
setTimeout(resolve,milliseconds);
});
};

return bestGlobals;

});
33 changes: 19 additions & 14 deletions web/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1794,30 +1794,25 @@ function isnan (val) {
},{"base64-js":1,"ieee754":2,"isarray":3}],1:[function(require,module,exports){
'use strict'

exports.byteLength = byteLength
exports.toByteArray = toByteArray
exports.fromByteArray = fromByteArray

var lookup = []
var revLookup = []
var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array

function init () {
var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
for (var i = 0, len = code.length; i < len; ++i) {
lookup[i] = code[i]
revLookup[code.charCodeAt(i)] = i
}

revLookup['-'.charCodeAt(0)] = 62
revLookup['_'.charCodeAt(0)] = 63
var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
for (var i = 0, len = code.length; i < len; ++i) {
lookup[i] = code[i]
revLookup[code.charCodeAt(i)] = i
}

init()
revLookup['-'.charCodeAt(0)] = 62
revLookup['_'.charCodeAt(0)] = 63

function toByteArray (b64) {
var i, j, l, tmp, placeHolders, arr
function placeHoldersCount (b64) {
var len = b64.length

if (len % 4 > 0) {
throw new Error('Invalid string. Length must be a multiple of 4')
}
Expand All @@ -1827,9 +1822,19 @@ function toByteArray (b64) {
// represent one byte
// if there is only one, then the three characters before it represent 2 bytes
// this is just a cheap hack to not do indexOf twice
placeHolders = b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0
return b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0
}

function byteLength (b64) {
// base64 is 4/3 + up to two characters of the original data
return b64.length * 3 / 4 - placeHoldersCount(b64)
}

function toByteArray (b64) {
var i, j, l, tmp, placeHolders, arr
var len = b64.length
placeHolders = placeHoldersCount(b64)

arr = new Arr(len * 3 / 4 - placeHolders)

// if there are placeholders, only get up to the last complete 4 chars
Expand Down
Loading

0 comments on commit e085769

Please sign in to comment.