forked from xusiyuan841028/coc-project-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
40 lines (31 loc) · 1.05 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { commands, ExtensionContext, listManager, workspace } from 'coc.nvim';
import fs from 'fs';
import DB from './db';
import ProjectList from './lists';
import { newProject, createItem } from './model';
import path from 'path';
export async function activate(context: ExtensionContext): Promise<void> {
const config = workspace.getConfiguration('project-manager');
const enable = config.get<boolean>('enabled', true);
if (!enable) return;
const { storagePath } = context;
const fileName = 'PM_Cache';
await fs.mkdir(storagePath, { recursive: true }, (err) => {
if (err) throw err;
});
const file = path.join(storagePath, `${fileName}.json`);
fs.exists(file, async (isExist) => {
if (!isExist) {
await fs.writeFile(file, '[]', (err) => {
if (err) throw err;
});
}
});
const db = new DB(storagePath, fileName);
context.subscriptions.push(
commands.registerCommand('project-manager.Create', async () => {
createItem(db);
}),
listManager.registerList(new ProjectList(workspace.nvim, db))
);
}