文件
mynode/packages/default-plugins/utils/readRepositoryJson.ts
chen 301194963b
一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
feat: Initial clean release of CHM
2026-11-04 11:29:39 +08:00

61 行
1.6 KiB
TypeScript

import { readFile } from 'fs-extra';
export enum BuiltInPluginType {
// Plugins that need to be built when building Joplin (e.g. if the plugin
// needs to be patched)
Built,
// Plugins that can be fetched directly from NPM. Must also be marked as a
// dev dependency.
FromNpm,
}
export interface RepositoryData {
type: BuiltInPluginType.Built;
cloneUrl: string;
branch: string;
commit: string;
}
export interface NpmReference {
type: BuiltInPluginType.FromNpm;
package: string;
}
export interface AllRepositoryData {
[pluginId: string]: RepositoryData|NpmReference;
}
const readRepositoryJson = async (repositoryDataFilepath: string): Promise<AllRepositoryData> => {
const fileContent = await readFile(repositoryDataFilepath, 'utf8');
const parsedJson = JSON.parse(fileContent);
// Validate
for (const pluginId in parsedJson) {
if (typeof parsedJson[pluginId] !== 'object') {
throw new Error('pluginRepositories should map from plugin IDs to objects.');
}
const assertPropertyIsString = (propertyName: string) => {
if (typeof parsedJson[pluginId][propertyName] !== 'string') {
throw new Error(`Plugin ${pluginId} should have field '${propertyName}' of type string.`);
}
};
let type;
if ('branch' in parsedJson[pluginId]) {
assertPropertyIsString('cloneUrl');
assertPropertyIsString('branch');
assertPropertyIsString('commit');
type = BuiltInPluginType.Built;
} else {
assertPropertyIsString('package');
type = BuiltInPluginType.FromNpm;
}
parsedJson[pluginId] = { ...parsedJson[pluginId], type };
}
return parsedJson;
};
export default readRepositoryJson;