| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- import { GrowiPluginType } from '~/consts';
- import { type GrowiPluginValidationData, GrowiPluginValidationError } from '~/model';
- import { importPackageJson } from './import';
- export const validatePackageJson = async(projectDirRoot: string, expectedPluginType?: GrowiPluginType): Promise<GrowiPluginValidationData> => {
- const pkg = await importPackageJson(projectDirRoot);
- const data: GrowiPluginValidationData = { projectDirRoot };
- const { growiPlugin } = pkg;
- if (growiPlugin == null) {
- throw new GrowiPluginValidationError("The package.json does not have 'growiPlugin' directive.", data);
- }
- // schema version checking
- const schemaVersion = Number(growiPlugin.schemaVersion);
- data.schemaVersion = schemaVersion;
- if (Number.isNaN(schemaVersion) || schemaVersion < 4) {
- throw new GrowiPluginValidationError("The growiPlugin directive must have a valid 'schemaVersion' directive.", data);
- }
- const types: GrowiPluginType[] = growiPlugin.types;
- data.actualPluginTypes = types;
- if (types == null) {
- throw new GrowiPluginValidationError("The growiPlugin directive does not have 'types' directive.", data);
- }
- // type checking
- if (expectedPluginType != null) {
- data.expectedPluginType = expectedPluginType;
- if (!types.includes(expectedPluginType)) {
- throw new GrowiPluginValidationError("The growiPlugin directive does not have 'types' directive.", data);
- }
- }
- return data;
- };
|