environmentService.ts 1.7 KB
Newer Older
J
Joao Moreno 已提交
1 2 3 4 5 6 7 8 9 10 11 12
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import * as paths from 'vs/base/node/paths';
import product from 'vs/platform/product';
import pkg from 'vs/platform/package';
import * as os from 'os';
import * as path from 'path';
import { parseArgs } from 'vs/code/node/argv';
13
import URI from 'vs/base/common/uri';
J
Joao Moreno 已提交
14 15 16

export class EnvironmentService implements IEnvironmentService {

17
	_serviceBrand: any;
J
Joao Moreno 已提交
18

19 20 21
	private _appRoot: string;
	get appRoot(): string { return this._appRoot; }

J
Joao Moreno 已提交
22 23 24 25 26 27
	private _userDataPath: string;
	get userDataPath(): string { return this._userDataPath; }

	private _extensionsPath: string;
	get extensionsPath(): string { return this._extensionsPath; }

28 29 30 31 32
	private _extensionDevelopmentPath: string;
	get extensionDevelopmentPath(): string { return this._extensionDevelopmentPath; }

	get isBuilt(): boolean { return !process.env['VSCODE_DEV']; }

J
Joao Moreno 已提交
33 34 35
	constructor() {
		const argv = parseArgs(process.argv);

36
		this._appRoot = path.dirname(URI.parse(require.toUrl('')).fsPath);
J
Joao Moreno 已提交
37 38 39 40 41
		this._userDataPath = paths.getUserDataPath(process.platform, pkg.name, process.argv);

		const userHome = path.join(os.homedir(), product.dataFolderName);
		this._extensionsPath = argv.extensionHomePath || path.join(userHome, 'extensions');
		this._extensionsPath = path.normalize(this._extensionsPath);
42 43

		this._extensionDevelopmentPath = argv.extensionDevelopmentPath;
J
Joao Moreno 已提交
44 45
	}
}