"lint" command for flipper-pkg tool
Summary: Implemented json schema for flipper plugin package.json and used it for validation in "flipper-pkg lint" command. Nice thing about json schema is that it not only allows to validate json, but also can be referenced using "$schema" property in json so IDEs like VSCode can find it and use for code completion, validation and to show properties documentation. I'm going to deploy the schema as a part of documentation website so it can be referenced as https://fbflipper.com/schemas/plugin-package/v2.json. Also the "$schema" field can be used instead of "specVersion" to determine the specification according to which the plugin is defined. E.g., if specification version 3 would be created, it will be described in schema https://fbflipper.com/schemas/plugin-package/v3.json, etc. Reviewed By: passy Differential Revision: D21228294 fbshipit-source-id: f21351e584ef936a7d6b314436448489691f83a6
This commit is contained in:
committed by
Facebook GitHub Bot
parent
01f8d80402
commit
21c574ac80
@@ -16,7 +16,7 @@ import {runBuild, getPluginDetails} from 'flipper-pkg-lib';
|
||||
export default class Bundle extends Command {
|
||||
public static description = 'transpiles and bundles plugin';
|
||||
|
||||
public static examples = [`$ flipper-pkg bundle optional/path/to/directory`];
|
||||
public static examples = [`$ flipper-pkg bundle path/to/plugin`];
|
||||
|
||||
public static args: args.IArg[] = [
|
||||
{
|
||||
|
||||
48
desktop/pkg/src/commands/lint.ts
Normal file
48
desktop/pkg/src/commands/lint.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* 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} from '@oclif/command';
|
||||
import {args} from '@oclif/parser';
|
||||
import path from 'path';
|
||||
import runLint from '../utils/runLint';
|
||||
|
||||
export default class Lint extends Command {
|
||||
public static description = 'validates a plugin package directory';
|
||||
|
||||
public static examples = [`$ flipper-pkg lint path/to/plugin`];
|
||||
|
||||
public static args: args.IArg[] = [
|
||||
{
|
||||
name: 'directory',
|
||||
required: false,
|
||||
default: '.',
|
||||
description:
|
||||
'Path to plugin package directory for linting. Defaults to the current working directory.',
|
||||
},
|
||||
];
|
||||
|
||||
public async run() {
|
||||
const {args} = this.parse(Lint);
|
||||
const inputDirectory: string = path.resolve(process.cwd(), args.directory);
|
||||
try {
|
||||
console.log(`⚙️ Validating ${inputDirectory}`);
|
||||
const errors = await runLint(inputDirectory);
|
||||
if (errors) {
|
||||
this.error(
|
||||
`Plugin package definition is invalid. See https://fbflipper.com/docs/extending/js-setup.html#plugin-definition for details.\n${errors.join(
|
||||
'\n',
|
||||
)}`,
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
this.error(error);
|
||||
}
|
||||
console.log('✅ Plugin package definition is valid');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user