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

babel-plugin-add-shopify-header

v1.0.6

Published

This plugin will add a standardized Shopify comment header to transpiled files

Downloads

57

Readme

babel-plugin-add-shopify-header

This plugin will add a standardized Shopify comment header to transpiled files. Since transpiling via Babel is becoming one of the last steps of the build process it's handy to add some tooling around this final step.

A standard Shopify Comment Header contains:

  • The license of the repo
  • Current version number derived from git tag or from package.json version and last git commit

Example header:

/**
* The MIT License (MIT)
* Copyright (c) 2016 Shopify Inc.
* 
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* 
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* 
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
* OR OTHER DEALINGS IN THE SOFTWARE.
* 
* 
* Version: 1.0.0 Commit: 2b93ca3
**/

This plugin is built ontop of babel-plugin-add-header-comment.

Installation

$ npm install babel-plugin-add-shopify-header

Example

Simple Example

The following is an example .babelrc file using this plugin:

{
  "plugins": [
    "add-shopify-header"
  ]
}

The above is useful when you just simply want to bundle one file and want to add the default Shopify header comment to that file.

Header Per File

If you are transpiling an entire folder and only want to add the comment header to one file (for instance src/shopify.js) do the following:

{
  "plugins": [
    ["add-shopify-header", {
      "files": [ "src/shopify.js" ]
    }]
  ]
}

Adding To Default Header

If you'd like to add to the default header you can do the following:

{
  "plugins": [
    ["add-shopify-header", {
      "header": [ "This will be added under the default Shopify header" ]
    }]
  ]
}

Adding To Default Header Per File

The following will add to the default header on a per file basis

{
  "plugins": [
    "files":
    ["add-shopify-header", {
      "files": {
        "src/shopify.js": {
          "header": [
            "This is added below the default header only for src/shopify.js"
          ]
        }
      }
    }]
  ]
}

Adding To Default Header From The Contents Of Another File

The following will show how to include the contents of the file readFromThisFile.txt under the default header. The ? charachter denotes that the path following should be read in and added to the header.

{
  "plugins": [
    ["add-shopify-header", {
      "header": [ "?readFromThisFile.txt" ]
    }]
  ]
}

Adding To Default Header From A Script Execution

Lets say you had a Node script getAdditionalContent.js that produces output you'd like to add to the header you can do the following. The ! denotes that the following script should be executed:

{
  "plugins": [
    ["add-shopify-header", {
      "header": [ "!node getAdditionalContent.js" ]
    }]
  ]
}

Options

The following are options you can pass this Babel plugin. All options are optional:

  • cwd - A String which is a path to the directory that contains a LICENSE.md file and a package.json file for your project. By default process.cwd() will be used.
  • header - An Array of strings which get appended to the standard header. This array can also contain strings starting with '!' or '?' which mean the string will not be appended but instead the string will be executed as a shell command (eg '!node someScript.js') or the path will be read in (?readInThisFile.md)
  • files - An Array or Object that defines which files will receive the comment header. If the header does not need to be customized just pass in array of paths (eg. "files": ["src/index.js", "src/index.polyfilled.js"]) or if you need to customize the header per file pass in an Object which defines customized headers (eg. "files": { "src/index.js": { 'A LINE ADDED TO HEADER'}})

License

MIT, see LICENSE.md for details.