UNPKG

@trapi/metadata

Version:

Generate REST-API metadata scheme from TypeScript Decorators.

53 lines 1.97 kB
"use strict"; /* * Copyright (c) 2021. * Author Peter Placzek (tada5hi) * For the full copyright and license information, * view the LICENSE file that was distributed with this source code. */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.generateFileHash = exports.buildCacheOptions = void 0; const node_os_1 = require("node:os"); const node_path_1 = __importDefault(require("node:path")); const node_crypto_1 = __importDefault(require("node:crypto")); const node_process_1 = __importDefault(require("node:process")); function buildCacheOptions(input) { if (typeof input === 'string') { input = { enabled: true, directoryPath: input, }; } if (typeof input === 'boolean') { input = { enabled: input, }; } input = input || {}; /* istanbul ignore next */ const isTestEnvironment = !!node_process_1.default.env.NODE_ENV && node_process_1.default.env.NODE_ENV === 'test'; let directoryPath = (0, node_os_1.tmpdir)(); if (typeof input.directoryPath === 'string') { directoryPath = node_path_1.default.isAbsolute(input.directoryPath) ? input.directoryPath : node_path_1.default.join(node_process_1.default.cwd(), input.directoryPath); } return { fileName: input.fileName, directoryPath, enabled: input.enabled ?? true, clearAtRandom: input.clearAtRandom ?? !isTestEnvironment, }; } exports.buildCacheOptions = buildCacheOptions; function generateFileHash(sourceFilesSize) { const hash = node_crypto_1.default.createHash('sha256'); const strSize = (sourceFilesSize ?? 0).toString(); hash.update(strSize); return hash.digest('hex'); } exports.generateFileHash = generateFileHash; //# sourceMappingURL=utils.js.map