12g-env-template
Advanced tools
Comparing version 1.0.3 to 1.0.4
{ | ||
"name": "12g-env-template", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "Create a .env template / example file based on a local .env", | ||
@@ -25,3 +25,7 @@ "main": "template.js", | ||
}, | ||
"homepage": "https://github.com/grrr-amsterdam/12g-env-template#readme" | ||
"homepage": "https://github.com/grrr-amsterdam/12g-env-template#readme", | ||
"dependencies": { | ||
"fs-extra": "^3.0.1", | ||
"mocha": "^3.4.2" | ||
} | ||
} |
# 12g-env-template | ||
[![Greenkeeper badge](https://badges.greenkeeper.io/grrr-amsterdam/12g-env-template.svg)](https://greenkeeper.io/) | ||
This package creates a template file based on your local `.env` file. | ||
It will empty out all values, but it will leave comments and newlines in. | ||
[![Greenkeeper badge](https://badges.greenkeeper.io/grrr-amsterdam/12g-env-template.svg)](https://greenkeeper.io/) | ||
## Usage | ||
@@ -8,0 +12,0 @@ Install the dependency: |
@@ -5,3 +5,3 @@ #!/usr/bin/env node | ||
*/ | ||
var fs = require('fs'); | ||
var fs = require('fs-extra'); | ||
@@ -16,49 +16,63 @@ var template = module.exports = { | ||
exists: function() { | ||
return fs.existsSync(this.dstPath) | ||
return fs.existsSync(template.dstPath) | ||
}, | ||
/** | ||
* Creates a template from a .env file. | ||
* @param string srcPath The path to the .env file | ||
* @param string dstPath The path to the .env.template file | ||
* @return Promise <bool> A Promise with the success state. | ||
*/ | ||
create: function(srcPath = null, dstPath = null) { | ||
if (srcPath) this.srcPath = srcPath | ||
if (dstPath) this.dstPath = dstPath | ||
return new Promise(function(resolve, reject) { | ||
if (srcPath) template.srcPath = srcPath | ||
if (dstPath) template.dstPath = dstPath | ||
var writeLine = function(element) { | ||
var split = element.split('=') | ||
if ( | ||
split[0] == "" || | ||
typeof split[0] == "undefined" | ||
) { | ||
fs.appendFileSync( | ||
template.dstPath, "\n" | ||
) | ||
return | ||
} | ||
if (!fs.existsSync(srcPath)) { | ||
var msg = 'Can\'t find the source file at ' | ||
+ srcPath | ||
return reject(msg) | ||
} | ||
var emptied = split[0] | ||
split[1] ? emptied += "=" : true | ||
emptied += "\n" | ||
fs.readFile(template.srcPath, 'utf8') | ||
.then(data => { | ||
if (template.exists()) { | ||
fs.unlinkSync(template.dstPath) | ||
} | ||
template._write(data) | ||
return resolve(true) | ||
}) | ||
.catch(err => { | ||
return reject(err) | ||
}) | ||
}) | ||
}, | ||
_writeLine: function(element) { | ||
var split = element.split('=') | ||
if ( | ||
split[0] == "" || | ||
typeof split[0] == "undefined" | ||
) { | ||
fs.appendFileSync( | ||
template.dstPath, emptied | ||
template.dstPath, "\n" | ||
) | ||
}; | ||
return | ||
} | ||
var write = function(data) { | ||
data.toString().split('\n').forEach(writeLine) | ||
}; | ||
var emptied = split[0] | ||
split[1] ? emptied += "=" : true | ||
emptied += "\n" | ||
fs.readFile(this.srcPath, 'utf8', function (err, data) { | ||
if (err) throw err; | ||
fs.appendFileSync( | ||
template.dstPath, emptied | ||
) | ||
}, | ||
if (template.exists()) { | ||
fs.truncate(template.dstPath, 0, (err) => { | ||
write(data) | ||
return | ||
}) | ||
} | ||
_write: function(data) { | ||
data.toString().split('\n').forEach(template._writeLine) | ||
}, | ||
write(data) | ||
}); | ||
return true; | ||
} | ||
}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13262
10
96
40
2
2
+ Addedfs-extra@^3.0.1
+ Addedmocha@^3.4.2
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedbrowser-stdout@1.3.0(transitive)
+ Addedcommander@2.9.0(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addeddebug@2.6.8(transitive)
+ Addeddiff@3.2.0(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedfs-extra@3.0.1(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedglob@7.1.1(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedgraceful-readlink@1.0.1(transitive)
+ Addedgrowl@1.9.2(transitive)
+ Addedhas-flag@1.0.0(transitive)
+ Addedhe@1.1.1(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedjson3@3.3.2(transitive)
+ Addedjsonfile@3.0.1(transitive)
+ Addedlodash._baseassign@3.2.0(transitive)
+ Addedlodash._basecopy@3.0.1(transitive)
+ Addedlodash._basecreate@3.0.3(transitive)
+ Addedlodash._getnative@3.9.1(transitive)
+ Addedlodash._isiterateecall@3.0.9(transitive)
+ Addedlodash.create@3.1.1(transitive)
+ Addedlodash.isarguments@3.1.0(transitive)
+ Addedlodash.isarray@3.0.4(transitive)
+ Addedlodash.keys@3.1.2(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedminimist@0.0.8(transitive)
+ Addedmkdirp@0.5.1(transitive)
+ Addedmocha@3.5.3(transitive)
+ Addedms@2.0.0(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedsupports-color@3.1.2(transitive)
+ Addeduniversalify@0.1.2(transitive)
+ Addedwrappy@1.0.2(transitive)