This repository has been archived by the owner on Apr 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
extension.ts
49 lines (39 loc) · 1.99 KB
/
extension.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
41
42
43
44
45
46
47
48
49
'use strict';
import * as vscode from 'vscode';
import { SvgDocumentContentProvider } from './svgProvider';
import { CommandManager } from './commandManager';
import { ShowPreviewCommand } from './commands/showPreview'
import exec = require('child_process');
import fs = require('pn/fs');
import path = require('path');
import phantomjs = require('phantomjs-prebuilt');
import { SvgWebviewManager, SvgExportWebviewManager } from './features/svgWebviewManager';
import { SaveAsCommand, SaveAsSizeCommand, CopyDataUriCommand } from './commands/saveFile';
import { ExportDocumentContentProvider } from './exportProvider';
import { ShowExportCommand } from './commands/exportByCanvas';
export function activate(context: vscode.ExtensionContext) {
const previewProvider = new SvgDocumentContentProvider(context);
const webviewManager = new SvgWebviewManager(previewProvider);
context.subscriptions.push(webviewManager);
const exportProvider = new ExportDocumentContentProvider(context);
const expWebviewManager = new SvgExportWebviewManager(exportProvider);
context.subscriptions.push(expWebviewManager);
const commandManager = new CommandManager();
commandManager.register(new ShowPreviewCommand(webviewManager));
commandManager.register(new ShowExportCommand(expWebviewManager));
commandManager.register(new SaveAsCommand());
commandManager.register(new SaveAsSizeCommand());
commandManager.register(new CopyDataUriCommand());
context.subscriptions.push(commandManager);
// Check PhantomJS Binary
if (!fs.existsSync(phantomjs.path)) {
exec.execSync('npm rebuild', { cwd: context.extensionPath });
process.env.PHANTOMJS_PLATFORM = process.platform;
process.env.PHANTOMJS_ARCH = process.arch;
phantomjs.path = process.platform === 'win32' ?
path.join(path.dirname(phantomjs.path), 'phantomjs.exe') :
path.join(path.dirname(phantomjs.path), 'phantom', 'bin', 'phantomjs');
}
}
export function deactivate() {
}