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:
committed by
Facebook Github Bot
parent
33bbeadfe9
commit
a1260a9789
@@ -23,6 +23,7 @@ const prettierConfig = {
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
parser: 'babel-eslint',
|
parser: 'babel-eslint',
|
||||||
|
root: true,
|
||||||
extends: 'fbjs',
|
extends: 'fbjs',
|
||||||
plugins: [...fbjs.plugins, 'header', 'prettier', '@typescript-eslint'],
|
plugins: [...fbjs.plugins, 'header', 'prettier', '@typescript-eslint'],
|
||||||
rules: {
|
rules: {
|
||||||
|
|||||||
1
pkg/.eslintignore
Normal file
1
pkg/.eslintignore
Normal file
@@ -0,0 +1 @@
|
|||||||
|
/lib
|
||||||
@@ -3,6 +3,68 @@
|
|||||||
`flipper-pkg` is a **work-in-progress** tool for bundling and publishing
|
`flipper-pkg` is a **work-in-progress** tool for bundling and publishing
|
||||||
Flipper plugins.
|
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
|
## License
|
||||||
|
|
||||||
[MIT](LICENSE)
|
[MIT](LICENSE)
|
||||||
10
pkg/src/cli.ts → pkg/bin/run
Normal file → Executable file
10
pkg/src/cli.ts → pkg/bin/run
Normal file → Executable file
@@ -1,3 +1,5 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
@@ -7,8 +9,6 @@
|
|||||||
* @format
|
* @format
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {PKG} from '.';
|
require('@oclif/command').run()
|
||||||
|
.then(require('@oclif/command/flush'))
|
||||||
(async () => {
|
.catch(require('@oclif/errors/handle'))
|
||||||
console.log(`Hello, ${PKG}.`);
|
|
||||||
})();
|
|
||||||
8
pkg/bin/run.cmd
Normal file
8
pkg/bin/run.cmd
Normal 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" %*
|
||||||
@@ -2,43 +2,64 @@
|
|||||||
"name": "flipper-pkg",
|
"name": "flipper-pkg",
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"description": "Utility for building and publishing Flipper plugins",
|
"description": "Utility for building and publishing Flipper plugins",
|
||||||
|
"repository": "facebook/flipper",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"types": "lib/index.d.ts",
|
"types": "lib/index.d.ts",
|
||||||
"license": "MIT",
|
"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": {
|
"devDependencies": {
|
||||||
|
"@oclif/dev-cli": "^1",
|
||||||
"@types/jest": "^24.0.21",
|
"@types/jest": "^24.0.21",
|
||||||
"@typescript-eslint/eslint-plugin": "^2.8.0",
|
"@types/listr": "^0.14.2",
|
||||||
"eslint": "^6.6.0",
|
"globby": "^10",
|
||||||
"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",
|
|
||||||
"jest": "^24.9.0",
|
"jest": "^24.9.0",
|
||||||
"prettier": "^1.19.1",
|
"prettier": "^1.19.1",
|
||||||
"ts-jest": "^24.1.0",
|
"ts-jest": "^24.1.0",
|
||||||
|
"ts-node": "^8",
|
||||||
"tslint-config-prettier": "^1.18.0",
|
"tslint-config-prettier": "^1.18.0",
|
||||||
"typescript": "^3.7.2"
|
"typescript": "^3.7.2"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
|
"postpack": "rm -f oclif.manifest.json",
|
||||||
|
"prepack": "rm -rf lib && tsc -b && oclif-dev manifest && oclif-dev readme",
|
||||||
"prepare": "yarn run build",
|
"prepare": "yarn run build",
|
||||||
"prepublishOnly": "yarn test && yarn run lint",
|
"prepublishOnly": "yarn test && yarn run lint",
|
||||||
"preversion": "yarn run lint",
|
"preversion": "yarn run lint",
|
||||||
"test": "jest --config jestconfig.json",
|
"test": "jest --config jestconfig.json",
|
||||||
"lint": "eslint -c ../../sonar/.eslintrc.js src/**/* --ext .js,.ts && tsc --noemit",
|
"run": "bin/run",
|
||||||
"fix": "eslint -c ../../sonar/.eslintrc.js src/**/* --fix --ext .js,.ts",
|
"version": "oclif-dev readme && git add README.md"
|
||||||
"run": "yarn run build && node lib/cli.js"
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8.0.0"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
|
"/bin",
|
||||||
|
"/npm-shrinkwrap.json",
|
||||||
|
"/oclif.manifest.json",
|
||||||
"lib/**/*"
|
"lib/**/*"
|
||||||
],
|
],
|
||||||
|
"homepage": "https://github.com/facebook/flipper",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"Flipper"
|
"Flipper"
|
||||||
],
|
],
|
||||||
"author": "Facebook, Inc",
|
"author": "Facebook, Inc",
|
||||||
"dependencies": {
|
"oclif": {
|
||||||
"@types/node": "^12.12.12"
|
"commands": "./lib/commands",
|
||||||
|
"bin": "flipper-pkg",
|
||||||
|
"plugins": [
|
||||||
|
"@oclif/plugin-help"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
40
pkg/src/commands/hello.ts
Normal file
40
pkg/src/commands/hello.ts
Normal 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}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,12 +1,14 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"lib": ["es7", "dom", "es2017"],
|
"target": "es2017",
|
||||||
"target": "es5",
|
|
||||||
"module": "commonjs",
|
"module": "commonjs",
|
||||||
"declaration": true,
|
"declaration": true,
|
||||||
"outDir": "./lib",
|
"outDir": "lib",
|
||||||
"strict": true
|
"rootDir": "src",
|
||||||
|
"strict": true,
|
||||||
|
"importHelpers": true
|
||||||
},
|
},
|
||||||
"include": ["src"],
|
"include": [
|
||||||
"exclude": ["node_modules", "**/__tests__/*"]
|
"src/**/*"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
1602
pkg/yarn.lock
1602
pkg/yarn.lock
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user