Skip to content

Commit

Permalink
move to cjs module export
Browse files Browse the repository at this point in the history
  • Loading branch information
arshaw committed Sep 22, 2021
1 parent c2a4283 commit 0655b3e
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 19 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ live(command [, options] [, callback]) => statusCode
Synchronous usage:

```js
const { live } = require('shelljs-live')
const live = require('shelljs-live')

const statusCode = live(['ps', '-ax']) // live('ps -ax') works too. not recommended
if (statusCode === 0) {
Expand All @@ -45,7 +45,7 @@ if (statusCode === 0) {
Asynchronous usage:

```js
const { live } = require('shelljs-live')
const live = require('shelljs-live')

live(['ps', '-ax'], (statusCode) => {
if (statusCode === 0) {
Expand All @@ -71,7 +71,7 @@ live(command [, options]) => promise
Usage:

```js
const { live } = require('shelljs-live/promise')
const live = require('shelljs-live/promise')

live(['ps', '-ax']).then(() => {
console.log('Success')
Expand All @@ -83,7 +83,7 @@ live(['ps', '-ax']).then(() => {
Or if you want to use `await` and don't care about handling errors:

```js
const { live } = require('shelljs-live/promise')
const live = require('shelljs-live/promise')

await live(['ps', '-ax'])
console.log('Success')
Expand Down
17 changes: 8 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import { SpawnOptions } from 'child_process'
import * as spawn from 'cross-spawn'
import spawn from 'cross-spawn'
import { config } from 'shelljs'
import { parseCommand, buildErrorMessage } from './utils'
import { Options, Callback, parseCommand, buildErrorMessage } from './utils'

export type Options = SpawnOptions & { async?: boolean, fatal?: boolean, silent?: boolean }
export type Callback = (status: number | null) => void

export function live(command: string | string[], options?: Options): number | null
export function live(command: string | string[], callback: Callback): number | null
export function live(
function live(command: string | string[], options?: Options): number | null
function live(command: string | string[], callback: Callback): number | null
function live(
command: string | string[],
options: Options | undefined,
callback: Callback,
): number | null
export function live(
function live(
command: string | string[],
optionsOrCallback?: Options | Callback,
callback?: Callback,
Expand Down Expand Up @@ -62,3 +59,5 @@ export function live(
return status
}
}

export = live
8 changes: 4 additions & 4 deletions src/promise.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { live as origLive, Options } from './'
import { parseCommand, buildErrorMessage } from './utils'
import origLive from './'
import { Options, parseCommand, buildErrorMessage } from './utils'

export function live(command: string | string[], options?: Options): Promise<void> {
function live(command: string | string[], options?: Options): Promise<void> {
return new Promise((resolve, reject) => {
origLive(command, options, (status) => {
if (status === 0) {
Expand All @@ -14,4 +14,4 @@ export function live(command: string | string[], options?: Options): Promise<voi
})
}

export { Options } from './'
export = live
4 changes: 4 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import { SpawnOptions } from 'child_process'

export type Options = SpawnOptions & { async?: boolean, fatal?: boolean, silent?: boolean }
export type Callback = (status: number | null) => void

export function parseCommand(command: string | string[]): [string, string[], boolean] {
return Array.isArray(command)
Expand Down
4 changes: 2 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const yargs = require('yargs/yargs')
const { hideBin } = require('yargs/helpers')
const shell = require('shelljs')
const { live } = require('./dist/index')
const { live: promiseLive } = require('./dist/promise')
const live = require('./dist/index')
const promiseLive = require('./dist/promise')

const argv = yargs(hideBin(process.argv)).argv
shell.config.silent = Boolean(argv.silent)
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"target": "ES2019",
"module": "CommonJS",
"moduleResolution": "Node",
"esModuleInterop": true,
"declaration": true,
"rootDir": "src",
"outDir": "dist"
Expand Down

0 comments on commit 0655b3e

Please sign in to comment.