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

generify

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

generify - npm Package Compare versions

Comparing version 1.1.0 to 2.0.0

.travis.yml

16

example.js

@@ -0,12 +1,10 @@

'use strict'
var generify = require('./')
, source = './fixture/template'
, dest = '/tmp/generify'
, data = { hello: 'hello world' }
var generify = require('./')
var source = './fixture/template'
var dest = '/tmp/generify'
var data = { hello: 'hello world' }
generify(source, dest, data, function(err) {
if (err)
console.log(err)
else
console.log('ok!')
generify(source, dest, data, function (err) {
if (err) { console.log(err) } else { console.log('ok!') }
})

@@ -5,31 +5,30 @@ #!/usr/bin/env node

var walker = require('walker')
, fs = require('fs')
, path = require('path')
, split = require('split2')
, mkdirp = require('mkdirp')
const walker = require('walker')
const fs = require('fs')
const path = require('path')
const split = require('split2')
const mkdirp = require('mkdirp')
const pump = require('pump')
module.exports = generify
if (require.main === module) execute()
function generify (source, dest, data, done) {
var count = 1 // the walker counts as 1
var keys = Object.keys(data)
function generify(source, dest, data, done) {
var count = 1 // the walker counts as 1
, keys = Object.keys(data)
// needed for the path replacing to work
source = path.resolve(source)
if (!done) done = function() {}
if (!done) done = function () {}
if (!data) data = {}
walker(source)
.on('file', function(file) {
.on('file', function (file) {
var relativePath = path.relative(source, file).replace(/^__/, '.')
, destFile = path.join(dest, relativePath)
var destFile = path.join(dest, relativePath)
count++
mkdirp(path.dirname(destFile), function(err) {
if (err) return done(err)
mkdirp(path.dirname(destFile), function (err) {
if (err) return complete(err)

@@ -42,11 +41,12 @@ copyAndReplace(file, destFile)

function copyAndReplace(source, dest) {
fs.createReadStream(source)
.pipe(split(replaceLine))
.pipe(fs.createWriteStream(dest))
.on('finish', complete)
function copyAndReplace (source, dest) {
pump(
fs.createReadStream(source),
split(replaceLine),
fs.createWriteStream(dest),
complete)
}
function replaceLine(line) {
keys.forEach(function(key) {
function replaceLine (line) {
keys.forEach(function (key) {
line = line.replace('__' + key + '__', data[key])

@@ -57,10 +57,15 @@ })

function complete() {
function complete (err) {
if (err) {
count = 0
done(err)
return
}
count--
if (count === 0)
done()
if (count === 0) { done() }
}
}
function execute() {
function execute () {
if (process.argv.length < 4) {

@@ -72,4 +77,4 @@ console.log('Usage: generify template destination [json file]')

var source = process.argv[2]
, dest = process.argv[3]
, json = {}
var dest = process.argv[3]
var json = {}

@@ -82,1 +87,3 @@ if (process.argv[4]) {

}
if (require.main === module) execute()
{
"name": "generify",
"version": "1.1.0",
"version": "2.0.0",
"description": "A reusable project generator",
"main": "generify.js",
"scripts": {
"test": "tape test.js | faucet"
"test": "standard | snazzy && tap test/*.js"
},

@@ -28,9 +28,12 @@ "bin": {

"devDependencies": {
"faucet": "0.0.1",
"osenv": "^0.1.0",
"pre-commit": "^1.2.2",
"rimraf": "^2.2.8",
"tape": "^3.0.0"
"snazzy": "^7.1.1",
"standard": "^11.0.0",
"tap": "^11.1.1"
},
"dependencies": {
"mkdirp": "^0.5.0",
"pump": "^3.0.0",
"split2": "^0.2.1",

@@ -37,0 +40,0 @@ "walker": "^1.0.6"

@@ -1,3 +0,2 @@

generify
========
# generify&nbsp;&nbsp;[![Build Status](https://travis-ci.org/mcollina/generify.svg?branch=master)](https://travis-ci.org/mcollina/generify)

@@ -7,16 +6,18 @@ A reusable project generator that _copies file recursively_, while

Example
-------
## Example
```js
var generify = require('generify')
, source = './template'
, dest = '/tmp/generify-test'
, data = { hello: 'hello world' }
'use strict'
const generify = require('generify')
const source = './template'
const dest = '/tmp/generify-test'
const data = { hello: 'hello world' }
generify(source, dest, data, function(err) {
if (err)
if (err) {
console.log(err)
else
} else {
console.log('ok!')
}
})

@@ -31,7 +32,5 @@ ```

If a file begins with `__` that will be automatically converted into a
`.`. This is useful for generating `.gitignore` files, as on NPM a
`.gitignore` file will be automatically converted into a `.npmignore`.
`.`. This is useful for generating `.gitignore` files.
Executable
----------
## Executable

@@ -44,10 +43,8 @@ __generify__ also offers an executable that can be called with:

Acknowledgements
----------------
## Acknowledgements
This project was kindly sponsored by [nearForm](http://nearform.com).
License
-------
## License
MIT

@@ -1,28 +0,23 @@

var generify = require('./')
, test = require('tape')
, walker = require('walker')
, fs = require('fs')
, path = require('path')
, osenv = require('osenv')
, rimraf = require('rimraf')
, base = './fixture'
'use strict'
const generify = require('./')
const t = require('tap')
const test = t.test
const walker = require('walker')
const fs = require('fs')
const path = require('path')
const osenv = require('osenv')
const rimraf = require('rimraf')
const base = './fixture'
fs.readdir('./fixture', function(err, fixtures) {
if (err) {
console.log(err)
process.exit(1)
}
const fixtures = fs.readdirSync('./fixture').filter((d) => !d.match(/expected$/))
fixtures.forEach(setup)
});
t.plan(fixtures.length)
fixtures.forEach(setup)
function setup(fixture) {
if (fixture.match(/expected$/))
return
function setup (fixture) {
var expectedPath = path.join(base, fixture + '-expected')
fs.stat(expectedPath, function(err, stat) {
if (!stat || !stat.isDirectory()) {
fs.stat(expectedPath, (err, stat) => {
if (err || !stat || !stat.isDirectory()) {
expectedPath = path.join(base, fixture)

@@ -34,14 +29,14 @@ }

function prepareExpectedData(path, fixture, cb) {
function prepareExpectedData (path, fixture, cb) {
var expected = {}
, files = []
, count = 0
var files = []
var count = 0
walker(path)
.on('file', function(file) {
.on('file', function (file) {
files.push(file)
})
.on('end', function() {
files.forEach(function(file) {
fs.readFile(file, function(err, data) {
.on('end', function () {
files.forEach(function (file) {
fs.readFile(file, function (err, data) {
if (err) {

@@ -63,25 +58,22 @@ return cb(err)

function createTest(err, expected, fixture) {
if (err) {
console.log(err)
process.exit(1)
}
function createTest (err, expected, fixture) {
test(fixture, function (t) {
t.plan(Object.keys(expected).length * 2 + 3)
t.error(err)
test(fixture, function(t) {
t.plan(Object.keys(expected).length + 2)
var dest = path.join(osenv.tmpdir(), 'generify', fixture)
, data = { hello: 'hello world' }
var data = { hello: 'hello world' }
generify(path.join(base, fixture), dest, data, function(err) {
generify(path.join(base, fixture), dest, data, function (err) {
t.notOk(err, 'no error')
walker(dest)
.on('file', function(file) {
fs.readFile(file, function(err, data) {
.on('file', function (file) {
fs.readFile(file, function (err, data) {
t.notOk(err)
file = file.replace(dest, '')
t.deepEqual(data.toString(), expected[file], file + ' matching');
t.deepEqual(data.toString(), expected[file], file + ' matching')
})
})
.on('end', function() {
rimraf(dest, function(err) {
.on('end', function () {
rimraf(dest, function (err) {
t.notOk(err, 'no error in deleting everything')

@@ -88,0 +80,0 @@ })

Sorry, the diff of this file is not supported yet

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