UNPKG

2.21 kBJavaScriptView Raw
1"use strict";
2/*
3 * Copyright (c) 2018, salesforce.com, inc.
4 * All rights reserved.
5 * SPDX-License-Identifier: BSD-3-Clause
6 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7 */
8Object.defineProperty(exports, "__esModule", { value: true });
9const kit_1 = require("@salesforce/kit");
10const os = require("os");
11const path = require("path");
12const fs_1 = require("./util/fs");
13/**
14 * Represents an environment mode. Supports `production`, `development`, `demo`, and `test`
15 * with the default mode being `production`.
16 *
17 * To set the mode, `export SFDX_ENV=<mode>` in your current environment.
18 */
19var Mode;
20(function (Mode) {
21 Mode["PRODUCTION"] = "production";
22 Mode["DEVELOPMENT"] = "development";
23 Mode["DEMO"] = "demo";
24 Mode["TEST"] = "test";
25})(Mode = exports.Mode || (exports.Mode = {}));
26/**
27 * Global constants, methods, and configuration.
28 */
29class Global {
30 /**
31 * Gets the current mode environment variable as a {@link Mode} instance.
32 *
33 * ```
34 * console.log(Global.getEnvironmentMode() === Mode.PRODUCTION);
35 * ```
36 */
37 static getEnvironmentMode() {
38 return Mode[kit_1.env.getKeyOf('SFDX_ENV', Mode, Mode.PRODUCTION, value => value.toUpperCase())];
39 }
40 /**
41 * Creates a directory within {@link Global.DIR}, or {@link Global.DIR} itself if the `dirPath` param
42 * is not provided. This is resolved or rejected when the directory creation operation has completed.
43 *
44 * @param dirPath The directory path to be created within {@link Global.DIR}.
45 */
46 static async createDir(dirPath) {
47 dirPath = dirPath ? path.join(Global.DIR, dirPath) : Global.DIR;
48 await fs_1.fs.mkdirp(dirPath, fs_1.fs.DEFAULT_USER_DIR_MODE);
49 }
50}
51/**
52 * The global folder in which state is stored.
53 */
54Global.STATE_FOLDER = '.sfdx';
55/**
56 * The full system path to the global state folder.
57 *
58 * **See** {@link Global.STATE_FOLDER}
59 */
60Global.DIR = path.join(os.homedir(), Global.STATE_FOLDER);
61/**
62 * The full system path to the global log file.
63 */
64Global.LOG_FILE_PATH = path.join(Global.DIR, 'sfdx.log');
65exports.Global = Global;
66//# sourceMappingURL=global.js.map
\No newline at end of file