npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

opendatalayer-builder

v0.0.4

Published

Buildtool for the opendatalayer

Downloads

11

Readme

Please note that this project is still in the process of being prepared and polished to become a standalone tool and project. Any documentation might be incomplete and/or misleading. So no complains, you've been warned ;-) ..

Build Status

OpenDataLayer Builder

The ODL builder generates a bundled "package" with the OpenDataLayer framework, combined with your configured plugins and their required initialization code. The resulting file can be directly included in your web project and offers all the benefits of the ODL right out-of-the-box. No further setup or manual intervention required.

Usage

Preparation

Install the OpenDataLayer and OpenDataLayer Builder modules from npm, together with any ODL plugins you want to use in your project:

npm install opendatalayer opendatalayer-builder --save-dev
npm install opendatalayer-plugin-example --save-dev

Simple example

In your project's buildfile you import and call ODL builder to create your package. The builder offers a bundle method which takes a configuration object to set up ODL and control name and target of the resulting file.

A very simple build script could look like this:.

import odlBuilder from 'opendatalayer-builder';

odlBuilder
  .bundle({
    outputPath: 'build',
    outputFilename: 'odl-bundle-test.js',
    // This block defines the plugins to be included in the package, together with
    // their configuration and the respective deployment rules. A rule defines the
    // circumstances und which the plugin will be activated (i.e. receive data)
    // during runtime.
    plugins: {
      'opendatalayer-plugin-example': {
        config: { someValue: 'FOO-BAR-123' },
        rule: function (data) {
          return data.page.type === 'homepage'; // only activate on pages with type "homepage"
        },
      },
    },
  })
  .catch(err => console.error(err));

Separating the ODL configuration

Another, more scalable approach is to completely separate your OpenDataLayer configuration into a dedicated file. This results in much better separation of concerns and doesn't mix up your ODL configuration with your project build settings.

For this you simply create a dedicated file named opendatalayer.config.js, include odlBuilder and add a call to the configure method, passing your usual configuration as you would when using bundle:

import odlBuilder from 'opendatalayer-builder';

odlBuilder.configure({
  outputPath: 'build',
  outputFilename: 'odl-bundle.max.js',
  plugins: {
    'opendatalayer-plugin-example': {
      config: {
        fooBar: 'FOO-BAR-123',
      },
      rule: (data) => (data.page.type === 'homepage'),
    },
  },
  debug: true,
});

Then, in your buildfile, you can simply include the configuration and call bundle without further options. Here is an example using gulp, which plays nicely together since bundle returns a Promise object which gulp can handle.

import odlBuilder from 'opendatalayer-builder';
import './opendatalayer.config.js';

gulp.task('opendatalayer', () => odlBuilder.bundle());

API

The opendatalayer-builder module provides the following public methods:

configure([config])

Pass the given configuration to the ODL builder. Read more about plugin configuration and options in the Configuration section.

bundle([config]) -> Promise

Build the ODL package based on the provided configuration (or any config passed to configure). Returns a Promise object which gets passed an error object when rejected.

Concepts

Behind the scenens the ODL Builder generates a piece of bootstrapping code and uses browserify to bundle it together with the ODL core library and all configured plugins. The bootstrapping code is a rather simple, ES5-compliant piece of Javascript that joins all the other parts together.

The following, commented example snippet demonstrates the bootstrapping code:

// load ODL library
var _odl = require("opendatalayer").odl;

// load standalone plugin
var opendatalayer_plugin_example = require("opendatalayer-plugin-example").default;
console.log("Plugin: opendatalayer-plugin-example", opendatalayer_plugin_example);

// load  set of local plugins
var ___node_modules_opendatalayer_plugins_kaufhof_dist_trbo = require("../node_modules/opendatalayer-plugins-kaufhof/dist/trbo").default;
console.log("Plugin: ../node_modules/opendatalayer-plugins-kaufhof/dist/trbo", ___node_modules_opendatalayer_plugins_kaufhof_dist_trbo);

// generate plugin configuration (as taken from config provided in builder)
var ODL_CONFIG = {
 "opendatalayer-plugin-example": {"fooBar":"FOO-BAR-123"},
 "../node_modules/opendatalayer-plugins-kaufhof/dist/trbo": {"scriptUrl":"..."},
};

// generate rules setup (as taken from config provided in builder)
var ODL_RULES = {
 "opendatalayer-plugin-example": function rule(data) {
        return data.page.type === 'homepage';
      },
 "../node_modules/opendatalayer-plugins-kaufhof/dist/trbo": function rule(data) {
        return true;
      },
};

// generate plugin references (used to look up constructor based on id)
var ODL_MAPPINGS = {
 "opendatalayer-plugin-example": opendatalayer_plugin_example,
 "../node_modules/opendatalayer-plugins-kaufhof/dist/trbo": ___node_modules_opendatalayer_plugins_kaufhof_dist_trbo,
};

// perform initialization (including an example of the onBeforeInitialization callback)
var ODL_DATA = {};
(function (odl, data, done) {
  // START: onBeforeInitialization callback
  window.require(['gk/lib/mediaQuery'], function (mq) {
    data.kaufhof = {
      breakpoint: mq.currentRange
    };
    done();
  });
// END: onBeforeInitialization callback
}(_odl, ODL_DATA, function () {
  _odl.initialize(ODL_DATA, ODL_RULES, ODL_CONFIG, {}, ODL_MAPPINGS);
}));