Skip to content

Commit

Permalink
🪚 OmniGraph™ I/O Utilities (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
janjakubnanista authored Dec 8, 2023
1 parent a665df2 commit c3ef1c8
Show file tree
Hide file tree
Showing 13 changed files with 155 additions and 10 deletions.
1 change: 1 addition & 0 deletions packages/create-lz-oapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"yoga-wasm-web": "~0.3.3"
},
"devDependencies": {
"@layerzerolabs/io-utils": "~0.0.1",
"@tanstack/react-query": "^5.8.4",
"@types/mocha": "^10.0.6",
"@types/prompts": "^2.4.9",
Expand Down
9 changes: 0 additions & 9 deletions packages/create-lz-oapp/src/utilities/filesystem.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/create-lz-oapp/src/utilities/prompts.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { EXAMPLES, PACKAGE_MANAGERS } from '@/config.js'
import prompts from 'prompts'
import { isPackageManagerAvailable } from './installation.js'
import { isDirectory } from './filesystem.js'
import { isDirectory } from '@layerzerolabs/io-utils'
import { resolve } from 'path'

const handlePromptState = (state: { aborted: boolean }) => {
Expand Down
3 changes: 3 additions & 0 deletions packages/io-utils/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.turbo
dist
node_modules
3 changes: 3 additions & 0 deletions packages/io-utils/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../.eslintrc.json"
}
47 changes: 47 additions & 0 deletions packages/io-utils/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<p align="center">
<a href="https://layerzero.network">
<img alt="LayerZero" style="max-width: 500px" src="https://d3a2dpnnrypp5h.cloudfront.net/bridge-app/lz.png"/>
</a>
</p>

<h1 align="center">@layerzerolabs/io-utils</h1>

<!-- The badges section -->
<p align="center">
<!-- Shields.io NPM published package version -->
<a href="https://www.npmjs.com/package/@layerzerolabs/io-utils"><img alt="NPM Version" src="https://img.shields.io/npm/v/@layerzerolabs/io-utils"/></a>
<!-- Shields.io NPM downloads -->
<a href="https://www.npmjs.com/package/@layerzerolabs/io-utils"><img alt="Downloads" src="https://img.shields.io/npm/dm/@layerzerolabs/io-utils"/></a>
<!-- Shields.io license badge -->
<a href="https://www.npmjs.com/package/@layerzerolabs/io-utils"><img alt="NPM License" src="https://img.shields.io/npm/l/@layerzerolabs/io-utils"/></a>
</p>

## Installation

```bash
pnpm install @layerzerolabs/io-utils
```

```bash
yarn install @layerzerolabs/io-utils
```

```bash
npm install @layerzerolabs/io-utils
```

## API Documentation

### Filesystem utilities

#### isDirectory(path)

Returns `true` if specified filesystem `path` points to a directory, `false` otherwise. Does not throw if `path` does not exist on the filesystem, instead returns `false`

#### isFile(path)

Returns `true` if specified filesystem `path` points to a file, `false` otherwise. Does not throw if `path` does not exist on the filesystem, instead returns `false`

#### isReadable(path)

Returns `true` if specified filesystem `path` can be read by the current user, `false` otherwise. Does not throw if `path` does not exist on the filesystem, instead returns `false`
8 changes: 8 additions & 0 deletions packages/io-utils/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
},
};
42 changes: 42 additions & 0 deletions packages/io-utils/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "@layerzerolabs/io-utils",
"version": "0.0.1",
"private": true,
"description": "Utilities for working with I/O in LayerZero utils",
"repository": {
"type": "git",
"url": "git+https://github.com/LayerZero-Labs/lz-utils.git",
"directory": "packages/io-utils"
},
"license": "MIT",
"exports": {
".": {
"types": "./dist/index.d.ts",
"require": "./dist/index.js",
"import": "./dist/index.mjs"
}
},
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"files": [
"dist"
],
"scripts": {
"prebuild": "tsc -noEmit",
"build": "npx tsup",
"clean": "rm -rf dist",
"lint": "npx eslint '**/*.{js,ts,json}'",
"test": "jest --passWithNoTests"
},
"devDependencies": {
"@types/jest": "^29.5.10",
"fast-check": "^3.14.0",
"jest": "^29.7.0",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"tslib": "~2.6.2",
"tsup": "~8.0.1",
"typescript": "^5.2.2"
}
}
25 changes: 25 additions & 0 deletions packages/io-utils/src/filesystem/filesystem.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { accessSync, constants, lstatSync } from 'fs'

export const isDirectory = (path: string): boolean => {
try {
return lstatSync(path).isDirectory()
} catch {
return false
}
}

export const isFile = (path: string): boolean => {
try {
return lstatSync(path).isFile()
} catch {
return false
}
}

export const isReadable = (path: string): boolean => {
try {
return accessSync(path, constants.R_OK), true
} catch {
return false
}
}
1 change: 1 addition & 0 deletions packages/io-utils/src/filesystem/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './filesystem'
1 change: 1 addition & 0 deletions packages/io-utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './filesystem'
11 changes: 11 additions & 0 deletions packages/io-utils/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../../tsconfig.json",
"exclude": ["dist", "node_modules"],
"include": ["src", "test"],
"compilerOptions": {
"types": ["node", "jest"],
"paths": {
"@/*": ["./src/*"]
}
}
}
12 changes: 12 additions & 0 deletions packages/io-utils/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { defineConfig } from 'tsup'

export default defineConfig({
entry: ['src/index.ts'],
outDir: './dist',
clean: true,
dts: true,
sourcemap: true,
splitting: false,
treeshake: true,
format: ['esm', 'cjs'],
})

0 comments on commit c3ef1c8

Please sign in to comment.