1.3.4 • Published 1 year ago

ncx-js v1.3.4

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

NPM Version NPM License

Effortless complex scripts with unlimited power. Ncx is a JavaScript library for writing complex scripts without complexity that can be used with Node.js

Welcome

Go to Github

Example

Here is a simple example of Ncx use

import { x } from 'ncx-js'

const myScripts = ['echo Hello World!', 'node scripts/hello.js', 'pnpm install', 'tsc']

await x(...myScripts)

API

ncx.x

The commands to be executed are determined by this function. It returns a object with stdout, stderr and error.

import { x } from 'ncx-js'

const data = await x('echo ncx is awesome!')

if (data.error) {
  throw new Error(data.error)
}

ncx.consoleX

The commands to be executed are determined by this function. It returns a object with stdout, stderr and error and prints the output to the console.

import { cx } from 'ncx-js'

const data = await cx('echo ncx is awesome!')

if (data.error) {
  throw new Error(data.error)
}

ncx.beforeAll

The argument function called before all the scripts and commands.

import { x, beforeAll } from 'ncx-js'

beforeAll(() => console.log('Running tests...'))
await x('node scripts/test.js')

ncx.before

The argument function called before scripts and commands.

import { x, before } from 'ncx-js'

before(() => console.log('Running command'))
await x('echo The commmand runned successfully')

ncx.use

The argument function called when scripts and commands executed

import { x, use } from 'ncx-js'

use((out) => {
  if (out.toLowerCase() === 'the command runned successfully') {
    console.log('All done with no errors')
  }

  // Return function handles the error
  // stderr is optional
  return (err, stderr) {
    console.log('All done with error: ' + err)
  }
})
await x('echo The commmand runned successfully')

ncx.after

The argument function called after scripts and commands executed

import { x, after } from 'ncx-js'

after(() => console.log('Runned command'))
await x('echo The commmand runned successfully')

ncx.afterAll

The argument function called after all scripts and commands.

import { x, afterAll } from 'ncx-js'

afterAll(() => console.log('All commands runned'))
await x('echo The commmand runned successfully')

How Ncx Works

Ncx uses globalThis for communication with other functions.

import fs from 'fs'
import path from 'path'
import { x, use, beforeAll } from 'ncx-js'

console.clear()
beforeAll(() => console.log('Running tests...'))

const files = fs.readdirSync(path.join(process.cwd(), 'tests'))

files.forEach(async (file) => {
  await x(`node ./tests/${file}`)
})

For example if we set beforeAll to a function the Ncx changes the globalThis.__ncx_before_all to argument function. With that x function can be use this.

License

MIT

1.3.4

1 year ago

1.3.3

1 year ago

1.3.2

1 year ago

1.2.2

2 years ago

1.2.1

2 years ago

1.1.1

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago