forgeplus-react/src/forge/Newfile/plugins/web-scm.plugin.jsx

73 lines
1.8 KiB
JavaScript

import localforage from 'localforage';
export const PLUGIN_ID = 'web-scm';
export const activate = ({ commands }) => {
console.log(localforage);
if (!localforage.supports(localforage.INDEXEDDB)) {
throw new Error('[SCM] IndexedDB Not Support');
}
// 只存储在IndexedDB
localforage.config({
driver: localforage.INDEXEDDB,
name: 'WEB_SCM',
storeName: 'WEB_SCM_TABLE',
});
commands.registerCommand('web-scm.localforage.get', async (key) => {
return await localforage.getItem(key);
});
commands.registerCommand(
'web-scm.localforage.set',
async (key, value) => {
return await localforage.setItem(key, value);
}
);
commands.registerCommand(
'web-scm.localforage.remove',
async (key, valye) => {
return await localforage.removeItem(key);
}
);
commands.registerCommand(
'web-scm.localforage.removeModify',
async (key, value) => {
return await localforage.removeItem(key);
}
);
commands.registerCommand('web-scm.localforage.clear', async () => {
return await localforage.clear();
});
commands.registerCommand(
'web-scm.localforage.iterate',
async (basePath) => {
const files = [];
await localforage.iterate((value, key) => {
if (key.startsWith(basePath)) {
if (key.endsWith(':MODIFY')) {
files.push(value);
}
// if (
// value.type === Status.ADDED ||
// value.type === Status.UNTRACKED
// ) {
// } else if (value.type === Status.DELETED) {
// } else if (value.type === Status.MODIFIED) {
// }
}
});
return files;
}
);
commands.registerCommand("web-scm.windowOpen", async (path) => {
window.open(path);
});
commands.registerCommand("web-scm.yuyanlog", (code, msg, extra) => { });
};