t-comm
Version:
专业、稳定、纯粹的工具库
35 lines (32 loc) • 1.1 kB
JavaScript
import * as fs from 'fs';
import * as path from 'path';
import { readEnvVariable } from '../env-variable/env-variable.mjs';
function getPublishRootDir() {
var rootDir = process.cwd();
return rootDir;
}
function findPublishSh(dir) {
var FILE_NAME = 'publish.sh';
var file = path.resolve(dir, FILE_NAME);
if (fs.existsSync(file)) {
return file;
}
}
function getPublishBashPath() {
return findPublishSh(path.resolve(__dirname, '..')) || findPublishSh(path.resolve(__dirname, '../bin')) || findPublishSh(path.resolve(__dirname, '../../bin')) || 'ERROR_FILE';
}
function getPublishEnvValue(key) {
var rootDir = getPublishRootDir();
var localEnvPath = path.join(rootDir, '.env.local');
var envPath = path.join(rootDir, '.env');
var envValue = readEnvVariable(key, envPath);
var localEnvValue = readEnvVariable(key, localEnvPath);
return localEnvValue || envValue || '';
}
function getPublishModuleName(dir) {
if (dir === void 0) {
dir = '';
}
return dir.split('/')[1] || '';
}
export { getPublishBashPath, getPublishEnvValue, getPublishModuleName, getPublishRootDir };