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

karmeneo

v0.3.0

Published

Karmeneo creates a RequireJS configuration of the Akeneo requirejs.yml files for running tests with Karma

Downloads

3

Readme

Karmeneo

Karmeneo creates a RequireJS configuration of the Akeneo requirejs.yml files for running tests with Karma.

This is a WIP / PoC project. Use it on your own responsibility. It was tested on Akeneo 3.2.

Why using this?

Creating RequireJS tests for Akeneo with karma are a mess when it comes to add all files to the RequireJS config. Akeneo is using a bundle that enables the user to add new RequireJS files and templates with YAML. To prevent changes in Akeneo AND your test config, Karmeneo will read the config files and create a new RequireJS config with the new changes of the packages automatically and reduces error sources and impediments during development.

Installation

yarn add --dev karmeneo

How does it work?

Currently the Akeneo requirejs.yml configs are going to be created when you run your tests with karma. A file will be created that contains the RequireJS config for your tests.

const requireJsWriter = require('karmeneo');

requireJsWriter.createRequireJsConfig('./tests/requirejs.config.js');

// Karma configuration
module.exports = function(config) {
  config.set({

    basePath: '',

    frameworks: ['jasmine', 'requirejs'],

    files: [
      { pattern: 'web/bundles/**/*.js', included: false },
      { pattern: 'tests/lib/**/*.js', included: false },

      // Add the created RequireJS config to Karma
      'tests/requirejs.config.js',
    ],

Use require to load Karmeneo and run the function createRequireJsConfig at the top of your karma.conf.js. The argument of the function is the name and relative path where the RequireJS config has to be saved. A new config file won't be generated if a file with that name exists.

Be sure to have added web/bundles to the pattern like in the example, because Karmeneo is using the path to the files there.

Additional packages

Not every RequireJS package is configured with Akeneo. But every other package can be added in the configuration with additionalLibs:

const requireJsWriter = require('karmeneo');

const config = {
  additionalLibs: {
    'underscore': '../node_modules/underscore/underscore',
    'backbone': '../node_modules/backbone/backbone',
    'jquery': '../node_modules/jquery/dist/jquery',
  }
};

requireJsWriter.createRequireJsConfig('./tests/requirejs.config.js', config);

// Karma configuration
module.exports = function(config) {
  config.set({

    basePath: '',

    frameworks: ['jasmine', 'requirejs'],

    files: [
      { pattern: 'web/bundles/**/*.js', included: false },
      { pattern: 'web/bundles/**/*.html', included: false },
      { pattern: 'tests/lib/**/*.js', included: false },
      { pattern: 'node_modules/*/*.js', included: false },
      { pattern: 'node_modules/jquery/dist/jquery.js', included: false },

      // Add the created RequireJS config to Karma
      'tests/requirejs.config.js',
    ],

Use in Akeneo 4

Akeneo 4 introduces the changed directory structure of Symfony where the web-directory became public. You can use the configuration key isAkeneo4 and set it to true in that case:

const requireJsWriter = require('karmeneo');

const config = {
  isAkeneo4: true
};

requireJsWriter.createRequireJsConfig('./tests/requirejs.config.js', config);

// Karma configuration
module.exports = function(config) {
  config.set({

Custom RequireJS config template

If the default config template file config.temp doesn't fit to your needs, you can create your own config template and add the relative path to the configuration with template:

const requireJsWriter = require('karmeneo');

const config = {
  template: './tests/my-template.js'
};

requireJsWriter.createRequireJsConfig('./tests/requirejs.config.js', config);

// Karma configuration
module.exports = function(config) {
  config.set({

    basePath: '',

    frameworks: ['jasmine', 'requirejs'],

    files: [
      { pattern: 'web/bundles/**/*.js', included: false },
      { pattern: 'web/bundles/**/*.html', included: false },
      { pattern: 'tests/lib/**/*.js', included: false },
      { pattern: 'node_modules/*/*.js', included: false },
      { pattern: 'node_modules/jquery/dist/jquery.js', included: false },
    
      // Add the created RequireJS config to Karma
      'tests/requirejs.config.js',
    ],

In the example the custom template's file name is ./tests/my-template.js that is relative to the project where you're executing the tests. lodash is used for the templating and has available variables for the packages that you'll have to use in your template:

requirejsFiles

The fetched file paths and ids of Akeneo and your custom ones as the AMD of RequireJS needs.

requirejs.config({

    paths: <%= requirejsFiles %>,

htmlAliasForText

Aliases used in map to handle Akeneo's HTML templates with the text! plugin.

    map: {
        '*': <%= htmlAliasForText %>,
    },