Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

12g-env-template

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

12g-env-template - npm Package Compare versions

Comparing version 1.0.3 to 1.0.4

.npmignore

8

package.json
{
"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;
}
};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc