Comparing version 4.0.0 to 4.1.0
@@ -18,3 +18,2 @@ #!/usr/bin/env node | ||
var count = 1 // the walker counts as 1 | ||
var keys = Object.keys(data) | ||
var copyFilesAsNamed = data.copyAsNamed | ||
@@ -84,3 +83,3 @@ if (copyFilesAsNamed) { | ||
if (transforms[this.key]) { | ||
return transforms[this.key](data[this.key], { | ||
return transforms[this.key](getNestedValue(data, this.key), { | ||
souce: this.source, | ||
@@ -91,3 +90,3 @@ dest: this.dest, | ||
} | ||
return data[this.key] | ||
return getNestedValue(data, this.key) | ||
} | ||
@@ -97,8 +96,9 @@ | ||
const ctx = { source: this.source, dest: this.dest } | ||
keys.forEach(function (key) { | ||
const matches = matchAll(line, /__([a-zA-Z/\\.]*?)__/g) | ||
for (const match of matches) { | ||
line = line.replace( | ||
new RegExp('__' + key + '__', 'g'), | ||
replacer.bind({ ...ctx, key }) | ||
new RegExp('__' + match[1] + '__', 'g'), | ||
replacer.bind({ ...ctx, key: match[1] }) | ||
) | ||
}) | ||
} | ||
return line + os.EOL | ||
@@ -119,2 +119,23 @@ } | ||
/** | ||
* Added for support of node versions < 12, since String.prototype.matchAll is only node >= 12 | ||
*/ | ||
function * matchAll (str, regexp) { | ||
const flags = regexp.global ? regexp.flags : regexp.flags + 'g' | ||
const re = new RegExp(regexp, flags) | ||
let match | ||
while ((match = re.exec(str))) { | ||
yield match | ||
} | ||
} | ||
function getNestedValue (obj, key) { | ||
return key.split('.').reduce(function (result, key) { | ||
if (!result || !key) { | ||
return 'notFound' | ||
} | ||
return result[key] | ||
}, obj) | ||
} | ||
function execute () { | ||
@@ -121,0 +142,0 @@ if (process.argv.length < 4) { |
{ | ||
"name": "generify", | ||
"version": "4.0.0", | ||
"version": "4.1.0", | ||
"description": "A reusable project generator", | ||
@@ -31,3 +31,3 @@ "main": "generify.js", | ||
"snazzy": "^8.0.0", | ||
"standard": "^14.0.0", | ||
"standard": "^14.3.3", | ||
"tap": "^14.0.0" | ||
@@ -34,0 +34,0 @@ }, |
@@ -78,2 +78,6 @@ 'use strict' | ||
if (fixture === 'nested') { | ||
data.foo = { more: { nesting: 'oh gee' } } | ||
} | ||
var expectedSet = new Set(Object.keys(expected).map(f => f.replace(/^[/\\]+/, ''))) | ||
@@ -80,0 +84,0 @@ |
@@ -78,2 +78,6 @@ 'use strict' | ||
if (fixture === 'nested') { | ||
data.foo = { more: { nesting: 'oh gee' } } | ||
} | ||
generify(path.join(base, fixture), dest, data, function (err) { | ||
@@ -80,0 +84,0 @@ t.notOk(err, 'no error') |
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
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
19014
26
323