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

file-system

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

file-system - npm Package Compare versions

Comparing version 2.1.1 to 2.1.2

6

file-system.js

@@ -191,3 +191,3 @@ /**

contents = fs.readFileSync(srcpath, options);
contents = options.process(contents, srcpath);
contents = options.process(contents, srcpath, options.relative);

@@ -332,3 +332,5 @@ if (util.isObject(contents) && contents.filepath) {

var newpath = path.join(destpath, relative);
var opts = {};
var opts = {
relative: relative
};

@@ -335,0 +337,0 @@ if (options.process && !noProcessCb(relative)) {

{
"name": "file-system",
"version": "2.1.1",
"version": "2.1.2",
"description": "Strengthen the ability of file system",

@@ -5,0 +5,0 @@ "main": "file-system.js",

@@ -125,3 +125,3 @@ # file-system — Simplified file system

* {string|array} ``options.filter``
* {function} ``options.process(contents, filepath)``
* {function} ``options.process(contents, filepath, relative)``
If custom the destpath, return object, otherwise return content

@@ -138,3 +138,3 @@ * {string|array} ``options.noProcess``

noProcess: '**/*.{jpg, png}', // Don't process images
process: function(contents, filepath) {
process: function(contents, filepath, relative) {
// only process file content

@@ -141,0 +141,0 @@ return contents;

@@ -10,131 +10,133 @@ var assert = require("assert");

// describe('copy', function() {
// var allFiles = [
// [
// getPath('var/copy/simple/1/demo.html'),
// getPath('var/copy/simple/1/demo.css'),
// getPath('var/copy/simple/1/demo.js'),
// getPath('var/copy/simple/1/2/demo.css'),
// getPath('var/copy/simple/1/2/demo.html'),
// getPath('var/copy/simple/file.js/demo.css'),
// getPath('var/copy/simple/demo.js'),
// getPath('var/copy/simple/demo.css')
// ]
// ];
describe('copy', function() {
var allFiles = [
[
getPath('var/copy/simple/1/demo.html'),
getPath('var/copy/simple/1/demo.css'),
getPath('var/copy/simple/1/demo.js'),
getPath('var/copy/simple/1/2/demo.css'),
getPath('var/copy/simple/1/2/demo.html'),
getPath('var/copy/simple/file.js/demo.css'),
getPath('var/copy/simple/demo.js'),
getPath('var/copy/simple/demo.css')
]
];
// before(function() {
// allFiles.forEach(function(files) {
// files.forEach(function(item) {
// file.writeFileSync(item, 'a');
// });
// });
// });
before(function() {
allFiles.forEach(function(files) {
files.forEach(function(item) {
file.writeFileSync(item, 'a');
});
});
});
// // it('copySync files with filter', function() {
// // var dirpath = getPath('var/copy/simple');
// // var destpath = getPath('var/copy/simpledest');
it('copySync files with filter', function() {
var dirpath = getPath('var/copy/simple');
var destpath = getPath('var/copy/simpledest');
// // file.copySync(dirpath, destpath, {
// // filter: [
// // '**/*.js',
// // '1/**/*.css',
// // '1/demo.html'
// // ]
// // });
file.copySync(dirpath, destpath, {
filter: [
'**/*.js',
'1/**/*.css',
'1/demo.html'
]
});
// // var dirDest = [
// // getPath('var/copy/simpledest/1/demo.html'),
// // getPath('var/copy/simpledest/1/demo.css'),
// // getPath('var/copy/simpledest/1/2/demo.css'),
// // getPath('var/copy/simpledest/1/demo.js'),
// // getPath('var/copy/simpledest/demo.js')
// // ];
// // var result = [];
var dirDest = [
getPath('var/copy/simpledest/1/demo.html'),
getPath('var/copy/simpledest/1/demo.css'),
getPath('var/copy/simpledest/1/2/demo.css'),
getPath('var/copy/simpledest/1/demo.js'),
getPath('var/copy/simpledest/demo.js')
];
var result = [];
// // file.recurseSync(destpath, function(filepath, filename) {
// // if (!filename) return;
file.recurseSync(destpath, function(filepath, filename) {
if (!filename) return;
// // result.push(filepath);
// // });
result.push(filepath);
});
// // assert.equal(result.length, dirDest.length);
// // });
assert.equal(result.length, dirDest.length);
});
// it('copySync replace filepath', function() {
// var dirpath = getPath('var/copy/simple');
// var destpath = getPath('var/copy/simple-replace');
it('copySync replace filepath', function() {
var dirpath = getPath('var/copy/simple');
var destpath = getPath('var/copy/simple-replace');
// file.copySync(dirpath, destpath, {
// process: function(contents, filepath) {
// var basename = path.basename(filepath);
// var relative = path.relative(dirpath, filepath);
// var newpath = path.join(destpath, relative);
file.copySync(dirpath, destpath, {
process: function(contents, filepath, relative) {
var basename = path.basename(filepath);
var newpath = path.join(destpath, relative);
// // Replace html to txt
// newpath = newpath.replace(
// /\.html$/,
// '.txt'
// );
// Validate relative
assert(path.relative(dirpath, filepath), relative);
// // Move all css to rootpath of destpath
// if (/\.css$/.test(basename)) {
// var prefix = path.basename(path.dirname(newpath));
// newpath = path.join(destpath, prefix + '-' + basename);
// }
// Replace html to txt
newpath = newpath.replace(
/\.html$/,
'.txt'
);
// return {
// contents: contents,
// filepath: newpath
// };
// }
// });
// Move all css to rootpath of destpath
if (/\.css$/.test(basename)) {
var prefix = path.basename(path.dirname(newpath));
newpath = path.join(destpath, prefix + '-' + basename);
}
// assert.equal(true, file.existsSync(
// path.join(destpath, '1/demo.txt')
// ));
// });
return {
contents: contents,
filepath: newpath
};
}
});
// it('copySync with noProcess', function() {
// var dirpath = getPath('var/copy/simple');
// var destpath = getPath('var/copy/simple-noprocess');
assert.equal(true, file.existsSync(
path.join(destpath, '1/demo.txt')
));
});
// file.copySync(dirpath, destpath, {
// filter: [
// '**/*demo.css',
// '!**/1/demo.css'
// ],
// noProcess: 'demo.css',
// process: function(contents, filepath) {
// return 'b';
// }
// });
it('copySync with noProcess', function() {
var dirpath = getPath('var/copy/simple');
var destpath = getPath('var/copy/simple-noprocess');
// assert.equal(true, file.existsSync(
// path.join(destpath, 'demo.css')
// ));
file.copySync(dirpath, destpath, {
filter: [
'**/*demo.css',
'!**/1/demo.css'
],
noProcess: 'demo.css',
process: function(contents, filepath) {
return 'b';
}
});
// assert.equal(false, file.existsSync(
// path.join(destpath, '1/demo.css')
// ));
assert.equal(true, file.existsSync(
path.join(destpath, 'demo.css')
));
// assert.equal(true, file.existsSync(
// path.join(destpath, '1/2/demo.css')
// ));
assert.equal(false, file.existsSync(
path.join(destpath, '1/demo.css')
));
// assert.equal(true, file.existsSync(
// path.join(destpath, 'file.js/demo.css')
// ));
assert.equal(true, file.existsSync(
path.join(destpath, '1/2/demo.css')
));
// var content = file.readFileSync(
// path.join(destpath, 'demo.css'),
// { encoding: 'utf8' }
// );
assert.equal(true, file.existsSync(
path.join(destpath, 'file.js/demo.css')
));
// assert.equal('a', content);
// });
var content = file.readFileSync(
path.join(destpath, 'demo.css'),
{ encoding: 'utf8' }
);
assert.equal('a', content);
});
// after(function() {
// file.rmdirSync(getPath('var/copy'));
// });
// });
after(function() {
file.rmdirSync(getPath('var/copy'));
});
});
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