Compare commits
158 Commits
Author | SHA1 | Date | |
---|---|---|---|
16d47ea348 | |||
dc92b7fe93 | |||
0001b433bf | |||
cd147ca38e | |||
9b0d89b9ef | |||
b34ae1362d | |||
2fa68c23a9 | |||
4083a36d8c | |||
3988ccbcb3 | |||
6eadbc654f | |||
fda1543701 | |||
a9660eda9a | |||
dfd1db152b | |||
7a32835a74 | |||
e78682d9b4 | |||
8dceea67be | |||
40018532a7 | |||
f6fb28d32f | |||
2d1ac0bd50 | |||
04a25221a5 | |||
13081b7344 | |||
0abbe8bbd7 | |||
de2a250a45 | |||
1657d0e1c6 | |||
e6b8240031 | |||
be011a4637 | |||
dbddf2a8ba | |||
207320ff26 | |||
be99bdae66 | |||
768d970918 | |||
a9799e05ee | |||
7c07c5c174 | |||
4c4e41b158 | |||
d557e4b4fe | |||
16ded5c3cf | |||
a2bd049ebd | |||
f95c5c9a15 | |||
b55a3eb83f | |||
fc8d994943 | |||
f1daec6f44 | |||
6698a583e9 | |||
bf52f01365 | |||
14adec5ba3 | |||
fb2880c995 | |||
0e0ae7e42f | |||
1391dbddbc | |||
477736da82 | |||
26a67d9662 | |||
14771fab27 | |||
b0ae383622 | |||
921f1cbb66 | |||
a9b373f5f8 | |||
f0d48cc763 | |||
255cc844ad | |||
50cc3fa8bf | |||
21b3870a7d | |||
023e1cdf29 | |||
493a235065 | |||
e4e48dc9db | |||
7de647daa1 | |||
34bc92137b | |||
954df5a0ee | |||
b9c15b11ad | |||
55e6e81957 | |||
f37956270c | |||
0c985b9c00 | |||
85ff487809 | |||
eb65c4e859 | |||
a1d6c37f18 | |||
915ad00801 | |||
910671bfc6 | |||
ae8835d430 | |||
d08cc0f350 | |||
1311039127 | |||
c267d2f226 | |||
5a9e1b5798 | |||
b1ec86ee2d | |||
a1353170f6 | |||
3ff6de201d | |||
f5c106b2ca | |||
d3c26d0d46 | |||
9935fe2d3c | |||
3b05aab39b | |||
53be2eb59d | |||
c92a0dddbd | |||
27403a73b5 | |||
b925e5e662 | |||
98a5d2c94d | |||
0e735cba20 | |||
f815457801 | |||
f7e47ae354 | |||
684e893801 | |||
d4b381d33d | |||
291a11aa60 | |||
ca592afec9 | |||
8b07197224 | |||
b60fd15ec6 | |||
853eccc780 | |||
c26aff85b5 | |||
321e4d9dea | |||
3d2789857c | |||
07b88a078d | |||
6fee0028d8 | |||
629c52f9bc | |||
fd056c29e9 | |||
36c456b509 | |||
16f8c25557 | |||
219e070ba2 | |||
ee97e1d88b | |||
279db74568 | |||
b84c504f11 | |||
7b3194cc13 | |||
e1e821efec | |||
6b613d1b8a | |||
70f1c58a82 | |||
5df76ca94b | |||
32cfda3c90 | |||
dd521398ea | |||
038e6cc33d | |||
2fc37d6892 | |||
3c1eb1ab70 | |||
5296e8859b | |||
160e0ae451 | |||
373c6538ae | |||
7a1476e106 | |||
b2a2035f00 | |||
03e4f03035 | |||
d74bbb2b12 | |||
22cfe1f5cb | |||
5fc2c4586d | |||
6ab81fb323 | |||
58ec27a1a0 | |||
88811646b7 | |||
412bb52eee | |||
b04750ecbd | |||
0c99475888 | |||
86317def88 | |||
0a5af0ba96 | |||
cf73ff4a54 | |||
788897e765 | |||
7fa3894f6e | |||
afdd654664 | |||
8277e0ca6d | |||
0892c87a68 | |||
841ba2e14d | |||
5b2953bf02 | |||
d3457fd65b | |||
3bf1eafe6b | |||
04a9b992d7 | |||
6206b55deb | |||
6c05bf6ae3 | |||
371074afc1 | |||
e0e665fe6d | |||
5483202972 | |||
24b3458888 | |||
cffa47ac3d | |||
9dadf3f78f | |||
b35a671fe9 |
66
.gitea/workflows/default_nottags.yaml
Normal file
66
.gitea/workflows/default_nottags.yaml
Normal file
@@ -0,0 +1,66 @@
|
||||
name: Default (not tags)
|
||||
|
||||
on:
|
||||
push:
|
||||
tags-ignore:
|
||||
- '**'
|
||||
|
||||
env:
|
||||
IMAGE: code.foss.global/host.today/ht-docker-node:npmci
|
||||
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@/${{gitea.repository}}.git
|
||||
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
||||
|
||||
jobs:
|
||||
security:
|
||||
runs-on: ubuntu-latest
|
||||
continue-on-error: true
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Install pnpm and npmci
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @ship.zone/npmci
|
||||
|
||||
- name: Run npm prepare
|
||||
run: npmci npm prepare
|
||||
|
||||
- name: Audit production dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --prod
|
||||
continue-on-error: true
|
||||
|
||||
- name: Audit development dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --dev
|
||||
continue-on-error: true
|
||||
|
||||
test:
|
||||
if: ${{ always() }}
|
||||
needs: security
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Test stable
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm test
|
||||
|
||||
- name: Test build
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm build
|
124
.gitea/workflows/default_tags.yaml
Normal file
124
.gitea/workflows/default_tags.yaml
Normal file
@@ -0,0 +1,124 @@
|
||||
name: Default (tags)
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- '*'
|
||||
|
||||
env:
|
||||
IMAGE: code.foss.global/host.today/ht-docker-node:npmci
|
||||
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@/${{gitea.repository}}.git
|
||||
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
||||
|
||||
jobs:
|
||||
security:
|
||||
runs-on: ubuntu-latest
|
||||
continue-on-error: true
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @ship.zone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Audit production dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --prod
|
||||
continue-on-error: true
|
||||
|
||||
- name: Audit development dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --dev
|
||||
continue-on-error: true
|
||||
|
||||
test:
|
||||
if: ${{ always() }}
|
||||
needs: security
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @ship.zone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Test stable
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm test
|
||||
|
||||
- name: Test build
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm build
|
||||
|
||||
release:
|
||||
needs: test
|
||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @ship.zone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Release
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm publish
|
||||
|
||||
metadata:
|
||||
needs: test
|
||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
continue-on-error: true
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @ship.zone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Code quality
|
||||
run: |
|
||||
npmci command npm install -g typescript
|
||||
npmci npm install
|
||||
|
||||
- name: Trigger
|
||||
run: npmci trigger
|
||||
|
||||
- name: Build docs and upload artifacts
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
pnpm install -g @git.zone/tsdoc
|
||||
npmci command tsdoc
|
||||
continue-on-error: true
|
7
.gitignore
vendored
7
.gitignore
vendored
@@ -3,7 +3,6 @@
|
||||
# artifacts
|
||||
coverage/
|
||||
public/
|
||||
pages/
|
||||
|
||||
# installs
|
||||
node_modules/
|
||||
@@ -17,4 +16,8 @@ node_modules/
|
||||
dist/
|
||||
dist_*/
|
||||
|
||||
# custom
|
||||
# AI
|
||||
.claude/
|
||||
.serena/
|
||||
|
||||
#------# custom
|
127
.gitlab-ci.yml
127
.gitlab-ci.yml
@@ -1,127 +0,0 @@
|
||||
# gitzone ci_default
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
|
||||
cache:
|
||||
paths:
|
||||
- .npmci_cache/
|
||||
key: '$CI_BUILD_STAGE'
|
||||
|
||||
stages:
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- metadata
|
||||
|
||||
before_script:
|
||||
- pnpm install -g pnpm
|
||||
- pnpm install -g @shipzone/pnpm
|
||||
- npmci npm prepare
|
||||
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
auditProductionDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command pnpm audit --audit-level=high --prod
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
|
||||
auditDevDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command pnpm audit --audit-level=high --dev
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
allow_failure: true
|
||||
|
||||
# ====================
|
||||
# test stage
|
||||
# ====================
|
||||
|
||||
testStable:
|
||||
stage: test
|
||||
script:
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
|
||||
testBuild:
|
||||
stage: test
|
||||
script:
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
|
||||
release:
|
||||
stage: release
|
||||
script:
|
||||
- npmci node install stable
|
||||
- npmci npm publish
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
# ====================
|
||||
# metadata stage
|
||||
# ====================
|
||||
codequality:
|
||||
stage: metadata
|
||||
allow_failure: true
|
||||
only:
|
||||
- tags
|
||||
script:
|
||||
- npmci command npm install -g typescript
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- priv
|
||||
|
||||
trigger:
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci trigger
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
pages:
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci command npm run buildDocs
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
only:
|
||||
- tags
|
||||
artifacts:
|
||||
expire_in: 1 week
|
||||
paths:
|
||||
- public
|
||||
allow_failure: true
|
476
changelog.md
Normal file
476
changelog.md
Normal file
@@ -0,0 +1,476 @@
|
||||
# Changelog
|
||||
|
||||
## 2025-08-18 - 11.2.7 - fix(ci)
|
||||
Remove .npmrc containing hard-coded npm registry configuration
|
||||
|
||||
- Removed .npmrc which contained 'registry=https://registry.npmjs.org/'
|
||||
- Avoids committing environment-specific npm registry configuration; rely on user or CI environment settings instead
|
||||
|
||||
## 2025-08-18 - 11.2.6 - fix(fs)
|
||||
Improve fs and stream handling, enhance SmartFile/StreamFile, update tests and CI configs
|
||||
|
||||
- Fix listFileTree to correctly handle '**/' patterns by running both root and nested patterns and deduplicating results.
|
||||
- Enhance waitForFileToBeReady: support directory paths (wait for first file) and improved file-stability checks with timeouts and retries.
|
||||
- StreamFile improvements: support Web ReadableStream -> Node Readable conversion, better multi-use buffering, more robust fromUrl/fromBuffer/fromStream implementations, and accurate byte-length computation.
|
||||
- SmartFile updates: switch fromUrl to SmartRequest, robust rename (optional on-disk rename), safer read/write paths and consistent Buffer handling for hashing and content edits.
|
||||
- fs module tweaks: copy/copySync gained replaceTargetDir option, improved toObjectSync error messages, toReadStream now validates existence, and various synchronous/async API consistency fixes.
|
||||
- memory module: consistent async/sync write APIs and smartfileArrayToFs formatting/behavior fixes.
|
||||
- fsstream: improved stream processing and SmartReadStream robustness (error handling, read logic and watcher improvements).
|
||||
- Tests: reformatted and strengthened tests (more explicit assertions, added tests for '**/*.ts' and '**/*' edge cases, updated imports to tapbundle usage).
|
||||
- CI/workflows: updated IMAGE and NPMCI_COMPUTED_REPOURL values and switched npmci package install to @ship.zone/npmci in workflow files.
|
||||
- package.json: bumped various dependencies, updated test script (timeout, logfile), added typings/main fields, homepage fix, pnpm overrides and minor metadata fixes.
|
||||
- .gitignore: added entries for AI tool folders (.claude/, .serena/).
|
||||
- Docs/readme: expanded README with clearer examples, features and TypeScript usage; updated readme hints for listFileTree behavior.
|
||||
|
||||
## 2025-05-26 - 11.2.5 - fix(dev)
|
||||
|
||||
Update dev dependencies and add local permission settings
|
||||
|
||||
- Bump @git.zone/tsbuild from 2.5.2 to 2.6.4
|
||||
- Bump @git.zone/tstest from 1.9.0 to 2.2.5
|
||||
- Add .claude/settings.local.json to configure permissions for Bash(pnpm test:\*)
|
||||
|
||||
## 2025-05-24 - 11.2.4 - fix(config)
|
||||
|
||||
Add local permissions configuration for pnpm test commands in .claude/settings.local.json
|
||||
|
||||
- Introduced .claude/settings.local.json to allow Bash(pnpm test:\*) permissions
|
||||
- Ensured local testing commands have proper execution rights
|
||||
|
||||
## 2025-05-21 - 11.2.2 - fix(tests/settings)
|
||||
|
||||
Improve test assertions and update local settings permissions
|
||||
|
||||
- Refactor StreamFile tests to assert content string type using toBeTypeofString
|
||||
- Update file existence tests to use resolves.toBeTrue and resolves.toBeFalse for cleaner promise handling
|
||||
- Add .claude/settings.local.json to allow specific Bash permissions for pnpm test commands
|
||||
|
||||
## 2025-05-21 - 11.2.1 - fix(fs)
|
||||
|
||||
Fix inconsistent glob matching in listFileTree and update test imports and dependency versions for enhanced stability.
|
||||
|
||||
- Enhanced listFileTree to support \*\*/ patterns by using dual patterns (root and nested) with deduplication.
|
||||
- Updated test imports to use '@git.zone/tstest/tapbundle' for consistency across test files.
|
||||
- Bumped dependency versions (@push.rocks/lik, smartpromise, smartrequest, glob) in package.json.
|
||||
- Added npm configuration (.npmrc) and local settings for improved test verbosity.
|
||||
|
||||
## 2025-01-29 - 11.2.0 - feat(fs)
|
||||
|
||||
Enhanced copy method with optional replaceTargetDir option for directory replacement
|
||||
|
||||
- Added optional 'replaceTargetDir' option to 'copy' and 'copySync' methods in 'fs.ts'.
|
||||
- The 'replaceTargetDir' option allows replacing the target directory if both source and target are directories.
|
||||
|
||||
## 2025-01-29 - 11.1.9 - fix(fs)
|
||||
|
||||
Fix directory handling in copy and copySync functions
|
||||
|
||||
- Ensured existing directories at destination are removed before copying over them in async copy.
|
||||
- Added a similar check and handling for synchronous copySync when destination is a directory.
|
||||
|
||||
## 2025-01-29 - 11.1.8 - fix(fs)
|
||||
|
||||
Fixed copy and copySync functions to ensure they always overwrite files.
|
||||
|
||||
- Fixed bug in copy function where files were not being overwritten when they already existed at the destination.
|
||||
- Fixed bug in copySync function to ensure files are overwritten to match the async function's behavior.
|
||||
|
||||
## 2025-01-29 - 11.1.7 - fix(fs)
|
||||
|
||||
Refactor copy and copySync functions to simplify return type
|
||||
|
||||
- Changed the return type of fs.copy and fs.copySync from boolean to void.
|
||||
- Removed unnecessary promise handling in fs.copy.
|
||||
|
||||
## 2025-01-29 - 11.1.6 - fix(fs)
|
||||
|
||||
Fix issues with fs file copy functions.
|
||||
|
||||
- Updated dependencies in package.json.
|
||||
- Corrected comments for asynchronous and synchronous file copy functions in fs.ts.
|
||||
|
||||
## 2025-01-07 - 11.1.5 - fix(fs)
|
||||
|
||||
Improve waitForFileToBeReady function to handle directories and file stabilization
|
||||
|
||||
- Enhanced the waitForFileToBeReady to handle directory paths by checking for file existence within directories and waiting for stabilization.
|
||||
- Modified the watcher logic to cater to changes when monitoring directories for file appearance.
|
||||
- Introduced a helper function to ensure paths exist and another to resolve the first file in directories.
|
||||
- Corrected logic for polling and stabilizing files within directories.
|
||||
|
||||
## 2025-01-07 - 11.1.4 - fix(fs)
|
||||
|
||||
Fix file existence check in waitForFileToBeReady method.
|
||||
|
||||
- Ensured that the directory and file exist before setting up the watcher in waitForFileToBeReady.
|
||||
- Changed ensureDirectoryExists to ensureFileExists for correct file path verification.
|
||||
- Handled ENOENT errors correctly to retry file existence checks until timeout is reached.
|
||||
|
||||
## 2025-01-07 - 11.1.3 - fix(fs)
|
||||
|
||||
Fix TypeScript type issue in fs module
|
||||
|
||||
- Corrected a TypeScript type in the fs module's checkFileStability function.
|
||||
|
||||
## 2025-01-07 - 11.1.2 - fix(fs)
|
||||
|
||||
Fix issues in file stability check and directory existence verification in fs module
|
||||
|
||||
- Removed unused variable 'isFileAvailable' in 'waitForFileToBeReady'.
|
||||
- Fixed logic for ensuring the target directory exists before setting up file stability watcher.
|
||||
- Refactored directory existence logic into 'ensureDirectoryExists' function.
|
||||
|
||||
## 2025-01-07 - 11.1.1 - fix(fs)
|
||||
|
||||
Improve waitForFileToBeReady function for file stability detection
|
||||
|
||||
- Enhanced error handling and file stability checks in waitForFileToBeReady function
|
||||
- Added timeout feature for file readiness check
|
||||
- Improved directory access check before file availability check
|
||||
|
||||
## 2025-01-07 - 11.1.0 - feat(SmartFile)
|
||||
|
||||
Add rename functionality to SmartFile class
|
||||
|
||||
- Implemented a new method to rename a file within the SmartFile class.
|
||||
- The rename method updates the file path and optionally writes the renamed file to the disk.
|
||||
|
||||
## 2024-12-15 - 11.0.23 - fix(fs)
|
||||
|
||||
Handle errors in toObjectSync method
|
||||
|
||||
- Added error handling in toObjectSync function to capture and provide more informative error messages.
|
||||
|
||||
## 2024-06-23 - 11.0.22 - fix(core)
|
||||
|
||||
Update dependencies and changelog
|
||||
|
||||
- Updated @push.rocks/smartstream to ^3.0.44
|
||||
- Updated glob to ^10.4.2
|
||||
- Updated @types/node to ^20.14.8
|
||||
|
||||
## 2024-06-23 - 11.0.21 - fix(dependencies)
|
||||
|
||||
Update dependencies to latest versions
|
||||
|
||||
- Updated @push.rocks/smartpromise to ^4.0.4
|
||||
- Updated @push.rocks/smartstream to ^3.0.44
|
||||
- Updated glob to ^10.4.2
|
||||
- Updated @types/node to ^20.14.8
|
||||
|
||||
## 2024-06-07 - 11.0.20 - Changelog
|
||||
|
||||
11.0.20
|
||||
|
||||
## 2024-06-07 - 11.0.19 - fix(core): update
|
||||
|
||||
11.0.19
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2024-06-07 - 11.0.18 - fix(core): update
|
||||
|
||||
11.0.18
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2024-06-06 - 11.0.17 - fix(core): update
|
||||
|
||||
11.0.17
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2024-06-06 - 11.0.16 - fix(core): update
|
||||
|
||||
11.0.16
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2024-05-29 - 11.0.16 - update description
|
||||
|
||||
11.0.16
|
||||
|
||||
- update description
|
||||
|
||||
## 2024-05-17 - 11.0.15 - fix(core): update
|
||||
|
||||
11.0.15
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2024-04-14 - 11.0.14 - update tsconfig
|
||||
|
||||
11.0.14
|
||||
|
||||
- update tsconfig
|
||||
|
||||
## 2024-04-12 - 11.0.13 - fix(core): update
|
||||
|
||||
11.0.13
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2024-04-12 - 11.0.12 - fix(core): update
|
||||
|
||||
11.0.12
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2024-04-12 - 11.0.11 - fix(core): update
|
||||
|
||||
11.0.11
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2024-04-03 - 11.0.10 - fix(core): update
|
||||
|
||||
11.0.10
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2024-04-03 - 11.0.9 - fix(core): update
|
||||
|
||||
11.0.9
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2024-04-02 - 11.0.8 - fix(core): update
|
||||
|
||||
11.0.8
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2024-04-02 - 11.0.7 - fix(core): update
|
||||
|
||||
11.0.7
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2024-04-02 - 11.0.6 - fix(core): update
|
||||
|
||||
11.0.6
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2024-04-01 - 11.0.5 - update npmextra.json
|
||||
|
||||
11.0.5
|
||||
|
||||
- update npmextra.json: githost
|
||||
|
||||
## 2024-04-01 - 11.0.4 - fix(core): update
|
||||
|
||||
11.0.4
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2023-11-24 - 11.0.3 - fix(core): update
|
||||
|
||||
11.0.3
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2023-11-07 - 11.0.2 - fix(core): update
|
||||
|
||||
11.0.2
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2023-11-07 - 11.0.1 - fix(core): update
|
||||
|
||||
11.0.1
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2023-11-06 - 11.0.0 - fix(core): update
|
||||
|
||||
11.0.0
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2023-11-06 - 10.0.40 - BREAKING CHANGE(core): update
|
||||
|
||||
10.0.40
|
||||
|
||||
- BREAKING CHANGE(core): update
|
||||
|
||||
## 2023-11-04 - 10.0.39 - fix(core): update
|
||||
|
||||
10.0.39
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2023-11-04 - 10.0.38 - fix(core): update
|
||||
|
||||
10.0.38
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2023-11-04 - 10.0.37 - fix(core): update
|
||||
|
||||
10.0.37
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2023-11-03 - 10.0.36 - fix(core): update
|
||||
|
||||
10.0.36
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2023-11-03 - 10.0.35 - fix(core): update
|
||||
|
||||
10.0.35
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2023-11-03 - 10.0.34 - fix(core): update
|
||||
|
||||
10.0.34
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2023-11-03 - 10.0.33 - fix(core): update
|
||||
|
||||
10.0.33
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2023-10-12 - 10.0.32 - fix(core): update
|
||||
|
||||
10.0.32
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2023-09-22 - 10.0.31 - fix(core): update
|
||||
|
||||
10.0.31
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2023-08-31 - 10.0.30 - fix(core): update
|
||||
|
||||
10.0.30
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2023-08-23 - 10.0.29 - fix(core): update
|
||||
|
||||
10.0.29
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2023-07-12 - 10.0.28 - fix(core): update
|
||||
|
||||
10.0.28
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2023-07-10 - 10.0.27 - fix(core): update
|
||||
|
||||
10.0.27
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2023-07-10 - 10.0.26 - fix(core): update
|
||||
|
||||
10.0.26
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2023-07-08 - 10.0.25 - fix(core): update
|
||||
|
||||
10.0.25
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2023-06-25 - 10.0.24 to 10.0.14 - Series of Fixes
|
||||
|
||||
10.0.24 to 10.0.14
|
||||
|
||||
- Series of fixes in the core module
|
||||
|
||||
## 2023-01-09 - 10.0.13 to 10.0.6 - Series of Fixes
|
||||
|
||||
10.0.13 to 10.0.6
|
||||
|
||||
- Series of fixes in the core module
|
||||
|
||||
## 2022-09-05 - 10.0.5 to 10.0.3 - Series of Fixes
|
||||
|
||||
10.0.5 to 10.0.3
|
||||
|
||||
- Series of fixes in the core module
|
||||
|
||||
## 2022-06-07 - 10.0.2 to 10.0.1 - Series of Fixes
|
||||
|
||||
10.0.2 to 10.0.1
|
||||
|
||||
- Series of fixes in the core module
|
||||
|
||||
## 2022-06-07 - 9.0.7 - BREAKING CHANGE(core): switch to esm
|
||||
|
||||
9.0.7
|
||||
|
||||
- BREAKING CHANGE(core): switch to esm
|
||||
|
||||
## 2022-03-11 - 9.0.6 to 9.0.2 - Series of Fixes
|
||||
|
||||
9.0.6 to 9.0.2
|
||||
|
||||
- Series of fixes in the core module
|
||||
|
||||
## 2021-12-01 - 9.0.1 - fix(core): update
|
||||
|
||||
9.0.1
|
||||
|
||||
- fix(core): update
|
||||
|
||||
## 2021-12-01 - 9.0.0 - fix(absolute pathing)
|
||||
|
||||
9.0.0
|
||||
|
||||
- add functions for easily getting absolute paths
|
||||
|
||||
## 2021-11-30 - 8.0.11 - BREAKING CHANGE(relative pathing)
|
||||
|
||||
8.0.11
|
||||
|
||||
- improved relative pathing
|
||||
|
||||
## 2020-08-10 - 8.0.10 to 7.0.12 - Series of Fixes and Updates
|
||||
|
||||
8.0.10 to 7.0.12
|
||||
|
||||
- Series of fixes in the core module
|
||||
- BREAKING CHANGE(Smartfile class): switch to a Buffer-only approach
|
||||
|
||||
## 2019-02-17 - 7.0.0 - fix(core): update dependencies
|
||||
|
||||
7.0.0
|
||||
|
||||
- fix(core): update dependencies
|
||||
|
||||
## 2019-01-27 - 6.0.12 - BREAKING CHANGE(smartfile.fs.fileExists)
|
||||
|
||||
6.0.12
|
||||
|
||||
- now returns a Promise<boolean>
|
||||
|
||||
## 2018-08-19 - 6.0.11 to 6.0.6 - Series of Fixes
|
||||
|
||||
6.0.11 to 6.0.6
|
||||
|
||||
- Series of fixes in core and dependencies
|
||||
|
||||
## 2018-07-03 - 6.0.5 to 5.0.0 - Series of Fixes
|
||||
|
||||
6.0.5 to 5.0.0
|
||||
|
||||
- Series of fixes in core and dependencies
|
||||
|
||||
## 2018-02-16 - 4.2.28 - BREAKING CHANGE(scope)
|
||||
|
||||
4.2.28
|
||||
|
||||
- switch to pushrocks scope
|
@@ -7,12 +7,39 @@
|
||||
"gitzone": {
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "pushrocks",
|
||||
"githost": "code.foss.global",
|
||||
"gitscope": "push.rocks",
|
||||
"gitrepo": "smartfile",
|
||||
"description": "smart ways to work with files in nodejs",
|
||||
"npmPackagename": "@pushrocks/smartfile",
|
||||
"license": "MIT"
|
||||
"description": "Provides comprehensive tools for efficient file management in Node.js using TypeScript, including handling streams, virtual directories, and various file operations.",
|
||||
"npmPackagename": "@push.rocks/smartfile",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"file management",
|
||||
"TypeScript",
|
||||
"Node.js",
|
||||
"file operations",
|
||||
"file manipulation",
|
||||
"file streaming",
|
||||
"virtual directory",
|
||||
"filesystem utilities",
|
||||
"memory-efficient file handling",
|
||||
"custom file operations",
|
||||
"write files",
|
||||
"read files",
|
||||
"copy files",
|
||||
"delete files",
|
||||
"list directories",
|
||||
"handle large files",
|
||||
"virtual filesystems",
|
||||
"buffer operations"
|
||||
]
|
||||
}
|
||||
},
|
||||
"tsdoc": {
|
||||
"classes": ["SmartFile", "StreamFile"],
|
||||
"descriptions": [
|
||||
"the purpose of the StreamFile class is to provide a hybrid interface between streaming files and simple handling when writing and reading those files multiple times."
|
||||
],
|
||||
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
79
package.json
79
package.json
@@ -1,55 +1,68 @@
|
||||
{
|
||||
"name": "@pushrocks/smartfile",
|
||||
"name": "@push.rocks/smartfile",
|
||||
"private": false,
|
||||
"version": "10.0.6",
|
||||
"description": "offers smart ways to work with files in nodejs",
|
||||
"version": "11.2.7",
|
||||
"description": "Provides comprehensive tools for efficient file management in Node.js using TypeScript, including handling streams, virtual directories, and various file operations.",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"test": "(tstest test/)",
|
||||
"test": "(tstest test/ --verbose --logfile --timeout 120)",
|
||||
"build": "(tsbuild --web --allowimplicitany)",
|
||||
"buildDocs": "tsdoc"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://gitlab.com/pushrocks/smartfile.git"
|
||||
"url": "https://code.foss.global/push.rocks/smartfile.git"
|
||||
},
|
||||
"keywords": [
|
||||
"filesystem",
|
||||
"json"
|
||||
"file management",
|
||||
"TypeScript",
|
||||
"Node.js",
|
||||
"file operations",
|
||||
"file manipulation",
|
||||
"file streaming",
|
||||
"virtual directory",
|
||||
"filesystem utilities",
|
||||
"memory-efficient file handling",
|
||||
"custom file operations",
|
||||
"write files",
|
||||
"read files",
|
||||
"copy files",
|
||||
"delete files",
|
||||
"list directories",
|
||||
"handle large files",
|
||||
"virtual filesystems",
|
||||
"buffer operations"
|
||||
],
|
||||
"author": "Lossless GmbH <hello@lossless.com> (https://lossless.com)",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://gitlab.com/pushrocks/smartfile/issues"
|
||||
"url": "https://code.foss.global/push.rocks/smartfile/issues"
|
||||
},
|
||||
"homepage": "https://gitlab.com/pushrocks/smartfile",
|
||||
"homepage": "https://code.foss.global/push.rocks/smartfile#readme",
|
||||
"dependencies": {
|
||||
"@pushrocks/lik": "^6.0.0",
|
||||
"@pushrocks/smartdelay": "^2.0.13",
|
||||
"@pushrocks/smartfile-interfaces": "^1.0.7",
|
||||
"@pushrocks/smarthash": "^3.0.1",
|
||||
"@pushrocks/smartjson": "^5.0.5",
|
||||
"@pushrocks/smartmime": "^1.0.5",
|
||||
"@pushrocks/smartpath": "^5.0.5",
|
||||
"@pushrocks/smartpromise": "^3.1.6",
|
||||
"@pushrocks/smartrequest": "^2.0.11",
|
||||
"@pushrocks/smartstream": "^2.0.3",
|
||||
"@pushrocks/streamfunction": "^4.0.4",
|
||||
"@types/fs-extra": "^11.0.0",
|
||||
"@types/glob": "^8.0.0",
|
||||
"@types/js-yaml": "^4.0.5",
|
||||
"fs-extra": "^11.1.0",
|
||||
"glob": "^8.0.3",
|
||||
"@push.rocks/lik": "^6.2.2",
|
||||
"@push.rocks/smartdelay": "^3.0.5",
|
||||
"@push.rocks/smartfile-interfaces": "^1.0.7",
|
||||
"@push.rocks/smarthash": "^3.2.3",
|
||||
"@push.rocks/smartjson": "^5.0.20",
|
||||
"@push.rocks/smartmime": "^2.0.4",
|
||||
"@push.rocks/smartpath": "^6.0.0",
|
||||
"@push.rocks/smartpromise": "^4.2.3",
|
||||
"@push.rocks/smartrequest": "^4.2.1",
|
||||
"@push.rocks/smartstream": "^3.2.5",
|
||||
"@types/fs-extra": "^11.0.4",
|
||||
"@types/js-yaml": "^4.0.9",
|
||||
"fs-extra": "^11.3.1",
|
||||
"glob": "^11.0.3",
|
||||
"js-yaml": "^4.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.1.65",
|
||||
"@gitzone/tsrun": "^1.2.39",
|
||||
"@gitzone/tstest": "^1.0.74",
|
||||
"@pushrocks/tapbundle": "^5.0.4",
|
||||
"@types/node": "^18.11.18"
|
||||
"@git.zone/tsbuild": "^2.6.4",
|
||||
"@git.zone/tsrun": "^1.3.3",
|
||||
"@git.zone/tstest": "^2.3.4",
|
||||
"@types/node": "^22.15.21"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
@@ -65,5 +78,9 @@
|
||||
],
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
]
|
||||
],
|
||||
"packageManager": "pnpm@10.10.0+sha512.d615db246fe70f25dcfea6d8d73dee782ce23e2245e3c4f6f888249fb568149318637dca73c2c5c8ef2a4ca0d5657fb9567188bfab47f566d1ee6ce987815c39",
|
||||
"pnpm": {
|
||||
"overrides": {}
|
||||
}
|
||||
}
|
||||
|
12743
pnpm-lock.yaml
generated
12743
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
33
readme.hints.md
Normal file
33
readme.hints.md
Normal file
@@ -0,0 +1,33 @@
|
||||
# SmartFile Implementation Hints
|
||||
|
||||
## listFileTree Function Enhancement (ts/fs.ts:367-415)
|
||||
|
||||
### Issue Fixed
|
||||
|
||||
The `listFileTree` function previously had inconsistent behavior with `**/*.extension` patterns across different systems and glob implementations. Some implementations would miss root-level files when using patterns like `**/*.ts`.
|
||||
|
||||
### Solution Implemented
|
||||
|
||||
Modified the function to explicitly handle `**/` patterns by:
|
||||
|
||||
1. Detecting when a pattern starts with `**/`
|
||||
2. Extracting the file pattern after `**/` (e.g., `*.ts` from `**/*.ts`)
|
||||
3. Running both the original pattern and the extracted root pattern
|
||||
4. Using a Set to deduplicate results and ensure consistent ordering
|
||||
|
||||
### Key Benefits
|
||||
|
||||
- Guarantees consistent behavior across all systems
|
||||
- Ensures both root-level and nested files are found with `**/*` patterns
|
||||
- Maintains backward compatibility
|
||||
- No performance degradation due to efficient deduplication
|
||||
|
||||
### Test Coverage
|
||||
|
||||
Added comprehensive tests to verify:
|
||||
|
||||
- Both root and nested files are found with `**/*.ts`
|
||||
- No duplicate entries in results
|
||||
- Edge cases with various file extensions work correctly
|
||||
|
||||
This fix ensures tools like `tsbuild check **/*.ts` work reliably across all systems.
|
355
readme.md
355
readme.md
@@ -1,51 +1,330 @@
|
||||
# @pushrocks/smartfile
|
||||
smart ways to work with files in nodejs
|
||||
# @push.rocks/smartfile 📁
|
||||
|
||||
## Availabililty and Links
|
||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartfile)
|
||||
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartfile)
|
||||
* [github.com (source mirror)](https://github.com/pushrocks/smartfile)
|
||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartfile/)
|
||||
> **A powerful, TypeScript-based file management library for Node.js**
|
||||
|
||||
## Status for master
|
||||
## 🚀 What is smartfile?
|
||||
|
||||
Status Category | Status Badge
|
||||
-- | --
|
||||
GitLab Pipelines | [](https://lossless.cloud)
|
||||
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||
npm | [](https://lossless.cloud)
|
||||
Snyk | [](https://lossless.cloud)
|
||||
TypeScript Support | [](https://lossless.cloud)
|
||||
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
Code Style | [](https://lossless.cloud)
|
||||
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||
Platform support | [](https://lossless.cloud) [](https://lossless.cloud)
|
||||
`@push.rocks/smartfile` is your go-to solution for file operations in Node.js. It offers a clean, promise-based API for handling files, directories, streams, and even virtual filesystems - all while maintaining maximum performance and reliability.
|
||||
|
||||
## Usage
|
||||
Think of it as `fs` on steroids, with TypeScript superpowers! 💪
|
||||
|
||||
smartfile is an approach of being one tool to handle files in diverse environments.
|
||||
## 💾 Installation
|
||||
|
||||
### Smartfile Sections
|
||||
```bash
|
||||
npm install @push.rocks/smartfile
|
||||
```
|
||||
|
||||
smartfile thinks in sections:
|
||||
## ✨ Features
|
||||
|
||||
| section | description |
|
||||
| ----------- | ---------------------------------------------------------------------------- |
|
||||
| fs | (object) gets data from fs to somewhere |
|
||||
| memory | gets data from memory to somewhere |
|
||||
| remote | gets data from remote locations to somewhere |
|
||||
| interpreter | (object) handles yaml and json |
|
||||
| smartfile | (class) a virtual representation of a file, alternative to vinyl file format |
|
||||
- 🔥 **Streaming Support** - Handle massive files with ease using `StreamFile`
|
||||
- 📦 **Virtual Directories** - Work with in-memory file structures
|
||||
- 🌐 **URL Support** - Directly work with files from URLs
|
||||
- 🎯 **TypeScript First** - Full type safety and IntelliSense support
|
||||
- ⚡ **Promise-based API** - Modern async/await patterns throughout
|
||||
- 🛠️ **Comprehensive Toolset** - From basic CRUD to advanced operations
|
||||
|
||||
## Contribution
|
||||
## 📚 Quick Start
|
||||
|
||||
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
||||
```typescript
|
||||
import * as smartfile from '@push.rocks/smartfile';
|
||||
|
||||
For further information read the linked docs at the top of this readme.
|
||||
// Read a file
|
||||
const content = await smartfile.fs.toStringSync('./my-file.txt');
|
||||
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||
// Write a file
|
||||
await smartfile.memory.toFs('Hello World!', './output.txt');
|
||||
|
||||
[](https://maintainedby.lossless.com)
|
||||
// Work with JSON
|
||||
const data = await smartfile.fs.toObjectSync('./data.json');
|
||||
```
|
||||
|
||||
## 🎨 Core Components
|
||||
|
||||
### SmartFile Class
|
||||
|
||||
The `SmartFile` class represents a single file with powerful manipulation capabilities:
|
||||
|
||||
```typescript
|
||||
import { SmartFile } from '@push.rocks/smartfile';
|
||||
|
||||
// Create from file path
|
||||
const fileFromPath = await SmartFile.fromFilePath('./data.json');
|
||||
|
||||
// Create from URL
|
||||
const fileFromUrl = await SmartFile.fromUrl('https://example.com/config.json');
|
||||
|
||||
// Create from text
|
||||
const fileFromText = await SmartFile.fromString(
|
||||
'./my-file.txt',
|
||||
'This is my content',
|
||||
'utf8'
|
||||
);
|
||||
|
||||
// Create from Buffer
|
||||
const fileFromBuffer = await SmartFile.fromBuffer(
|
||||
'./binary.dat',
|
||||
Buffer.from([0x00, 0x01, 0x02])
|
||||
);
|
||||
|
||||
// Edit content
|
||||
await fileFromPath.editContentAsString(async (content) => {
|
||||
return content.replace(/old/g, 'new');
|
||||
});
|
||||
|
||||
// Write to disk
|
||||
await fileFromPath.write();
|
||||
|
||||
// Get content
|
||||
const contentString = fileFromPath.parseContentAsString();
|
||||
const contentBuffer = fileFromPath.parseContentAsBuffer();
|
||||
```
|
||||
|
||||
### StreamFile Class 🌊
|
||||
|
||||
Perfect for handling large files without memory overhead:
|
||||
|
||||
```typescript
|
||||
import { StreamFile } from '@push.rocks/smartfile';
|
||||
|
||||
// Create from path
|
||||
const streamFile = await StreamFile.fromPath('./bigfile.zip');
|
||||
|
||||
// Create from URL
|
||||
const urlStream = await StreamFile.fromUrl('https://example.com/large.mp4');
|
||||
|
||||
// Create from buffer
|
||||
const bufferStream = StreamFile.fromBuffer(
|
||||
Buffer.from('streaming content'),
|
||||
'stream.txt'
|
||||
);
|
||||
|
||||
// Write to disk
|
||||
await streamFile.writeToDisk('./output/bigfile.zip');
|
||||
|
||||
// Get as buffer (careful with large files!)
|
||||
const buffer = await streamFile.getContentAsBuffer();
|
||||
|
||||
// Get as stream
|
||||
const readStream = await streamFile.createReadStream();
|
||||
```
|
||||
|
||||
### VirtualDirectory Class 📂
|
||||
|
||||
Manage collections of files as virtual filesystems:
|
||||
|
||||
```typescript
|
||||
import { VirtualDirectory } from '@push.rocks/smartfile';
|
||||
|
||||
// Create from filesystem
|
||||
const vDir = await VirtualDirectory.fromFsDirPath('./src');
|
||||
|
||||
// Create from file array
|
||||
const vDirFromFiles = await VirtualDirectory.fromFileArray([
|
||||
await SmartFile.fromFilePath('./file1.txt'),
|
||||
await SmartFile.fromFilePath('./file2.txt')
|
||||
]);
|
||||
|
||||
// Add files
|
||||
vDir.addSmartfiles([
|
||||
await SmartFile.fromString('./virtual/new.txt', 'content')
|
||||
]);
|
||||
|
||||
// List files
|
||||
const files = vDir.listFiles();
|
||||
const directories = vDir.listDirectories();
|
||||
|
||||
// Get file
|
||||
const file = vDir.getFileByPath('./some/path.txt');
|
||||
|
||||
// Save to disk
|
||||
await vDir.saveToDisk('./output');
|
||||
|
||||
// Load from disk
|
||||
await vDir.loadFromDisk('./source');
|
||||
```
|
||||
|
||||
## 🛠️ File Operations
|
||||
|
||||
### Basic Operations
|
||||
|
||||
```typescript
|
||||
// Check existence
|
||||
const exists = await smartfile.fs.fileExists('./file.txt');
|
||||
const existsSync = smartfile.fs.fileExistsSync('./file.txt');
|
||||
|
||||
// Read operations
|
||||
const content = await smartfile.fs.toStringSync('./file.txt');
|
||||
const buffer = await smartfile.fs.toBuffer('./file.txt');
|
||||
const object = await smartfile.fs.toObjectSync('./data.json');
|
||||
|
||||
// Write operations
|
||||
await smartfile.memory.toFs('content', './output.txt');
|
||||
smartfile.memory.toFsSync('content', './output-sync.txt');
|
||||
|
||||
// Copy operations
|
||||
await smartfile.fs.copy('./source.txt', './dest.txt');
|
||||
await smartfile.fs.copy('./src-dir', './dest-dir');
|
||||
|
||||
// Delete operations
|
||||
await smartfile.fs.remove('./file.txt');
|
||||
await smartfile.fs.removeSync('./file-sync.txt');
|
||||
await smartfile.fs.removeMany(['./file1.txt', './file2.txt']);
|
||||
|
||||
// Ensure operations (create if not exists)
|
||||
await smartfile.fs.ensureDir('./my/deep/directory');
|
||||
await smartfile.fs.ensureFile('./my/file.txt');
|
||||
await smartfile.fs.ensureEmptyDir('./empty-dir');
|
||||
```
|
||||
|
||||
### Directory Operations
|
||||
|
||||
```typescript
|
||||
// List contents
|
||||
const files = await smartfile.fs.listFiles('./directory');
|
||||
const folders = await smartfile.fs.listFolders('./directory');
|
||||
const items = await smartfile.fs.listAllItems('./directory');
|
||||
|
||||
// Get file tree
|
||||
const tree = await smartfile.fs.listFileTree('./src', '**/*.ts');
|
||||
|
||||
// Directory checks
|
||||
const isDir = await smartfile.fs.isDirectory('./path');
|
||||
const isFile = await smartfile.fs.isFile('./path');
|
||||
```
|
||||
|
||||
### Advanced Features
|
||||
|
||||
```typescript
|
||||
// Wait for file to be ready
|
||||
await smartfile.fs.waitForFileToBeReady('./file.txt');
|
||||
|
||||
// Stream operations
|
||||
const readStream = smartfile.fsStream.createReadStream('./input.txt');
|
||||
const writeStream = smartfile.fsStream.createWriteStream('./output.txt');
|
||||
|
||||
// File type detection
|
||||
const fileType = smartfile.interpreter.filetype('./document.pdf');
|
||||
// Returns: 'pdf'
|
||||
|
||||
// Smart read stream (with custom processing)
|
||||
const smartStream = new smartfile.fsStream.SmartReadStream('./data.txt');
|
||||
smartStream.on('data', (chunk) => {
|
||||
// Process chunk
|
||||
console.log(chunk.toString());
|
||||
});
|
||||
```
|
||||
|
||||
## 🔄 Working with Multiple Files
|
||||
|
||||
```typescript
|
||||
// Process multiple SmartFiles
|
||||
const files = await smartfile.fs.fileTreeToObject(
|
||||
'./src',
|
||||
'**/*.{ts,js}'
|
||||
);
|
||||
|
||||
// Write array to disk
|
||||
const smartfiles = [
|
||||
await SmartFile.fromString('file1.txt', 'content1'),
|
||||
await SmartFile.fromString('file2.txt', 'content2')
|
||||
];
|
||||
await smartfile.memory.smartfileArrayToFs(smartfiles, './output');
|
||||
```
|
||||
|
||||
## 🎯 Real-World Examples
|
||||
|
||||
### Website Bundler
|
||||
```typescript
|
||||
// Bundle website assets
|
||||
const website = await VirtualDirectory.fromFsDirPath('./website');
|
||||
const bundle = await website.smartfileArray;
|
||||
|
||||
// Process all CSS files
|
||||
for (const file of bundle.filter(f => f.path.endsWith('.css'))) {
|
||||
await file.editContentAsString(async (css) => {
|
||||
// Minify CSS here
|
||||
return css.replace(/\s+/g, ' ');
|
||||
});
|
||||
}
|
||||
|
||||
// Save processed bundle
|
||||
await website.saveToDisk('./dist');
|
||||
```
|
||||
|
||||
### File Watcher & Processor
|
||||
```typescript
|
||||
// Watch for new files and process them
|
||||
import { SmartFile, StreamFile } from '@push.rocks/smartfile';
|
||||
|
||||
async function processLargeFile(filePath: string) {
|
||||
const streamFile = await StreamFile.fromPath(filePath);
|
||||
|
||||
// Stream to processed location
|
||||
await streamFile.writeToDisk(`./processed/${path.basename(filePath)}`);
|
||||
|
||||
// Clean up original
|
||||
await smartfile.fs.remove(filePath);
|
||||
}
|
||||
```
|
||||
|
||||
### Configuration Manager
|
||||
```typescript
|
||||
// Load and merge config files
|
||||
const defaultConfig = await smartfile.fs.toObjectSync('./config.default.json');
|
||||
const userConfig = await smartfile.fs.toObjectSync('./config.user.json');
|
||||
|
||||
const merged = { ...defaultConfig, ...userConfig };
|
||||
|
||||
await smartfile.memory.toFs(
|
||||
JSON.stringify(merged, null, 2),
|
||||
'./config.final.json'
|
||||
);
|
||||
```
|
||||
|
||||
## 🌟 API Reference
|
||||
|
||||
### Core Modules
|
||||
|
||||
- `fs` - File system operations
|
||||
- `fsStream` - Streaming operations
|
||||
- `memory` - Memory/buffer operations
|
||||
- `interpreter` - File type detection
|
||||
|
||||
### Main Classes
|
||||
|
||||
- `SmartFile` - Single file representation
|
||||
- `StreamFile` - Streaming file operations
|
||||
- `VirtualDirectory` - Virtual filesystem management
|
||||
|
||||
## 🏗️ TypeScript Support
|
||||
|
||||
Full TypeScript support with comprehensive type definitions:
|
||||
|
||||
```typescript
|
||||
import type { SmartFile, StreamFile, VirtualDirectory } from '@push.rocks/smartfile';
|
||||
|
||||
// All methods are fully typed
|
||||
const processFile = async (file: SmartFile): Promise<void> => {
|
||||
const content = file.parseContentAsString();
|
||||
// TypeScript knows content is string
|
||||
};
|
||||
```
|
||||
|
||||
## License and Legal Information
|
||||
|
||||
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
|
||||
|
||||
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
||||
|
||||
### Trademarks
|
||||
|
||||
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
|
||||
|
||||
### Company Information
|
||||
|
||||
Task Venture Capital GmbH
|
||||
Registered at District court Bremen HRB 35230 HB, Germany
|
||||
|
||||
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
|
||||
|
||||
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
|
97
test/test.streamfile.ts
Normal file
97
test/test.streamfile.ts
Normal file
@@ -0,0 +1,97 @@
|
||||
import * as path from 'path';
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import * as smartfile from '../ts/index.js'; // adjust the import path as needed
|
||||
|
||||
// Test assets path
|
||||
const testAssetsPath = './test/testassets/';
|
||||
|
||||
// ---------------------------
|
||||
// StreamFile tests
|
||||
// ---------------------------
|
||||
|
||||
tap.test(
|
||||
'StreamFile.fromPath should create a StreamFile from a file path',
|
||||
async () => {
|
||||
const streamFile = await smartfile.StreamFile.fromPath(
|
||||
path.join(testAssetsPath, 'mytest.json'),
|
||||
);
|
||||
expect(streamFile).toBeInstanceOf(smartfile.StreamFile);
|
||||
const contentBuffer = await streamFile.getContentAsBuffer();
|
||||
expect(contentBuffer).toBeInstanceOf(Buffer);
|
||||
},
|
||||
);
|
||||
|
||||
tap.test(
|
||||
'StreamFile.fromUrl should create a StreamFile from a URL',
|
||||
async () => {
|
||||
const streamFile = await smartfile.StreamFile.fromUrl(
|
||||
'http://example.com/somefile.json',
|
||||
);
|
||||
expect(streamFile).toBeInstanceOf(smartfile.StreamFile);
|
||||
},
|
||||
);
|
||||
|
||||
tap.test(
|
||||
'StreamFile.fromBuffer should create a StreamFile from a Buffer',
|
||||
async () => {
|
||||
const buffer = Buffer.from('Some content');
|
||||
const streamFile = smartfile.StreamFile.fromBuffer(
|
||||
buffer,
|
||||
'bufferfile.txt',
|
||||
);
|
||||
expect(streamFile).toBeInstanceOf(smartfile.StreamFile);
|
||||
},
|
||||
);
|
||||
|
||||
tap.test('StreamFile should write the stream to disk', async () => {
|
||||
const streamFile = await smartfile.StreamFile.fromPath(
|
||||
path.join(testAssetsPath, 'mytest.json'),
|
||||
);
|
||||
await streamFile.writeToDisk(
|
||||
path.join(testAssetsPath, 'temp', 'mytest.json'),
|
||||
);
|
||||
// Verify the file was written
|
||||
expect(
|
||||
// We'll use the fileExists method from your smartfile library
|
||||
// Replace with the actual method you use to check file existence
|
||||
await smartfile.fs.fileExists(
|
||||
path.join(testAssetsPath, 'temp', 'mytest.json'),
|
||||
),
|
||||
).toBeTrue();
|
||||
});
|
||||
|
||||
tap.test('StreamFile should write to a directory', async () => {
|
||||
const streamFile = await smartfile.StreamFile.fromPath(
|
||||
path.join(testAssetsPath, 'mytest.json'),
|
||||
);
|
||||
await streamFile.writeToDir(path.join(testAssetsPath, 'temp'));
|
||||
// Verify the file was written
|
||||
expect(
|
||||
await smartfile.fs.fileExists(
|
||||
path.join(testAssetsPath, 'temp', 'mytest.json'),
|
||||
),
|
||||
).toBeTrue();
|
||||
});
|
||||
|
||||
tap.test('StreamFile should return content as a buffer', async () => {
|
||||
const streamFile = await smartfile.StreamFile.fromPath(
|
||||
path.join(testAssetsPath, 'mytest.json'),
|
||||
);
|
||||
const contentBuffer = await streamFile.getContentAsBuffer();
|
||||
expect(contentBuffer).toBeInstanceOf(Buffer);
|
||||
// Further checks on the content can be added here if necessary
|
||||
});
|
||||
|
||||
tap.test('StreamFile should return content as a string', async () => {
|
||||
const streamFile = await smartfile.StreamFile.fromPath(
|
||||
path.join(testAssetsPath, 'mytest.json'),
|
||||
);
|
||||
const contentString = await streamFile.getContentAsString();
|
||||
expect(contentString).toBeTypeofString();
|
||||
// Verify the content matches what's expected
|
||||
// This assumes the file contains a JSON object with a key 'key1' with value 'this works'
|
||||
expect(JSON.parse(contentString).key1).toEqual('this works');
|
||||
});
|
||||
|
||||
// Start the test sequence
|
||||
tap.start();
|
319
test/test.ts
319
test/test.ts
@@ -1,85 +1,168 @@
|
||||
import * as smartfile from '../ts/index.js';
|
||||
import * as path from 'path';
|
||||
|
||||
import { expect, tap } from '@pushrocks/tapbundle';
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
|
||||
// ---------------------------
|
||||
// smartfile.fs
|
||||
// ---------------------------
|
||||
|
||||
tap.test('.fs.fileExistsSync -> should return an accurate boolean', async () => {
|
||||
// tslint:disable-next-line: no-unused-expression
|
||||
expect(smartfile.fs.fileExistsSync('./test/testassets/mytest.json')).toBeTrue();
|
||||
// tslint:disable-next-line: no-unused-expression
|
||||
expect(smartfile.fs.fileExistsSync('./test/testassets/notthere.json')).toBeFalse();
|
||||
});
|
||||
tap.test(
|
||||
'.fs.fileExistsSync -> should return an accurate boolean',
|
||||
async () => {
|
||||
// tslint:disable-next-line: no-unused-expression
|
||||
expect(
|
||||
smartfile.fs.fileExistsSync('./test/testassets/mytest.json'),
|
||||
).toBeTrue();
|
||||
// tslint:disable-next-line: no-unused-expression
|
||||
expect(
|
||||
smartfile.fs.fileExistsSync('./test/testassets/notthere.json'),
|
||||
).toBeFalse();
|
||||
},
|
||||
);
|
||||
|
||||
tap.test('.fs.fileExists -> should resolve or reject a promise', async () => {
|
||||
expect(smartfile.fs.fileExists('./test/testassets/mytest.json')).toBeInstanceOf(Promise);
|
||||
await smartfile.fs.fileExists('./test/testassets/mytest.json');
|
||||
await smartfile.fs.fileExists('./test/testassets/notthere.json').catch((err) => {
|
||||
return expect(err.message).toEqual(
|
||||
"ENOENT: no such file or directory, access './test/testassets/notthere.json'"
|
||||
await expect(
|
||||
smartfile.fs.fileExists('./test/testassets/mytest.json'),
|
||||
).resolves.toBeTrue();
|
||||
await expect(
|
||||
smartfile.fs.fileExists('./test/testassets/notthere.json'),
|
||||
).resolves.toBeFalse();
|
||||
});
|
||||
|
||||
tap.test(
|
||||
'.fs.listFoldersSync() -> should get the file type from a string',
|
||||
async () => {
|
||||
expect(smartfile.fs.listFoldersSync('./test/testassets/')).toContain(
|
||||
'testfolder',
|
||||
);
|
||||
});
|
||||
});
|
||||
expect(smartfile.fs.listFoldersSync('./test/testassets/')).not.toContain(
|
||||
'notExistentFolder',
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
tap.test('.fs.listFoldersSync() -> should get the file type from a string', async () => {
|
||||
expect(smartfile.fs.listFoldersSync('./test/testassets/')).toContain('testfolder');
|
||||
expect(smartfile.fs.listFoldersSync('./test/testassets/')).not.toContain('notExistentFolder');
|
||||
});
|
||||
tap.test(
|
||||
'.fs.listFolders() -> should get the file type from a string',
|
||||
async () => {
|
||||
const folderArrayArg = await smartfile.fs.listFolders('./test/testassets/');
|
||||
expect(folderArrayArg).toContain('testfolder');
|
||||
expect(folderArrayArg).not.toContain('notExistentFolder');
|
||||
},
|
||||
);
|
||||
|
||||
tap.test('.fs.listFolders() -> should get the file type from a string', async () => {
|
||||
const folderArrayArg = await smartfile.fs.listFolders('./test/testassets/');
|
||||
expect(folderArrayArg).toContain('testfolder');
|
||||
expect(folderArrayArg).not.toContain('notExistentFolder');
|
||||
});
|
||||
tap.test(
|
||||
'.fs.listFilesSync() -> should get the file type from a string',
|
||||
async () => {
|
||||
expect(smartfile.fs.listFilesSync('./test/testassets/')).toContain(
|
||||
'mytest.json',
|
||||
);
|
||||
expect(smartfile.fs.listFilesSync('./test/testassets/')).not.toContain(
|
||||
'notExistentFile',
|
||||
);
|
||||
expect(
|
||||
smartfile.fs.listFilesSync('./test/testassets/', /mytest\.json/),
|
||||
).toContain('mytest.json');
|
||||
expect(
|
||||
smartfile.fs.listFilesSync('./test/testassets/', /mytests.json/),
|
||||
).not.toContain('mytest.json');
|
||||
},
|
||||
);
|
||||
|
||||
tap.test('.fs.listFilesSync() -> should get the file type from a string', async () => {
|
||||
expect(smartfile.fs.listFilesSync('./test/testassets/')).toContain('mytest.json');
|
||||
expect(smartfile.fs.listFilesSync('./test/testassets/')).not.toContain('notExistentFile');
|
||||
expect(smartfile.fs.listFilesSync('./test/testassets/', /mytest\.json/)).toContain('mytest.json');
|
||||
expect(smartfile.fs.listFilesSync('./test/testassets/', /mytests.json/)).not.toContain(
|
||||
'mytest.json'
|
||||
);
|
||||
});
|
||||
|
||||
tap.test('.fs.listFiles() -> should get the file type from a string', async () => {
|
||||
const folderArrayArg = await smartfile.fs.listFiles('./test/testassets/');
|
||||
expect(folderArrayArg).toContain('mytest.json');
|
||||
expect(folderArrayArg).not.toContain('notExistentFile');
|
||||
});
|
||||
tap.test(
|
||||
'.fs.listFiles() -> should get the file type from a string',
|
||||
async () => {
|
||||
const folderArrayArg = await smartfile.fs.listFiles('./test/testassets/');
|
||||
expect(folderArrayArg).toContain('mytest.json');
|
||||
expect(folderArrayArg).not.toContain('notExistentFile');
|
||||
},
|
||||
);
|
||||
|
||||
tap.test('.fs.listFileTree() -> should get a file tree', async () => {
|
||||
const folderArrayArg = await smartfile.fs.listFileTree(
|
||||
path.resolve('./test/testassets/'),
|
||||
'**/*.txt'
|
||||
'**/*.txt',
|
||||
);
|
||||
expect(folderArrayArg).toContain('testfolder/testfile1.txt');
|
||||
expect(folderArrayArg).not.toContain('mytest.json');
|
||||
});
|
||||
|
||||
tap.test('.fs.fileTreeToObject -> should read a file tree into an Object', async () => {
|
||||
const fileArrayArg = await smartfile.fs.fileTreeToObject(
|
||||
path.resolve('./test/testassets/'),
|
||||
'**/*.txt'
|
||||
);
|
||||
expect(fileArrayArg[0]).toBeInstanceOf(smartfile.Smartfile);
|
||||
expect(fileArrayArg[0].contents.toString()).toEqual(fileArrayArg[0].contentBuffer.toString());
|
||||
});
|
||||
tap.test(
|
||||
'.fs.listFileTree() -> should find both root and nested .ts files with **/*.ts pattern',
|
||||
async () => {
|
||||
const tsFiles = await smartfile.fs.listFileTree(process.cwd(), '**/*.ts');
|
||||
// Should find both root-level and nested TypeScript files
|
||||
expect(tsFiles).toContain('ts/index.ts');
|
||||
expect(tsFiles).toContain('ts/classes.smartfile.ts');
|
||||
expect(tsFiles).toContain('test/test.ts');
|
||||
// Should find files in multiple levels of nesting
|
||||
expect(tsFiles.filter((f) => f.endsWith('.ts')).length).toBeGreaterThan(5);
|
||||
// Verify it finds files at all levels (root 'ts/' and nested 'test/')
|
||||
const hasRootLevelTs = tsFiles.some(
|
||||
(f) => f.startsWith('ts/') && f.endsWith('.ts'),
|
||||
);
|
||||
const hasNestedTs = tsFiles.some(
|
||||
(f) => f.startsWith('test/') && f.endsWith('.ts'),
|
||||
);
|
||||
expect(hasRootLevelTs).toBeTrue();
|
||||
expect(hasNestedTs).toBeTrue();
|
||||
},
|
||||
);
|
||||
|
||||
tap.test(
|
||||
'.fs.listFileTree() -> should handle edge cases with **/ patterns consistently',
|
||||
async () => {
|
||||
// Test that our fix ensures no duplicate files in results
|
||||
const jsonFiles = await smartfile.fs.listFileTree(
|
||||
path.resolve('./test/testassets/'),
|
||||
'**/*.json',
|
||||
);
|
||||
const uniqueFiles = [...new Set(jsonFiles)];
|
||||
expect(jsonFiles.length).toEqual(uniqueFiles.length);
|
||||
|
||||
// Test that it finds root level files with **/ patterns
|
||||
const txtFiles = await smartfile.fs.listFileTree(
|
||||
path.resolve('./test/testassets/'),
|
||||
'**/*.txt',
|
||||
);
|
||||
// Should include both direct files and nested files
|
||||
expect(txtFiles).toContain('mytest.txt');
|
||||
expect(txtFiles).toContain('testfolder/testfile1.txt');
|
||||
},
|
||||
);
|
||||
|
||||
tap.test(
|
||||
'.fs.fileTreeToObject -> should read a file tree into an Object',
|
||||
async () => {
|
||||
const fileArrayArg = await smartfile.fs.fileTreeToObject(
|
||||
path.resolve('./test/testassets/'),
|
||||
'**/*.txt',
|
||||
);
|
||||
expect(fileArrayArg[0]).toBeInstanceOf(smartfile.SmartFile);
|
||||
expect(fileArrayArg[0].contents.toString()).toEqual(
|
||||
fileArrayArg[0].contentBuffer.toString(),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
tap.test('.fs.copy() -> should copy a directory', async () => {
|
||||
await smartfile.fs.copy('./test/testassets/testfolder/', './test/testassets/temp/');
|
||||
await smartfile.fs.copy(
|
||||
'./test/testassets/testfolder/',
|
||||
'./test/testassets/temp/',
|
||||
);
|
||||
});
|
||||
|
||||
tap.test('.fs.copy() -> should copy a file', async () => {
|
||||
await smartfile.fs.copy('./test/testassets/mytest.yaml', './test/testassets/temp/mytest.yaml');
|
||||
await smartfile.fs.copy(
|
||||
'./test/testassets/mytest.yaml',
|
||||
'./test/testassets/temp/mytest.yaml',
|
||||
);
|
||||
});
|
||||
|
||||
tap.test('.fs.copy() -> should copy a file and rename it', async () => {
|
||||
await smartfile.fs.copy(
|
||||
'./test/testassets/mytest.yaml',
|
||||
'./test/testassets/temp/mytestRenamed.yaml'
|
||||
'./test/testassets/temp/mytestRenamed.yaml',
|
||||
);
|
||||
});
|
||||
|
||||
@@ -89,70 +172,105 @@ tap.test('.fs.remove -> should remove single files', async () => {
|
||||
await smartfile.fs.remove('./test/testassets/temp/mytestRenamed.yaml');
|
||||
});
|
||||
|
||||
tap.test('.fs.removeSync -> should remove single files synchronouly', async () => {
|
||||
smartfile.fs.removeSync('./test/testassets/temp/testfile1.txt');
|
||||
expect(smartfile.fs.fileExistsSync('./test/testassets/temp/testfile1.txt')).toBeFalse();
|
||||
});
|
||||
tap.test(
|
||||
'.fs.removeSync -> should remove single files synchronouly',
|
||||
async () => {
|
||||
smartfile.fs.removeSync('./test/testassets/temp/testfile1.txt');
|
||||
expect(
|
||||
smartfile.fs.fileExistsSync('./test/testassets/temp/testfile1.txt'),
|
||||
).toBeFalse();
|
||||
},
|
||||
);
|
||||
|
||||
tap.test('.fs.removeMany -> should remove and array of files', async () => {
|
||||
smartfile.fs
|
||||
.removeMany(['./test/testassets/temp/testfile1.txt', './test/testassets/temp/testfile2.txt'])
|
||||
.removeMany([
|
||||
'./test/testassets/temp/testfile1.txt',
|
||||
'./test/testassets/temp/testfile2.txt',
|
||||
])
|
||||
.then(() => {
|
||||
expect(smartfile.fs.fileExistsSync('./test/testassets/temp/testfile1.txt')).toBeFalse();
|
||||
expect(smartfile.fs.fileExistsSync('./test/testassets/temp/testfile2.txt')).toBeFalse();
|
||||
expect(
|
||||
smartfile.fs.fileExistsSync('./test/testassets/temp/testfile1.txt'),
|
||||
).toBeFalse();
|
||||
expect(
|
||||
smartfile.fs.fileExistsSync('./test/testassets/temp/testfile2.txt'),
|
||||
).toBeFalse();
|
||||
});
|
||||
});
|
||||
|
||||
tap.test('.fs.removeManySync -> should remove and array of single files synchronouly', async () => {
|
||||
smartfile.fs.removeManySync([
|
||||
'./test/testassets/temp/testfile1.txt',
|
||||
'./test/testassets/temp/testfile2.txt',
|
||||
]);
|
||||
expect(smartfile.fs.fileExistsSync('./test/testassets/temp/testfile1.txt')).toBeFalse();
|
||||
expect(smartfile.fs.fileExistsSync('./test/testassets/temp/testfile2.txt')).toBeFalse();
|
||||
});
|
||||
tap.test(
|
||||
'.fs.removeManySync -> should remove and array of single files synchronouly',
|
||||
async () => {
|
||||
smartfile.fs.removeManySync([
|
||||
'./test/testassets/temp/testfile1.txt',
|
||||
'./test/testassets/temp/testfile2.txt',
|
||||
]);
|
||||
expect(
|
||||
smartfile.fs.fileExistsSync('./test/testassets/temp/testfile1.txt'),
|
||||
).toBeFalse();
|
||||
expect(
|
||||
smartfile.fs.fileExistsSync('./test/testassets/temp/testfile2.txt'),
|
||||
).toBeFalse();
|
||||
},
|
||||
);
|
||||
|
||||
tap.test('.fs.toObjectSync() -> should read an .yaml file to an object', async () => {
|
||||
const testData = smartfile.fs.toObjectSync('./test/testassets/mytest.yaml');
|
||||
expect(testData.key1).toEqual('this works');
|
||||
expect(testData.key2).toEqual('this works too');
|
||||
});
|
||||
tap.test(
|
||||
'.fs.toObjectSync() -> should read an .yaml file to an object',
|
||||
async () => {
|
||||
const testData = smartfile.fs.toObjectSync('./test/testassets/mytest.yaml');
|
||||
expect(testData.key1).toEqual('this works');
|
||||
expect(testData.key2).toEqual('this works too');
|
||||
},
|
||||
);
|
||||
tap.test(
|
||||
'.fs.toObjectSync() -> should state unknown file type for unknown file types',
|
||||
async () => {
|
||||
const testData = smartfile.fs.toObjectSync('./test/testassets/mytest.txt');
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
tap.test('.fs.toObjectSync() -> should read an .json file to an object', async () => {
|
||||
const testData = smartfile.fs.toObjectSync('./test/testassets/mytest.json');
|
||||
expect(testData.key1).toEqual('this works');
|
||||
expect(testData.key2).toEqual('this works too');
|
||||
});
|
||||
tap.test(
|
||||
'.fs.toObjectSync() -> should read an .json file to an object',
|
||||
async () => {
|
||||
const testData = smartfile.fs.toObjectSync('./test/testassets/mytest.json');
|
||||
expect(testData.key1).toEqual('this works');
|
||||
expect(testData.key2).toEqual('this works too');
|
||||
},
|
||||
);
|
||||
|
||||
tap.test('.fs.toStringSync() -> should read a file to a string', async () => {
|
||||
expect(smartfile.fs.toStringSync('./test/testassets/mytest.txt')).toEqual('Some TestString &&%$');
|
||||
expect(smartfile.fs.toStringSync('./test/testassets/mytest.txt')).toEqual(
|
||||
'Some TestString &&%$',
|
||||
);
|
||||
});
|
||||
|
||||
// ---------------------------
|
||||
// smartfile.interpreter
|
||||
// ---------------------------
|
||||
|
||||
tap.test('.interpreter.filetype() -> should get the file type from a string', async () => {
|
||||
expect(smartfile.interpreter.filetype('./somefolder/data.json')).toEqual('json');
|
||||
});
|
||||
tap.test(
|
||||
'.interpreter.filetype() -> should get the file type from a string',
|
||||
async () => {
|
||||
expect(smartfile.interpreter.filetype('./somefolder/data.json')).toEqual(
|
||||
'json',
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
// ---------------------------
|
||||
// smartfile.memory
|
||||
// ---------------------------
|
||||
|
||||
tap.test('.memory.toFs() -> should write a file to disk and return a promise', async () => {
|
||||
const localString = 'myString';
|
||||
await smartfile.memory.toFs(
|
||||
localString,
|
||||
path.join(process.cwd(), './test/testassets/temp/testMemToFs.txt')
|
||||
);
|
||||
});
|
||||
tap.test(
|
||||
'.memory.toFs() -> should write a file to disk and return a promise',
|
||||
async () => {
|
||||
const localString = 'myString';
|
||||
await smartfile.memory.toFs(
|
||||
localString,
|
||||
path.join(process.cwd(), './test/testassets/temp/testMemToFs.txt'),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
tap.test(
|
||||
'.memory.toFsSync() -> should write a file to disk and return true if successfull',
|
||||
@@ -160,9 +278,9 @@ tap.test(
|
||||
const localString = 'myString';
|
||||
smartfile.memory.toFsSync(
|
||||
localString,
|
||||
path.join(process.cwd(), './test/testassets/temp/testMemToFsSync.txt')
|
||||
path.join(process.cwd(), './test/testassets/temp/testMemToFsSync.txt'),
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
// ---------------------------
|
||||
@@ -172,10 +290,10 @@ tap.test(
|
||||
tap.test('.Smartfile -> should produce vinyl compatible files', async () => {
|
||||
const smartfileArray = await smartfile.fs.fileTreeToObject(
|
||||
process.cwd(),
|
||||
'./test/testassets/testfolder/**/*'
|
||||
'./test/testassets/testfolder/**/*',
|
||||
);
|
||||
const localSmartfile = smartfileArray[0];
|
||||
expect(localSmartfile).toBeInstanceOf(smartfile.Smartfile);
|
||||
expect(localSmartfile).toBeInstanceOf(smartfile.SmartFile);
|
||||
expect(localSmartfile.contents).toBeInstanceOf(Buffer);
|
||||
// tslint:disable-next-line:no-unused-expression
|
||||
expect(localSmartfile.isBuffer()).toBeTrue();
|
||||
@@ -186,7 +304,10 @@ tap.test('.Smartfile -> should produce vinyl compatible files', async () => {
|
||||
});
|
||||
|
||||
tap.test('should output a smartfile array to disk', async () => {
|
||||
const smartfileArray = await smartfile.fs.fileTreeToObject('./test/testassets/testfolder/', '*');
|
||||
const smartfileArray = await smartfile.fs.fileTreeToObject(
|
||||
'./test/testassets/testfolder/',
|
||||
'*',
|
||||
);
|
||||
for (const smartfileInstance of smartfileArray) {
|
||||
console.log(smartfileInstance.relative);
|
||||
console.log(smartfileInstance.path);
|
||||
@@ -195,16 +316,20 @@ tap.test('should output a smartfile array to disk', async () => {
|
||||
}
|
||||
await smartfile.memory.smartfileArrayToFs(
|
||||
smartfileArray,
|
||||
path.resolve('./test/testassets/temp/testoutput/')
|
||||
path.resolve('./test/testassets/temp/testoutput/'),
|
||||
);
|
||||
});
|
||||
|
||||
tap.test('should create, store and retrieve valid smartfiles', async () => {
|
||||
const fileString = 'hi there';
|
||||
const filePath = './test/testassets/utf8.txt';
|
||||
const smartfileInstance = await smartfile.Smartfile.fromString(filePath, fileString, 'utf8');
|
||||
const smartfileInstance = await smartfile.SmartFile.fromString(
|
||||
filePath,
|
||||
fileString,
|
||||
'utf8',
|
||||
);
|
||||
smartfileInstance.write();
|
||||
const smartfileInstance2 = await smartfile.Smartfile.fromFilePath(filePath);
|
||||
const smartfileInstance2 = await smartfile.SmartFile.fromFilePath(filePath);
|
||||
const retrievedString = smartfileInstance.contents.toString();
|
||||
expect(retrievedString).toEqual(fileString);
|
||||
});
|
||||
@@ -212,7 +337,11 @@ tap.test('should create, store and retrieve valid smartfiles', async () => {
|
||||
tap.test('should get a hash', async () => {
|
||||
const fileString = 'hi there';
|
||||
const filePath = './test/testassets/utf8.txt';
|
||||
const smartfileInstance = await smartfile.Smartfile.fromString(filePath, fileString, 'utf8');
|
||||
const smartfileInstance = await smartfile.SmartFile.fromString(
|
||||
filePath,
|
||||
fileString,
|
||||
'utf8',
|
||||
);
|
||||
const hash = await smartfileInstance.getHash();
|
||||
console.log(hash);
|
||||
});
|
||||
|
@@ -1,14 +1,18 @@
|
||||
import { tap, expect } from '@pushrocks/tapbundle';
|
||||
import { tap, expect } from '@git.zone/tstest/tapbundle';
|
||||
|
||||
import * as smartfile from '../ts/index.js';
|
||||
|
||||
tap.test('should create a virtualdirectory', async () => {
|
||||
const virtualDir = await smartfile.VirtualDirectory.fromFsDirPath('./test/testassets/testfolder');
|
||||
const virtualDir = await smartfile.VirtualDirectory.fromFsDirPath(
|
||||
'./test/testassets/testfolder',
|
||||
);
|
||||
expect(virtualDir.smartfileArray.length).toEqual(4);
|
||||
});
|
||||
|
||||
tap.test('should write to a directory', async () => {
|
||||
const virtualDir = await smartfile.VirtualDirectory.fromFsDirPath('./test/testassets/testfolder');
|
||||
const virtualDir = await smartfile.VirtualDirectory.fromFsDirPath(
|
||||
'./test/testassets/testfolder',
|
||||
);
|
||||
virtualDir.saveToDisk('./test/testassets/test');
|
||||
});
|
||||
|
||||
|
@@ -5,4 +5,3 @@
|
||||
"nestedkey1": "hello"
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
key1: this works
|
||||
key2: this works too
|
||||
key3:
|
||||
nestedkey1: hello
|
||||
nestedkey1: hello
|
||||
|
7
test/testassets/temp/mytest.json
Normal file
7
test/testassets/temp/mytest.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"key1": "this works",
|
||||
"key2": "this works too",
|
||||
"key3": {
|
||||
"nestedkey1": "hello"
|
||||
}
|
||||
}
|
@@ -1,4 +1,4 @@
|
||||
key1: this works
|
||||
key2: this works too
|
||||
key3:
|
||||
nestedkey1: hello
|
||||
nestedkey1: hello
|
||||
|
7
test/testassets/temp/test/testassets/mytest.json
Normal file
7
test/testassets/temp/test/testassets/mytest.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"key1": "this works",
|
||||
"key2": "this works too",
|
||||
"key3": {
|
||||
"nestedkey1": "hello"
|
||||
}
|
||||
}
|
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
* autocreated commitinfo by @push.rocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@pushrocks/smartfile',
|
||||
version: '10.0.6',
|
||||
description: 'offers smart ways to work with files in nodejs'
|
||||
name: '@push.rocks/smartfile',
|
||||
version: '11.2.7',
|
||||
description: 'Provides comprehensive tools for efficient file management in Node.js using TypeScript, including handling streams, virtual directories, and various file operations.'
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import * as plugins from './smartfile.plugins.js';
|
||||
import * as fs from './smartfile.fs.js';
|
||||
import * as memory from './smartfile.memory.js';
|
||||
import * as plugins from './plugins.js';
|
||||
import * as fs from './fs.js';
|
||||
import * as memory from './memory.js';
|
||||
|
||||
export interface ISmartfileConstructorOptions {
|
||||
path: string;
|
||||
@@ -9,10 +9,9 @@ export interface ISmartfileConstructorOptions {
|
||||
}
|
||||
|
||||
/**
|
||||
* class Smartfile
|
||||
* -> is vinyl file compatible
|
||||
* an vinyl file compatible in memory file class
|
||||
*/
|
||||
export class Smartfile extends plugins.smartjson.Smartjson {
|
||||
export class SmartFile extends plugins.smartjson.Smartjson {
|
||||
// ======
|
||||
// STATIC
|
||||
// ======
|
||||
@@ -21,10 +20,13 @@ export class Smartfile extends plugins.smartjson.Smartjson {
|
||||
* creates a Smartfile from a filePath
|
||||
* @param filePath
|
||||
*/
|
||||
public static async fromFilePath(filePath: string, baseArg: string = process.cwd()) {
|
||||
public static async fromFilePath(
|
||||
filePath: string,
|
||||
baseArg: string = process.cwd(),
|
||||
) {
|
||||
filePath = plugins.path.resolve(filePath);
|
||||
const fileBuffer = fs.toBufferSync(filePath);
|
||||
const smartfile = new Smartfile({
|
||||
const smartfile = new SmartFile({
|
||||
contentBuffer: fileBuffer,
|
||||
base: baseArg,
|
||||
path: plugins.path.relative(baseArg, filePath),
|
||||
@@ -35,9 +37,9 @@ export class Smartfile extends plugins.smartjson.Smartjson {
|
||||
public static async fromBuffer(
|
||||
filePath: string,
|
||||
contentBufferArg: Buffer,
|
||||
baseArg: string = process.cwd()
|
||||
baseArg: string = process.cwd(),
|
||||
) {
|
||||
const smartfile = new Smartfile({
|
||||
const smartfile = new SmartFile({
|
||||
contentBuffer: contentBufferArg,
|
||||
base: baseArg,
|
||||
path: plugins.path.relative(baseArg, filePath),
|
||||
@@ -50,9 +52,9 @@ export class Smartfile extends plugins.smartjson.Smartjson {
|
||||
filePath: string,
|
||||
contentStringArg: string,
|
||||
encodingArg: 'utf8' | 'binary',
|
||||
baseArg = process.cwd()
|
||||
baseArg = process.cwd(),
|
||||
) {
|
||||
const smartfile = new Smartfile({
|
||||
const smartfile = new SmartFile({
|
||||
contentBuffer: Buffer.from(contentStringArg, encodingArg),
|
||||
base: baseArg,
|
||||
path: plugins.path.relative(baseArg, filePath),
|
||||
@@ -62,7 +64,44 @@ export class Smartfile extends plugins.smartjson.Smartjson {
|
||||
}
|
||||
|
||||
public static async fromFoldedJson(foldedJsonArg: string) {
|
||||
return new Smartfile(plugins.smartjson.parse(foldedJsonArg));
|
||||
return new SmartFile(plugins.smartjson.parse(foldedJsonArg));
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a Smartfile from a ReadableStream
|
||||
* @param stream a readable stream that provides file content
|
||||
* @param filePath the file path to associate with the content
|
||||
* @param baseArg the base path to use for the file
|
||||
*/
|
||||
public static async fromStream(
|
||||
stream: plugins.stream.Readable,
|
||||
filePath: string,
|
||||
baseArg: string = process.cwd(),
|
||||
): Promise<SmartFile> {
|
||||
return new Promise<SmartFile>((resolve, reject) => {
|
||||
const chunks: Buffer[] = [];
|
||||
stream.on('data', (chunk) => chunks.push(Buffer.from(chunk)));
|
||||
stream.on('error', (error) => reject(error));
|
||||
stream.on('end', () => {
|
||||
const contentBuffer = Buffer.concat(chunks);
|
||||
const smartfile = new SmartFile({
|
||||
contentBuffer: contentBuffer,
|
||||
base: baseArg,
|
||||
path: plugins.path.relative(baseArg, filePath),
|
||||
});
|
||||
resolve(smartfile);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public static async fromUrl(urlArg: string) {
|
||||
const response = await plugins.smartrequest.SmartRequest.create()
|
||||
.url(urlArg)
|
||||
.accept('binary')
|
||||
.get();
|
||||
const buffer = Buffer.from(await response.arrayBuffer());
|
||||
const smartfile = await SmartFile.fromBuffer(urlArg, buffer);
|
||||
return smartfile;
|
||||
}
|
||||
|
||||
// ========
|
||||
@@ -127,8 +166,11 @@ export class Smartfile extends plugins.smartjson.Smartjson {
|
||||
* set contents from string
|
||||
* @param contentString
|
||||
*/
|
||||
public setContentsFromString(contentString: string, encodingArg: 'utf8' | 'binary' = 'utf8') {
|
||||
this.contents = new Buffer(contentString, encodingArg);
|
||||
public setContentsFromString(
|
||||
contentString: string,
|
||||
encodingArg: 'utf8' | 'binary' = 'utf8',
|
||||
) {
|
||||
this.contents = Buffer.from(contentString, encodingArg);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -137,7 +179,12 @@ export class Smartfile extends plugins.smartjson.Smartjson {
|
||||
* - no argument write to exactly where the file was picked up
|
||||
*/
|
||||
public async write() {
|
||||
await memory.toFs(this.contentBuffer, plugins.path.join(this.base, this.path));
|
||||
let writePath = plugins.smartpath.transform.makeAbsolute(
|
||||
this.path,
|
||||
this.base,
|
||||
);
|
||||
console.log(`writing to ${writePath}`);
|
||||
await memory.toFs(this.contentBuffer, writePath);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -168,7 +215,9 @@ export class Smartfile extends plugins.smartjson.Smartjson {
|
||||
* read file from disk
|
||||
*/
|
||||
public async read() {
|
||||
this.contentBuffer = await fs.toBuffer(plugins.path.join(this.base, this.path));
|
||||
this.contentBuffer = await fs.toBuffer(
|
||||
plugins.path.join(this.base, this.path),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -178,6 +227,52 @@ export class Smartfile extends plugins.smartjson.Smartjson {
|
||||
await fs.remove(plugins.path.join(this.base, this.path));
|
||||
}
|
||||
|
||||
/**
|
||||
* Renames the file to the specified new name.
|
||||
* - Updates the `path` property with the new name.
|
||||
* - Writes the file to the new location if it exists on disk.
|
||||
* @param newName The new name of the file (including extension if applicable).
|
||||
* @param writeToDisk (optional) If true, also renames the file on the disk.
|
||||
* @returns The updated file path after renaming.
|
||||
*/
|
||||
public async rename(
|
||||
newName: string,
|
||||
writeToDisk: boolean = false,
|
||||
): Promise<string> {
|
||||
// Validate the new name
|
||||
if (!newName || typeof newName !== 'string') {
|
||||
throw new Error('Invalid new name provided.');
|
||||
}
|
||||
|
||||
// Extract the directory path
|
||||
const oldFilePath = this.path;
|
||||
const dirPath = plugins.path.dirname(this.path);
|
||||
|
||||
// Create the new file path
|
||||
const newFilePath = plugins.path.join(dirPath, newName);
|
||||
|
||||
// Update the `path` property
|
||||
this.path = newFilePath;
|
||||
|
||||
// Optionally write the renamed file to disk
|
||||
if (writeToDisk) {
|
||||
const oldAbsolutePath = plugins.smartpath.transform.makeAbsolute(
|
||||
oldFilePath,
|
||||
this.base,
|
||||
);
|
||||
const newAbsolutePath = plugins.smartpath.transform.makeAbsolute(
|
||||
newFilePath,
|
||||
this.base,
|
||||
);
|
||||
|
||||
// Rename the file on disk
|
||||
await plugins.fsExtra.rename(oldAbsolutePath, newAbsolutePath);
|
||||
}
|
||||
|
||||
// Return the new path
|
||||
return this.path;
|
||||
}
|
||||
|
||||
// -----------------------------------------------
|
||||
// vinyl compatibility
|
||||
// -----------------------------------------------
|
||||
@@ -239,9 +334,13 @@ export class Smartfile extends plugins.smartjson.Smartjson {
|
||||
|
||||
public async getHash(typeArg: 'path' | 'content' | 'all' = 'all') {
|
||||
const pathHash = await plugins.smarthash.sha256FromString(this.path);
|
||||
const contentHash = await plugins.smarthash.sha256FromBuffer(this.contentBuffer);
|
||||
const combinedHash = await plugins.smarthash.sha256FromString(pathHash + contentHash);
|
||||
switch(typeArg) {
|
||||
const contentHash = await plugins.smarthash.sha256FromBuffer(
|
||||
this.contentBuffer,
|
||||
);
|
||||
const combinedHash = await plugins.smarthash.sha256FromString(
|
||||
pathHash + contentHash,
|
||||
);
|
||||
switch (typeArg) {
|
||||
case 'path':
|
||||
return pathHash;
|
||||
case 'content':
|
||||
@@ -258,8 +357,27 @@ export class Smartfile extends plugins.smartjson.Smartjson {
|
||||
this.path = this.path.replace(new RegExp(oldFileName + '$'), fileNameArg);
|
||||
}
|
||||
|
||||
public async editContentAsString(editFuncArg: (fileStringArg: string) => Promise<string>) {
|
||||
public async editContentAsString(
|
||||
editFuncArg: (fileStringArg: string) => Promise<string>,
|
||||
) {
|
||||
const newFileString = await editFuncArg(this.contentBuffer.toString());
|
||||
this.contentBuffer = Buffer.from(newFileString);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a ReadableStream from the file's content buffer
|
||||
*/
|
||||
public getStream(): plugins.stream.Readable {
|
||||
const stream = new plugins.stream.Readable();
|
||||
stream.push(this.contentBuffer); // Push the content buffer to the stream
|
||||
stream.push(null); // Push null to signify the end of the stream (EOF)
|
||||
return stream;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the size of the file in bytes
|
||||
*/
|
||||
public async getSize(): Promise<number> {
|
||||
return this.contentBuffer.length;
|
||||
}
|
||||
}
|
199
ts/classes.streamfile.ts
Normal file
199
ts/classes.streamfile.ts
Normal file
@@ -0,0 +1,199 @@
|
||||
import * as plugins from './plugins.js';
|
||||
import * as smartfileFs from './fs.js';
|
||||
import * as smartfileFsStream from './fsstream.js';
|
||||
import { Readable } from 'stream';
|
||||
|
||||
type TStreamSource = (streamFile: StreamFile) => Promise<Readable | ReadableStream>;
|
||||
|
||||
/**
|
||||
* The StreamFile class represents a file as a stream.
|
||||
* It allows creating streams from a file path, a URL, or a buffer.
|
||||
*/
|
||||
export class StreamFile {
|
||||
// STATIC
|
||||
|
||||
public static async fromPath(filePath: string): Promise<StreamFile> {
|
||||
const streamSource: TStreamSource = async (streamFileArg) =>
|
||||
smartfileFsStream.createReadStream(filePath);
|
||||
const streamFile = new StreamFile(streamSource, filePath);
|
||||
streamFile.multiUse = true;
|
||||
streamFile.byteLengthComputeFunction = async () => {
|
||||
const stats = await smartfileFs.stat(filePath);
|
||||
return stats.size;
|
||||
};
|
||||
return streamFile;
|
||||
}
|
||||
|
||||
public static async fromUrl(url: string): Promise<StreamFile> {
|
||||
const streamSource: TStreamSource = async (streamFileArg) => {
|
||||
const response = await plugins.smartrequest.SmartRequest.create()
|
||||
.url(url)
|
||||
.get();
|
||||
return response.stream();
|
||||
};
|
||||
const streamFile = new StreamFile(streamSource);
|
||||
streamFile.multiUse = true;
|
||||
streamFile.byteLengthComputeFunction = async () => {
|
||||
const response = await plugins.smartrequest.SmartRequest.create()
|
||||
.url(url)
|
||||
.accept('binary')
|
||||
.get();
|
||||
const buffer = Buffer.from(await response.arrayBuffer());
|
||||
return buffer.length;
|
||||
};
|
||||
return streamFile;
|
||||
}
|
||||
|
||||
public static fromBuffer(
|
||||
buffer: Buffer,
|
||||
relativeFilePath?: string,
|
||||
): StreamFile {
|
||||
const streamSource: TStreamSource = async (streamFileArg) => {
|
||||
const stream = new Readable();
|
||||
stream.push(buffer);
|
||||
stream.push(null); // End of stream
|
||||
return stream;
|
||||
};
|
||||
const streamFile = new StreamFile(streamSource, relativeFilePath);
|
||||
streamFile.multiUse = true;
|
||||
streamFile.byteLengthComputeFunction = async () => buffer.length;
|
||||
return streamFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a StreamFile from an existing Readable stream with an option for multiple uses.
|
||||
* @param stream A Node.js Readable stream.
|
||||
* @param relativeFilePath Optional file path for the stream.
|
||||
* @param multiUse If true, the stream can be read multiple times, caching its content.
|
||||
* @returns A StreamFile instance.
|
||||
*/
|
||||
public static fromStream(
|
||||
stream: Readable,
|
||||
relativeFilePath?: string,
|
||||
multiUse: boolean = false,
|
||||
): StreamFile {
|
||||
const streamSource: TStreamSource = (streamFileArg) => {
|
||||
if (streamFileArg.multiUse) {
|
||||
// If multi-use is enabled and we have cached content, create a new readable stream from the buffer
|
||||
const bufferedStream = new Readable();
|
||||
bufferedStream.push(streamFileArg.cachedStreamBuffer);
|
||||
bufferedStream.push(null); // No more data to push
|
||||
return Promise.resolve(bufferedStream);
|
||||
} else {
|
||||
return Promise.resolve(stream);
|
||||
}
|
||||
};
|
||||
|
||||
const streamFile = new StreamFile(streamSource, relativeFilePath);
|
||||
streamFile.multiUse = multiUse;
|
||||
|
||||
// If multi-use is enabled, cache the stream when it's first read
|
||||
if (multiUse) {
|
||||
const chunks: Buffer[] = [];
|
||||
stream.on('data', (chunk) => chunks.push(Buffer.from(chunk)));
|
||||
stream.on('end', () => {
|
||||
streamFile.cachedStreamBuffer = Buffer.concat(chunks);
|
||||
});
|
||||
// It's important to handle errors that may occur during streaming
|
||||
stream.on('error', (err) => {
|
||||
console.error('Error while caching stream:', err);
|
||||
});
|
||||
}
|
||||
|
||||
return streamFile;
|
||||
}
|
||||
|
||||
// INSTANCE
|
||||
relativeFilePath?: string;
|
||||
private streamSource: TStreamSource;
|
||||
|
||||
// enable stream based multi use
|
||||
private cachedStreamBuffer?: Buffer;
|
||||
public multiUse: boolean;
|
||||
public used: boolean = false;
|
||||
public byteLengthComputeFunction: () => Promise<number>;
|
||||
|
||||
private constructor(streamSource: TStreamSource, relativeFilePath?: string) {
|
||||
this.streamSource = streamSource;
|
||||
this.relativeFilePath = relativeFilePath;
|
||||
}
|
||||
|
||||
// METHODS
|
||||
|
||||
private checkMultiUse() {
|
||||
if (!this.multiUse && this.used) {
|
||||
throw new Error('This stream can only be used once.');
|
||||
}
|
||||
this.used = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new readable stream from the source.
|
||||
*/
|
||||
public async createReadStream(): Promise<Readable> {
|
||||
const stream = await this.streamSource(this);
|
||||
|
||||
// Check if it's a Web ReadableStream and convert to Node.js Readable
|
||||
if (stream && typeof (stream as any).getReader === 'function') {
|
||||
// This is a Web ReadableStream, convert it to Node.js Readable
|
||||
return Readable.fromWeb(stream as any);
|
||||
}
|
||||
|
||||
// It's already a Node.js Readable stream
|
||||
return stream as Readable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the stream to the disk at the specified path.
|
||||
* @param filePathArg The file path where the stream should be written.
|
||||
*/
|
||||
public async writeToDisk(filePathArg: string): Promise<void> {
|
||||
this.checkMultiUse();
|
||||
const readStream = await this.createReadStream();
|
||||
const writeStream = smartfileFsStream.createWriteStream(filePathArg);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
readStream.pipe(writeStream);
|
||||
readStream.on('error', reject);
|
||||
writeStream.on('error', reject);
|
||||
writeStream.on('finish', resolve);
|
||||
});
|
||||
}
|
||||
|
||||
public async writeToDir(dirPathArg: string) {
|
||||
this.checkMultiUse();
|
||||
const filePath = plugins.path.join(dirPathArg, this.relativeFilePath);
|
||||
await smartfileFs.ensureDir(plugins.path.parse(filePath).dir);
|
||||
return this.writeToDisk(filePath);
|
||||
}
|
||||
|
||||
public async getContentAsBuffer() {
|
||||
this.checkMultiUse();
|
||||
const done = plugins.smartpromise.defer<Buffer>();
|
||||
const readStream = await this.createReadStream();
|
||||
const chunks: Buffer[] = [];
|
||||
readStream.on('data', (chunk) => chunks.push(Buffer.from(chunk)));
|
||||
readStream.on('error', done.reject);
|
||||
readStream.on('end', () => {
|
||||
const contentBuffer = Buffer.concat(chunks);
|
||||
done.resolve(contentBuffer);
|
||||
});
|
||||
return done.promise;
|
||||
}
|
||||
|
||||
public async getContentAsString(formatArg: 'utf8' | 'binary' = 'utf8') {
|
||||
const contentBuffer = await this.getContentAsBuffer();
|
||||
return contentBuffer.toString(formatArg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the size of the file content in bytes.
|
||||
*/
|
||||
public async getSize(): Promise<number> {
|
||||
if (this.byteLengthComputeFunction) {
|
||||
return this.byteLengthComputeFunction();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
92
ts/classes.virtualdirectory.ts
Normal file
92
ts/classes.virtualdirectory.ts
Normal file
@@ -0,0 +1,92 @@
|
||||
import { SmartFile } from './classes.smartfile.js';
|
||||
import * as plugins from './plugins.js';
|
||||
import * as fs from './fs.js';
|
||||
|
||||
export interface IVirtualDirectoryConstructorOptions {
|
||||
mode: '';
|
||||
}
|
||||
|
||||
/**
|
||||
* a virtual directory exposes a fs api
|
||||
*/
|
||||
export class VirtualDirectory {
|
||||
consstructor(options = {}) {}
|
||||
|
||||
// STATIC
|
||||
public static async fromFsDirPath(
|
||||
pathArg: string,
|
||||
): Promise<VirtualDirectory> {
|
||||
const newVirtualDir = new VirtualDirectory();
|
||||
newVirtualDir.addSmartfiles(await fs.fileTreeToObject(pathArg, '**/*'));
|
||||
return newVirtualDir;
|
||||
}
|
||||
|
||||
public static async fromVirtualDirTransferableObject(
|
||||
virtualDirTransferableObjectArg: plugins.smartfileInterfaces.VirtualDirTransferableObject,
|
||||
): Promise<VirtualDirectory> {
|
||||
const newVirtualDir = new VirtualDirectory();
|
||||
for (const fileArg of virtualDirTransferableObjectArg.files) {
|
||||
newVirtualDir.addSmartfiles([
|
||||
SmartFile.enfoldFromJson(fileArg) as SmartFile,
|
||||
]);
|
||||
}
|
||||
return newVirtualDir;
|
||||
}
|
||||
|
||||
// INSTANCE
|
||||
public smartfileArray: SmartFile[] = [];
|
||||
|
||||
constructor() {}
|
||||
|
||||
public addSmartfiles(smartfileArrayArg: SmartFile[]) {
|
||||
this.smartfileArray = this.smartfileArray.concat(smartfileArrayArg);
|
||||
}
|
||||
|
||||
public async getFileByPath(pathArg: string) {
|
||||
for (const smartfile of this.smartfileArray) {
|
||||
if (smartfile.path === pathArg) {
|
||||
return smartfile;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async toVirtualDirTransferableObject(): Promise<plugins.smartfileInterfaces.VirtualDirTransferableObject> {
|
||||
return {
|
||||
files: this.smartfileArray.map((smartfileArg) =>
|
||||
smartfileArg.foldToJson(),
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
public async saveToDisk(dirArg: string) {
|
||||
console.log(`writing VirtualDirectory with ${this.smartfileArray.length} files to directory:
|
||||
--> ${dirArg}`);
|
||||
for (const smartfileArg of this.smartfileArray) {
|
||||
const filePath = await smartfileArg.writeToDir(dirArg);
|
||||
console.log(`wrote ${smartfileArg.relative} to
|
||||
--> ${filePath}`);
|
||||
}
|
||||
}
|
||||
|
||||
public async shiftToSubdirectory(subDir: string): Promise<VirtualDirectory> {
|
||||
const newVirtualDir = new VirtualDirectory();
|
||||
for (const file of this.smartfileArray) {
|
||||
if (file.path.startsWith(subDir)) {
|
||||
const adjustedFilePath = plugins.path.relative(subDir, file.path);
|
||||
file.path = adjustedFilePath;
|
||||
newVirtualDir.addSmartfiles([file]);
|
||||
}
|
||||
}
|
||||
return newVirtualDir;
|
||||
}
|
||||
|
||||
public async addVirtualDirectory(
|
||||
virtualDir: VirtualDirectory,
|
||||
newRoot: string,
|
||||
): Promise<void> {
|
||||
for (const file of virtualDir.smartfileArray) {
|
||||
file.path = plugins.path.join(newRoot, file.path);
|
||||
}
|
||||
this.addSmartfiles(virtualDir.smartfileArray);
|
||||
}
|
||||
}
|
715
ts/fs.ts
Normal file
715
ts/fs.ts
Normal file
@@ -0,0 +1,715 @@
|
||||
import * as plugins from './plugins.js';
|
||||
import * as interpreter from './interpreter.js';
|
||||
|
||||
import { SmartFile } from './classes.smartfile.js';
|
||||
|
||||
import * as memory from './memory.js';
|
||||
import type { StreamFile } from './classes.streamfile.js';
|
||||
/*===============================================================
|
||||
============================ Checks =============================
|
||||
===============================================================*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @param filePath
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export const fileExistsSync = (filePath): boolean => {
|
||||
let fileExistsBool: boolean = false;
|
||||
try {
|
||||
plugins.fsExtra.readFileSync(filePath);
|
||||
fileExistsBool = true;
|
||||
} catch (err) {
|
||||
fileExistsBool = false;
|
||||
}
|
||||
return fileExistsBool;
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @param filePath
|
||||
* @returns {any}
|
||||
*/
|
||||
export const fileExists = async (filePath): Promise<boolean> => {
|
||||
const done = plugins.smartpromise.defer<boolean>();
|
||||
plugins.fs.access(filePath, 4, (err) => {
|
||||
err ? done.resolve(false) : done.resolve(true);
|
||||
});
|
||||
return done.promise;
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks if given path points to an existing directory
|
||||
*/
|
||||
export const isDirectory = (pathArg: string): boolean => {
|
||||
try {
|
||||
return plugins.fsExtra.statSync(pathArg).isDirectory();
|
||||
} catch (err) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks if given path points to an existing directory
|
||||
*/
|
||||
export const isDirectorySync = (pathArg: string): boolean => {
|
||||
try {
|
||||
return plugins.fsExtra.statSync(pathArg).isDirectory();
|
||||
} catch (err) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks if a given path points to an existing file
|
||||
*/
|
||||
export const isFile = (pathArg): boolean => {
|
||||
return plugins.fsExtra.statSync(pathArg).isFile();
|
||||
};
|
||||
|
||||
/*===============================================================
|
||||
============================ FS ACTIONS =========================
|
||||
===============================================================*/
|
||||
|
||||
/**
|
||||
* copies a file or directory from A to B on the local disk
|
||||
*/
|
||||
export const copy = async (
|
||||
fromArg: string,
|
||||
toArg: string,
|
||||
optionsArg?: plugins.fsExtra.CopyOptions & { replaceTargetDir?: boolean },
|
||||
): Promise<void> => {
|
||||
if (
|
||||
optionsArg?.replaceTargetDir &&
|
||||
isDirectory(fromArg) &&
|
||||
isDirectory(toArg)
|
||||
) {
|
||||
await remove(toArg);
|
||||
}
|
||||
return await plugins.fsExtra.copy(
|
||||
fromArg,
|
||||
toArg,
|
||||
optionsArg as plugins.fsExtra.CopyOptions,
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* copies a file or directory SYNCHRONOUSLY from A to B on the local disk
|
||||
*/
|
||||
export const copySync = (
|
||||
fromArg: string,
|
||||
toArg: string,
|
||||
optionsArg?: plugins.fsExtra.CopyOptionsSync & { replaceTargetDir?: boolean },
|
||||
): void => {
|
||||
if (
|
||||
optionsArg?.replaceTargetDir &&
|
||||
isDirectory(fromArg) &&
|
||||
isDirectory(toArg)
|
||||
) {
|
||||
removeSync(toArg);
|
||||
}
|
||||
return plugins.fsExtra.copySync(
|
||||
fromArg,
|
||||
toArg,
|
||||
optionsArg as plugins.fsExtra.CopyOptionsSync,
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* ensures that a directory is in place
|
||||
*/
|
||||
export const ensureDir = async (dirPathArg: string) => {
|
||||
await plugins.fsExtra.ensureDir(dirPathArg);
|
||||
};
|
||||
|
||||
/**
|
||||
* ensures that a directory is in place
|
||||
*/
|
||||
export const ensureDirSync = (dirPathArg: string) => {
|
||||
plugins.fsExtra.ensureDirSync(dirPathArg);
|
||||
};
|
||||
|
||||
/**
|
||||
* ensure an empty directory
|
||||
* @executes ASYNC
|
||||
*/
|
||||
export const ensureEmptyDir = async (dirPathArg: string) => {
|
||||
await plugins.fsExtra.ensureDir(dirPathArg);
|
||||
await plugins.fsExtra.emptyDir(dirPathArg);
|
||||
};
|
||||
|
||||
/**
|
||||
* ensure an empty directory
|
||||
* @executes SYNC
|
||||
*/
|
||||
export const ensureEmptyDirSync = (dirPathArg: string) => {
|
||||
plugins.fsExtra.ensureDirSync(dirPathArg);
|
||||
plugins.fsExtra.emptyDirSync(dirPathArg);
|
||||
};
|
||||
|
||||
/**
|
||||
* ensures that a file is on disk
|
||||
* @param filePath the filePath to ensureDir
|
||||
* @param the fileContent to place into a new file in case it doesn't exist yet
|
||||
* @returns Promise<void>
|
||||
* @exec ASYNC
|
||||
*/
|
||||
export const ensureFile = async (
|
||||
filePathArg,
|
||||
initFileStringArg,
|
||||
): Promise<void> => {
|
||||
ensureFileSync(filePathArg, initFileStringArg);
|
||||
};
|
||||
|
||||
/**
|
||||
* ensures that a file is on disk
|
||||
* @param filePath the filePath to ensureDir
|
||||
* @param the fileContent to place into a new file in case it doesn't exist yet
|
||||
* @returns Promise<void>
|
||||
* @exec SYNC
|
||||
*/
|
||||
export const ensureFileSync = (
|
||||
filePathArg: string,
|
||||
initFileStringArg: string,
|
||||
): void => {
|
||||
if (fileExistsSync(filePathArg)) {
|
||||
return null;
|
||||
} else {
|
||||
memory.toFsSync(initFileStringArg, filePathArg);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* removes a file or folder from local disk
|
||||
*/
|
||||
export const remove = async (pathArg: string): Promise<void> => {
|
||||
await plugins.fsExtra.remove(pathArg);
|
||||
};
|
||||
|
||||
/**
|
||||
* removes a file SYNCHRONOUSLY from local disk
|
||||
*/
|
||||
export const removeSync = (pathArg: string): void => {
|
||||
plugins.fsExtra.removeSync(pathArg);
|
||||
};
|
||||
|
||||
/**
|
||||
* removes an array of filePaths from disk
|
||||
*/
|
||||
export const removeMany = async (filePathArrayArg: string[]) => {
|
||||
const promiseArray: Array<Promise<void>> = [];
|
||||
for (const filePath of filePathArrayArg) {
|
||||
promiseArray.push(remove(filePath));
|
||||
}
|
||||
await Promise.all(promiseArray);
|
||||
};
|
||||
|
||||
/**
|
||||
* like removeFilePathArray but SYNCHRONOUSLY
|
||||
*/
|
||||
export const removeManySync = (filePathArrayArg: string[]): void => {
|
||||
for (const filePath of filePathArrayArg) {
|
||||
removeSync(filePath);
|
||||
}
|
||||
};
|
||||
|
||||
/*===============================================================
|
||||
============================ Write/Read =========================
|
||||
===============================================================*/
|
||||
|
||||
/**
|
||||
* reads a file content to an object
|
||||
* good for JSON, YAML, TOML, etc.
|
||||
* @param filePathArg
|
||||
* @param fileTypeArg
|
||||
* @returns {any}
|
||||
*/
|
||||
export const toObjectSync = (filePathArg, fileTypeArg?) => {
|
||||
const fileString = plugins.fsExtra.readFileSync(filePathArg, 'utf8');
|
||||
let fileType;
|
||||
fileTypeArg
|
||||
? (fileType = fileTypeArg)
|
||||
: (fileType = interpreter.filetype(filePathArg));
|
||||
try {
|
||||
return interpreter.objectFile(fileString, fileType);
|
||||
} catch (err) {
|
||||
err.message = `Failed to read file at ${filePathArg}` + err.message;
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* reads a file content to a String
|
||||
*/
|
||||
export const toStringSync = (filePath: string): string => {
|
||||
const encoding = plugins.smartmime.getEncodingForPathSync(filePath);
|
||||
let fileString: string | Buffer = plugins.fsExtra.readFileSync(
|
||||
filePath,
|
||||
encoding,
|
||||
);
|
||||
if (Buffer.isBuffer(fileString)) {
|
||||
fileString = fileString.toString('binary');
|
||||
}
|
||||
return fileString;
|
||||
};
|
||||
|
||||
export const toBuffer = async (filePath: string): Promise<Buffer> => {
|
||||
return plugins.fsExtra.readFile(filePath);
|
||||
};
|
||||
|
||||
export const toBufferSync = (filePath: string): Buffer => {
|
||||
return plugins.fsExtra.readFileSync(filePath);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a Readable Stream from a file path.
|
||||
* @param filePath The path to the file.
|
||||
* @returns {fs.ReadStream}
|
||||
*/
|
||||
export const toReadStream = (filePath: string): plugins.fs.ReadStream => {
|
||||
if (!fileExistsSync(filePath)) {
|
||||
throw new Error(`File does not exist at path: ${filePath}`);
|
||||
}
|
||||
return plugins.fsExtra.createReadStream(filePath);
|
||||
};
|
||||
|
||||
export const fileTreeToHash = async (
|
||||
dirPathArg: string,
|
||||
miniMatchFilter: string,
|
||||
) => {
|
||||
const fileTreeObject = await fileTreeToObject(dirPathArg, miniMatchFilter);
|
||||
let combinedString = '';
|
||||
for (const smartfile of fileTreeObject) {
|
||||
combinedString += await smartfile.getHash();
|
||||
}
|
||||
const hash = await plugins.smarthash.sha256FromString(combinedString);
|
||||
return hash;
|
||||
};
|
||||
|
||||
/**
|
||||
* creates a smartfile array from a directory
|
||||
* @param dirPathArg the directory to start from
|
||||
* @param miniMatchFilter a minimatch filter of what files to include
|
||||
*/
|
||||
export const fileTreeToObject = async (
|
||||
dirPathArg: string,
|
||||
miniMatchFilter: string,
|
||||
) => {
|
||||
// handle absolute miniMatchFilter
|
||||
let dirPath: string;
|
||||
if (plugins.path.isAbsolute(miniMatchFilter)) {
|
||||
dirPath = '/';
|
||||
} else {
|
||||
dirPath = plugins.smartpath.transform.toAbsolute(dirPathArg) as string;
|
||||
}
|
||||
|
||||
const fileTree = await listFileTree(dirPath, miniMatchFilter);
|
||||
const smartfileArray: SmartFile[] = [];
|
||||
for (const filePath of fileTree) {
|
||||
const readPath = ((): string => {
|
||||
if (!plugins.path.isAbsolute(filePath)) {
|
||||
return plugins.path.join(dirPath, filePath);
|
||||
} else {
|
||||
return filePath;
|
||||
}
|
||||
})();
|
||||
const fileBuffer = plugins.fs.readFileSync(readPath);
|
||||
|
||||
// push a read file as Smartfile
|
||||
smartfileArray.push(
|
||||
new SmartFile({
|
||||
contentBuffer: fileBuffer,
|
||||
base: dirPath,
|
||||
path: filePath,
|
||||
}),
|
||||
);
|
||||
}
|
||||
return smartfileArray;
|
||||
};
|
||||
|
||||
/**
|
||||
* lists Folders in a directory on local disk
|
||||
* @returns Promise with an array that contains the folder names
|
||||
*/
|
||||
export const listFolders = async (
|
||||
pathArg: string,
|
||||
regexFilter?: RegExp,
|
||||
): Promise<string[]> => {
|
||||
return listFoldersSync(pathArg, regexFilter);
|
||||
};
|
||||
|
||||
/**
|
||||
* lists Folders SYNCHRONOUSLY in a directory on local disk
|
||||
* @returns an array with the folder names as strings
|
||||
*/
|
||||
export const listFoldersSync = (
|
||||
pathArg: string,
|
||||
regexFilter?: RegExp,
|
||||
): string[] => {
|
||||
let folderArray = plugins.fsExtra.readdirSync(pathArg).filter((file) => {
|
||||
return plugins.fsExtra
|
||||
.statSync(plugins.path.join(pathArg, file))
|
||||
.isDirectory();
|
||||
});
|
||||
if (regexFilter) {
|
||||
folderArray = folderArray.filter((fileItem) => {
|
||||
return regexFilter.test(fileItem);
|
||||
});
|
||||
}
|
||||
return folderArray;
|
||||
};
|
||||
|
||||
/**
|
||||
* lists Files in a directory on local disk
|
||||
* @returns Promise
|
||||
*/
|
||||
export const listFiles = async (
|
||||
pathArg: string,
|
||||
regexFilter?: RegExp,
|
||||
): Promise<string[]> => {
|
||||
return listFilesSync(pathArg, regexFilter);
|
||||
};
|
||||
|
||||
/**
|
||||
* lists Files SYNCHRONOUSLY in a directory on local disk
|
||||
* @returns an array with the folder names as strings
|
||||
*/
|
||||
export const listFilesSync = (
|
||||
pathArg: string,
|
||||
regexFilter?: RegExp,
|
||||
): string[] => {
|
||||
let fileArray = plugins.fsExtra.readdirSync(pathArg).filter((file) => {
|
||||
return plugins.fsExtra.statSync(plugins.path.join(pathArg, file)).isFile();
|
||||
});
|
||||
if (regexFilter) {
|
||||
fileArray = fileArray.filter((fileItem) => {
|
||||
return regexFilter.test(fileItem);
|
||||
});
|
||||
}
|
||||
return fileArray;
|
||||
};
|
||||
|
||||
/**
|
||||
* lists all items (folders AND files) in a directory on local disk
|
||||
* @returns Promise<string[]>
|
||||
*/
|
||||
export const listAllItems = async (
|
||||
pathArg: string,
|
||||
regexFilter?: RegExp,
|
||||
): Promise<string[]> => {
|
||||
return listAllItemsSync(pathArg, regexFilter);
|
||||
};
|
||||
|
||||
/**
|
||||
* lists all items (folders AND files) in a directory on local disk
|
||||
* @returns an array with the folder names as strings
|
||||
* @executes SYNC
|
||||
*/
|
||||
export const listAllItemsSync = (
|
||||
pathArg: string,
|
||||
regexFilter?: RegExp,
|
||||
): string[] => {
|
||||
let allItmesArray = plugins.fsExtra.readdirSync(pathArg).filter((file) => {
|
||||
return plugins.fsExtra.statSync(plugins.path.join(pathArg, file)).isFile();
|
||||
});
|
||||
if (regexFilter) {
|
||||
allItmesArray = allItmesArray.filter((fileItem) => {
|
||||
return regexFilter.test(fileItem);
|
||||
});
|
||||
}
|
||||
return allItmesArray;
|
||||
};
|
||||
|
||||
/**
|
||||
* lists a file tree using a miniMatch filter
|
||||
* note: if the miniMatch Filter is an absolute path, the cwdArg will be omitted
|
||||
* @returns Promise<string[]> string array with the absolute paths of all matching files
|
||||
*/
|
||||
export const listFileTree = async (
|
||||
dirPathArg: string,
|
||||
miniMatchFilter: string,
|
||||
absolutePathsBool: boolean = false,
|
||||
): Promise<string[]> => {
|
||||
// handle absolute miniMatchFilter
|
||||
let dirPath: string;
|
||||
if (plugins.path.isAbsolute(miniMatchFilter)) {
|
||||
dirPath = '/';
|
||||
} else {
|
||||
dirPath = dirPathArg;
|
||||
}
|
||||
|
||||
const options = {
|
||||
cwd: dirPath,
|
||||
nodir: true,
|
||||
dot: true,
|
||||
};
|
||||
|
||||
// Fix inconsistent **/* glob behavior across systems
|
||||
// Some glob implementations don't include root-level files when using **/*
|
||||
// To ensure consistent behavior, we expand **/* patterns to include both root and nested files
|
||||
let patterns: string[];
|
||||
if (miniMatchFilter.startsWith('**/')) {
|
||||
// Extract the part after **/ (e.g., "*.ts" from "**/*.ts")
|
||||
const rootPattern = miniMatchFilter.substring(3);
|
||||
// Use both the root pattern and the original pattern to ensure we catch everything
|
||||
patterns = [rootPattern, miniMatchFilter];
|
||||
} else {
|
||||
patterns = [miniMatchFilter];
|
||||
}
|
||||
|
||||
// Collect results from all patterns
|
||||
const allFiles = new Set<string>();
|
||||
for (const pattern of patterns) {
|
||||
const files = await plugins.glob.glob(pattern, options);
|
||||
files.forEach((file) => allFiles.add(file));
|
||||
}
|
||||
|
||||
let fileList = Array.from(allFiles).sort();
|
||||
|
||||
if (absolutePathsBool) {
|
||||
fileList = fileList.map((filePath) => {
|
||||
return plugins.path.resolve(plugins.path.join(dirPath, filePath));
|
||||
});
|
||||
}
|
||||
|
||||
return fileList;
|
||||
};
|
||||
|
||||
/**
|
||||
* Watches for file stability before resolving the promise.
|
||||
* Ensures that the directory/file exists before setting up the watcher.
|
||||
*
|
||||
* **New behavior**: If the given path is a directory, this function will:
|
||||
* 1. Wait for that directory to exist (creating a timeout if needed).
|
||||
* 2. Watch the directory until at least one file appears.
|
||||
* 3. Then wait for the first file in the directory to stabilize before resolving.
|
||||
*
|
||||
* @param fileOrDirPathArg The path of the file or directory to monitor.
|
||||
* @param timeoutMs The maximum time to wait for the file to stabilize (in milliseconds). Default is 60 seconds.
|
||||
* @returns A promise that resolves when the target is stable or rejects on timeout/error.
|
||||
*/
|
||||
export const waitForFileToBeReady = async (
|
||||
fileOrDirPathArg: string,
|
||||
timeoutMs: number = 60000,
|
||||
): Promise<void> => {
|
||||
const startTime = Date.now();
|
||||
|
||||
/**
|
||||
* Ensure that a path (file or directory) exists. If it doesn't yet exist,
|
||||
* wait until it does (or time out).
|
||||
* @param pathToCheck The file or directory path to check.
|
||||
*/
|
||||
const ensurePathExists = async (pathToCheck: string): Promise<void> => {
|
||||
while (true) {
|
||||
try {
|
||||
await plugins.smartpromise.fromCallback((cb) =>
|
||||
plugins.fs.access(pathToCheck, plugins.fs.constants.F_OK, cb),
|
||||
);
|
||||
return;
|
||||
} catch (err: any) {
|
||||
if (err.code !== 'ENOENT') {
|
||||
throw err; // Propagate unexpected errors
|
||||
}
|
||||
if (Date.now() - startTime > timeoutMs) {
|
||||
throw new Error(`Timeout waiting for path to exist: ${pathToCheck}`);
|
||||
}
|
||||
await plugins.smartdelay.delayFor(500);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks if a file (not directory) is stable by comparing sizes
|
||||
* across successive checks.
|
||||
* @param filePathArg The path of the file to check.
|
||||
* @returns A promise that resolves once the file stops changing.
|
||||
*/
|
||||
const waitForSingleFileToBeStable = async (
|
||||
filePathArg: string,
|
||||
): Promise<void> => {
|
||||
let lastFileSize = -1;
|
||||
let fileIsStable = false;
|
||||
|
||||
// We'll create a helper for repeated stats-checking logic
|
||||
const checkFileStability = async () => {
|
||||
try {
|
||||
const stats = await plugins.smartpromise.fromCallback<plugins.fs.Stats>(
|
||||
(cb) => plugins.fs.stat(filePathArg, cb),
|
||||
);
|
||||
if (stats.isDirectory()) {
|
||||
// If it unexpectedly turns out to be a directory here, throw
|
||||
throw new Error(
|
||||
`Expected a file but found a directory: ${filePathArg}`,
|
||||
);
|
||||
}
|
||||
if (stats.size === lastFileSize) {
|
||||
fileIsStable = true;
|
||||
} else {
|
||||
lastFileSize = stats.size;
|
||||
fileIsStable = false;
|
||||
}
|
||||
} catch (err: any) {
|
||||
// Ignore only if file not found
|
||||
if (err.code !== 'ENOENT') {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Ensure file exists first
|
||||
await ensurePathExists(filePathArg);
|
||||
|
||||
// Set up a watcher on the file itself
|
||||
const fileWatcher = plugins.fs.watch(
|
||||
filePathArg,
|
||||
{ persistent: true },
|
||||
async () => {
|
||||
if (!fileIsStable) {
|
||||
await checkFileStability();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
try {
|
||||
// Poll until stable or timeout
|
||||
while (!fileIsStable) {
|
||||
if (Date.now() - startTime > timeoutMs) {
|
||||
throw new Error(
|
||||
`Timeout waiting for file to stabilize: ${filePathArg}`,
|
||||
);
|
||||
}
|
||||
await checkFileStability();
|
||||
if (!fileIsStable) {
|
||||
await plugins.smartdelay.delayFor(1000);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
fileWatcher.close();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Main logic: check if we have a directory or file at fileOrDirPathArg.
|
||||
* If directory, wait for first file in the directory to appear and stabilize.
|
||||
* If file, do the old single-file wait logic.
|
||||
*/
|
||||
const statsForGivenPath = await (async () => {
|
||||
try {
|
||||
await ensurePathExists(fileOrDirPathArg);
|
||||
return await plugins.smartpromise.fromCallback<plugins.fs.Stats>((cb) =>
|
||||
plugins.fs.stat(fileOrDirPathArg, cb),
|
||||
);
|
||||
} catch (err) {
|
||||
// If there's an error (including timeout), just rethrow
|
||||
throw err;
|
||||
}
|
||||
})();
|
||||
|
||||
if (!statsForGivenPath.isDirectory()) {
|
||||
// It's a file – just do the single-file stability wait
|
||||
await waitForSingleFileToBeStable(fileOrDirPathArg);
|
||||
return;
|
||||
}
|
||||
|
||||
// Otherwise, it's a directory. Wait for the first file inside to appear and be stable
|
||||
const dirPath = fileOrDirPathArg;
|
||||
|
||||
// Helper to find the first file in the directory if it exists
|
||||
const getFirstFileInDirectory = async (): Promise<string | null> => {
|
||||
const entries = await plugins.smartpromise.fromCallback<string[]>((cb) =>
|
||||
plugins.fs.readdir(dirPath, cb),
|
||||
);
|
||||
// We only want actual files, not subdirectories
|
||||
for (const entry of entries) {
|
||||
const entryPath = plugins.path.join(dirPath, entry);
|
||||
const entryStats =
|
||||
await plugins.smartpromise.fromCallback<plugins.fs.Stats>((cb) =>
|
||||
plugins.fs.stat(entryPath, cb),
|
||||
);
|
||||
if (entryStats.isFile()) {
|
||||
return entryPath;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
// Wait for a file to appear in this directory
|
||||
let firstFilePath = await getFirstFileInDirectory();
|
||||
if (!firstFilePath) {
|
||||
// Set up a watcher on the directory to see if a file appears
|
||||
const directoryWatcher = plugins.fs.watch(dirPath, { persistent: true });
|
||||
try {
|
||||
// We'll poll for the existence of a file in that directory
|
||||
while (!firstFilePath) {
|
||||
if (Date.now() - startTime > timeoutMs) {
|
||||
throw new Error(
|
||||
`Timeout waiting for a file to appear in directory: ${dirPath}`,
|
||||
);
|
||||
}
|
||||
firstFilePath = await getFirstFileInDirectory();
|
||||
if (!firstFilePath) {
|
||||
await plugins.smartdelay.delayFor(1000);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
directoryWatcher.close();
|
||||
}
|
||||
}
|
||||
|
||||
// Now that we have a file path, wait for that file to stabilize
|
||||
await waitForSingleFileToBeStable(firstFilePath);
|
||||
};
|
||||
|
||||
/**
|
||||
* writes string or Smartfile to disk.
|
||||
* @param fileArg
|
||||
* @param fileNameArg
|
||||
* @param fileBaseArg
|
||||
*/
|
||||
export let toFs = async (
|
||||
fileContentArg: string | Buffer | SmartFile | StreamFile,
|
||||
filePathArg: string,
|
||||
optionsArg: {
|
||||
respectRelative?: boolean;
|
||||
} = {},
|
||||
) => {
|
||||
const done = plugins.smartpromise.defer();
|
||||
|
||||
// check args
|
||||
if (!fileContentArg || !filePathArg) {
|
||||
throw new Error('expected valid arguments');
|
||||
}
|
||||
|
||||
// prepare actual write action
|
||||
let fileContent: string | Buffer;
|
||||
let fileEncoding: 'utf8' | 'binary' = 'utf8';
|
||||
let filePath: string = filePathArg;
|
||||
|
||||
// handle Smartfile
|
||||
if (fileContentArg instanceof SmartFile) {
|
||||
fileContent = fileContentArg.contentBuffer;
|
||||
// handle options
|
||||
if (optionsArg.respectRelative) {
|
||||
filePath = plugins.path.join(filePath, fileContentArg.path);
|
||||
}
|
||||
} else if (Buffer.isBuffer(fileContentArg)) {
|
||||
fileContent = fileContentArg;
|
||||
fileEncoding = 'binary';
|
||||
} else if (typeof fileContentArg === 'string') {
|
||||
fileContent = fileContentArg;
|
||||
} else {
|
||||
throw new Error('fileContent is neither string nor Smartfile');
|
||||
}
|
||||
await ensureDir(plugins.path.parse(filePath).dir);
|
||||
plugins.fsExtra.writeFile(
|
||||
filePath,
|
||||
fileContent,
|
||||
{ encoding: fileEncoding },
|
||||
done.resolve,
|
||||
);
|
||||
return await done.promise;
|
||||
};
|
||||
|
||||
export const stat = async (filePathArg: string) => {
|
||||
return plugins.fsPromises.stat(filePathArg);
|
||||
};
|
215
ts/fsstream.ts
Normal file
215
ts/fsstream.ts
Normal file
@@ -0,0 +1,215 @@
|
||||
/*
|
||||
This file contains logic for streaming things from and to the filesystem
|
||||
*/
|
||||
import * as plugins from './plugins.js';
|
||||
|
||||
export const createReadStream = (pathArg: string) => {
|
||||
return plugins.fs.createReadStream(pathArg);
|
||||
};
|
||||
|
||||
export const createWriteStream = (pathArg: string) => {
|
||||
return plugins.fs.createWriteStream(pathArg);
|
||||
};
|
||||
|
||||
export const processFile = async (
|
||||
filePath: string,
|
||||
asyncFunc: (fileStream: plugins.stream.Readable) => Promise<void>,
|
||||
): Promise<void> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const fileStream = createReadStream(filePath);
|
||||
asyncFunc(fileStream).then(resolve).catch(reject);
|
||||
});
|
||||
};
|
||||
|
||||
export const processDirectory = async (
|
||||
directoryPath: string,
|
||||
asyncFunc: (fileStream: plugins.stream.Readable) => Promise<void>,
|
||||
): Promise<void> => {
|
||||
const files = plugins.fs.readdirSync(directoryPath, { withFileTypes: true });
|
||||
|
||||
for (const file of files) {
|
||||
const fullPath = plugins.path.join(directoryPath, file.name);
|
||||
|
||||
if (file.isDirectory()) {
|
||||
await processDirectory(fullPath, asyncFunc); // Recursively call processDirectory for directories
|
||||
} else if (file.isFile()) {
|
||||
await processFile(fullPath, asyncFunc); // Call async function with the file stream and wait for it
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks if a file is ready to be streamed (exists and is not empty).
|
||||
*/
|
||||
export const isFileReadyForStreaming = async (
|
||||
filePathArg: string,
|
||||
): Promise<boolean> => {
|
||||
try {
|
||||
const stats = await plugins.fs.promises.stat(filePathArg);
|
||||
return stats.size > 0;
|
||||
} catch (error) {
|
||||
if (error.code === 'ENOENT') {
|
||||
// File does not exist
|
||||
return false;
|
||||
}
|
||||
throw error; // Rethrow other unexpected errors
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Waits for a file to be ready for streaming (exists and is not empty).
|
||||
*/
|
||||
export const waitForFileToBeReadyForStreaming = (
|
||||
filePathArg: string,
|
||||
): Promise<void> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
// Normalize and resolve the file path
|
||||
const filePath = plugins.path.resolve(filePathArg);
|
||||
|
||||
// Function to check file stats
|
||||
const checkFile = (resolve: () => void, reject: (reason: any) => void) => {
|
||||
plugins.fs.stat(filePath, (err, stats) => {
|
||||
if (err) {
|
||||
if (err.code === 'ENOENT') {
|
||||
// File not found, wait and try again
|
||||
return;
|
||||
}
|
||||
// Some other error occurred
|
||||
return reject(err);
|
||||
}
|
||||
if (stats.size > 0) {
|
||||
// File exists and is not empty, resolve the promise
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// Set up file watcher
|
||||
const watcher = plugins.fs.watch(
|
||||
filePath,
|
||||
{ persistent: false },
|
||||
(eventType) => {
|
||||
if (eventType === 'change' || eventType === 'rename') {
|
||||
checkFile(resolve, reject);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
// Check file immediately in case it's already ready
|
||||
checkFile(resolve, reject);
|
||||
|
||||
// Error handling
|
||||
watcher.on('error', (error) => {
|
||||
watcher.close();
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export class SmartReadStream extends plugins.stream.Readable {
|
||||
private watcher: plugins.fs.FSWatcher | null = null;
|
||||
private lastReadSize: number = 0;
|
||||
private endTimeout: NodeJS.Timeout | null = null;
|
||||
private filePath: string;
|
||||
private endDelay: number;
|
||||
private reading: boolean = false;
|
||||
|
||||
constructor(
|
||||
filePath: string,
|
||||
endDelay = 60000,
|
||||
opts?: plugins.stream.ReadableOptions,
|
||||
) {
|
||||
super(opts);
|
||||
this.filePath = filePath;
|
||||
this.endDelay = endDelay;
|
||||
}
|
||||
|
||||
private startWatching(): void {
|
||||
this.watcher = plugins.fs.watch(this.filePath, (eventType) => {
|
||||
if (eventType === 'change') {
|
||||
this.resetEndTimeout();
|
||||
}
|
||||
});
|
||||
|
||||
this.watcher.on('error', (error) => {
|
||||
this.cleanup();
|
||||
this.emit('error', error);
|
||||
});
|
||||
}
|
||||
|
||||
private resetEndTimeout(): void {
|
||||
if (this.endTimeout) clearTimeout(this.endTimeout);
|
||||
this.endTimeout = setTimeout(() => this.checkForEnd(), this.endDelay);
|
||||
}
|
||||
|
||||
private checkForEnd(): void {
|
||||
plugins.fs.stat(this.filePath, (err, stats) => {
|
||||
if (err) {
|
||||
this.emit('error', err);
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.lastReadSize === stats.size) {
|
||||
this.push(null); // Signal the end of the stream
|
||||
this.cleanup();
|
||||
} else {
|
||||
this.lastReadSize = stats.size;
|
||||
this.resetEndTimeout();
|
||||
if (!this.reading) {
|
||||
// We only want to continue reading if we were previously waiting for more data
|
||||
this.reading = true;
|
||||
this._read(10000); // Try to read more data
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private cleanup(): void {
|
||||
if (this.endTimeout) clearTimeout(this.endTimeout);
|
||||
if (this.watcher) this.watcher.close();
|
||||
}
|
||||
|
||||
_read(size: number): void {
|
||||
this.reading = true;
|
||||
const chunkSize = Math.min(size, 16384); // Read in chunks of 16KB
|
||||
const buffer = Buffer.alloc(chunkSize);
|
||||
plugins.fs.open(this.filePath, 'r', (err, fd) => {
|
||||
if (err) {
|
||||
this.emit('error', err);
|
||||
return;
|
||||
}
|
||||
plugins.fs.read(
|
||||
fd,
|
||||
buffer,
|
||||
0,
|
||||
chunkSize,
|
||||
this.lastReadSize,
|
||||
(err, bytesRead, buffer) => {
|
||||
if (err) {
|
||||
this.emit('error', err);
|
||||
return;
|
||||
}
|
||||
|
||||
if (bytesRead > 0) {
|
||||
this.lastReadSize += bytesRead;
|
||||
this.push(buffer.slice(0, bytesRead)); // Push the data onto the stream
|
||||
} else {
|
||||
this.reading = false; // No more data to read for now
|
||||
this.resetEndTimeout();
|
||||
}
|
||||
|
||||
plugins.fs.close(fd, (err) => {
|
||||
if (err) {
|
||||
this.emit('error', err);
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
_destroy(error: Error | null, callback: (error: Error | null) => void): void {
|
||||
this.cleanup();
|
||||
callback(error);
|
||||
}
|
||||
}
|
15
ts/index.ts
15
ts/index.ts
@@ -1,11 +1,12 @@
|
||||
import * as plugins from './smartfile.plugins.js';
|
||||
import * as fsMod from './smartfile.fs.js';
|
||||
import * as fsStreamMod from './smartfile.fsstream.js';
|
||||
import * as interpreterMod from './smartfile.interpreter.js';
|
||||
import * as memoryMod from './smartfile.memory.js';
|
||||
import * as plugins from './plugins.js';
|
||||
import * as fsMod from './fs.js';
|
||||
import * as fsStreamMod from './fsstream.js';
|
||||
import * as interpreterMod from './interpreter.js';
|
||||
import * as memoryMod from './memory.js';
|
||||
|
||||
export * from './smartfile.classes.smartfile.js';
|
||||
export * from './smartfile.classes.virtualdirectory.js';
|
||||
export * from './classes.smartfile.js';
|
||||
export * from './classes.streamfile.js';
|
||||
export * from './classes.virtualdirectory.js';
|
||||
|
||||
export const fs = fsMod;
|
||||
export const fsStream = fsStreamMod;
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import * as plugins from './smartfile.plugins.js';
|
||||
import * as plugins from './plugins.js';
|
||||
|
||||
export let filetype = (pathArg: string): string => {
|
||||
const extName = plugins.path.extname(pathArg);
|
@@ -1,7 +1,8 @@
|
||||
import * as plugins from './smartfile.plugins.js';
|
||||
import { Smartfile } from './smartfile.classes.smartfile.js';
|
||||
import * as smartfileFs from './smartfile.fs.js';
|
||||
import * as interpreter from './smartfile.interpreter.js';
|
||||
import * as plugins from './plugins.js';
|
||||
import { SmartFile } from './classes.smartfile.js';
|
||||
import * as smartfileFs from './fs.js';
|
||||
import * as interpreter from './interpreter.js';
|
||||
import type { StreamFile } from './classes.streamfile.js';
|
||||
|
||||
/**
|
||||
* converts file to Object
|
||||
@@ -24,9 +25,9 @@ export interface IToFsOptions {
|
||||
* @param fileBaseArg
|
||||
*/
|
||||
export let toFs = async (
|
||||
fileContentArg: string | Buffer | Smartfile,
|
||||
fileContentArg: string | Buffer | SmartFile | StreamFile,
|
||||
filePathArg: string,
|
||||
optionsArg: IToFsOptions = {}
|
||||
optionsArg: IToFsOptions = {},
|
||||
) => {
|
||||
const done = plugins.smartpromise.defer();
|
||||
|
||||
@@ -41,7 +42,7 @@ export let toFs = async (
|
||||
let filePath: string = filePathArg;
|
||||
|
||||
// handle Smartfile
|
||||
if (fileContentArg instanceof Smartfile) {
|
||||
if (fileContentArg instanceof SmartFile) {
|
||||
fileContent = fileContentArg.contentBuffer;
|
||||
// handle options
|
||||
if (optionsArg.respectRelative) {
|
||||
@@ -56,7 +57,12 @@ export let toFs = async (
|
||||
throw new Error('fileContent is neither string nor Smartfile');
|
||||
}
|
||||
await smartfileFs.ensureDir(plugins.path.parse(filePath).dir);
|
||||
plugins.fsExtra.writeFile(filePath, fileContent, { encoding: fileEncoding }, done.resolve);
|
||||
plugins.fsExtra.writeFile(
|
||||
filePath,
|
||||
fileContent,
|
||||
{ encoding: fileEncoding },
|
||||
done.resolve,
|
||||
);
|
||||
return await done.promise;
|
||||
};
|
||||
|
||||
@@ -83,7 +89,10 @@ export const toFsSync = (fileArg: string, filePathArg: string) => {
|
||||
plugins.fsExtra.writeFileSync(filePath, fileString, { encoding: 'utf8' });
|
||||
};
|
||||
|
||||
export let smartfileArrayToFs = async (smartfileArrayArg: Smartfile[], dirArg: string) => {
|
||||
export let smartfileArrayToFs = async (
|
||||
smartfileArrayArg: SmartFile[],
|
||||
dirArg: string,
|
||||
) => {
|
||||
await smartfileFs.ensureDir(dirArg);
|
||||
for (const smartfile of smartfileArrayArg) {
|
||||
await toFs(smartfile, dirArg, {
|
39
ts/plugins.ts
Normal file
39
ts/plugins.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
// node native scope
|
||||
import * as fs from 'fs';
|
||||
import * as fsPromises from 'fs/promises';
|
||||
import * as path from 'path';
|
||||
import * as stream from 'stream';
|
||||
|
||||
export { fs, fsPromises, path, stream };
|
||||
|
||||
// @pushrocks scope
|
||||
import * as lik from '@push.rocks/lik';
|
||||
import * as smartfileInterfaces from '@push.rocks/smartfile-interfaces';
|
||||
import * as smartdelay from '@push.rocks/smartdelay';
|
||||
import * as smarthash from '@push.rocks/smarthash';
|
||||
import * as smartjson from '@push.rocks/smartjson';
|
||||
import * as smartmime from '@push.rocks/smartmime';
|
||||
import * as smartpath from '@push.rocks/smartpath';
|
||||
import * as smartpromise from '@push.rocks/smartpromise';
|
||||
import * as smartrequest from '@push.rocks/smartrequest';
|
||||
import * as smartstream from '@push.rocks/smartstream';
|
||||
|
||||
export {
|
||||
lik,
|
||||
smartfileInterfaces,
|
||||
smartdelay,
|
||||
smarthash,
|
||||
smartjson,
|
||||
smartmime,
|
||||
smartpath,
|
||||
smartpromise,
|
||||
smartrequest,
|
||||
smartstream,
|
||||
};
|
||||
|
||||
// third party scope
|
||||
import fsExtra from 'fs-extra';
|
||||
import * as glob from 'glob';
|
||||
import yaml from 'js-yaml';
|
||||
|
||||
export { fsExtra, glob, yaml };
|
@@ -1,61 +0,0 @@
|
||||
import { Smartfile } from './smartfile.classes.smartfile.js';
|
||||
import * as plugins from './smartfile.plugins.js';
|
||||
import * as fs from './smartfile.fs.js';
|
||||
|
||||
/**
|
||||
* a virtual directory exposes a fs api
|
||||
*/
|
||||
export class VirtualDirectory {
|
||||
// STATIC
|
||||
public static async fromFsDirPath(pathArg: string): Promise<VirtualDirectory> {
|
||||
const newVirtualDir = new VirtualDirectory();
|
||||
newVirtualDir.addSmartfiles(await fs.fileTreeToObject(pathArg, '**/*'));
|
||||
return newVirtualDir;
|
||||
}
|
||||
|
||||
public static async fromVirtualDirTransferableObject(
|
||||
virtualDirTransferableObjectArg: plugins.smartfileInterfaces.VirtualDirTransferableObject
|
||||
): Promise<VirtualDirectory> {
|
||||
const newVirtualDir = new VirtualDirectory();
|
||||
for (const fileArg of virtualDirTransferableObjectArg.files) {
|
||||
newVirtualDir.addSmartfiles([Smartfile.enfoldFromJson(fileArg) as Smartfile]);
|
||||
}
|
||||
return newVirtualDir;
|
||||
}
|
||||
|
||||
// INSTANCE
|
||||
public smartfileArray: Smartfile[] = [];
|
||||
|
||||
constructor() {}
|
||||
|
||||
public addSmartfiles(smartfileArrayArg: Smartfile[]) {
|
||||
this.smartfileArray = this.smartfileArray.concat(smartfileArrayArg);
|
||||
}
|
||||
|
||||
public async getFileByPath(pathArg: string) {
|
||||
for (const smartfile of this.smartfileArray) {
|
||||
if (smartfile.path === pathArg) {
|
||||
return smartfile;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async toVirtualDirTransferableObject(): Promise<plugins.smartfileInterfaces.VirtualDirTransferableObject> {
|
||||
return {
|
||||
files: this.smartfileArray.map((smartfileArg) => smartfileArg.foldToJson()),
|
||||
};
|
||||
}
|
||||
|
||||
public async saveToDisk(dirArg: string) {
|
||||
console.log(`writing VirtualDirectory with ${this.smartfileArray.length} to directory:
|
||||
--> ${dirArg}`);
|
||||
for (const smartfileArg of this.smartfileArray) {
|
||||
const filePath = await smartfileArg.writeToDir(dirArg);
|
||||
console.log(`wrote ${smartfileArg.relative} to
|
||||
--> ${filePath}`);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO implement root shifting to get subdirectories as new virtual directories
|
||||
// TODO implement root shifting to combine VirtualDirecotries in a parent virtual directory
|
||||
}
|
@@ -1,401 +0,0 @@
|
||||
import * as plugins from './smartfile.plugins.js';
|
||||
import * as interpreter from './smartfile.interpreter.js';
|
||||
|
||||
import { Smartfile } from './smartfile.classes.smartfile.js';
|
||||
|
||||
import * as memory from './smartfile.memory.js';
|
||||
/*===============================================================
|
||||
============================ Checks =============================
|
||||
===============================================================*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @param filePath
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export const fileExistsSync = (filePath): boolean => {
|
||||
let fileExistsBool: boolean = false;
|
||||
try {
|
||||
plugins.fsExtra.readFileSync(filePath);
|
||||
fileExistsBool = true;
|
||||
} catch (err) {
|
||||
fileExistsBool = false;
|
||||
}
|
||||
return fileExistsBool;
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @param filePath
|
||||
* @returns {any}
|
||||
*/
|
||||
export const fileExists = async (filePath): Promise<boolean> => {
|
||||
const done = plugins.smartpromise.defer<boolean>();
|
||||
plugins.fs.access(filePath, 4, (err) => {
|
||||
err ? done.resolve(false) : done.resolve(true);
|
||||
});
|
||||
return done.promise;
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks if given path points to an existing directory
|
||||
*/
|
||||
export const isDirectory = (pathArg): boolean => {
|
||||
try {
|
||||
return plugins.fsExtra.statSync(pathArg).isDirectory();
|
||||
} catch (err) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks if a given path points to an existing file
|
||||
*/
|
||||
export const isFile = (pathArg): boolean => {
|
||||
return plugins.fsExtra.statSync(pathArg).isFile();
|
||||
};
|
||||
|
||||
/*===============================================================
|
||||
============================ FS ACTIONS =========================
|
||||
===============================================================*/
|
||||
|
||||
/**
|
||||
* copies a file from A to B on the local disk
|
||||
*/
|
||||
export const copy = async (fromArg: string, toArg: string): Promise<boolean> => {
|
||||
const done = plugins.smartpromise.defer<boolean>();
|
||||
plugins.fsExtra.copy(fromArg, toArg, {}, (err) => {
|
||||
if (err) {
|
||||
throw new Error(`Could not copy from ${fromArg} to ${toArg}: ${err}`);
|
||||
}
|
||||
done.resolve(true);
|
||||
});
|
||||
return done.promise;
|
||||
};
|
||||
|
||||
/**
|
||||
* copies a file SYNCHRONOUSLY from A to B on the local disk
|
||||
*/
|
||||
export const copySync = (fromArg: string, toArg: string): boolean => {
|
||||
plugins.fsExtra.copySync(fromArg, toArg);
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* ensures that a directory is in place
|
||||
*/
|
||||
export const ensureDir = async (dirPathArg: string) => {
|
||||
await plugins.fsExtra.ensureDir(dirPathArg);
|
||||
};
|
||||
|
||||
/**
|
||||
* ensures that a directory is in place
|
||||
*/
|
||||
export const ensureDirSync = (dirPathArg: string) => {
|
||||
plugins.fsExtra.ensureDirSync(dirPathArg);
|
||||
};
|
||||
|
||||
/**
|
||||
* ensure an empty directory
|
||||
* @executes ASYNC
|
||||
*/
|
||||
export const ensureEmptyDir = async (dirPathArg: string) => {
|
||||
await plugins.fsExtra.ensureDir(dirPathArg);
|
||||
await plugins.fsExtra.emptyDir(dirPathArg);
|
||||
};
|
||||
|
||||
/**
|
||||
* ensure an empty directory
|
||||
* @executes SYNC
|
||||
*/
|
||||
export const ensureEmptyDirSync = (dirPathArg: string) => {
|
||||
plugins.fsExtra.ensureDirSync(dirPathArg);
|
||||
plugins.fsExtra.emptyDirSync(dirPathArg);
|
||||
};
|
||||
|
||||
/**
|
||||
* ensures that a file is on disk
|
||||
* @param filePath the filePath to ensureDir
|
||||
* @param the fileContent to place into a new file in case it doesn't exist yet
|
||||
* @returns Promise<void>
|
||||
* @exec ASYNC
|
||||
*/
|
||||
export const ensureFile = async (filePathArg, initFileStringArg): Promise<void> => {
|
||||
ensureFileSync(filePathArg, initFileStringArg);
|
||||
};
|
||||
|
||||
/**
|
||||
* ensures that a file is on disk
|
||||
* @param filePath the filePath to ensureDir
|
||||
* @param the fileContent to place into a new file in case it doesn't exist yet
|
||||
* @returns Promise<void>
|
||||
* @exec SYNC
|
||||
*/
|
||||
export const ensureFileSync = (filePathArg: string, initFileStringArg: string): void => {
|
||||
if (fileExistsSync(filePathArg)) {
|
||||
return null;
|
||||
} else {
|
||||
memory.toFsSync(initFileStringArg, filePathArg);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* removes a file or folder from local disk
|
||||
*/
|
||||
export const remove = async (pathArg: string): Promise<void> => {
|
||||
await plugins.fsExtra.remove(pathArg);
|
||||
};
|
||||
|
||||
/**
|
||||
* removes a file SYNCHRONOUSLY from local disk
|
||||
*/
|
||||
export const removeSync = (pathArg: string): void => {
|
||||
plugins.fsExtra.removeSync(pathArg);
|
||||
};
|
||||
|
||||
/**
|
||||
* removes an array of filePaths from disk
|
||||
*/
|
||||
export const removeMany = async (filePathArrayArg: string[]) => {
|
||||
const promiseArray: Array<Promise<void>> = [];
|
||||
for (const filePath of filePathArrayArg) {
|
||||
promiseArray.push(remove(filePath));
|
||||
}
|
||||
await Promise.all(promiseArray);
|
||||
};
|
||||
|
||||
/**
|
||||
* like removeFilePathArray but SYNCHRONOUSLY
|
||||
*/
|
||||
export const removeManySync = (filePathArrayArg: string[]): void => {
|
||||
for (const filePath of filePathArrayArg) {
|
||||
removeSync(filePath);
|
||||
}
|
||||
};
|
||||
|
||||
/*===============================================================
|
||||
============================ Write/Read =========================
|
||||
===============================================================*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @param filePathArg
|
||||
* @param fileTypeArg
|
||||
* @returns {any}
|
||||
*/
|
||||
export const toObjectSync = (filePathArg, fileTypeArg?) => {
|
||||
const fileString = plugins.fsExtra.readFileSync(filePathArg, 'utf8');
|
||||
let fileType;
|
||||
fileTypeArg ? (fileType = fileTypeArg) : (fileType = interpreter.filetype(filePathArg));
|
||||
return interpreter.objectFile(fileString, fileType);
|
||||
};
|
||||
|
||||
/**
|
||||
* reads a file content to a String
|
||||
*/
|
||||
export const toStringSync = (filePath: string): string => {
|
||||
const encoding = plugins.smartmime.getEncoding(filePath);
|
||||
let fileString: string | Buffer = plugins.fsExtra.readFileSync(filePath, encoding);
|
||||
if (Buffer.isBuffer(fileString)) {
|
||||
fileString = fileString.toString('binary');
|
||||
}
|
||||
return fileString;
|
||||
};
|
||||
|
||||
export const toBuffer = async (filePath: string): Promise<Buffer> => {
|
||||
return plugins.fsExtra.readFile(filePath);
|
||||
};
|
||||
|
||||
export const toBufferSync = (filePath: string): Buffer => {
|
||||
return plugins.fsExtra.readFileSync(filePath);
|
||||
};
|
||||
|
||||
export const fileTreeToHash = async (dirPathArg: string, miniMatchFilter: string) => {
|
||||
const fileTreeObject = await fileTreeToObject(dirPathArg, miniMatchFilter);
|
||||
let combinedString = '';
|
||||
for (const smartfile of fileTreeObject) {
|
||||
combinedString += await smartfile.getHash();
|
||||
}
|
||||
const hash = await plugins.smarthash.sha256FromString(combinedString);
|
||||
return hash;
|
||||
};
|
||||
|
||||
/**
|
||||
* creates a smartfile array from a directory
|
||||
* @param dirPathArg the directory to start from
|
||||
* @param miniMatchFilter a minimatch filter of what files to include
|
||||
*/
|
||||
export const fileTreeToObject = async (dirPathArg: string, miniMatchFilter: string) => {
|
||||
// handle absolute miniMatchFilter
|
||||
let dirPath: string;
|
||||
if (plugins.path.isAbsolute(miniMatchFilter)) {
|
||||
dirPath = '/';
|
||||
} else {
|
||||
dirPath = plugins.smartpath.transform.toAbsolute(dirPathArg) as string;
|
||||
}
|
||||
|
||||
const fileTree = await listFileTree(dirPath, miniMatchFilter);
|
||||
const smartfileArray: Smartfile[] = [];
|
||||
for (const filePath of fileTree) {
|
||||
const readPath = ((): string => {
|
||||
if (!plugins.path.isAbsolute(filePath)) {
|
||||
return plugins.path.join(dirPath, filePath);
|
||||
} else {
|
||||
return filePath;
|
||||
}
|
||||
})();
|
||||
const fileContentString = toStringSync(readPath);
|
||||
|
||||
// push a read file as Smartfile
|
||||
smartfileArray.push(
|
||||
new Smartfile({
|
||||
contentBuffer: Buffer.from(fileContentString),
|
||||
base: dirPath,
|
||||
path: filePath,
|
||||
})
|
||||
);
|
||||
}
|
||||
return smartfileArray;
|
||||
};
|
||||
|
||||
/**
|
||||
* lists Folders in a directory on local disk
|
||||
* @returns Promise with an array that contains the folder names
|
||||
*/
|
||||
export const listFolders = async (pathArg: string, regexFilter?: RegExp): Promise<string[]> => {
|
||||
return listFoldersSync(pathArg, regexFilter);
|
||||
};
|
||||
|
||||
/**
|
||||
* lists Folders SYNCHRONOUSLY in a directory on local disk
|
||||
* @returns an array with the folder names as strings
|
||||
*/
|
||||
export const listFoldersSync = (pathArg: string, regexFilter?: RegExp): string[] => {
|
||||
let folderArray = plugins.fsExtra.readdirSync(pathArg).filter((file) => {
|
||||
return plugins.fsExtra.statSync(plugins.path.join(pathArg, file)).isDirectory();
|
||||
});
|
||||
if (regexFilter) {
|
||||
folderArray = folderArray.filter((fileItem) => {
|
||||
return regexFilter.test(fileItem);
|
||||
});
|
||||
}
|
||||
return folderArray;
|
||||
};
|
||||
|
||||
/**
|
||||
* lists Files in a directory on local disk
|
||||
* @returns Promise
|
||||
*/
|
||||
export const listFiles = async (pathArg: string, regexFilter?: RegExp): Promise<string[]> => {
|
||||
return listFilesSync(pathArg, regexFilter);
|
||||
};
|
||||
|
||||
/**
|
||||
* lists Files SYNCHRONOUSLY in a directory on local disk
|
||||
* @returns an array with the folder names as strings
|
||||
*/
|
||||
export const listFilesSync = (pathArg: string, regexFilter?: RegExp): string[] => {
|
||||
let fileArray = plugins.fsExtra.readdirSync(pathArg).filter((file) => {
|
||||
return plugins.fsExtra.statSync(plugins.path.join(pathArg, file)).isFile();
|
||||
});
|
||||
if (regexFilter) {
|
||||
fileArray = fileArray.filter((fileItem) => {
|
||||
return regexFilter.test(fileItem);
|
||||
});
|
||||
}
|
||||
return fileArray;
|
||||
};
|
||||
|
||||
/**
|
||||
* lists all items (folders AND files) in a directory on local disk
|
||||
* @returns Promise<string[]>
|
||||
*/
|
||||
export const listAllItems = async (pathArg: string, regexFilter?: RegExp): Promise<string[]> => {
|
||||
return listAllItemsSync(pathArg, regexFilter);
|
||||
};
|
||||
|
||||
/**
|
||||
* lists all items (folders AND files) in a directory on local disk
|
||||
* @returns an array with the folder names as strings
|
||||
* @executes SYNC
|
||||
*/
|
||||
export const listAllItemsSync = (pathArg: string, regexFilter?: RegExp): string[] => {
|
||||
let allItmesArray = plugins.fsExtra.readdirSync(pathArg).filter((file) => {
|
||||
return plugins.fsExtra.statSync(plugins.path.join(pathArg, file)).isFile();
|
||||
});
|
||||
if (regexFilter) {
|
||||
allItmesArray = allItmesArray.filter((fileItem) => {
|
||||
return regexFilter.test(fileItem);
|
||||
});
|
||||
}
|
||||
return allItmesArray;
|
||||
};
|
||||
|
||||
/**
|
||||
* lists a file tree using a miniMatch filter
|
||||
* note: if the miniMatch Filter is an absolute path, the cwdArg will be omitted
|
||||
* @returns Promise<string[]> string array with the absolute paths of all matching files
|
||||
*/
|
||||
export const listFileTree = async (
|
||||
dirPathArg: string,
|
||||
miniMatchFilter: string,
|
||||
absolutePathsBool: boolean = false
|
||||
): Promise<string[]> => {
|
||||
const done = plugins.smartpromise.defer<string[]>();
|
||||
|
||||
// handle absolute miniMatchFilter
|
||||
let dirPath: string;
|
||||
if (plugins.path.isAbsolute(miniMatchFilter)) {
|
||||
dirPath = '/';
|
||||
} else {
|
||||
dirPath = dirPathArg;
|
||||
}
|
||||
|
||||
const options = {
|
||||
cwd: dirPath,
|
||||
nodir: true,
|
||||
dot: true,
|
||||
};
|
||||
plugins.glob(miniMatchFilter, options, (err, files: string[]) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
done.reject(err);
|
||||
}
|
||||
done.resolve(files);
|
||||
});
|
||||
|
||||
let fileList = await done.promise;
|
||||
if (absolutePathsBool) {
|
||||
fileList = fileList.map((filePath) => {
|
||||
return plugins.path.resolve(plugins.path.join(dirPath, filePath));
|
||||
});
|
||||
}
|
||||
|
||||
return fileList;
|
||||
};
|
||||
|
||||
/**
|
||||
* checks wether a file is ready for processing
|
||||
*/
|
||||
export const waitForFileToBeReady = async (filePathArg: string): Promise<void> => {
|
||||
if (!plugins.path.isAbsolute(filePathArg)) {
|
||||
filePathArg = plugins.path.resolve(filePathArg);
|
||||
}
|
||||
const limitedArray = new plugins.lik.LimitedArray<number>(3);
|
||||
let fileReady = false;
|
||||
while (!fileReady) {
|
||||
const stats = await plugins.fsExtra.stat(filePathArg);
|
||||
limitedArray.addOne(stats.size);
|
||||
if (
|
||||
limitedArray.array.length < 3 ||
|
||||
!(
|
||||
limitedArray.array[0] === limitedArray.array[1] &&
|
||||
limitedArray.array[1] === limitedArray.array[2]
|
||||
)
|
||||
) {
|
||||
await plugins.smartdelay.delayFor(5000);
|
||||
} else {
|
||||
fileReady = true;
|
||||
}
|
||||
}
|
||||
};
|
@@ -1,14 +0,0 @@
|
||||
/*
|
||||
This file contains logic for streaming things from and to the filesystem
|
||||
*/
|
||||
import * as plugins from './smartfile.plugins.js';
|
||||
|
||||
export const createReadStream = (pathArg: string) => {
|
||||
return plugins.fs.createReadStream(pathArg);
|
||||
};
|
||||
|
||||
export const createWriteStream = (pathArg: string) => {
|
||||
return plugins.fs.createWriteStream(pathArg);
|
||||
};
|
||||
|
||||
export const streamDirectory = async (dirPathArg: string) => {};
|
@@ -1,37 +0,0 @@
|
||||
// node native scope
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
export { fs, path };
|
||||
|
||||
// @pushrocks scope
|
||||
import * as lik from '@pushrocks/lik';
|
||||
import * as smartfileInterfaces from '@pushrocks/smartfile-interfaces';
|
||||
import * as smartdelay from '@pushrocks/smartdelay';
|
||||
import * as smarthash from '@pushrocks/smarthash';
|
||||
import * as smartjson from '@pushrocks/smartjson';
|
||||
import * as smartmime from '@pushrocks/smartmime';
|
||||
import * as smartpath from '@pushrocks/smartpath';
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
import * as smartrequest from '@pushrocks/smartrequest';
|
||||
import * as smartstream from '@pushrocks/smartstream';
|
||||
|
||||
export {
|
||||
lik,
|
||||
smartfileInterfaces,
|
||||
smartdelay,
|
||||
smarthash,
|
||||
smartjson,
|
||||
smartmime,
|
||||
smartpath,
|
||||
smartpromise,
|
||||
smartrequest,
|
||||
smartstream,
|
||||
};
|
||||
|
||||
// third party scope
|
||||
import fsExtra from 'fs-extra';
|
||||
import glob from 'glob';
|
||||
import yaml from 'js-yaml';
|
||||
|
||||
export { fsExtra, glob, yaml };
|
@@ -1,8 +1,14 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"experimentalDecorators": true,
|
||||
"useDefineForClassFields": false,
|
||||
"target": "ES2022",
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"esModuleInterop": true,
|
||||
"target": "ES2017",
|
||||
"moduleResolution": "node"
|
||||
}
|
||||
}
|
||||
"verbatimModuleSyntax": true,
|
||||
"baseUrl": ".",
|
||||
"paths": {}
|
||||
},
|
||||
"exclude": ["dist_*/**/*.d.ts"]
|
||||
}
|
||||
|
Reference in New Issue
Block a user