mem-fs-editor 4.0.2 → 4.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -1
- package/lib/actions/copy-tpl.js +7 -4
- package/lib/actions/copy.js +7 -3
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -63,7 +63,7 @@ Delete a file or a directory.
|
|
|
63
63
|
|
|
64
64
|
`filePath` can also be a `glob`. If `filePath` is glob, you can optionally pass in an `options.globOptions` object to change its pattern matching behavior. The full list of options are being described [here](https://github.com/isaacs/node-glob#options). The `sync` flag is forced to be `true` in `globOptions`.
|
|
65
65
|
|
|
66
|
-
### `#copy(from, to, [options])`
|
|
66
|
+
### `#copy(from, to, [options], context[, templateOptions ])`
|
|
67
67
|
|
|
68
68
|
Copy a file from the `from` path to the `to` path.
|
|
69
69
|
|
|
@@ -85,6 +85,10 @@ Templates syntax looks like this:
|
|
|
85
85
|
<%= value %>
|
|
86
86
|
<%- include('partial.ejs', { name: 'Simon' }) %>
|
|
87
87
|
```
|
|
88
|
+
Dir syntax looks like this:
|
|
89
|
+
```
|
|
90
|
+
/some/path/dir<%= value %>/...
|
|
91
|
+
```
|
|
88
92
|
|
|
89
93
|
Refer to the [ejs documentation](http://ejs.co/) for more details.
|
|
90
94
|
|
package/lib/actions/copy-tpl.js
CHANGED
|
@@ -7,8 +7,9 @@ var isBinaryFile = require('isbinaryfile');
|
|
|
7
7
|
function render(contents, filename, context, tplSettings) {
|
|
8
8
|
let result;
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
const contentsBuffer = Buffer.from(contents, 'binary');
|
|
11
|
+
if (isBinaryFile.sync(contentsBuffer, contentsBuffer.length)) {
|
|
12
|
+
result = contentsBuffer;
|
|
12
13
|
} else {
|
|
13
14
|
result = ejs.render(
|
|
14
15
|
contents.toString(),
|
|
@@ -23,10 +24,12 @@ function render(contents, filename, context, tplSettings) {
|
|
|
23
24
|
|
|
24
25
|
module.exports = function (from, to, context, tplSettings, options) {
|
|
25
26
|
context = context || {};
|
|
27
|
+
tplSettings = tplSettings || {}
|
|
26
28
|
|
|
27
29
|
this.copy(from, to, extend(options || {}, {
|
|
28
30
|
process: function (contents, filename) {
|
|
29
|
-
return render(contents, filename, context, tplSettings
|
|
31
|
+
return render(contents, filename, context, tplSettings);
|
|
30
32
|
}
|
|
31
|
-
})
|
|
33
|
+
}),
|
|
34
|
+
context, tplSettings);
|
|
32
35
|
};
|
package/lib/actions/copy.js
CHANGED
|
@@ -7,6 +7,7 @@ var glob = require('glob');
|
|
|
7
7
|
var globby = require('globby');
|
|
8
8
|
var extend = require('deep-extend');
|
|
9
9
|
var multimatch = require('multimatch');
|
|
10
|
+
var ejs = require('ejs');
|
|
10
11
|
var util = require('../util');
|
|
11
12
|
|
|
12
13
|
function applyProcessingFunc(process, contents, filename) {
|
|
@@ -14,7 +15,7 @@ function applyProcessingFunc(process, contents, filename) {
|
|
|
14
15
|
return output instanceof Buffer ? output : Buffer.from(output);
|
|
15
16
|
}
|
|
16
17
|
|
|
17
|
-
exports.copy = function (from, to, options) {
|
|
18
|
+
exports.copy = function (from, to, options, context, tplSettings) {
|
|
18
19
|
to = path.resolve(to);
|
|
19
20
|
options = options || {};
|
|
20
21
|
var fromGlob = util.globify(from);
|
|
@@ -47,11 +48,11 @@ exports.copy = function (from, to, options) {
|
|
|
47
48
|
assert(files.length > 0, 'Trying to copy from a source that does not exist: ' + from);
|
|
48
49
|
|
|
49
50
|
files.forEach(file => {
|
|
50
|
-
this._copySingle(file, generateDestination(file), options);
|
|
51
|
+
this._copySingle(file, generateDestination(file), options, context, tplSettings);
|
|
51
52
|
});
|
|
52
53
|
};
|
|
53
54
|
|
|
54
|
-
exports._copySingle = function (from, to, options) {
|
|
55
|
+
exports._copySingle = function (from, to, options, context, tplSettings) {
|
|
55
56
|
options = options || {};
|
|
56
57
|
|
|
57
58
|
assert(this.exists(from), 'Trying to copy from a source that does not exist: ' + from);
|
|
@@ -62,6 +63,9 @@ exports._copySingle = function (from, to, options) {
|
|
|
62
63
|
if (options.process) {
|
|
63
64
|
contents = applyProcessingFunc(options.process, file.contents, file.path);
|
|
64
65
|
}
|
|
66
|
+
if (context) {
|
|
67
|
+
to = ejs.render(to, context, tplSettings);
|
|
68
|
+
}
|
|
65
69
|
|
|
66
70
|
this.write(to, contents, file.stat);
|
|
67
71
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mem-fs-editor",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.3",
|
|
4
4
|
"description": "File edition helpers working on top of mem-fs",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"pretest": "eslint **/*.js",
|
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
],
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"commondir": "^1.0.1",
|
|
19
|
-
"deep-extend": "^0.
|
|
19
|
+
"deep-extend": "^0.6.0",
|
|
20
20
|
"ejs": "^2.5.9",
|
|
21
21
|
"glob": "^7.0.3",
|
|
22
|
-
"globby": "^
|
|
22
|
+
"globby": "^7.1.1",
|
|
23
23
|
"isbinaryfile": "^3.0.2",
|
|
24
24
|
"mkdirp": "^0.5.0",
|
|
25
25
|
"multimatch": "^2.0.0",
|