Skip to content

Commit

Permalink
Refactor to TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
rwu823 committed Sep 21, 2018
1 parent 2486b9f commit 1fa97f4
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 114 deletions.
3 changes: 0 additions & 3 deletions .eslintrc

This file was deleted.

3 changes: 0 additions & 3 deletions .prettierrc.js

This file was deleted.

17 changes: 0 additions & 17 deletions .travis.yml

This file was deleted.

7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ git commit -m '${version}'
`
```

## Silent
If you don't like to see the command output or something security issue.

```js
import { shSilent } from 'sh-exec'
```

## Promise Based

```js
Expand Down
9 changes: 1 addition & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,7 @@
"scripts"
],
"devDependencies": {
"@rwu823/base": "https://github.com/rwu823/base",
"@rwu823/eslint-config-base": "https://github.com/rwu823/base#eslint-config-base",
"@types/jest": "^22.0.0",
"eslint": "^4.14.0",
"husky": "^0.14.3",
"jest": "^22.0.4",
"lint-staged": "^6.0.0",
"prettier": "^1.9.2"
"@rwu823/ts-base": "github:rwu823/ts-base"
},
"scripts": {
"precommit": "lint-staged",
Expand Down
49 changes: 0 additions & 49 deletions scripts/deploy.js

This file was deleted.

20 changes: 0 additions & 20 deletions src/index.js

This file was deleted.

9 changes: 9 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import shExec from "./libs/sh";

const sh = shExec()
const shSilent = shExec({ silent: true })

export default sh
exports = sh

export { shSilent }
30 changes: 30 additions & 0 deletions src/libs/sh.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { exec } from 'child_process'
import tStrings from '../utils/tStrings'

type SHExec = {
(
options?: Partial<{
silent: boolean,
}>,
): (tString: TemplateStringsArray, ...args: any[]) => Promise<string>,
}

const shExec: SHExec = (opts = {}) => (tString, ...args) =>
new Promise((resolve, reject) => {
const cmds = tStrings(tString, ...args)
const child = exec(cmds, (err, stdout, stderr) => {
if (err) {
reject(err)
}
const output = stderr || stdout

resolve(output)
})

if (!opts.silent) {
child.stdout.on('data', console.log)
child.stderr.on('data', console.log)
}
})

export default shExec
13 changes: 0 additions & 13 deletions src/tStrings.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const tStrings = require('../tStrings')
import tStrings from '../tStrings'

describe('tStrings Spec', () => {
it('tStrings to long text', () => {
Expand Down
11 changes: 11 additions & 0 deletions src/utils/tStrings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
type TString = {
(tString: TemplateStringsArray, ...vars: any[]): string
}

const tStrings: TString = (tStrings, ...vars) =>
tStrings.reduce(
(s, v, i) => s + v + (vars[i] !== undefined ? vars[i] : ''),
'',
);

export default tStrings;

0 comments on commit 1fa97f4

Please sign in to comment.