Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=crlf
10 changes: 5 additions & 5 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
release:
types: [created]
workflow_dispatch:

jobs:
build-windows:
runs-on: windows-latest
Expand All @@ -12,7 +12,7 @@ jobs:
packages: write
steps:
- uses: actions/checkout@v2
- run: yarn build:gyp
- run: yarn build:gyp
- uses: actions/upload-artifact@v2
with:
name: windows-binaries
Expand All @@ -32,11 +32,11 @@ jobs:
path: build/Release
- uses: actions/setup-node@v2
with:
node-version: '16.x'
registry-url: 'https://npm.pkg.github.com'
node-version: "16.x"
registry-url: "https://npm.pkg.github.com"
- run: yarn
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: yarn publish
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9 changes: 6 additions & 3 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:

jobs:
type-check:
runs-on: ubuntu-latest
runs-on: windows-latest

steps:
- name: Checkout code
Expand All @@ -22,5 +22,8 @@ jobs:
- name: Run TypeScript compiler
run: yarn tsc

# - name: Run Vitest
# run: yarn vitest:once
- name: Run Prettier
run: yarn prettier . --check

- name: Run tests
run: yarn test:once
4 changes: 2 additions & 2 deletions examples/populate.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import VirtualDrive from "@/virtual-drive";

import { execSync } from "child_process";
import { join } from "path";
import { v4 } from "uuid";

import VirtualDrive from "@/virtual-drive";

import settings from "./settings";

const rootFileName1 = v4();
Expand Down
65 changes: 32 additions & 33 deletions examples/utils.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,46 @@
import fs from 'fs';
import path from 'path';
import fs from "fs";
import path from "path";

interface FileDetail {
path: string;
size: number;
baseDir: string;
path: string;
size: number;
baseDir: string;
}

function readFilesRecursively(dir: string, fileList: FileDetail[] = []): FileDetail[] {
fs.readdirSync(dir).forEach(file => {
const filePath = path.join(dir, file);
if (fs.statSync(filePath).isDirectory()) {
readFilesRecursively(filePath, fileList);
} else {
fileList.push({
path: filePath,
size: fs.statSync(filePath).size,
baseDir: dir
});
}
});
return fileList;
fs.readdirSync(dir).forEach((file) => {
const filePath = path.join(dir, file);
if (fs.statSync(filePath).isDirectory()) {
readFilesRecursively(filePath, fileList);
} else {
fileList.push({
path: filePath,
size: fs.statSync(filePath).size,
baseDir: dir,
});
}
});
return fileList;
}

function createFilesWithSize(sourceFolder: string, destFolder: string): void {
const files: FileDetail[] = readFilesRecursively(sourceFolder);
const files: FileDetail[] = readFilesRecursively(sourceFolder);

if (!fs.existsSync(destFolder)) {
fs.mkdirSync(destFolder, { recursive: true });
}

files.forEach(file => {
const relativePath = path.relative(file.baseDir, file.path);
const destFilePath = path.join(file.baseDir.replace(sourceFolder, destFolder), relativePath);//path.join(destFolder, relativePath);
const destFileDir = file.baseDir.replace(sourceFolder, destFolder);//path.dirname(destFilePath);
if (!fs.existsSync(destFolder)) {
fs.mkdirSync(destFolder, { recursive: true });
}

if (!fs.existsSync(destFileDir)){
fs.mkdirSync(destFileDir, { recursive: true });
}
files.forEach((file) => {
const relativePath = path.relative(file.baseDir, file.path);
const destFilePath = path.join(file.baseDir.replace(sourceFolder, destFolder), relativePath); //path.join(destFolder, relativePath);
const destFileDir = file.baseDir.replace(sourceFolder, destFolder); //path.dirname(destFilePath);

fs.writeFileSync(destFilePath, Buffer.alloc(file.size));
});
if (!fs.existsSync(destFileDir)) {
fs.mkdirSync(destFileDir, { recursive: true });
}

fs.writeFileSync(destFilePath, Buffer.alloc(file.size));
});
}

export { createFilesWithSize };
export { createFilesWithSize };
53 changes: 11 additions & 42 deletions examples/utils/generate-random-file-tree.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import VirtualDrive from '@/virtual-drive';
import { v4 as uuidv4 } from 'uuid';
import { v4 as uuidv4 } from "uuid";

import VirtualDrive from "@/virtual-drive";

interface GenerateOptions {
rootPath: string
rootPath: string;
depth: number;
filesPerFolder: number;
foldersPerLevel: number;
Expand All @@ -26,18 +27,7 @@ function randomNormal(mean: number, stdDev: number): number {
}

function getRandomExtension(): string {
const extensions = [
".txt",
".pdf",
".rar",
".jpg",
".docx",
".xlsx",
".mp4",
".mkv",
".json",
""
];
const extensions = [".txt", ".pdf", ".rar", ".jpg", ".docx", ".xlsx", ".mp4", ".mkv", ".json", ""];
const index = Math.floor(Math.random() * extensions.length);
return extensions[index];
}
Expand All @@ -47,17 +37,11 @@ async function createStructureRecursively(
currentPath: string,
level: number,
options: GenerateOptions,
result: Record<string, string>
result: Record<string, string>,
): Promise<void> {
if (level < 0) return;

const {
filesPerFolder,
foldersPerLevel,
meanSize,
stdDev,
timeOffset
} = options;
const { filesPerFolder, foldersPerLevel, meanSize, stdDev, timeOffset } = options;

for (let i = 0; i < filesPerFolder; i++) {
const fileName = `file_${generateRandomId()}${getRandomExtension()}`;
Expand All @@ -69,13 +53,7 @@ async function createStructureRecursively(
const createdAt = Date.now() - (timeOffset || 0);
const updatedAt = Date.now() - (timeOffset || 0) + 2000;

drive.createFileByPath(
fullPath,
fileId,
fileSize,
createdAt,
updatedAt
);
drive.createFileByPath(fullPath, fileId, fileSize, createdAt, updatedAt);

result[fileId] = fullPath;
}
Expand All @@ -88,22 +66,13 @@ async function createStructureRecursively(
const createdAt = Date.now() - (timeOffset || 0) - 10000; // Ejemplo
const updatedAt = Date.now() - (timeOffset || 0);

drive.createFolderByPath(
newFolderPath,
folderId,
1000,
createdAt,
updatedAt
);
drive.createFolderByPath(newFolderPath, folderId, 1000, createdAt, updatedAt);

await createStructureRecursively(drive, newFolderPath, level - 1, options, result);
}
}

async function generateRandomFilesAndFolders(
drive: VirtualDrive,
options: GenerateOptions
): Promise<Record<string, string>> {
async function generateRandomFilesAndFolders(drive: VirtualDrive, options: GenerateOptions): Promise<Record<string, string>> {
const { rootPath } = options;

const result: Record<string, string> = {};
Expand All @@ -114,4 +83,4 @@ async function generateRandomFilesAndFolders(
}

export { generateRandomFilesAndFolders };
export type { GenerateOptions }
export type { GenerateOptions };
12 changes: 6 additions & 6 deletions gyp.config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"gyp_file": "binding.gyp",
"source_dirs": ["native-src/**/*.cpp"],
"ignored_source_dirs": [],
"include_dirs": ["include"],
"ignored_include_dirs": []
}
"gyp_file": "binding.gyp",
"source_dirs": ["native-src/**/*.cpp"],
"ignored_source_dirs": [],
"include_dirs": ["include"],
"ignored_include_dirs": []
}
102 changes: 52 additions & 50 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,52 +1,54 @@
{
"name": "virtual-drive",
"version": "1.0.1",
"description": "",
"main": "dist/index.ts",
"types": "dist/index.d.ts",
"scripts": {
"========== Testing ==========": "",
"test": "vitest",
"test:once": "yarn vitest --run",
"test:one": "yarn vitest related x",
"========== Build ==========": "",
"clean": "node-gyp clean",
"build:gyp": "node-gyp configure build",
"build:ts": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json",
"config:gyp": "python gyp.config.py",
"build": "python gyp.config.py && node-gyp clean && node-gyp configure build && yarn build:ts",
"========== Examples ==========": "",
"prod:register": "node ./dist/examples/register.js",
"register": "nodemon",
"populate": "ts-node -r tsconfig-paths/register ./examples/populate.ts",
"get-state": "ts-node -r tsconfig-paths/register ./examples/get-state.ts",
"unregister": "ts-node -r tsconfig-paths/register ./examples/unregister.ts",
"disconnect": "ts-node -r tsconfig-paths/register ./examples/disconnect.ts"
},
"author": "",
"license": "ISC",
"gypfile": true,
"devDependencies": {
"@trivago/prettier-plugin-sort-imports": "^5.2.1",
"@types/lodash.chunk": "^4.2.9",
"@types/node": "^20.5.0",
"@types/yargs": "^17.0.32",
"nodemon": "^3.1.9",
"prettier": "^3.4.2",
"ts-node": "^10.9.2",
"tsc-alias": "^1.8.10",
"typescript": "^5.1.6",
"vite-tsconfig-paths": "^5.1.4",
"vitest": "^3.0.3",
"vitest-mock-extended": "^2.0.2"
},
"dependencies": {
"chokidar": "^3.6.0",
"lodash.chunk": "^4.2.0",
"tsconfig-paths": "^4.2.0",
"uuid": "^11.0.3",
"winston": "^3.17.0",
"yargs": "^17.7.2",
"zod": "^3.24.1"
}
"name": "virtual-drive",
"version": "1.0.1",
"description": "",
"main": "dist/index.ts",
"types": "dist/index.d.ts",
"scripts": {
"========== Testing ==========": "",
"test": "vitest",
"test:once": "yarn vitest --run",
"test:one": "yarn vitest related x",
"========== Build ==========": "",
"clean": "node-gyp clean",
"build:gyp": "node-gyp configure build",
"build:ts": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json",
"config:gyp": "python gyp.config.py",
"build": "python gyp.config.py && node-gyp clean && node-gyp configure build && yarn build:ts",
"========== Linter ==========": "",
"format": "prettier . --write",
"========== Examples ==========": "",
"prod:register": "node ./dist/examples/register.js",
"register": "nodemon",
"populate": "ts-node -r tsconfig-paths/register ./examples/populate.ts",
"get-state": "ts-node -r tsconfig-paths/register ./examples/get-state.ts",
"unregister": "ts-node -r tsconfig-paths/register ./examples/unregister.ts",
"disconnect": "ts-node -r tsconfig-paths/register ./examples/disconnect.ts"
},
"author": "",
"license": "ISC",
"gypfile": true,
"devDependencies": {
"@trivago/prettier-plugin-sort-imports": "^5.2.1",
"@types/lodash.chunk": "^4.2.9",
"@types/node": "^20.5.0",
"@types/yargs": "^17.0.32",
"nodemon": "^3.1.9",
"prettier": "^3.4.2",
"ts-node": "^10.9.2",
"tsc-alias": "^1.8.10",
"typescript": "^5.1.6",
"vite-tsconfig-paths": "^5.1.4",
"vitest": "^3.0.3",
"vitest-mock-extended": "^2.0.2"
},
"dependencies": {
"chokidar": "^3.6.0",
"lodash.chunk": "^4.2.0",
"tsconfig-paths": "^4.2.0",
"uuid": "^11.0.3",
"winston": "^3.17.0",
"yargs": "^17.7.2",
"zod": "^3.24.1"
}
}
6 changes: 0 additions & 6 deletions src/queue/queueManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,3 @@ export type HandleAction = (task: QueueItem) => Promise<void>;
export type HandleActions = {
[key in typeQueue]: HandleAction;
};

export interface IQueueManager {
actions: HandleActions;

enqueue(task: QueueItem): void;
}
Loading