|
@@ -13,9 +13,9 @@ import { resolveFromRoot } from '~/utils/project-dir-utils';
|
|
|
|
|
|
|
|
import { GrowiPluginResourceType } from '../interfaces';
|
|
import { GrowiPluginResourceType } from '../interfaces';
|
|
|
import type {
|
|
import type {
|
|
|
- GrowiPlugin, GrowiPluginOrigin, GrowiThemePluginMeta, GrowiPluginMeta,
|
|
|
|
|
|
|
+ IGrowiPlugin, IGrowiPluginOrigin, IGrowiThemePluginMeta, IGrowiPluginMeta,
|
|
|
} from '../interfaces';
|
|
} from '../interfaces';
|
|
|
-import type { GrowiPluginModel } from '../models';
|
|
|
|
|
|
|
+import { GrowiPlugin } from '../models';
|
|
|
|
|
|
|
|
const logger = loggerFactory('growi:plugins:plugin-utils');
|
|
const logger = loggerFactory('growi:plugins:plugin-utils');
|
|
|
|
|
|
|
@@ -28,7 +28,7 @@ const PLUGINS_STATIC_DIR = '/static/plugins'; // configured by express.static
|
|
|
|
|
|
|
|
export type GrowiPluginResourceEntries = [installedPath: string, href: string][];
|
|
export type GrowiPluginResourceEntries = [installedPath: string, href: string][];
|
|
|
|
|
|
|
|
-function retrievePluginManifest(growiPlugin: GrowiPlugin): ViteManifest {
|
|
|
|
|
|
|
+function retrievePluginManifest(growiPlugin: IGrowiPlugin): ViteManifest {
|
|
|
const manifestPath = resolveFromRoot(path.join('tmp/plugins', growiPlugin.installedPath, 'dist/manifest.json'));
|
|
const manifestPath = resolveFromRoot(path.join('tmp/plugins', growiPlugin.installedPath, 'dist/manifest.json'));
|
|
|
const manifestStr: string = readFileSync(manifestPath, 'utf-8');
|
|
const manifestStr: string = readFileSync(manifestPath, 'utf-8');
|
|
|
return JSON.parse(manifestStr);
|
|
return JSON.parse(manifestStr);
|
|
@@ -36,13 +36,13 @@ function retrievePluginManifest(growiPlugin: GrowiPlugin): ViteManifest {
|
|
|
|
|
|
|
|
|
|
|
|
|
type FindThemePluginResult = {
|
|
type FindThemePluginResult = {
|
|
|
- growiPlugin: GrowiPlugin,
|
|
|
|
|
|
|
+ growiPlugin: IGrowiPlugin,
|
|
|
themeMetadata: GrowiThemeMetadata,
|
|
themeMetadata: GrowiThemeMetadata,
|
|
|
themeHref: string,
|
|
themeHref: string,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export interface IGrowiPluginService {
|
|
export interface IGrowiPluginService {
|
|
|
- install(origin: GrowiPluginOrigin): Promise<string>
|
|
|
|
|
|
|
+ install(origin: IGrowiPluginOrigin): Promise<string>
|
|
|
findThemePlugin(theme: string): Promise<FindThemePluginResult | null>
|
|
findThemePlugin(theme: string): Promise<FindThemePluginResult | null>
|
|
|
retrieveAllPluginResourceEntries(): Promise<GrowiPluginResourceEntries>
|
|
retrieveAllPluginResourceEntries(): Promise<GrowiPluginResourceEntries>
|
|
|
downloadNotExistPluginRepositories(): Promise<void>
|
|
downloadNotExistPluginRepositories(): Promise<void>
|
|
@@ -56,7 +56,6 @@ export class GrowiPluginService implements IGrowiPluginService {
|
|
|
async downloadNotExistPluginRepositories(): Promise<void> {
|
|
async downloadNotExistPluginRepositories(): Promise<void> {
|
|
|
try {
|
|
try {
|
|
|
// find all growi plugin documents
|
|
// find all growi plugin documents
|
|
|
- const GrowiPlugin = mongoose.model<GrowiPlugin>('GrowiPlugin');
|
|
|
|
|
const growiPlugins = await GrowiPlugin.find({});
|
|
const growiPlugins = await GrowiPlugin.find({});
|
|
|
|
|
|
|
|
// if not exists repository in file system, download latest plugin repository
|
|
// if not exists repository in file system, download latest plugin repository
|
|
@@ -114,7 +113,7 @@ export class GrowiPluginService implements IGrowiPluginService {
|
|
|
/*
|
|
/*
|
|
|
* Install a plugin from URL and save it in the DB and file system.
|
|
* Install a plugin from URL and save it in the DB and file system.
|
|
|
*/
|
|
*/
|
|
|
- async install(origin: GrowiPluginOrigin): Promise<string> {
|
|
|
|
|
|
|
+ async install(origin: IGrowiPluginOrigin): Promise<string> {
|
|
|
const ghUrl = new URL(origin.url);
|
|
const ghUrl = new URL(origin.url);
|
|
|
const ghPathname = ghUrl.pathname;
|
|
const ghPathname = ghUrl.pathname;
|
|
|
// TODO: Branch names can be specified.
|
|
// TODO: Branch names can be specified.
|
|
@@ -138,7 +137,7 @@ export class GrowiPluginService implements IGrowiPluginService {
|
|
|
const organizationPath = path.join(pluginStoringPath, ghOrganizationName);
|
|
const organizationPath = path.join(pluginStoringPath, ghOrganizationName);
|
|
|
|
|
|
|
|
|
|
|
|
|
- let plugins: GrowiPlugin<GrowiPluginMeta>[];
|
|
|
|
|
|
|
+ let plugins: IGrowiPlugin<IGrowiPluginMeta>[];
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
// download github repository to file system's temporary path
|
|
// download github repository to file system's temporary path
|
|
@@ -185,7 +184,6 @@ export class GrowiPluginService implements IGrowiPluginService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private async deleteOldPluginDocument(path: string): Promise<void> {
|
|
private async deleteOldPluginDocument(path: string): Promise<void> {
|
|
|
- const GrowiPlugin = mongoose.model<GrowiPlugin>('GrowiPlugin');
|
|
|
|
|
await GrowiPlugin.deleteMany({ installedPath: path });
|
|
await GrowiPlugin.deleteMany({ installedPath: path });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -231,13 +229,12 @@ export class GrowiPluginService implements IGrowiPluginService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private async savePluginMetaData(plugins: GrowiPlugin[]): Promise<void> {
|
|
|
|
|
- const GrowiPlugin = mongoose.model('GrowiPlugin');
|
|
|
|
|
|
|
+ private async savePluginMetaData(plugins: IGrowiPlugin[]): Promise<void> {
|
|
|
await GrowiPlugin.insertMany(plugins);
|
|
await GrowiPlugin.insertMany(plugins);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, max-len
|
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, max-len
|
|
|
- private static async detectPlugins(origin: GrowiPluginOrigin, ghOrganizationName: string, ghReposName: string, parentPackageJson?: any): Promise<GrowiPlugin[]> {
|
|
|
|
|
|
|
+ private static async detectPlugins(origin: IGrowiPluginOrigin, ghOrganizationName: string, ghReposName: string, parentPackageJson?: any): Promise<IGrowiPlugin[]> {
|
|
|
const packageJsonPath = path.resolve(pluginStoringPath, ghReposName, 'package.json');
|
|
const packageJsonPath = path.resolve(pluginStoringPath, ghReposName, 'package.json');
|
|
|
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
|
|
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
|
|
|
|
|
|
|
@@ -280,7 +277,7 @@ export class GrowiPluginService implements IGrowiPluginService {
|
|
|
|
|
|
|
|
// add theme metadata
|
|
// add theme metadata
|
|
|
if (growiPlugin.types.includes(GrowiPluginResourceType.Theme)) {
|
|
if (growiPlugin.types.includes(GrowiPluginResourceType.Theme)) {
|
|
|
- (plugin as GrowiPlugin<GrowiThemePluginMeta>).meta = {
|
|
|
|
|
|
|
+ (plugin as IGrowiPlugin<IGrowiThemePluginMeta>).meta = {
|
|
|
...plugin.meta,
|
|
...plugin.meta,
|
|
|
themes: growiPlugin.themes,
|
|
themes: growiPlugin.themes,
|
|
|
};
|
|
};
|
|
@@ -291,7 +288,7 @@ export class GrowiPluginService implements IGrowiPluginService {
|
|
|
return [plugin];
|
|
return [plugin];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- async listPlugins(): Promise<GrowiPlugin[]> {
|
|
|
|
|
|
|
+ async listPlugins(): Promise<IGrowiPlugin[]> {
|
|
|
return [];
|
|
return [];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -303,7 +300,6 @@ export class GrowiPluginService implements IGrowiPluginService {
|
|
|
return fs.promises.rm(path, { recursive: true });
|
|
return fs.promises.rm(path, { recursive: true });
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- const GrowiPlugin = mongoose.model<GrowiPlugin>('GrowiPlugin');
|
|
|
|
|
const growiPlugins = await GrowiPlugin.findById(pluginId);
|
|
const growiPlugins = await GrowiPlugin.findById(pluginId);
|
|
|
|
|
|
|
|
if (growiPlugins == null) {
|
|
if (growiPlugins == null) {
|
|
@@ -331,14 +327,12 @@ export class GrowiPluginService implements IGrowiPluginService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async findThemePlugin(theme: string): Promise<FindThemePluginResult | null> {
|
|
async findThemePlugin(theme: string): Promise<FindThemePluginResult | null> {
|
|
|
- const GrowiPlugin = mongoose.model('GrowiPlugin') as GrowiPluginModel;
|
|
|
|
|
-
|
|
|
|
|
- let matchedPlugin: GrowiPlugin | undefined;
|
|
|
|
|
|
|
+ let matchedPlugin: IGrowiPlugin | undefined;
|
|
|
let matchedThemeMetadata: GrowiThemeMetadata | undefined;
|
|
let matchedThemeMetadata: GrowiThemeMetadata | undefined;
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
// retrieve plugin manifests
|
|
// retrieve plugin manifests
|
|
|
- const growiPlugins = await GrowiPlugin.findEnabledPluginsIncludingAnyTypes([GrowiPluginResourceType.Theme]) as GrowiPlugin<GrowiThemePluginMeta>[];
|
|
|
|
|
|
|
+ const growiPlugins = await GrowiPlugin.findEnabledPluginsIncludingAnyTypes([GrowiPluginResourceType.Theme]) as IGrowiPlugin<IGrowiThemePluginMeta>[];
|
|
|
|
|
|
|
|
growiPlugins
|
|
growiPlugins
|
|
|
.forEach(async(growiPlugin) => {
|
|
.forEach(async(growiPlugin) => {
|
|
@@ -374,8 +368,6 @@ export class GrowiPluginService implements IGrowiPluginService {
|
|
|
|
|
|
|
|
async retrieveAllPluginResourceEntries(): Promise<GrowiPluginResourceEntries> {
|
|
async retrieveAllPluginResourceEntries(): Promise<GrowiPluginResourceEntries> {
|
|
|
|
|
|
|
|
- const GrowiPlugin = mongoose.model('GrowiPlugin') as GrowiPluginModel;
|
|
|
|
|
-
|
|
|
|
|
const entries: GrowiPluginResourceEntries = [];
|
|
const entries: GrowiPluginResourceEntries = [];
|
|
|
|
|
|
|
|
try {
|
|
try {
|