Shopify / babel-plugin-add-shopify-header

MIT License
4 stars 7 forks source link

Travis

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:

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:

License

MIT, see LICENSE.md for details.