Browse Source

add build process

mightyplow 7 years ago
parent
commit
a89f46c737
8 changed files with 282 additions and 5 deletions
  1. 64 0
      dist/array.js
  2. 29 0
      dist/file.js
  3. 108 0
      dist/function.js
  4. 11 0
      dist/html.js
  5. 28 0
      dist/object.js
  6. 15 0
      dist/string.js
  7. 21 0
      dist/stylesheet.js
  8. 6 5
      package.json

File diff suppressed because it is too large
+ 64 - 0
dist/array.js


+ 29 - 0
dist/file.js

@@ -0,0 +1,29 @@
+'use strict';
+
+var fs = require('fs');
+
+module.exports = {
+    readFile: function readFile(filename) {
+        return new Promise(function (resolve, reject) {
+            fs.readFile(filename, function (err, data) {
+                if (err) {
+                    reject(err);
+                } else {
+                    resolve(data);
+                }
+            });
+        });
+    },
+
+    writeFile: function writeFile(filename, data) {
+        return new Promise(function (resolve, reject) {
+            fs.writeFile(filename, data, function (err) {
+                if (err) {
+                    reject(err);
+                } else {
+                    resolve();
+                }
+            });
+        });
+    }
+};

+ 108 - 0
dist/function.js

@@ -0,0 +1,108 @@
+'use strict';
+
+var toArray = require('./array').toArray;
+
+var argsToArray = function argsToArray(fn) {
+    // must not be a fat arrow since it breaks the arguments
+    return function () {
+        return fn(toArray(arguments));
+    };
+};
+
+var curry = function curry(fn) {
+    return function curried() {
+        var that = this;
+
+        for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
+            args[_key] = arguments[_key];
+        }
+
+        if (args.length < fn.length) {
+            return curried.bind.apply(curried, [that].concat(args));
+        } else {
+            return fn.apply(that, args);
+        }
+    };
+};
+
+var combine = argsToArray(function (fns) {
+    return fns.reverse().reduce(function (fnc, fn) {
+        return function (val) {
+            return fnc(fn(val));
+        };
+    });
+});
+
+// cannot use fat arrow function since we don't get the arguments, then
+var promisify = function promisify(fn) {
+    var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
+    return function () {
+        // copy passed arguments to a new array
+        var args = toArray(arguments);
+
+        return new Promise(function (resolve, reject) {
+            // add a callback to the arguments, which resolves the promise with the result
+            args.push(function (err, data) {
+                if (err) {
+                    reject(err);
+                } else {
+                    resolve(data);
+                }
+            });
+
+            // call the original function with our callback flavoured arguments
+            fn.apply(context, args);
+        });
+    };
+};
+
+/**
+ returns a function which executes promises one after another
+ @param promiseGenerators an array of functions which return a promise
+ @return function which executes the promises
+ */
+var enqueue = function enqueue(promiseGenerators) {
+    return promiseGenerators.reduce(function (f, promiseGenerator) {
+        return function () {
+            return f().then(promiseGenerator);
+        };
+    });
+};
+
+/**
+ Returns a function which executes promises one after another. The resulting function
+ returns a promise, which gets filled with an array of the results of the single promises.
+ @param promiseGenerators an array of functions which return a promise
+ @return function which executes the promises
+ */
+var enqueueWithResults = function () {
+    var fnQueue = function fnQueue(results, promiseGenerators) {
+        return promiseGenerators.reduce(function (f, promiseGenerator) {
+            return function () {
+                return f().then(function (result) {
+                    results.push(result);
+                    return promiseGenerator();
+                });
+            };
+        });
+    };
+
+    return function (promiseGenerators) {
+        return function () {
+            var results = [];
+            return fnQueue(results, promiseGenerators)().then(function (result) {
+                results.push(result);
+                return results;
+            });
+        };
+    };
+}();
+
+module.exports = {
+    argsToArray: argsToArray,
+    combine: combine,
+    curry: curry,
+    promisify: promisify,
+    enqueue: enqueue,
+    enqueueWithResults: enqueueWithResults
+};

+ 11 - 0
dist/html.js

@@ -0,0 +1,11 @@
+'use strict';
+
+module.exports = {
+    createLinkTag: function createLinkTag(filename, mediaQuery) {
+        if (mediaQuery) {
+            return '<link rel="stylesheet" type="text/css" href="' + filename + '" media="' + mediaQuery + '" />';
+        }
+
+        return '<link rel="stylesheet" type="text/css" href="' + filename + '" />';
+    }
+};

+ 28 - 0
dist/object.js

@@ -0,0 +1,28 @@
+'use strict';
+
+module.exports = {
+    prop: function prop(_prop) {
+        return function (obj) {
+            return obj[_prop];
+        };
+    },
+
+    filter: function filter(obj, pred) {
+        return Object.keys(obj).reduce(function (filtered, key) {
+            var value = obj[key];
+
+            if (pred(key, value)) {
+                filtered[key] = value;
+            }
+
+            return filtered;
+        }, {});
+    },
+    defaults: function defaults(obj, values) {
+        Object.keys(values).forEach(function (key) {
+            if (!obj.hasOwnProperty(key)) {
+                obj[key] = values[key];
+            }
+        });
+    }
+};

+ 15 - 0
dist/string.js

@@ -0,0 +1,15 @@
+'use strict';
+
+module.exports = {
+    append: function append(str, _append) {
+        return str + _append;
+    },
+    toBool: function toBool(val) {
+        return val === 'true';
+    },
+    ciCompare: function ciCompare() {
+        var val1 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
+        var val2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
+        return val1.toLowerCase() === val2.toLowerCase();
+    }
+};

+ 21 - 0
dist/stylesheet.js

@@ -0,0 +1,21 @@
+'use strict';
+
+module.exports = {
+    getRules: function getRules(css) {
+        return css.stylesheet.rules;
+    },
+    isRuleType: function isRuleType(type) {
+        return function (rule) {
+            return rule.type === type;
+        };
+    },
+
+    createStylesheetAst: function createStylesheetAst(rules) {
+        return {
+            type: 'stylesheet',
+            stylesheet: {
+                rules: rules
+            }
+        };
+    }
+};

+ 6 - 5
package.json

@@ -4,12 +4,15 @@
   "description": "js, helpers library",
   "main": "jslib.js",
   "devDependencies": {
+    "babel-cli": "^6.26.0",
     "babel-preset-es2015": "^6.22.0",
     "nodeunit": "^0.10.2"
   },
   "scripts": {
     "nodeunit": "nodeunit",
-    "test": "nodeunit tests"
+    "test": "nodeunit tests",
+    "build": "babel lib -d dist",
+    "prebublish": "npm run test && npm run build"
   },
   "files": [
     "lib",
@@ -27,9 +30,7 @@
     "url": "http://mightyplow.net"
   },
   "license": "ISC",
-  "browserify": {
-    "transform": [
-      "babelify"
-    ]
+  "babel": {
+    "presets": ["es2015"]
   }
 }