start adding auto-registering of addon sections in the Plugin entity

pull/67/head
dperolio 3 years ago
parent 9c22009094
commit b277745c12
No known key found for this signature in database
GPG Key ID: 3E9BBAA710D3DDCE

@ -7,9 +7,9 @@ import { createElement } from '@vizality/util/dom';
import { Directories } from '@vizality/constants';
import { isArray } from '@vizality/util/array';
import { debounce } from 'lodash';
import { join, sep } from 'path';
import { join, sep, extname } from 'path';
import { watch } from 'chokidar';
import { existsSync } from 'fs';
import { existsSync, readFileSync } from 'fs';
import Updatable from './Updatable';
@ -314,6 +314,7 @@ export default class Plugin extends Updatable {
*
*/
await this._registerSettings();
await this._registerSections();
} else {
this.warn(`${toTitleCase(this.type)} has no "start" method!`);
}
@ -370,6 +371,53 @@ export default class Plugin extends Updatable {
}
}
/**
*
* @private
*/
async _registerSections () {
try {
/**
*
*/
let changelogPath;
if (this.type !== 'builtin') {
if (!this.sections.changelog) {
if (this.manifest?.sections?.changelog) {
if (existsSync(join(this.path, this.manifest.sections.changelog))) {
changelogPath = join(this.path, this.manifest.sections.changelog);
}
} else if (existsSync(join(this.path, 'CHANGELOG.md'))) {
changelogPath = join(this.path, 'CHANGELOG.md');
} else if (existsSync(join(this.path, 'CHANGELOG'))) {
changelogPath = join(this.path, 'CHANGELOG');
}
}
if (changelogPath) {
this.sections.changelog = readFileSync(changelogPath, 'utf8');
}
let readmePath;
if (!this.sections.overview) {
if (this.manifest?.sections?.overview) {
if (existsSync(join(this.path, this.manifest.sections.overview))) {
readmePath = join(this.path, this.manifest.sections.overview);
}
} else if (existsSync(join(this.path, 'README.md'))) {
readmePath = join(this.path, 'README.md');
} else if (existsSync(join(this.path, 'README'))) {
readmePath = join(this.path, 'README');
}
}
if (readmePath) {
this.sections.overview = readFileSync(readmePath, 'utf8');
}
}
} catch (err) {
return this.error(err);
}
}
/**
*
* @private

Loading…
Cancel
Save