@js-sh/js-sh
Using the bash command simply for Javascript/Typescript
Install
npm i @js-sh/js-sh
Usage
Example
import { ls, cp, mkdir, rm } from '@js-sh/js-sh'
const CACHE_FOLDER = '.nyc_output'
rm(CACHE_FOLDER)
mkdir(CACHE_FOLDER)
ls('./apps/*/coverage/coverage-final.json')
.forEach((p) => {
cp.force(p, `${CACHE_FOLDER}/`)
})
Functions
$(command: string)
import { $ } from '@js-sh/js-sh'
await $('npm run test')
within(callback: Function)
import { within } from '@js-sh/js-sh'
within(() => {
cd('./oneFolder')
})
await within(async () => {
cd('./otherFolder')
})
retry(time: number, callback: Function)
import { retry } from '@js-sh/js-sh'
await retry(3, async () => {
// ...
})
cat(path: string)
import { cat } from '@js-sh/js-sh'
cat('./package.json')
cd(path: string)
import { cd } from '@js-sh/js-sh'
cd('./apps')
cp(source: string, target: string, options?: { force: boolean })
Copy File to File
import { cp } from '@js-sh/js-sh'
cp('./package.json', './package-backup.json')
Copy File into Folder
import { cp } from '@js-sh/js-sh'
cp('./package.json', './targetFolder/')
Copy Folder to Folder
import { cp } from '@js-sh/js-sh'
cp('./sourceFolder/*', './targetFolder')
Copy Folder into Folder
import { cp } from '@js-sh/js-sh'
cp('./sourceFolder', './targetFolder/')
cp.force(source: string, target: string)
See cp
method
echo(content: string)
import { echo } from '@js-sh/js-sh'
echo('Hello World')
ls(path: string | string[])
import { ls } from '@js-sh/js-sh'
ls('./')
ls('./package.json')
ls('./apps', './packages')
mkdir(path: string)
import { mkdir } from '@js-sh/js-sh'
mkdir('./newFolder')
mv(source: string, target: string, options?: { force: boolean })
Move File to File
import { mv } from '@js-sh/js-sh'
mv('./package.json', './package-backup.json')
Move File into Folder
import { mv } from '@js-sh/js-sh'
mv('./package.json', './targetFolder/')
Move Folder to Folder
import { mv } from '@js-sh/js-sh'
mv('./sourceFolder/*', './targetFolder')
Move Folder into Folder
import { mv } from '@js-sh/js-sh'
mv('./sourceFolder', './targetFolder/')
mv.force(source: string, target: string)
See mv
method
pwd()
Default return the process.cwd()
value until you use the cd
method
import { pwd } from '@js-sh/js-sh'
pwd()
rm(path: string)
import { rm } from '@js-sh/js-sh'
rm('./oldFolder')
sleep(time: number)
import { sleep } from '@js-sh/js-sh'
await sleep(50)
exit(code: number, msg?: string)
import { exit } from '@js-sh/js-sh'
exit(0, 'Bye~')
readFile(filepath: string, encoding?: string)
import { readFile } from '@js-sh/js-sh'
readFile('foo.txt', 'utf-8')
writeFile(filepath: string, data: any, encoding?: string)
import { writeFile } from '@js-sh/js-sh'
writeFile('foo.txt', '["Test"]', 'utf-8')