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

fabricator-dna

v1.0.7

Published

Fabricator module that creates a dependency tracker.

Downloads

2

Readme

Fabricator DNA

Fabricator module that creates a dependency tracker within the notes section of each material.

alt text

Installation

npm install fabricator-dna --save-dev

Adding to Fabricator

Open the Fabricator gulp.js file and include the module.

const dna = require('fabricator-dna');

Add the helpers to your config object.

config = {
    helpers: {
      "dependencies": dna.dependencies,
      "dependents" : dna.dependents,
      "hasDependencies": dna.hasDependencies,
      "hasDependents": dna.hasDependents
    }
}

Exclude the dependencies.json file from the config.templates.watch array. This will ensure that changes to the file will not trigger a rebuild and recursive loop.

config = {
    templates: {
        watch: ['src/**/*.{html,md,json,yml}', '!src/data/dependencies.json'],
    }
}

Add the helpers to the assembler gulp task. * Note: You will use the config.helpers object here.

gulp.task('assembler', (done) => {
  assembler({
    logErrors: config.dev,
    dest: config.dest,
    helpers: config.helpers
  });
  done();
});

Create the dna gulp task. If you've changed the location of your data, materials, or views, you will want to reflect that in the dna.scan() parameters.

gulp.task('dna', (done) => {
  dna.scan({
    dna: 'src/data/dependencies.json',
    materials: ['src/materials/**/*'],
    views: ['src/views/**/*', '!src/views/+(layouts)/**']
  });

  done();
});

Add the dna gulp task to the assemble:watch task. * Note: In order for the task to accurately generate the dependencies, put the dna task before the assembler task.

gulp.task('assembler:watch', ['dna', 'assembler'], browserSync.reload);

Adding to the Toolkit

Update ~/src/views/layouts/includes/f-item-contents.html with the following:

<div class="f-item-notes" data-f-toggle="notes">
  {{#if notes}}
	<h3>Notes</h3>
  {{{notes}}}
  {{/if}}

  {{#if this.data.dna}}
  <div class="f-item-dependencies">
    {{#hasDependents this.data.dna @root.dependencies.helix}}
    <div class="f-item-column">
      <strong>Dependents</strong>
      <table class="table">
        <thead>
          <tr>
            <th style="width: 60%;">Files</th>
            <th>Selectors</th>
            <th style="width: 40px;"></th>
          </tr>
        </thead>
        <tbody>
          {{#dependents this.data.dna @root.dependencies.helix}}
          <tr>
            <td>
              <a href="{{baseurl}}{{this.link}}" title="{{baseurl}}{{this.link}}">{{this.file}}</a>
            </td>
            <td>
              {{#each this.selectors}}
              <div>{{this}}</div>
              {{/each}}
            </td>
            <td>
              <span class="badge badge-default">{{this.count}}</span>
            </td>
          </tr>
          {{/dependents}}
        </tbody>
      </table>
    </div>
    {{/hasDependents}}
    {{#hasDependencies this.data.dna @root.dependencies.helix}}
    <div class="f-item-column">
      <strong>Dependencies</strong>
      <table class="table">
        <thead>
          <tr>
            <th style="width: 60%;">Files</th>
            <th>Selectors</th>
            <th style="width: 40px;"></th>
          </tr>
        </thead>
        <tbody>
          {{#dependencies this.data.dna @root.dependencies.helix}}
          <tr>
            <td>
              <a href="{{baseurl}}{{this.link}}" title="{{baseurl}}{{this.link}}">{{this.file}}</a>
            </td>
            <td>
              {{#each this.selectors}}
              <div>{{this}}</div>
              {{/each}}
            </td>
            <td>
              <span class="badge badge-default">{{this.count}}</span>
            </td>
          </tr>
          {{/dependencies}}
        </tbody>
      </table>
    </div>
    {{/hasDependencies}}
  </div>
  {{/if}}
</div>

<div class="f-item-preview" id="preview-{{@key}}">
	{{{material @key @root}}}
</div>
<div class="f-item-code f-item-hidden" data-f-toggle="code">
	<pre><code class="language-markup">{{material @key @root}}</code></pre>
</div>

Usage

Within your partials you will need to add the following front-matter:

{
  "dna": [
    "btn", "btn-primary", "btn-secondary", "btn-success", "btn-info", "btn-warning",
    "btn-outline-primary", "btn-outline-secondary", "btn-outline-success", "btn-outline-info", "btn-outline-warning"
  ]
}

The first element in the dna array is the ID of the partial and must be unique. The other values are css selectors that relate to the partial. Optionally you can just specify a string:

{
  "dna": "btn"
}

Within your HTML you will need to apply the data-dna attribute. The value of the attribute should be the same as the dna ID.

<button type="button" class="btn btn-primary" data-dna="btn">Primary</button>

As you use the partial through out your toolkit, be sure to include the data-dna attribute. When the dna.scan() function executes, it will add any file containing data-dna="btn" or id="btn" to the dependents list.

Knowing that this could be a bit of work in exsisting projects, if you specify class selectors in the dna front-matter array, the dna.scan() function will add any file containing any of the specified classes to the dependents list. For instance if you specified class="btn-primary" anywhere in your toolkit, that file would then be added to the dependents list.