Giter Club home page Giter Club logo

babel-plugin-add-shopify-header's Introduction

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:

  • 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.

babel-plugin-add-shopify-header's People

Contributors

mikkoh avatar minasmart avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

babel-plugin-add-shopify-header's Issues

no git repository found

add-shopify-header seems to be throwing an error for me. The git repository can't be found.

Log

Error: src/index.js: [git-rev-sync] no git repository found
    at _getGitDirectory (/Users/ryanmacdonald/Shopify/node-themekit/node_modules/git-rev-sync/index.js:46:11)
    at _getGitDirectory (/Users/ryanmacdonald/Shopify/node-themekit/node_modules/git-rev-sync/index.js:57:10)
    at _getGitDirectory (/Users/ryanmacdonald/Shopify/node-themekit/node_modules/git-rev-sync/index.js:57:10)
    at _getGitDirectory (/Users/ryanmacdonald/Shopify/node-themekit/node_modules/git-rev-sync/index.js:57:10)
    at _getGitDirectory (/Users/ryanmacdonald/Shopify/node-themekit/node_modules/git-rev-sync/index.js:57:10)
    at branch (/Users/ryanmacdonald/Shopify/node-themekit/node_modules/git-rev-sync/index.js:61:16)
    at long (/Users/ryanmacdonald/Shopify/node-themekit/node_modules/git-rev-sync/index.js:74:11)
    at Object.short (/Users/ryanmacdonald/Shopify/node-themekit/node_modules/git-rev-sync/index.js:102:10)
    at exports.default.opts (/Users/ryanmacdonald/Shopify/node-themekit/node_modules/get-project-version/lib/index.js:42:57)
    at exports.default (/Users/ryanmacdonald/Shopify/node-themekit/node_modules/babel-plugin-add-shopify-header/lib/get-default-header.js:33:47)

npm WARN [email protected] requires a peer of [email protected] but none was installed.
npm ERR! Darwin 15.6.0
npm ERR! argv "/Users/ryanmacdonald/.nvm/versions/node/v6.5.0/bin/node" "/Users/ryanmacdonald/.nvm/versions/node/v6.5.0/bin/npm" "install"
npm ERR! node v6.5.0
npm ERR! npm  v3.10.3
npm ERR! code ELIFECYCLE
npm ERR! [email protected] prepublish: `babel -d lib/ src/`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] prepublish script 'babel -d lib/ src/'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the node-themekit package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     babel -d lib/ src/
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs node-themekit
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls node-themekit
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/ryanmacdonald/Shopify/node-themekit/npm-debug.log
Error: npm i exited with non-zero code 1. Please try running "npm i" again as administrator.
    at ChildProcess.<anonymous> (/Users/ryanmacdonald/Shopify/shopify-module-generator/node_modules/nyg/lib/npm.js:9:31)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)
    at maybeClose (internal/child_process.js:877:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)

Make repo public

@Shopify/javascript wondering if you guys could take a look at this module. The idea is to have a babel plugin that standardizes a "comment header" across projects. Just setup the plugin and don't think about it after that.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.