97 lines
5.4 KiB
JavaScript
97 lines
5.4 KiB
JavaScript
"use strict";
|
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
}
|
|
Object.defineProperty(o, k2, desc);
|
|
}) : (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
o[k2] = m[k];
|
|
}));
|
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
}) : function(o, v) {
|
|
o["default"] = v;
|
|
});
|
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
if (mod && mod.__esModule) return mod;
|
|
var result = {};
|
|
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
__setModuleDefault(result, mod);
|
|
return result;
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.CONFIG_DEFAULT = exports.DEFAULT_ROOTS = exports.POLYMECH_ROOT = exports.OSR_USER_ASSETS = exports.OA_ROOT = exports.OSR_CUSTOMER_DRIVE = exports.PRODUCT_ROOT = exports.OSR_LIBRARY_DIRECTORY = exports.OSR_LIBRARY_MACHINES = exports.OSR_LIBRARY = exports.KB_ROOT = exports.OSR_PRIVATE = exports.OSR_CACHE = exports.OSR_TEMP = exports.CONFIG_DEFAULT_PATH = exports.OSR_SUB_DEFAULT = exports.OSR_ROOT = exports.get_var = exports.HOME = exports.API_PREFIX_NEXT = exports.API_PREFIX = void 0;
|
|
const env = __importStar(require("env-var"));
|
|
const debug = __importStar(require("@plastichub/core/debug"));
|
|
const read_1 = require("@plastichub/fs/read");
|
|
const exists_1 = require("@plastichub/fs/exists");
|
|
const path = __importStar(require("path"));
|
|
exports.API_PREFIX = 'osr';
|
|
exports.API_PREFIX_NEXT = 'polymech';
|
|
const HOME = (sub = '') => path.join(process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME'], sub);
|
|
exports.HOME = HOME;
|
|
const get_var = (key = '') => env.get(key).asString() || env.get(key.replace(/-/g, '_')).asString() || env.get(key.replace(/_/g, '-')).asString();
|
|
exports.get_var = get_var;
|
|
const OSR_ROOT = (key = 'OSR-ROOT') => (0, exports.get_var)(key) || path.join((0, exports.HOME)('desktop'), exports.API_PREFIX);
|
|
exports.OSR_ROOT = OSR_ROOT;
|
|
const OSR_SUB_DEFAULT = (key = '') => (0, exports.get_var)(key) || path.join((0, exports.OSR_ROOT)(), key);
|
|
exports.OSR_SUB_DEFAULT = OSR_SUB_DEFAULT;
|
|
const CONFIG_DEFAULT_PATH = (key = 'OSR-CONFIG') => (0, exports.get_var)(key) || path.join((0, exports.HOME)(`${exports.API_PREFIX}`), '.config.json');
|
|
exports.CONFIG_DEFAULT_PATH = CONFIG_DEFAULT_PATH;
|
|
const OSR_TEMP = (key = 'OSR-TEMP') => (0, exports.get_var)(key) || (0, exports.OSR_SUB_DEFAULT)(`.${exports.API_PREFIX}/temp`);
|
|
exports.OSR_TEMP = OSR_TEMP;
|
|
const OSR_CACHE = (key = 'OSR-CACHE') => (0, exports.get_var)(key) || (0, exports.OSR_SUB_DEFAULT)(`.${exports.API_PREFIX}/cache`);
|
|
exports.OSR_CACHE = OSR_CACHE;
|
|
const OSR_PRIVATE = (key = 'OSR-PRIVATE') => (0, exports.get_var)(key);
|
|
exports.OSR_PRIVATE = OSR_PRIVATE;
|
|
const KB_ROOT = (key = 'OSR-KB') => (0, exports.get_var)(key);
|
|
exports.KB_ROOT = KB_ROOT;
|
|
const OSR_LIBRARY = (key = 'OSR-LIBRARY') => (0, exports.get_var)(key);
|
|
exports.OSR_LIBRARY = OSR_LIBRARY;
|
|
const OSR_LIBRARY_MACHINES = (key = 'OSR-LIBRARY-MACHINES') => (0, exports.get_var)(key);
|
|
exports.OSR_LIBRARY_MACHINES = OSR_LIBRARY_MACHINES;
|
|
const OSR_LIBRARY_DIRECTORY = (key = 'OSR-LIBRARY-DIRECTORY') => (0, exports.get_var)(key);
|
|
exports.OSR_LIBRARY_DIRECTORY = OSR_LIBRARY_DIRECTORY;
|
|
const PRODUCT_ROOT = (key = 'PRODUCT-ROOT') => (0, exports.get_var)(key);
|
|
exports.PRODUCT_ROOT = PRODUCT_ROOT;
|
|
const OSR_CUSTOMER_DRIVE = (key = 'OSR-CUSTOMER-DRIVE') => (0, exports.get_var)(key);
|
|
exports.OSR_CUSTOMER_DRIVE = OSR_CUSTOMER_DRIVE;
|
|
const OA_ROOT = (key = 'OA-ROOT') => (0, exports.get_var)(key);
|
|
exports.OA_ROOT = OA_ROOT;
|
|
const OSR_USER_ASSETS = (key = 'OSR-USER-ASSETS') => (0, exports.get_var)(key);
|
|
exports.OSR_USER_ASSETS = OSR_USER_ASSETS;
|
|
const POLYMECH_ROOT = (key = 'POLYMECH-ROOT') => (0, exports.get_var)(key) || path.join((0, exports.HOME)('desktop'), exports.API_PREFIX_NEXT);
|
|
exports.POLYMECH_ROOT = POLYMECH_ROOT;
|
|
exports.DEFAULT_ROOTS = {
|
|
OSR_ROOT: (0, exports.OSR_ROOT)(),
|
|
OSR_TEMP: (0, exports.OSR_TEMP)(),
|
|
PRODUCT_ROOT: (0, exports.PRODUCT_ROOT)(),
|
|
OA_ROOT: (0, exports.OA_ROOT)(),
|
|
KB_ROOT: (0, exports.KB_ROOT)(),
|
|
OSR_CACHE: (0, exports.OSR_CACHE)(),
|
|
OSR_LIBRARY: (0, exports.OSR_LIBRARY)(),
|
|
OSR_LIBRARY_MACHINES: (0, exports.OSR_LIBRARY_MACHINES)(),
|
|
OSR_LIBRARY_DIRECTORY: (0, exports.OSR_LIBRARY_DIRECTORY)(),
|
|
OSR_USER_ASSETS: (0, exports.OSR_USER_ASSETS)(),
|
|
OSR_PRIVATE: (0, exports.OSR_PRIVATE)(),
|
|
OSR_TEMPLATES: path.join((0, exports.OSR_SUB_DEFAULT)('osr-templates')),
|
|
OSR_CONTENT: path.join((0, exports.OSR_SUB_DEFAULT)('osr-content')),
|
|
OSR_PROFILES: path.join((0, exports.OSR_SUB_DEFAULT)('osr-profiles')),
|
|
OSR_CUSTOMER_DRIVE: (0, exports.OSR_CUSTOMER_DRIVE)(),
|
|
POLYMECH_ROOT: (0, exports.POLYMECH_ROOT)()
|
|
};
|
|
const CONFIG_DEFAULT = (key = 'OSR-CONFIG') => {
|
|
const cPath = path.resolve((0, exports.CONFIG_DEFAULT_PATH)(key));
|
|
if ((0, exists_1.sync)(cPath)) {
|
|
return (0, read_1.sync)(cPath, 'json');
|
|
}
|
|
else {
|
|
debug.error(`CLI-COMMONS: Can't read config for key "${key}" at ${cPath}`);
|
|
}
|
|
return false;
|
|
};
|
|
exports.CONFIG_DEFAULT = CONFIG_DEFAULT;
|
|
//# sourceMappingURL=config.js.map
|