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 3.0.3 to 4.0.0

.github/workflows/ci.yml

33

generify.js

@@ -12,3 +12,3 @@ #!/usr/bin/env node

const os = require('os')
const isBinaryFile = require('isbinaryfile')
const { isBinaryFile } = require('isbinaryfile')

@@ -26,2 +26,8 @@ module.exports = generify

}
var transforms = data.transforms
if (transforms) {
delete data.transforms
} else {
transforms = {}
}

@@ -61,5 +67,3 @@ // needed for the path replacing to work

function copyAndReplace (source, dest) {
isBinaryFile(source, function (err, isBinary) {
if (err) return complete(err)
isBinaryFile(source).then(function (isBinary) {
if (isBinary) {

@@ -73,12 +77,27 @@ pump(

fs.createReadStream(source),
split(replaceLine),
split(replaceLine.bind({ source, dest })),
fs.createWriteStream(dest),
complete)
}
})
}, complete)
}
function replacer () {
if (transforms[this.key]) {
return transforms[this.key](data[this.key], {
souce: this.source,
dest: this.dest,
key: this.key
})
}
return data[this.key]
}
function replaceLine (line) {
const ctx = { source: this.source, dest: this.dest }
keys.forEach(function (key) {
line = line.replace(new RegExp('__' + key + '__', 'g'), data[key])
line = line.replace(
new RegExp('__' + key + '__', 'g'),
replacer.bind({ ...ctx, key })
)
})

@@ -85,0 +104,0 @@ return line + os.EOL

{
"name": "generify",
"version": "3.0.3",
"version": "4.0.0",
"description": "A reusable project generator",
"main": "generify.js",
"scripts": {
"test": "standard | snazzy && tap test/*.js"
"test": "standard | snazzy && tap --no-esm --no-ts --no-jsx test/*.js"
},

@@ -28,16 +28,15 @@ "bin": {

"devDependencies": {
"osenv": "^0.1.0",
"pre-commit": "^1.2.2",
"rimraf": "^2.6.3",
"rimraf": "^3.0.0",
"snazzy": "^8.0.0",
"standard": "^12.0.1",
"tap": "^12.5.3"
"standard": "^14.0.0",
"tap": "^14.0.0"
},
"dependencies": {
"isbinaryfile": "^3.0.2",
"isbinaryfile": "^4.0.2",
"mkdirp": "^0.5.0",
"pump": "^3.0.0",
"split2": "^2.0.0",
"split2": "^3.0.0",
"walker": "^1.0.6"
}
}

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

# generify  [![Build Status](https://travis-ci.org/mcollina/generify.svg?branch=master)](https://travis-ci.org/mcollina/generify)
# generify  ![Build Status](https://github.com/mcollina/generify/workflows/ci/badge.svg)

@@ -44,2 +44,19 @@ A reusable project generator that _copies file recursively_, while

If the supplied `data` has a key `transforms`, with a hash of tranformation
functions, then the found tokens will be used to run a corresponding
transform on the supplied data. Example:
```js
const data = {
transforms: { foo: (data, context) => data.toUpperCase() },
foo: 'foo'
}
// __foo__ => foo_transform(data = 'foo') => 'FOO'
```
The `context` object contains properties: `source` (input file path),
`dest` (output file path), `key` (the matched key).
### `__` handling

@@ -46,0 +63,0 @@

@@ -9,6 +9,6 @@ 'use strict'

const path = require('path')
const osenv = require('osenv')
const rimraf = require('rimraf')
const base = path.join(__dirname, 'fixtures')
const testRun = 'fixture-notification-' + new Date().getTime()
const fixtures = fs.readdirSync(base).filter((d) => !d.match(/expected$/))

@@ -63,3 +63,3 @@

var dest = path.join(osenv.tmpdir(), 'generify', fixture)
var dest = path.join(process.cwd(), 'test-runs', testRun, fixture)
var data = { hello: 'hello world' }

@@ -70,2 +70,11 @@

}
if (fixture === 'transforms') {
data.transforms = {
foo: (d, ctx) => {
if (ctx.dest.endsWith('b')) return d
return d.toUpperCase()
}
}
data.foo = 'foo'
}

@@ -72,0 +81,0 @@ var expectedSet = new Set(Object.keys(expected).map(f => f.replace(/^[/\\]+/, '')))

@@ -9,6 +9,6 @@ 'use strict'

const path = require('path')
const osenv = require('osenv')
const rimraf = require('rimraf')
const base = path.join(__dirname, 'fixtures')
const testRun = 'fixtures-' + new Date().getTime()
const fixtures = fs.readdirSync(base).filter((d) => !d.match(/expected$/))

@@ -63,3 +63,3 @@

var dest = path.join(osenv.tmpdir(), 'generify', fixture)
var dest = path.join(process.cwd(), 'test-runs', testRun, fixture)
var data = { hello: 'hello world' }

@@ -70,2 +70,11 @@

}
if (fixture === 'transforms') {
data.transforms = {
foo: (d, ctx) => {
if (ctx.dest.endsWith('b')) return d
return d.toUpperCase()
}
}
data.foo = 'foo'
}

@@ -72,0 +81,0 @@ generify(path.join(base, fixture), dest, data, function (err) {

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