UNPKG

3.71 kBJavaScriptView Raw
1"use strict";
2/*
3 * Copyright (c) 2020, salesforce.com, inc.
4 * All rights reserved.
5 * Licensed under the BSD 3-Clause license.
6 * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7 */
8Object.defineProperty(exports, "__esModule", { value: true });
9exports.Global = exports.Mode = void 0;
10const fs = require("fs");
11const os = require("os");
12const path = require("path");
13const kit_1 = require("@salesforce/kit");
14const sfError_1 = require("./sfError");
15/**
16 * Represents an environment mode. Supports `production`, `development`, `demo`, and `test`
17 * with the default mode being `production`.
18 *
19 * To set the mode, `export SFDX_ENV=<mode>` in your current environment.
20 */
21var Mode;
22(function (Mode) {
23 Mode["PRODUCTION"] = "production";
24 Mode["DEVELOPMENT"] = "development";
25 Mode["DEMO"] = "demo";
26 Mode["TEST"] = "test";
27})(Mode = exports.Mode || (exports.Mode = {}));
28/**
29 * Global constants, methods, and configuration.
30 */
31class Global {
32 /**
33 * The full system path to the global sfdx state folder.
34 *
35 * **See** {@link Global.SFDX_STATE_FOLDER}
36 */
37 static get SFDX_DIR() {
38 return path.join(os.homedir(), Global.SFDX_STATE_FOLDER);
39 }
40 /**
41 * The full system path to the global sf state folder.
42 *
43 * **See** {@link Global.SF_STATE_FOLDER}
44 */
45 static get SF_DIR() {
46 return path.join(os.homedir(), Global.SF_STATE_FOLDER);
47 }
48 /**
49 * The full system path to the preferred global state folder
50 */
51 static get DIR() {
52 return path.join(os.homedir(), Global.SFDX_STATE_FOLDER);
53 }
54 /**
55 * Gets the current mode environment variable as a {@link Mode} instance.
56 *
57 * ```
58 * console.log(Global.getEnvironmentMode() === Mode.PRODUCTION);
59 * ```
60 */
61 static getEnvironmentMode() {
62 return Mode[kit_1.env.getKeyOf('SFDX_ENV', Mode, Mode.PRODUCTION, (value) => value.toUpperCase())];
63 }
64 /**
65 * Creates a directory within {@link Global.SFDX_DIR}, or {@link Global.SFDX_DIR} itself if the `dirPath` param
66 * is not provided. This is resolved or rejected when the directory creation operation has completed.
67 *
68 * @param dirPath The directory path to be created within {@link Global.SFDX_DIR}.
69 */
70 static async createDir(dirPath) {
71 dirPath = dirPath ? path.join(Global.SFDX_DIR, dirPath) : Global.SFDX_DIR;
72 try {
73 if (process.platform === 'win32') {
74 await fs.promises.mkdir(dirPath, { recursive: true });
75 }
76 else {
77 await fs.promises.mkdir(dirPath, { recursive: true, mode: 0o700 });
78 }
79 }
80 catch (error) {
81 throw new sfError_1.SfError(`Failed to create directory or set permissions for: ${dirPath}`);
82 }
83 }
84}
85exports.Global = Global;
86/**
87 * Enable interoperability between `.sfdx` and `.sf`.
88 *
89 * When @salesforce/core@v2 is deprecated and no longer used, this can be removed.
90 */
91Global.SFDX_INTEROPERABILITY = kit_1.env.getBoolean('SF_SFDX_INTEROPERABILITY', true);
92/**
93 * The global folder in which sfdx state is stored.
94 */
95Global.SFDX_STATE_FOLDER = '.sfdx';
96/**
97 * The global folder in which sf state is stored.
98 */
99Global.SF_STATE_FOLDER = '.sf';
100/**
101 * The preferred global folder in which state is stored.
102 */
103Global.STATE_FOLDER = Global.SFDX_STATE_FOLDER;
104/**
105 * The full system path to the global log file.
106 */
107// member ordering conflicts with the TS use-before-declaration error
108// eslint-disable-next-line @typescript-eslint/member-ordering
109Global.LOG_FILE_PATH = path.join(Global.SF_DIR, 'sf.log');
110//# sourceMappingURL=global.js.map
\No newline at end of file