一些检查失败了
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
64 行
1.7 KiB
TypeScript
64 行
1.7 KiB
TypeScript
import { join } from 'path';
|
|
import { PluginManifest } from '../../services/plugins/utils/types';
|
|
import Setting from '../../models/Setting';
|
|
import { mkdirp, writeFile } from 'fs-extra';
|
|
import { defaultPluginSetting } from '../../services/plugins/PluginService';
|
|
import shim from '../../shim';
|
|
|
|
|
|
const setPluginEnabled = (id: string, enabled: boolean) => {
|
|
const newPluginStates = {
|
|
...Setting.value('plugins.states'),
|
|
[id]: {
|
|
...defaultPluginSetting(),
|
|
enabled,
|
|
},
|
|
};
|
|
Setting.setValue('plugins.states', newPluginStates);
|
|
};
|
|
|
|
interface Options {
|
|
onStart?: string;
|
|
enabled?: boolean;
|
|
format?: 'js' | 'jpl';
|
|
}
|
|
|
|
const createTestPlugin = async (manifest: PluginManifest, { onStart = '', enabled = true, format = 'js' }: Options = {}) => {
|
|
const scriptSource = `joplin.plugins.register({
|
|
onStart: async function() {
|
|
${onStart}
|
|
},
|
|
});`;
|
|
|
|
if (format === 'jpl') {
|
|
const tempDir = join(Setting.value('tempDir'), `plugin-build-${manifest.id}`);
|
|
await mkdirp(tempDir);
|
|
await writeFile(join(tempDir, 'manifest.json'), JSON.stringify(manifest), 'utf-8');
|
|
await writeFile(join(tempDir, 'index.js'), scriptSource, 'utf-8');
|
|
|
|
const jplPath = join(Setting.value('pluginDir'), `${manifest.id}.jpl`);
|
|
await shim.fsDriver().tarCreate({ cwd: tempDir, file: jplPath }, ['manifest.json', 'index.js']);
|
|
} else {
|
|
const pluginSource = `
|
|
/* joplin-manifest:
|
|
${JSON.stringify(manifest)}
|
|
*/
|
|
|
|
${scriptSource}
|
|
`;
|
|
const pluginPath = join(Setting.value('pluginDir'), `${manifest.id}.js`);
|
|
await writeFile(pluginPath, pluginSource, 'utf-8');
|
|
}
|
|
|
|
setPluginEnabled(manifest.id, enabled);
|
|
|
|
return {
|
|
manifest,
|
|
setEnabled: (enabled: boolean) => {
|
|
setPluginEnabled(manifest.id, enabled);
|
|
},
|
|
};
|
|
};
|
|
|
|
export default createTestPlugin;
|