Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

drizzle-builder

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

drizzle-builder - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

24

dist/helpers/page.js

@@ -19,2 +19,4 @@ 'use strict';

var splitPath = _object.splitPath;
var normalizePath = _object.normalizePath;
var isPathChild = _object.isPathChild;

@@ -33,3 +35,3 @@ var _list = require('../utils/list');

var isDir = isType(undefined);
var pickProps = R.pick(['id', 'url', 'data']);
var pickProps = R.pick(['id', 'url', 'name', 'data']);

@@ -67,6 +69,8 @@ /**

function destRoot(type, drizzle) {
var options = drizzle.options;
// TODO: this is unfortunate, and due to difficulty using defaults.keys
var keys = new Map([['page', 'pages'], ['collection', 'collections'], ['pattern', 'patterns']]);
return relativePath(drizzle.options.dest.root, drizzle.options.dest[keys.get(type)]);
return relativePath(options.dest.root, options.dest[keys.get(type)]);
}

@@ -113,3 +117,2 @@

if (options.sortby) {
// TODO: do we want to access via "data.foo" or just "foo"
results = sortByProp(['data', options.sortby], results);

@@ -135,4 +138,19 @@ }

Handlebars.registerHelper('collections', function () {
var path = R.is(String, arguments.length <= 0 ? undefined : arguments[0]) ? arguments.length <= 0 ? undefined : arguments[0] : '.';
var context = (arguments.length <= 1 ? undefined : arguments[1]) || (arguments.length <= 0 ? undefined : arguments[0]);
var drizzle = context.data.root.drizzle;
var tree = drizzle.tree.collections;
var treePath = normalizePath('collections.' + path);
var results = tree.filter(function (item) {
return isPathChild(item.id, treePath);
}).map(function (item) {
return menuItem(item, drizzle);
});
return results;
});
return Handlebars;
}
module.exports = exports['default'];

@@ -7,16 +7,27 @@ 'use strict';

var _deepmerge = require('deepmerge');
var _handlebars = require('handlebars');
var merge = _interopRequireDefault(_deepmerge).default;
var Handlebars = _interopRequireDefault(_handlebars).default;
var _defaults = require('./defaults');
var _utils = require('./utils');
var defaults = _interopRequireDefault(_defaults).default;
var merge = _utils.merge;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var defaults = {
templates: {
handlebars: Handlebars,
helpers: {},
layouts: ['src/layouts/*'],
pages: ['src/pages/**/*'],
partials: ['src/partials/**/*']
}
};
/**
* Merge defaults into passed options
* Merge defaults into options.
* @return {object} merged options
*/
function parseOptions() {
function mergeDefaults() {
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];

@@ -27,3 +38,49 @@

/**
* Map old options object shape onto new shape
* so that we can provide backwards-compatibility with fabricator
* The returned options {object} is of the correct shape to have
* defaults merged into it.
*
* @TODO Eventually, support for fabricator/deprecated things should be
* moved into their own module
* @return {object} User options
*/
function translateOptions() {
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
/* eslint-disable prefer-const */
var handlebars = options.handlebars;
var helpers = options.helpers;
var layouts = options.layouts;
var pages = options.views;
var partials = options.layoutIncludes;
var result = {
templates: {
handlebars: handlebars,
helpers: helpers,
layouts: layouts,
pages: pages,
partials: partials
}
};
return result;
/* eslint-enable prefer-const */
}
var parseOptions = function parseOptions(options) {
return mergeDefaults(translateOptions(options));
};
/**
* Sigh...
* > Single exports and multiple exports are mutually exclusive. You have to use
* > either one the two styles. Some modules combine both styles as follows:
* http://www.2ality.com/2015/12/babel-commonjs.html
*/
parseOptions.translator = translateOptions;
exports.default = parseOptions;
module.exports = exports['default'];

12

dist/parse/layouts.js

@@ -7,10 +7,14 @@ 'use strict';

var _utils = require('../utils');
var _parse = require('../utils/parse');
var utils = _interopRequireWildcard(_utils);
var readFileTree = _parse.readFileTree;
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
/**
* Parse layout files.
* @param {Object} options
* @return {Promise} resolving to layout data
*/
function parseLayouts(options) {
return utils.readFilesKeyed(options.src.layouts, options);
return readFileTree(options.src.layouts, options);
}

@@ -17,0 +21,0 @@

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,13 +6,7 @@ Object.defineProperty(exports, "__esModule", {

});
/**
* Build an object representing the upcoming output tree
* @module parse/tree
*/
var _shared = require('../utils/shared');
var /**
* Build an object representing the upcoming output tree
* @module parse/tree
*/
resourcePath = _shared.resourcePath;
/**

@@ -29,15 +23,10 @@ return {

function walkResources(resources, options, resourceType) {
var resourceTree = arguments.length <= 3 || arguments[3] === undefined ? {} : arguments[3];
var resourceTree = arguments.length <= 3 || arguments[3] === undefined ? [] : arguments[3];
for (var resourceKey in resources) {
if (resources[resourceKey].resourceType && resources[resourceKey].resourceType === resourceType.singular) {
resourceTree.items = resourceTree.items || [];
resourceTree.items.push({
id: resources[resourceKey].id,
key: resourceKey,
path: resourcePath(resources[resourceKey].id, options.dest[resourceType.plural], options)
});
var item = resources[resourceKey];
if (item.resourceType && item.resourceType === resourceType.singular) {
resourceTree.push(item);
} else {
resourceTree.children = resourceTree.children || [];
resourceTree.children.push(walkResources(resources[resourceKey], options, resourceType, resourceTree[resourceKey]));
walkResources(item, options, resourceType, resourceTree);
}

@@ -44,0 +33,0 @@ }

@@ -89,4 +89,5 @@ 'use strict';

function prepareTemplates(opts) {
return Promise.all([prepareHelpers(opts.handlebars, opts.helpers), preparePartials(opts.handlebars, opts.partials)]).then(function (handlebarsInfo) {
return opts.handlebars;
var templateOpts = opts.templates;
return Promise.all([prepareHelpers(templateOpts.handlebars, templateOpts.helpers), preparePartials(templateOpts.handlebars, templateOpts.partials)]).then(function (handlebarsInfo) {
return templateOpts.handlebars;
});

@@ -93,0 +94,0 @@ }

@@ -6,3 +6,3 @@ 'use strict';

});
exports.titleCase = exports.resourceKey = exports.resourceId = exports.relativePathArray = exports.readFilesKeyed = exports.readFiles = exports.parentDirname = exports.matchParser = exports.localDirname = exports.keyname = exports.isGlob = exports.getFiles = exports.getDirs = exports.dirname = exports.deepObj = exports.commonRoot = undefined;
exports.titleCase = exports.readFilesKeyed = exports.readFiles = exports.parentDirname = exports.merge = exports.keyname = exports.isGlob = exports.getFiles = exports.dirname = undefined;

@@ -30,129 +30,19 @@ var _globby = require('globby');

/* Helper functions */
/**
* Return extension-less basename of filepath
* @param {String} filepath
* @example basename('foo/bar/baz.txt'); // -> 'baz'
*/
function basename(filepath) {
var basename = function basename(filepath) {
return path.basename(filepath, path.extname(filepath));
}
/**
* Return normalized (no '..', '.') full dirname of filepath
* @param {String} filepath
* @example dirname('../ding/foo.txt'); // -> '/Users/shiela/ding/'
*/
function dirname(filepath) {
};
var dirname = function dirname(filepath) {
return path.normalize(path.dirname(filepath));
}
/**
* Return the name of this file's directory's immediate parent directory
* @param {String} filepath
* @example basename('foo/bar/baz.txt'); // -> 'bar'
*/
function localDirname(filepath) {
};
var parentDirname = function parentDirname(filepath) {
return dirname(filepath).split(path.sep).pop();
}
/**
* Return the name of this file's directory's immediate parent directory
* @param {String} filepath
* @example basename('foo/bar/baz.txt'); // -> 'foo'
*/
function parentDirname(filepath) {
return dirname(filepath).split(path.sep).slice(-2, -1)[0];
}
/**
* TODO: see https://github.com/cloudfour/drizzle-builder/issues/8
*/
function removeLeadingNumbers(str) {
};
var removeNumbers = function removeNumbers(str) {
return str.replace(/^[0-9|\.\-]+/, '');
}
};
var getFiles = function getFiles(glob) {
return globby(glob, { nodir: true });
};
/**
* Given an array of file objects, take all of their paths and find
* what the common root directory is for all of them.
* @example commonRoot([
* 'foo/bar/baz/ding/dong.html',
* 'foo/bar/baz/huff/dumb.txt',
* 'foo/bar/baz/oleo.html',
* 'foo/bar/baz/one/two.html']); // -> 'foo/bar/baz/'
*
* @param {Array} files File objects. Each should have a `path` property
* @return {String} Common root path
*/
function commonRoot(files) {
var paths = files.map(function (file) {
return file.path;
});
var relativePath = paths.reduce(function (prev, curr) {
prev = prev.split(path.sep);
curr = curr.split(path.sep);
prev = prev.filter(function (prevBit) {
return curr.some(function (currBit) {
return prevBit === currBit;
});
});
return prev.join(path.sep);
});
return relativePath;
}
/**
* Return (creating if necessary) a deep reference to a nested object
* based on path elements. This will mutate `obj` by adding needed properties
* to it. Think of it like mkdir with a multi-directory path that will create
* directory entries if they don't exist.
*
* @param {Array} pathKeys Elements making up the "path" to the reference
* @param {Object} Object to add needed references to
*
* @example deepRef(['foo', 'bar', 'baz'], { foo: {} }); // => foo.bar.baz
*/
function deepObj(pathKeys, obj) {
return pathKeys.reduce(function (prev, curr) {
prev[curr] = prev[curr] || {};
return prev[curr];
}, obj);
}
/**
* Take a given glob and convert it to a glob that will match directories
* (instead of files). Return Promise that resolves to matching dirs.
*
* @example getDirs('foo/bar/baz')
*
* @param {glob} glob to convert to directory glob
* @param {Object} options to pass on to getFiles/globby
* @return {Promise} resolving to glob matches
*/
function getDirs(glob) {
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
var opts = Object.assign({
nodir: false
}, options);
var dirGlob = typeof glob === 'string' ? Array.of(glob) : glob;
return getFiles(dirGlob.map(function (dirEntry) {
return path.dirname(dirEntry) + '/*/';
}), opts);
}
/**
* @param {glob} glob
* @return {Promise} resolving to {Array} of files matching glob
*/
function getFiles(glob) {
var globOpts = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
var opts = Object.assign({
nodir: true
}, globOpts);
return globby(glob, opts);
}
/**
* Utility function to test if a value COULD be a glob. A single string or

@@ -178,85 +68,15 @@ * an Array of strings counts. Just because this returns true, however,

/**
* Utility function to provide a consistent "key" for elements, materials,
* partials, etc, based on a filepath:
* - replace whitespace characters with `-`
* - use only the basename, no extension
* - unless stripNumbers option false, remove numbers from the string as well
*
* @param {String} str filepath
* @param {Object} options
* @return {String}
* Take a glob; read the files. Return a Promise that ultimately resolves
* to an Array of objects:
* [{ path: original filepath,
* contents: utf-8 file contents}...]
*/
function keyname(str) {
var _ref = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
var _ref$stripNumbers = _ref.stripNumbers;
var stripNumbers = _ref$stripNumbers === undefined ? true : _ref$stripNumbers;
var name = basename(str).replace(/\s/g, '-');
return stripNumbers ? removeLeadingNumbers(name) : name;
}
/**
* Retrieve the correct parsing function for a file based on its
* path. Each parser with a `pattern` property will compile that pattern
* to a RegExp and test it against the filepath. If no match is found
* against any of the parsers by path pattern, a default parser will be
* returned: either a parser keyed by `default` in the `parsers` object
* or, lacking that, a default function that leaves the contents of the
* file untouched.
*
* @param {String} filepath
* @param {Object} parsers
* @see options module
* @return {Function} applicable parsing function for file contents
*/
function matchParser(filepath) {
var parsers = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
for (var parserKey in parsers) {
if (parsers[parserKey].pattern) {
if (new RegExp(parsers[parserKey].pattern).test(filepath)) {
return parsers[parserKey].parseFn;
}
}
}
return parsers.default && parsers.default.parseFn || function (contents, filepath) {
return { contents: contents };
};
}
/**
* Take a glob; read the files, optionally running a `contentFn` over
* the contents of the file.
*
* @param {glob} glob of files to read
* @param {Object} Options:
* - {Object} available parsers
* - {String} encoding
* - {Object} globOpts gets passed to getFiles
* @return {Promise} resolving to Array of Objects:
* - {String} path
* - {String || Mixed} contents: contents of file after contentFn
*/
function readFiles(glob) {
var _ref2 = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
var _ref2$parsers = _ref2.parsers;
var parsers = _ref2$parsers === undefined ? {} : _ref2$parsers;
var _ref2$encoding = _ref2.encoding;
var encoding = _ref2$encoding === undefined ? 'utf-8' : _ref2$encoding;
var _ref2$globOpts = _ref2.globOpts;
var globOpts = _ref2$globOpts === undefined ? {} : _ref2$globOpts;
return getFiles(glob, globOpts).then(function (paths) {
return Promise.all(paths.map(function (filepath) {
return readFile(filepath, encoding).then(function (fileData) {
var parser = matchParser(filepath, parsers);
fileData = parser(fileData, filepath);
if (typeof fileData === 'string') {
fileData = { contents: fileData };
}
return Object.assign(fileData, { path: filepath });
return getFiles(glob).then(function (paths) {
var fileReadPromises = paths.map(function (path) {
return readFile(path, 'utf-8').then(function (contents) {
return { path: path, contents: contents };
});
}));
});
return Promise.all(fileReadPromises);
});

@@ -269,20 +89,9 @@ }

* single object; each file's contents is keyed by its filename run
* through optional `keyFn(filePath, options)`` (default: keyname).
* Will pass other options on to readFiles and keyFn
* through keyname().
*
* @param {glob}
* @param {Object} options (all optional):
* - keyFn
* - contentFn
* - stripNumbers
* @return {Promise} resolving to {Object} of keyed file contents
*/
function readFilesKeyed(glob) {
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
var _options$keyFn = options.keyFn;
var keyFn = _options$keyFn === undefined ? function (path, options) {
return keyname(path, options);
} : _options$keyFn;
var preserveNumbers = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1];
return readFiles(glob, options).then(function (allFileData) {
return readFiles(glob).then(function (allFileData) {
var keyedFileData = new Object();

@@ -297,3 +106,3 @@ var _iteratorNormalCompletion = true;

keyedFileData[keyFn(aFile.path, options)] = aFile;
keyedFileData[keyname(aFile.path, preserveNumbers)] = aFile.contents;
}

@@ -320,50 +129,20 @@ } catch (err) {

/**
* Given a file's path and a string representing a directory name,
* return an Array that only contains directories at or beneath that
* directory.
* Utility function to provide a consistent "key" for elements, materials,
* partials, etc, based on a filepath:
* - replace whitespace characters with `-`
* - use only the basename, no extension
* - unless preserveNumbers, remove numbers from the string as well
*
* @example relativePathArray('/foo/bar/baz/ding/dong/tink.txt', 'baz')
* // -> ['baz', 'ding', 'dong']
* @param {String} filePath
* @param {String} fromPath
* @return {Array}
* @param {String} str filepath
* @param {Boolean} preserveNumbers
* @return {String}
*/
function relativePathArray(filePath, fromPath) {
var keys = path.relative(fromPath, path.dirname(filePath));
if (keys && keys.length) {
return keys.split(path.sep);
}
return [];
}
function keyname(str) {
var preserveNumbers = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1];
/**
* Generate a resourceId for a file. Use file.path and base the
* ID elements on the path elements between relativeRoot and file. Path
* elements will have special characters removed.
* @example resourceId(
* '/foo/bar/baz/ole/01-fun-times.hbs', '/foo/bar/baz/', 'patterns'
* ); // -> patterns.ole.fun-times
* @param {Object} Object representing file. Needs to have a `path` property
* @param {String} || {Array} relativeRoot path to relative root or path
* elements to same in Array
* @param {String} resourceCollection Will be prepended as first element in ID
* @return {String} ID for this resource
*/
function resourceId(resourceFile, relativeRoot, resourceCollection) {
var pathKeys = relativePathArray(resourceFile.path, relativeRoot).map(keyname);
return [resourceCollection].concat(pathKeys).concat([keyname(resourceFile.path)]).join('.');
var name = basename(str).replace(/\s/g, '-');
return preserveNumbers ? name : removeNumbers(name);
}
/**
* Convenience function to create proper variant of file's basename for
* use as a key in a data object.
* @example resourceKey({ path: '/foo/bar/baz/04-fun' }); // -> '04-fun'
* @param {Object} resourceFile Object representing a file. Needs `path` prop
* @return {String}
*/
function resourceKey(resourceFile) {
return keyname(resourceFile.path, { stripNumbers: false });
}
/**
* Convert str to title case (every word will be capitalized)

@@ -379,17 +158,30 @@ * @param {String} str

exports.commonRoot = commonRoot;
exports.deepObj = deepObj;
/**
* Perform a deep merge of two objects.
* @param {Object} target
* @param {Object} source
* @return {Object}
* @example merge(defaults, options);
*/
function merge(target, source) {
Object.keys(source).forEach(function (key) {
if (Object.isExtensible(source[key])) {
merge(target[key], source[key]);
} else {
if (typeof source[key] !== 'undefined') {
target[key] = source[key];
}
}
});
return target;
}
exports.dirname = dirname;
exports.getDirs = getDirs;
exports.getFiles = getFiles;
exports.isGlob = isGlob;
exports.keyname = keyname;
exports.localDirname = localDirname;
exports.matchParser = matchParser;
exports.merge = merge;
exports.parentDirname = parentDirname;
exports.readFiles = readFiles;
exports.readFilesKeyed = readFilesKeyed;
exports.relativePathArray = relativePathArray;
exports.resourceId = resourceId;
exports.resourceKey = resourceKey;
exports.titleCase = titleCase;

@@ -6,3 +6,3 @@ 'use strict';

});
exports.splitPath = exports.resourceKey = exports.resourceId = exports.keyname = exports.flattenById = exports.deepPattern = exports.deepObj = exports.deepCollection = undefined;
exports.isPathChild = exports.normalizePath = exports.splitPath = exports.resourceKey = exports.resourceId = exports.keyname = exports.flattenById = exports.deepPattern = exports.deepObj = exports.deepCollection = undefined;

@@ -25,4 +25,11 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };

var _path = require('path');
var join = _path.join;
var relative = _path.relative;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
/**

@@ -170,2 +177,35 @@ * Return a reference to the deeply-nested object indicated by the items

/**
* Normalize a sloppy (or dot-separated) path into a "valid" path.
*
* @param {String} path
* A raw input path string.
*
* @return {String}
* A normalized path string.
*
* @example
* normalizePath('foo/bar//baz.bang.1./');
* // 'foo/bar/baz/bang/1'
*/
function normalizePath(path) {
return join.apply(undefined, _toConsumableArray(splitPath(path)));
}
/**
* Check if one path is a direct child of another.
*
* @param {String} pathA
* @param {String} pathB
* @return {Boolean}
*
* @example
* isPathChild('components/button', 'components');
* // true
*/
function isPathChild(pathA, pathB) {
var relPath = relative(normalizePath(pathA), normalizePath(pathB));
return relPath === '..';
}
exports.deepCollection = deepCollection;

@@ -184,2 +224,4 @@ exports. // object

exports. // object
splitPath = splitPath;
splitPath = splitPath;
exports.normalizePath = normalizePath;
exports.isPathChild = isPathChild;
{
"name": "drizzle-builder",
"version": "0.0.5",
"version": "0.0.6",
"description": "The builder for Drizzle",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc