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

bulk-curd-files

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bulk-curd-files - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

30

lib/bulkCopy.js

@@ -38,2 +38,9 @@ "use strict";

};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -43,9 +50,11 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

Object.defineProperty(exports, "__esModule", { value: true });
var fs_1 = __importDefault(require("fs"));
var path_1 = __importDefault(require("path"));
var useFsByAsync_1 = __importDefault(require("./utils/useFsByAsync"));
var fs = __importStar(require("fs"));
var path = __importStar(require("path"));
var util_1 = __importDefault(require("util"));
var readFile = util_1.default.promisify(fs.readFile);
var writeFile = util_1.default.promisify(fs.writeFile);
function bulkCopy(dir, originFileName, targetFileName, alsoReplaceExistFile) {
if (alsoReplaceExistFile === void 0) { alsoReplaceExistFile = false; }
return __awaiter(this, void 0, void 0, function () {
var files;
var inputPath, files;
var _this = this;

@@ -55,3 +64,4 @@ return __generator(this, function (_a) {

case 0:
files = fs_1.default.readdirSync(dir);
inputPath = path.resolve(__dirname, dir);
files = fs.readdirSync(inputPath);
return [4 /*yield*/, Promise.all(files.map(function (filePath) { return __awaiter(_this, void 0, void 0, function () {

@@ -62,4 +72,4 @@ var fileOrFolderPath, isFolder, content;

case 0:
fileOrFolderPath = path_1.default.resolve(dir, filePath);
isFolder = fs_1.default.lstatSync(fileOrFolderPath).isDirectory();
fileOrFolderPath = path.resolve(inputPath, filePath);
isFolder = fs.lstatSync(fileOrFolderPath).isDirectory();
if (!isFolder) return [3 /*break*/, 2];

@@ -75,7 +85,7 @@ return [4 /*yield*/, bulkCopy(fileOrFolderPath, originFileName, targetFileName, alsoReplaceExistFile)

if (!(new RegExp(originFileName).test(filePath.toString()) &&
(alsoReplaceExistFile || !fs_1.default.existsSync(path_1.default.resolve(dir, targetFileName))))) return [3 /*break*/, 5];
return [4 /*yield*/, useFsByAsync_1.default('readFile', fileOrFolderPath, 'utf8')];
(alsoReplaceExistFile || !fs.existsSync(path.resolve(inputPath, targetFileName))))) return [3 /*break*/, 5];
return [4 /*yield*/, readFile(fileOrFolderPath, 'utf8')];
case 3:
content = _a.sent();
return [4 /*yield*/, useFsByAsync_1.default('writeFile', dir + "/" + targetFileName, content)];
return [4 /*yield*/, writeFile(inputPath + "/" + targetFileName, content)];
case 4:

@@ -82,0 +92,0 @@ _a.sent();

@@ -38,2 +38,9 @@ "use strict";

};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -43,5 +50,6 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

Object.defineProperty(exports, "__esModule", { value: true });
var fs_1 = __importDefault(require("fs"));
var path_1 = __importDefault(require("path"));
var useFsByAsync_1 = __importDefault(require("./utils/useFsByAsync"));
var fs = __importStar(require("fs"));
var path = __importStar(require("path"));
var util_1 = __importDefault(require("util"));
var unlink = util_1.default.promisify(fs.unlink);
function bulkDelete(dir, targetFileName, ignoreFolder) {

@@ -54,3 +62,3 @@ return __awaiter(this, void 0, void 0, function () {

case 0:
files = fs_1.default.readdirSync(dir);
files = fs.readdirSync(dir);
return [4 /*yield*/, Promise.all(files.map(function (filePath) { return __awaiter(_this, void 0, void 0, function () {

@@ -61,4 +69,4 @@ var fileOrFolderPath, isFolder;

case 0:
fileOrFolderPath = path_1.default.resolve(dir, filePath);
isFolder = fs_1.default.lstatSync(fileOrFolderPath).isDirectory();
fileOrFolderPath = path.resolve(dir, filePath);
isFolder = fs.lstatSync(fileOrFolderPath).isDirectory();
if (!(isFolder && ignoreFolder !== fileOrFolderPath.toString())) return [3 /*break*/, 2];

@@ -73,3 +81,3 @@ return [4 /*yield*/, bulkDelete(fileOrFolderPath, targetFileName, ignoreFolder)

if (!new RegExp(targetFileName).test(filePath.toString())) return [3 /*break*/, 4];
return [4 /*yield*/, useFsByAsync_1.default('unlink', path_1.default.resolve(dir, filePath))];
return [4 /*yield*/, unlink(path.resolve(dir, filePath))];
case 3:

@@ -76,0 +84,0 @@ _a.sent();

{
"name": "bulk-curd-files",
"version": "0.0.2",
"version": "0.0.3",
"description": "A files bulk copy lib",

@@ -5,0 +5,0 @@ "main": "./index.js",

{
"name": "bulk-curd-files",
"version": "0.0.2",
"version": "0.0.3",
"description": "A files bulk curd lib",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

# A files bulk curd lib
`node version` >= 8.0.0
## usage example

@@ -11,6 +13,6 @@

//create fileB by copying fileA in bulk
bulkCopy(path.resolve(__dirname, './'), 'fileA.ts', 'fileB.ts');
await bulkCopy('./', 'fileA.ts', 'fileB.ts');
//delete fileA exclude node_modules folder in bulk
bulkDelete('./', 'fileA.ts', 'node_modules');
await bulkDelete('./', 'fileA.ts', 'node_modules');
```

@@ -1,5 +0,8 @@

import fs from 'fs'
import path from 'path'
import useFsByAsync from './utils/useFsByAsync'
import * as fs from 'fs'
import * as path from 'path'
import util from 'util';
const readFile = util.promisify(fs.readFile);
const writeFile = util.promisify(fs.writeFile);
export default async function bulkCopy(

@@ -11,6 +14,7 @@ dir: string,

) {
const files = fs.readdirSync(dir)
const inputPath = path.resolve(__dirname, dir);
const files = fs.readdirSync(inputPath)
await Promise.all(
files.map(async filePath => {
const fileOrFolderPath = path.resolve(dir, filePath)
const fileOrFolderPath = path.resolve(inputPath, filePath)
// if this is a folder, Recursive call it to handle the files from this folder;

@@ -24,6 +28,6 @@ const isFolder = fs.lstatSync(fileOrFolderPath).isDirectory()

new RegExp(originFileName).test(filePath.toString()) &&
(alsoReplaceExistFile || !fs.existsSync(path.resolve(dir, targetFileName)))
(alsoReplaceExistFile || !fs.existsSync(path.resolve(inputPath, targetFileName)))
) {
const content = await useFsByAsync('readFile', fileOrFolderPath, 'utf8')
await useFsByAsync('writeFile', `${dir}/${targetFileName}`, content)
const content = await readFile(fileOrFolderPath, 'utf8')
await writeFile(`${inputPath}/${targetFileName}`, content)
}

@@ -30,0 +34,0 @@ }),

@@ -1,5 +0,7 @@

import fs from 'fs'
import path from 'path'
import useFsByAsync from './utils/useFsByAsync'
import * as fs from 'fs'
import * as path from 'path'
import util from 'util';
const unlink = util.promisify(fs.unlink);
export default async function bulkDelete(dir: string, targetFileName: string, ignoreFolder?: string) {

@@ -16,3 +18,3 @@ const files = fs.readdirSync(dir)

} else if (new RegExp(targetFileName).test(filePath.toString())) {
await useFsByAsync('unlink', path.resolve(dir, filePath))
await unlink(path.resolve(dir, filePath))
}

@@ -19,0 +21,0 @@ }),

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