12g-env-template
Advanced tools
Comparing version
{ | ||
"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 | ||
[](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. | ||
[](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; | ||
} | ||
}; |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
13262
232.88%10
100%96
88.24%40
11.11%2
Infinity%2
100%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added