Skip to content

Commit

Permalink
feat(models): validate plugin icons using portal-client package
Browse files Browse the repository at this point in the history
  • Loading branch information
matejchalk committed Oct 2, 2023
1 parent dd0a180 commit f52cc75
Show file tree
Hide file tree
Showing 17 changed files with 95 additions and 22 deletions.
10 changes: 7 additions & 3 deletions esbuild.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ esbuild.build({
build.onEnd(result => {
if (result.errors.length > 0) return;

execSync(
`tsc --emitDeclarationOnly --project packages/${project}/tsconfig.lib.json --outDir dist`,
);
try {
execSync(
`tsc --emitDeclarationOnly --project packages/${project}/tsconfig.lib.json --outDir dist`,
);
} catch (err) {
console.error(err);
}
});
},
},
Expand Down
67 changes: 62 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"node": ">=18.16"
},
"dependencies": {
"@code-pushup/portal-client": "^0.1.2",
"bundle-require": "^4.0.1",
"chalk": "^5.3.0",
"cliui": "^8.0.1",
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/lib/cli.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { CollectOptions } from '@quality-metrics/utils';
import { join } from 'path';
import { describe, expect, it } from 'vitest';
import { yargsCli } from './cli';
import { middlewares } from './middlewares';
import { options as defaultOptions } from './options';
import { CollectOptions } from '@quality-metrics/core';
import { getDirname } from './implementation/helper.mock';
import { middlewares } from './middlewares';
import { GlobalOptions } from './model';
import { options as defaultOptions } from './options';

const __dirname = getDirname(import.meta.url);
const withDirName = (path: string) => join(__dirname, path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = {
},
slug: 'execute-plugin',
title: 'execute plugin',
icon: 'javascript',
},
],
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
persist: { outputPath: 'cjs-out.json' },
persist: { outputPath: 'tmp/cjs-out.json' },
plugins: [],
categories: [],
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default {
persist: { outputPath: 'mjs-out.json' },
persist: { outputPath: 'tmp/mjs-out.json' },
plugins: [],
categories: [],
};
5 changes: 3 additions & 2 deletions packages/core/src/lib/execute-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import {
PluginOutput,
auditOutputsSchema,
} from '@quality-metrics/models';
import { ProcessObserver, executeProcess } from '@quality-metrics/utils';
import { readFile } from 'fs/promises';
import { join } from 'path';
import { executeProcess, ProcessObserver } from '@quality-metrics/utils';

/**
* Error thrown when plugin output is invalid.
Expand Down Expand Up @@ -48,7 +48,7 @@ export async function executePlugin(
pluginConfig: PluginConfig,
observer?: ProcessObserver,
): Promise<PluginOutput> {
const { slug, title, description, docsUrl, version, packageName } =
const { slug, title, icon, description, docsUrl, version, packageName } =
pluginConfig;
const { args, command } = pluginConfig.runner;

Expand All @@ -73,6 +73,7 @@ export async function executePlugin(
packageName,
slug,
title,
icon,
description,
docsUrl,
date,
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/lib/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { CollectOptions, collect } from './collect';
const baseOptions: CollectOptions = {
...mockCoreConfig(),
configPath: '',
interactive: true,
verbose: false,
};

Expand Down
1 change: 1 addition & 0 deletions packages/models/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@quality-metrics/models",
"version": "0.0.1",
"dependencies": {
"@code-pushup/portal-client": "^0.1.2",
"zod": "^3.22.1"
}
}
10 changes: 7 additions & 3 deletions packages/models/src/lib/plugin-config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { MATERIAL_ICONS, MaterialIcon } from '@code-pushup/portal-client';
import { z } from 'zod';
import {
executionMetaSchema,
Expand All @@ -17,6 +18,11 @@ import {
hasMissingStrings,
} from './implementation/utils';

export const materialIconSchema = z.enum(
MATERIAL_ICONS as [MaterialIcon, MaterialIcon, ...MaterialIcon[]],
{ description: 'Icon from VSCode Material Icons extension' },
);

export const pluginSchema = packageVersionSchema({
optional: true,
})
Expand All @@ -31,9 +37,7 @@ export const pluginSchema = packageVersionSchema({
.merge(
z.object({
slug: slugSchema('References plugin. ID (unique within core config)'),
icon: z.union([z.unknown(), z.string()], {
description: 'Icon from VSCode Material Icons extension',
}),
icon: materialIconSchema,
}),
);

Expand Down
5 changes: 3 additions & 2 deletions packages/models/test/schema.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export function mockPluginConfig(opt?: {
},
slug: pluginSlug,
title: 'execute plugin',
icon: 'nrwl',
description: 'Plugin description for ' + pluginSlug,
docsUrl: 'https://my-plugin.docs.dev?' + pluginSlug,
};
Expand Down Expand Up @@ -204,7 +205,7 @@ export function mockPluginReport(opt?: {
title: 'Title of ' + pluginSlug,
description: 'Plugin description of ' + pluginSlug,
docsUrl: `http://plugin.io/docs/${pluginSlug}`,
icon: 'socket',
icon: 'nrwl',
version: '0.0.1',
packageName: '@' + pluginSlug,
audits: Array.isArray(auditSlug)
Expand Down Expand Up @@ -256,7 +257,7 @@ export function mockUploadConfig(opt?: Partial<UploadConfig>): UploadConfig {

export function mockAuditOutputs(opt?: {
auditSlug: string | string[];
}): AuditOutputs {
}): AuditOutput[] {
let { auditSlug } = opt || {};
auditSlug = auditSlug || 'mock-audit-output-slug';
return Array.isArray(auditSlug)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const lighthousePlugin: () => PluginConfig = () =>
},
slug: 'lighthouse',
title: 'lighthouse',
icon: 'lighthouse',
description: '',
docsUrl: `https://github.com/GoogleChrome/lighthouse/tree/main/README.md`,
groups: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const nxValidatorsPlugin: () => PluginConfig = (): PluginConfig =>
},
slug: 'nx-validators',
title: 'NxValidatorsPlugin',
icon: 'nrwl',
docsUrl: `https://github.com/BioPhoton/nx-validators/tree/main/README.md`,
groups: [
{
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-eslint/src/lib/eslint-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ export function eslintPlugin(_: ESLintPluginConfig): PluginConfig {
},
slug: 'eslint',
title: 'execute plugin',
icon: 'eslint',
};
}
1 change: 1 addition & 0 deletions packages/plugin-lighthouse/src/lib/lighthouse-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ export function lighthousePlugin(_: LighthousePluginConfig): PluginConfig {
},
slug: 'lighthouse',
title: 'ChromeDevTools Lighthouse',
icon: 'lighthouse',
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export function mockPluginReport(opt?: {
slug: pluginSlug,
docsUrl: `http://plugin.io/docs/${pluginSlug}`,
title: 'Mock plugin Name',
icon: 'socket',
icon: 'nrwl',
audits: Array.isArray(auditSlug)
? auditSlug.map(a => mockAuditReport({ auditSlug: a }))
: [mockAuditReport({ auditSlug })],
Expand Down

0 comments on commit f52cc75

Please sign in to comment.