Set up oclif

Summary:
Provides some really nice helpers and generators for
multi command CLIs, including test helpers and all
sorts of output niceties. This should make it quite
easy for us to add additional sub-commands for
bundling, publishing and keeping docs for all of it.

Heroku maintains this and provides some excellent
docs, too: https://oclif.io/

My only complaint is that it's class-based but that's
effectively only the way to declare new commands and
enforces a set of required/static properties on it.

Reviewed By: nikoant

Differential Revision: D19970293

fbshipit-source-id: 4228e502198c6fd376854a90ed2f01da29e96bc2
This commit is contained in:
Pascal Hartig
2020-02-24 14:02:31 -08:00
committed by Facebook Github Bot
parent 33bbeadfe9
commit a1260a9789
9 changed files with 1130 additions and 657 deletions

View File

@@ -23,6 +23,7 @@ const prettierConfig = {
module.exports = {
parser: 'babel-eslint',
root: true,
extends: 'fbjs',
plugins: [...fbjs.plugins, 'header', 'prettier', '@typescript-eslint'],
rules: {

1
pkg/.eslintignore Normal file
View File

@@ -0,0 +1 @@
/lib

View File

@@ -3,6 +3,68 @@
`flipper-pkg` is a **work-in-progress** tool for bundling and publishing
Flipper plugins.
<!-- toc -->
* [Usage](#usage)
* [Commands](#commands)
<!-- tocstop -->
# Usage
<!-- usage -->
```sh-session
$ npm install -g mycli
$ mycli COMMAND
running command...
$ mycli (-v|--version|version)
mycli/0.0.0 darwin-x64 node-v12.14.0
$ mycli --help [COMMAND]
USAGE
$ mycli COMMAND
...
```
<!-- usagestop -->
# Commands
<!-- commands -->
* [`mycli hello [FILE]`](#mycli-hello-file)
* [`mycli help [COMMAND]`](#mycli-help-command)
## `mycli hello [FILE]`
describe the command here
```
USAGE
$ mycli hello [FILE]
OPTIONS
-f, --force
-h, --help show CLI help
-n, --name=name name to print
EXAMPLE
$ mycli hello
hello world from ./src/hello.ts!
```
_See code: [src/commands/hello.ts](https://github.com/passy/mycli/blob/v0.0.0/src/commands/hello.ts)_
## `mycli help [COMMAND]`
display help for mycli
```
USAGE
$ mycli help [COMMAND]
ARGUMENTS
COMMAND command to show help for
OPTIONS
--all see all commands in CLI
```
_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v2.2.3/src/commands/help.ts)_
<!-- commandsstop -->
## License
[MIT](LICENSE)

10
pkg/src/cli.ts → pkg/bin/run Normal file → Executable file
View File

@@ -1,3 +1,5 @@
#!/usr/bin/env node
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
@@ -7,8 +9,6 @@
* @format
*/
import {PKG} from '.';
(async () => {
console.log(`Hello, ${PKG}.`);
})();
require('@oclif/command').run()
.then(require('@oclif/command/flush'))
.catch(require('@oclif/errors/handle'))

8
pkg/bin/run.cmd Normal file
View File

@@ -0,0 +1,8 @@
@REM Copyright (c) Facebook, Inc. and its affiliates.
@REM
@REM This source code is licensed under the MIT license found in the
@REM LICENSE file in the root directory of this source tree.
@echo off
node "%~dp0run" %*

View File

@@ -2,43 +2,64 @@
"name": "flipper-pkg",
"version": "0.0.0",
"description": "Utility for building and publishing Flipper plugins",
"repository": "facebook/flipper",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"license": "MIT",
"bin": {
"flipper-pkg": "./bin/run"
},
"bugs": "https://github.com/facebook/flipper/issues",
"dependencies": {
"@oclif/command": "^1",
"@oclif/config": "^1",
"@oclif/plugin-help": "^2",
"@types/node": "^10",
"listr": "^0.14.3",
"tslib": "^1"
},
"devDependencies": {
"@oclif/dev-cli": "^1",
"@types/jest": "^24.0.21",
"@typescript-eslint/eslint-plugin": "^2.8.0",
"eslint": "^6.6.0",
"eslint-plugin-babel": "^5.3.0",
"eslint-plugin-flowtype": "^4.5.2",
"eslint-plugin-header": "^3.0.0",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-prettier": "^3.1.1",
"eslint-plugin-react": "^7.16.0",
"@types/listr": "^0.14.2",
"globby": "^10",
"jest": "^24.9.0",
"prettier": "^1.19.1",
"ts-jest": "^24.1.0",
"ts-node": "^8",
"tslint-config-prettier": "^1.18.0",
"typescript": "^3.7.2"
},
"scripts": {
"build": "tsc",
"postpack": "rm -f oclif.manifest.json",
"prepack": "rm -rf lib && tsc -b && oclif-dev manifest && oclif-dev readme",
"prepare": "yarn run build",
"prepublishOnly": "yarn test && yarn run lint",
"preversion": "yarn run lint",
"test": "jest --config jestconfig.json",
"lint": "eslint -c ../../sonar/.eslintrc.js src/**/* --ext .js,.ts && tsc --noemit",
"fix": "eslint -c ../../sonar/.eslintrc.js src/**/* --fix --ext .js,.ts",
"run": "yarn run build && node lib/cli.js"
"run": "bin/run",
"version": "oclif-dev readme && git add README.md"
},
"engines": {
"node": ">=8.0.0"
},
"files": [
"/bin",
"/npm-shrinkwrap.json",
"/oclif.manifest.json",
"lib/**/*"
],
"homepage": "https://github.com/facebook/flipper",
"keywords": [
"Flipper"
],
"author": "Facebook, Inc",
"dependencies": {
"@types/node": "^12.12.12"
"oclif": {
"commands": "./lib/commands",
"bin": "flipper-pkg",
"plugins": [
"@oclif/plugin-help"
]
}
}

40
pkg/src/commands/hello.ts Normal file
View File

@@ -0,0 +1,40 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
import {Command, flags} from '@oclif/command';
export default class Hello extends Command {
static description = 'describe the command here';
static examples = [
`$ flipper-pkg hello
hello world from ./src/hello.ts!
`,
];
static flags = {
help: flags.help({char: 'h'}),
// flag with a value (-n, --name=VALUE)
name: flags.string({char: 'n', description: 'name to print'}),
// flag with no value (-f, --force)
force: flags.boolean({char: 'f'}),
};
static args = [{name: 'file'}];
async run() {
const {args, flags} = this.parse(Hello);
const name = flags.name || 'world';
this.log(`hello ${name} from ./src/commands/hello.ts`);
if (args.file && flags.force) {
this.log(`you input --force and --file: ${args.file}`);
}
}
}

View File

@@ -1,12 +1,14 @@
{
"compilerOptions": {
"lib": ["es7", "dom", "es2017"],
"target": "es5",
"target": "es2017",
"module": "commonjs",
"declaration": true,
"outDir": "./lib",
"strict": true
"outDir": "lib",
"rootDir": "src",
"strict": true,
"importHelpers": true
},
"include": ["src"],
"exclude": ["node_modules", "**/__tests__/*"]
"include": [
"src/**/*"
]
}

File diff suppressed because it is too large Load Diff