Skip to content

Commit

Permalink
feat: Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrsteele committed Aug 3, 2016
1 parent 9068003 commit 8be89e5
Show file tree
Hide file tree
Showing 10 changed files with 245 additions and 11 deletions.
13 changes: 2 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,18 @@ pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
docs

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
dist

# Dependency directories
node_modules
jspm_packages

# Optional npm cache directory
.npm
Expand Down
27 changes: 27 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
sudo: false
language: node_js
cache:
directories:
- node_modules
notifications:
email: false
node_js:
- '5'
- '4'
- iojs-v3
- iojs-v2
- '0.12'
before_install:
- npm i -g npm@^2.0.0
before_script:
- npm prune
script:
- npm run travis
after_success:
- 'curl -Lo travis_after_all.py https://git.io/travis_after_all'
- python travis_after_all.py
- export $(cat .to_export_back) &> /dev/null
- npm run semantic-release
branches:
except:
- /^v\d+\.\d+\.\d+$/
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# dotenv-webpack

A simple webpack plugin to support dotenv.

### Status

[![npm](https://img.shields.io/npm/v/dotenv-webpack.svg?maxAge=0&style=flat)](https://www.npmjs.com/package/dotenv-webpack)
[![Travis](https://travis-ci.org/mrsteele/dotenv-webpack.svg?branch=master)](https://travis-ci.org/mrsteele/dotenv-webpack)
[![Coverage Status](https://coveralls.io/repos/github/mrsteele/dotenv-webpack/badge.svg?branch=master)](https://coveralls.io/github/mrsteele/dotenv-webpack?branch=master)
[![Dependency Status](https://david-dm.org/mrsteele/dotenv-webpack.svg)](https://david-dm.org/mrsteele/dotenv-webpack)
[![devDependency Status](https://david-dm.org/mrsteele/dotenv-webpack/dev-status.svg)](https://david-dm.org/mrsteele/dotenv-webpack#info=devDependencies)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
[![npm](https://img.shields.io/npm/l/dotenv-webpack.svg?maxAge=0&style=flat)](https://raw.githubusercontent.com/mrsteele/dotenv-webpack/master/LICENSE)
[![pull requests](https://img.shields.io/badge/pull%20requests-accepting-brightgreen.svg?style=flat)](https://github.com/mrsteele/dotenv-webpack/fork)

### Installation

Include the package locally in your repository.

`npm install dotenv-webpack --save`

### Basic Usage

The plugin can be installed with little-to-no configuration needed.

```javascript
// webpack.config.js
const Dotenv = require('dotenv-webpack');

module.exports = {
...
plugins: [
new Dotenv({
path: './.env' // can be ommitted as this is the default
})
]
...
};
```

### LICENSE

MIT
3 changes: 3 additions & 0 deletions browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var plugin = require('./dist').default

module.exports = plugin
23 changes: 23 additions & 0 deletions conf/doc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"tags": {
"allowUnknownTags": true
},
"source": {
"include": [
"./src/"
],
"excludePattern": "(^|\\/|\\\\)_"
},
"opts": {
"encoding": "utf8",
"recurse": true,
"private": false,
"destination": "./docs",
"readme": "./README.md",
"package": "./package.json",
"tutorials": "./tutorials"
},
"plugins": [
"plugins/markdown"
]
}
16 changes: 16 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict'

let plugin
try {
plugin = require('./dist').default
} catch (err) {
if (err.code === 'MODULE_NOT_FOUND') {
require('babel-register')
plugin = require('./src').default
} else {
console.log(err)
process.exit(1)
}
}

module.exports = plugin
87 changes: 87 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{
"name": "dotenv-webpack",
"description": "A simple webpack plugin to support dotenv.",
"version": "0.0.0-semantically-released",
"main": "index.js",
"scripts": {
"precommit": "npm run standard && npm run build && npm run cover",
"commit": "git-cz",
"standard": "standard",
"predoc": "rimraf docs",
"doc": "jsdoc -c doc.json",
"cover": "nyc npm t && npm run coverage-report",
"coverage-check": "nyc check-coverage --branches 0 --statements 0 --functions 0 --lines 0",
"coverage-report": "nyc report --reporter=lcov",
"test": "_mocha --compilers js:babel-register",
"prebuild": "rimraf dist",
"build": "babel --copy-files --out-dir dist src",
"coveralls": "nyc report --reporter=text-lcov | coveralls",
"travis": "npm run precommit && npm run coveralls && npm run coverage-check",
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
},
"repository": {
"type": "git",
"url": "https://github.com/mrsteele/dotenv-webpack.git"
},
"keywords": [
"dotenv",
"webpack",
"plugin"
],
"author": "Matt Steele <[email protected]> (http://omnionline.us/)",
"license": "MIT",
"bugs": {
"url": "https://github.com/mrsteele/dotenv-webpack/issues"
},
"homepage": "https://github.com/mrsteele/dotenv-webpack#readme",
"dependencies": {
"dotenv-safe": "^2.3.1",
"webpack": "^1.13.0"
},
"devDependencies": {
"babel-cli": "^6.10.1",
"babel-eslint": "^6.1.0",
"babel-plugin-transform-object-assign": "^6.8.0",
"babel-preset-es2015": "^6.9.0",
"babel-register": "^6.9.0",
"chai": "^3.5.0",
"chai-subset": "^1.2.2",
"commitizen": "^2.8.2",
"coveralls": "^2.11.9",
"cz-conventional-changelog": "^1.1.6",
"jsdoc": "^3.4.0",
"mocha": "^2.5.3",
"mocha-lcov-reporter": "^1.2.0",
"nyc": "^6.6.1",
"rimraf": "^2.5.2",
"semantic-release": "^4.3.5",
"standard": "^7.1.2"
},
"files": [
"dist",
"browser.js",
"README.md"
],
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
},
"standard": {
"parser": "babel-eslint"
},
"browser": "./browser.js",
"babel": {
"presets": [
"es2015"
],
"plugins": [
"transform-object-assign"
]
},
"nyc": {
"include": [
"src/**/*.js"
]
}
}
29 changes: 29 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import dotenv from 'dotenv-safe'
import fs from 'fs'
import { DefinePlugin } from 'webpack'

class Dotenv {
constructor (options) {
options = options || {}
if (!options.path) options.path = './.env'

dotenv.config(options)
this.env = {}

try {
this.env = dotenv.parse(fs.readFileSync(options.path))
} catch (err) {}
}

apply (compiler) {
const plugin = Object.keys(this.example).reduce((definitions, key) => {
const value = process.env[key] || this.env[key]
definitions[`process.env.${key}`] = JSON.stringify(value)
return definitions
}, {})

compiler.apply(new DefinePlugin(plugin))
}
}

export default Dotenv
11 changes: 11 additions & 0 deletions test/main.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* global describe, it */

// Tests suite
import chai from 'chai'
chai.should()

describe('The tests', () => {
it('Should be able to run tests.', () => {
true.should.be.true
})
})
4 changes: 4 additions & 0 deletions test/mocha.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
--require chai
--reporter spec
--ui bdd
--recursive

0 comments on commit 8be89e5

Please sign in to comment.