chore(repo): consolidate local env and clean root files
This commit is contained in:
@@ -9,13 +9,12 @@ import {
|
||||
createAwsV4Headers,
|
||||
encodeObjectKey,
|
||||
getCacheControl,
|
||||
loadRepoEnv,
|
||||
normalizeEndpoint,
|
||||
parseSimpleEnv,
|
||||
requestDogeCloudTemporaryS3Session,
|
||||
} from './oss-deploy-lib.mjs';
|
||||
|
||||
const repoRoot = process.cwd();
|
||||
const envFilePath = path.join(repoRoot, '.env.oss.local');
|
||||
const apkSourcePath = path.join(repoRoot, 'front', 'android', 'app', 'build', 'outputs', 'apk', 'debug', 'app-debug.apk');
|
||||
|
||||
function parseArgs(argv) {
|
||||
@@ -24,24 +23,6 @@ function parseArgs(argv) {
|
||||
};
|
||||
}
|
||||
|
||||
async function loadEnvFileIfPresent() {
|
||||
try {
|
||||
const raw = await fs.readFile(envFilePath, 'utf-8');
|
||||
const values = parseSimpleEnv(raw);
|
||||
for (const [key, value] of Object.entries(values)) {
|
||||
if (!process.env[key]) {
|
||||
process.env[key] = value;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
if (error && typeof error === 'object' && 'code' in error && error.code === 'ENOENT') {
|
||||
return;
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
function requireEnv(name) {
|
||||
const value = process.env[name];
|
||||
if (!value) {
|
||||
@@ -133,7 +114,7 @@ async function uploadFile({
|
||||
|
||||
async function main() {
|
||||
const {dryRun} = parseArgs(process.argv.slice(2));
|
||||
await loadEnvFileIfPresent();
|
||||
await loadRepoEnv({repoRoot});
|
||||
|
||||
const androidScope = getAndroidReleaseScope();
|
||||
if (!androidScope) {
|
||||
|
||||
@@ -13,16 +13,15 @@ import {
|
||||
getFrontendSpaAliasKeys,
|
||||
getCacheControl,
|
||||
getContentType,
|
||||
loadRepoEnv,
|
||||
listFiles,
|
||||
normalizeEndpoint,
|
||||
parseSimpleEnv,
|
||||
requestDogeCloudTemporaryS3Session,
|
||||
} from './oss-deploy-lib.mjs';
|
||||
|
||||
const repoRoot = process.cwd();
|
||||
const frontDir = path.join(repoRoot, 'front');
|
||||
const distDir = path.join(frontDir, 'dist');
|
||||
const envFilePath = path.join(repoRoot, '.env.oss.local');
|
||||
|
||||
function parseArgs(argv) {
|
||||
return {
|
||||
@@ -31,24 +30,6 @@ function parseArgs(argv) {
|
||||
};
|
||||
}
|
||||
|
||||
async function loadEnvFileIfPresent() {
|
||||
try {
|
||||
const raw = await fs.readFile(envFilePath, 'utf-8');
|
||||
const values = parseSimpleEnv(raw);
|
||||
for (const [key, value] of Object.entries(values)) {
|
||||
if (!process.env[key]) {
|
||||
process.env[key] = value;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
if (error && typeof error === 'object' && 'code' in error && error.code === 'ENOENT') {
|
||||
return;
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
function requireEnv(name) {
|
||||
const value = process.env[name];
|
||||
if (!value) {
|
||||
@@ -156,7 +137,7 @@ async function uploadSpaAliases({
|
||||
async function main() {
|
||||
const {dryRun, skipBuild} = parseArgs(process.argv.slice(2));
|
||||
|
||||
await loadEnvFileIfPresent();
|
||||
await loadRepoEnv({repoRoot});
|
||||
|
||||
const apiAccessKey = requireEnv('YOYUZH_DOGECLOUD_API_ACCESS_KEY');
|
||||
const apiSecretKey = requireEnv('YOYUZH_DOGECLOUD_API_SECRET_KEY');
|
||||
|
||||
@@ -299,3 +299,28 @@ export function parseSimpleEnv(rawText) {
|
||||
|
||||
return parsed;
|
||||
}
|
||||
|
||||
export async function loadRepoEnv({
|
||||
repoRoot,
|
||||
candidateFileNames = ['.env.local', '.env', '.env.oss.local'],
|
||||
}) {
|
||||
for (const fileName of candidateFileNames) {
|
||||
const filePath = path.join(repoRoot, fileName);
|
||||
|
||||
try {
|
||||
const raw = await fs.readFile(filePath, 'utf-8');
|
||||
const values = parseSimpleEnv(raw);
|
||||
for (const [key, value] of Object.entries(values)) {
|
||||
if (!process.env[key]) {
|
||||
process.env[key] = value;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
if (error && typeof error === 'object' && 'code' in error && error.code === 'ENOENT') {
|
||||
continue;
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user