"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:
Anton Nikolaev
2020-04-27 17:31:39 -07:00
committed by Facebook GitHub Bot
parent 01f8d80402
commit 21c574ac80
24 changed files with 1062 additions and 84 deletions

View File

@@ -41,7 +41,7 @@ test('getPluginDetailsV1', async () => {
test('getPluginDetailsV2', async () => {
const pluginV2 = {
specVersion: 2,
$schema: 'https://fbflipper.com/schemas/plugin-package/v2.json',
name: 'flipper-plugin-test',
title: 'Test',
version: '3.0.1',
@@ -72,7 +72,7 @@ test('getPluginDetailsV2', async () => {
test('id used as title if the latter omited', async () => {
const pluginV2 = {
specVersion: 2,
$schema: 'https://fbflipper.com/schemas/plugin-package/v2.json',
name: 'flipper-plugin-test',
id: 'test',
version: '3.0.1',
@@ -103,7 +103,7 @@ test('id used as title if the latter omited', async () => {
test('name without "flipper-plugin-" prefix is used as title if the latter omited', async () => {
const pluginV2 = {
specVersion: 2,
$schema: 'https://fbflipper.com/schemas/plugin-package/v2.json',
name: 'flipper-plugin-test',
version: '3.0.1',
main: 'dist/bundle.js',

View File

@@ -17,9 +17,12 @@ export default async function (
): Promise<PluginDetails> {
packageJson =
packageJson || (await fs.readJson(path.join(pluginDir, 'package.json')));
const specVersion = !packageJson.specVersion
? 1
: (packageJson.specVersion as number);
const specVersion =
packageJson.$schema &&
packageJson.$schema ===
'https://fbflipper.com/schemas/plugin-package/v2.json'
? 2
: 1;
switch (specVersion) {
case 1:
return await getPluginDetailsV1(pluginDir, packageJson);