Repository navigation
Expand file tree
/
Copy pathextension.js
More file actions
93 lines (77 loc) · 2.16 KB
/
Copy pathextension.js
File metadata and controls
93 lines (77 loc) · 2.16 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
'use strict';
import { tasks, workspace, Task, TaskScope, ShellExecution, TaskGroup } from 'vscode';
import { platform } from 'os';
import { resolve } from 'path';
import { exists } from 'fs';
import { promisify } from 'util';
const existsPromise = promisify(exists);
const files = [
'lcp_manifest.json',
'manufacturers.json',
'core_bonuses.json',
'environments.json',
'frames.json',
'weapons.json',
'systems.json',
'mods.json',
'pilot_gear.json',
'reserves.json',
'sitreps.json',
'skills.json',
'statuses.json',
'talents.json',
'tags.json',
'npc_classes.json',
'npc_features.json',
'npc_templates.json',
'lists.json',
'tables.json',
'eidolon_layers.json'
];
function activate() {
var type = 'compconTaskProvider';
tasks.registerTaskProvider(type, {
async provideTasks() {
const root =
workspace.workspaceFolders
? workspace.workspaceFolders[0].uri.fsPath
: null;
if (!root) return [];
const manifestExists = await existsPromise(root + '/lcp_manifest.json');
if (!manifestExists) return [];
const textDoc = await workspace.openTextDocument(root + '/lcp_manifest.json');
const existingFiles = (
await Promise.all(
files.map(async (filename) => {
const doesExist = await existsPromise(resolve(root, filename));
return doesExist ? filename : null;
})
)
).filter((x) => x);
const manifest = JSON.parse(textDoc.getText());
const { name, version } = manifest;
const cmd = platform() === 'win32' ? '7z a -tzip' : 'zip';
const packageName = `${name}-${version}.lcp`;
const filesStr = existingFiles.join(' ');
const task = new Task(
{ type },
TaskScope.Workspace,
'Build .LCP package',
'compcon',
new ShellExecution(`${cmd} "${packageName.replace('"', '\\"')}" ${filesStr}`),
[]
);
task.group = TaskGroup.Build;
return [task];
},
resolveTask(task) {
return task;
},
});
}
// this method is called when your extension is deactivated
function deactivate() {}
export default {
activate,
deactivate,
};