Comparing version 0.0.8 to 1.0.0
@@ -12,4 +12,8 @@ 'use strict' | ||
var _find = require('../utilities/find') | ||
var _isEmpty = _interopRequireDefault(require('is-empty')) | ||
var _SelectInput = _interopRequireDefault(require('./SelectInput')) | ||
var _shelljs = _interopRequireDefault(require('shelljs')) | ||
function _interopRequireDefault(obj) { | ||
@@ -44,2 +48,57 @@ return obj && obj.__esModule ? obj : { default: obj } | ||
function _objectSpread(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {} | ||
var ownKeys = Object.keys(source) | ||
if (typeof Object.getOwnPropertySymbols === 'function') { | ||
ownKeys = ownKeys.concat( | ||
Object.getOwnPropertySymbols(source).filter(function(sym) { | ||
return Object.getOwnPropertyDescriptor(source, sym).enumerable | ||
}) | ||
) | ||
} | ||
ownKeys.forEach(function(key) { | ||
_defineProperty(target, key, source[key]) | ||
}) | ||
} | ||
return target | ||
} | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}) | ||
} else { | ||
obj[key] = value | ||
} | ||
return obj | ||
} | ||
const generateScriptItems = scripts => { | ||
const scriptPairs = Object.entries(scripts) | ||
const sortedByNameLength = scriptPairs.sort((a, b) => { | ||
return a[0].length < b[0].length | ||
}) | ||
const totalNameLength = sortedByNameLength[0][0].length + 5 | ||
const items = scriptPairs.reduce((final, [name, script]) => { | ||
const item = { | ||
name: | ||
name + | ||
Array(totalNameLength - name.length) | ||
.fill(' ') | ||
.join(''), | ||
script | ||
} | ||
final.push(item) | ||
return final | ||
}, []) | ||
return items.sort((a, b) => { | ||
return a.name[0] > b.name[0] | ||
}) | ||
} | ||
class App extends _ink.default.Component { | ||
@@ -51,8 +110,2 @@ constructor(...args) { | ||
(_temp = super(...args)), | ||
Object.defineProperty(this, 'json', { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: '' | ||
}), | ||
Object.defineProperty(this, 'state', { | ||
@@ -62,30 +115,14 @@ configurable: true, | ||
writable: true, | ||
value: { | ||
gotJSON: false | ||
} | ||
value: {} | ||
}), | ||
Object.defineProperty(this, 'getJSON', { | ||
Object.defineProperty(this, 'onSelect', { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: async () => { | ||
const { packageJsonPath, propertyPath } = this.context.appVars | ||
const json = await (0, _find.find)(packageJsonPath, propertyPath) | ||
this.setJSON(json === 'null' ? '{}' : json) | ||
value: item => { | ||
_shelljs.default.exec(item.script) | ||
_shelljs.default.exit() | ||
} | ||
}), | ||
Object.defineProperty(this, 'setJSON', { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: json => { | ||
this.json = json | ||
this.setState( | ||
state => ({ | ||
gotJSON: true | ||
}), | ||
() => setTimeout(() => process.exit(0), 250) | ||
) | ||
} | ||
}), | ||
_temp | ||
@@ -96,3 +133,8 @@ ) | ||
componentDidMount() { | ||
this.getJSON() | ||
const { packageJsonPath } = this.context.appVars | ||
const pkg = require(packageJsonPath) | ||
this.scripts = generateScriptItems(pkg.scripts) | ||
this.setState(_objectSpread({}, pkg)) | ||
} | ||
@@ -104,6 +146,6 @@ | ||
null, | ||
!state.gotJSON | ||
(0, _isEmpty.default)(state) | ||
? [ | ||
(0, _ink.h)(_inkSpaces.BlankLines, { | ||
count: 2, | ||
count: 1, | ||
key: '0' | ||
@@ -116,33 +158,40 @@ }), | ||
(0, _ink.h)( | ||
_ink.Text, | ||
_ink.Color, | ||
{ | ||
key: '2' | ||
}, | ||
'Getting the JSON.' | ||
'Loading scripts.' | ||
) | ||
] | ||
: state.gotJSON | ||
: !(0, _isEmpty.default)(state) | ||
? [ | ||
(0, _ink.h)(_inkSpaces.BlankLines, { | ||
count: 2, | ||
count: 1, | ||
key: '0' | ||
}), | ||
(0, _ink.h)( | ||
_ink.Text, | ||
_ink.Color, | ||
{ | ||
key: '1' | ||
}, | ||
'abt: ', | ||
this.pathText | ||
'[ abt \u2206 choose a script ]' | ||
), | ||
(0, _ink.h)(_inkSpaces.BlankLines, { | ||
count: 2, | ||
count: 1, | ||
key: '2' | ||
}), | ||
(0, _ink.h)(_inkSpaces.BlankLines, { | ||
count: 1, | ||
key: '3' | ||
}), | ||
(0, _ink.h)( | ||
'div', | ||
{ | ||
key: '3' | ||
key: '4' | ||
}, | ||
(0, _ink.h)(_ink.Text, null, this.json) | ||
(0, _ink.h)(_SelectInput.default, { | ||
items: this.scripts, | ||
onSelect: this.onSelect, | ||
itemComponent: Item | ||
}) | ||
) | ||
@@ -153,9 +202,19 @@ ] | ||
} | ||
get pathText() { | ||
const { appVars } = this.context | ||
return `["${appVars.packageJsonPath}"].${appVars.propertyPath}` | ||
} | ||
} | ||
exports.App = App | ||
const Item = props => { | ||
return (0, _ink.h)( | ||
'span', | ||
null, | ||
(0, _ink.h)( | ||
_ink.Color, | ||
{ | ||
green: true | ||
}, | ||
props.name | ||
), | ||
(0, _ink.h)(_ink.Color, null, props.script) | ||
) | ||
} |
@@ -17,7 +17,3 @@ 'use strict' | ||
const readJsonFile = filePath => { | ||
var _fs$readFileSync | ||
return ( | ||
(_fs$readFileSync = _fs.default.readFileSync(filePath, 'utf8')), JSON.parse(_fs$readFileSync) | ||
) | ||
return require(filePath) // return fs.readFileSync(filePath, 'utf8') |> JSON.parse | ||
} | ||
@@ -24,0 +20,0 @@ |
{ | ||
"name": "abt", | ||
"version": "0.0.8", | ||
"version": "1.0.0", | ||
"description": "A CLI tool to get easy info from your package.json.", | ||
@@ -57,9 +57,12 @@ "main": "./code/index.js", | ||
"dependencies": { | ||
"ink": "^0.4.1", | ||
"ink": "^0.5.0", | ||
"ink-select-input": "^1.1.0", | ||
"ink-spaces": "^0.0.1", | ||
"ink-spinner": "^1.0.0", | ||
"ink-spinner": "^2.0.0", | ||
"is-empty": "^1.2.0", | ||
"prettyjson": "^1.2.1", | ||
"regenerator-runtime": "^0.11.1", | ||
"yargs": "^11.0.0" | ||
"regenerator-runtime": "^0.12.0", | ||
"shelljs": "^0.8.2", | ||
"yargs": "^12.0.0" | ||
} | ||
} |
# abt | ||
> A CLI tool to get easy info from your `package.json`. | ||
> A tool that makes it simple as fuck to find and execute npm scripts. | ||
``` | ||
```sh | ||
npm i -g abt | ||
@@ -11,46 +11,12 @@ ``` | ||
abt takes only one argument, being the `.dotNoted` reference to the part of your `package.json` that you wish to fetch. When called with no arguments at all, abt will present you with your `.scripts` by default. When called with multiple arguments, abt will only use the first. abt also provides shortcuts. (See below.) | ||
### Examples | ||
Given the command `abt` or `abt .scripts`, abt will give you your `package.json`'s `scripts` value: | ||
```json | ||
["<path/to/projectRoot>/package.json"].scripts == { | ||
"start": "node bin", | ||
"test": "jest" | ||
} | ||
```sh | ||
abt | ||
``` | ||
Given the command `abt .dependencies`, abt will give you the `dependencies` value found in your `package.json`: | ||
abt will show you a list of your scripts and allow you to run them. That is all there is to it. | ||
```json | ||
["<path/to/projectRoot>/package.json"].dependencies == { | ||
"ink": "^0.4.1", | ||
"ink-spaces": "^0.0.1", | ||
"ink-spinner": "^1.0.0", | ||
"node-jq": "^1.2.0", | ||
"yargs": "^11.0.0" | ||
} | ||
``` | ||
![example](example.png) | ||
Given the command `abt .version`, abt will give you the `version` value found in your `package.json`: | ||
### Notes | ||
```json | ||
["<path/to/projectRoot>/package.json"].version == "0.0.2" | ||
``` | ||
## Shortcuts | ||
| arg | same as | | ||
| ----- | ------------------- | | ||
| `.DD` | '.devDependencies' | | ||
| `.PD` | '.peerDependencies' | | ||
| `.D` | '.dependencies' | | ||
| `.V` | '.version' | | ||
_Example: `abt .DD` -> `abt .devDependencies`_ | ||
## Notes | ||
_abt is not guaranteed to work on Node < 8.1_ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
46212
10
493
1
9
22
4
+ Addedink-select-input@^1.1.0
+ Addedis-empty@^1.2.0
+ Addedshelljs@^0.8.2
+ Addedarr-rotate@1.0.0(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedcamelcase@5.3.1(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedfigures@2.0.0(transitive)
+ Addedfind-up@3.0.0(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedink@0.5.1(transitive)
+ Addedink-select-input@1.1.0(transitive)
+ Addedink-spinner@2.0.0(transitive)
+ Addedinterpret@1.4.0(transitive)
+ Addedis-core-module@2.16.0(transitive)
+ Addedis-empty@1.2.0(transitive)
+ Addedlocate-path@3.0.0(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedp-limit@2.3.0(transitive)
+ Addedp-locate@3.0.0(transitive)
+ Addedp-try@2.2.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedpath-parse@1.0.7(transitive)
+ Addedrechoir@0.6.2(transitive)
+ Addedregenerator-runtime@0.12.1(transitive)
+ Addedresolve@1.22.9(transitive)
+ Addedshelljs@0.8.5(transitive)
+ Addedsupports-preserve-symlinks-flag@1.0.0(transitive)
+ Addedy18n@4.0.3(transitive)
+ Addedyargs@12.0.5(transitive)
+ Addedyargs-parser@11.1.1(transitive)
- Removedcamelcase@4.1.0(transitive)
- Removedfind-up@2.1.0(transitive)
- Removedink@0.4.1(transitive)
- Removedink-spinner@1.0.0(transitive)
- Removedlocate-path@2.0.0(transitive)
- Removedp-limit@1.3.0(transitive)
- Removedp-locate@2.0.0(transitive)
- Removedp-try@1.0.0(transitive)
- Removedregenerator-runtime@0.11.1(transitive)
- Removedy18n@3.2.2(transitive)
- Removedyargs@11.1.1(transitive)
- Removedyargs-parser@9.0.2(transitive)
Updatedink@^0.5.0
Updatedink-spinner@^2.0.0
Updatedregenerator-runtime@^0.12.0
Updatedyargs@^12.0.0