1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | var __importStar = (this && this.__importStar) || function (mod) {
|
6 | if (mod && mod.__esModule) return mod;
|
7 | var result = {};
|
8 | if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
9 | result["default"] = mod;
|
10 | return result;
|
11 | };
|
12 | Object.defineProperty(exports, "__esModule", { value: true });
|
13 | const path_1 = __importDefault(require("path"));
|
14 | const util_1 = __importDefault(require("util"));
|
15 | const child_process_1 = __importDefault(require("child_process"));
|
16 | const state_1 = require("./state");
|
17 | const config_1 = require("./config");
|
18 | const request = __importStar(require("./request"));
|
19 | const types_1 = require("./types");
|
20 | const pExec = util_1.default.promisify(child_process_1.default.exec);
|
21 | async function exec(command) {
|
22 | try {
|
23 | return pExec(command);
|
24 | }
|
25 | catch (err) {
|
26 | return err;
|
27 | }
|
28 | }
|
29 | exports.exec = exec;
|
30 | function getHostOS() {
|
31 | return process.env.OPS_HOST_PLATFORM || 'unknown';
|
32 | }
|
33 | exports.getHostOS = getHostOS;
|
34 | function getInterfaceType() {
|
35 | return process.env.SDK_INTERFACE_TYPE || types_1.Interfaces.Terminal;
|
36 | }
|
37 | exports.getInterfaceType = getInterfaceType;
|
38 | function homeDir() {
|
39 | return process.env.SDK_HOME_DIR || '/root';
|
40 | }
|
41 | exports.homeDir = homeDir;
|
42 | function log(...args) {
|
43 | console.log(...args);
|
44 | }
|
45 | exports.log = log;
|
46 | function getStatePath() {
|
47 | return path_1.default.resolve(process.env.SDK_STATE_DIR || '');
|
48 | }
|
49 | exports.getStatePath = getStatePath;
|
50 | function getConfigPath() {
|
51 | return path_1.default.resolve(process.env.SDK_CONFIG_DIR || '');
|
52 | }
|
53 | exports.getConfigPath = getConfigPath;
|
54 | async function setState(key, value) {
|
55 | const state = new state_1.State(getStatePath());
|
56 | await state.set(key, value);
|
57 | }
|
58 | exports.setState = setState;
|
59 | async function getState(key) {
|
60 | const state = new state_1.State(getStatePath());
|
61 | return await state.get(key);
|
62 | }
|
63 | exports.getState = getState;
|
64 | async function setConfig(key, value) {
|
65 | const config = new config_1.Config(getConfigPath());
|
66 | await config.set(key, value);
|
67 | }
|
68 | exports.setConfig = setConfig;
|
69 | async function getConfig(key) {
|
70 | const config = new config_1.Config(getConfigPath());
|
71 | return await config.get(key);
|
72 | }
|
73 | exports.getConfig = getConfig;
|
74 |
|
75 | async function track(tags, metadata) {
|
76 | try {
|
77 | await request.track(Object.assign({ tags: Array.isArray(tags) ? tags : [tags] }, metadata));
|
78 | }
|
79 | catch (e) {
|
80 |
|
81 | }
|
82 | }
|
83 | exports.track = track;
|