- Removed obsolete test script `test_crawl4ai_fit_markdown.py`. - Deleted `verify-package-main-obfuscation.mjs` as it is no longer needed. - Updated paths in `app-update-publish-config.test.ts` to reflect new script locations. - Refactored `package-content-policy.test.ts` to use new paths for content policy scripts. - Adjusted `package-main-obfuscation.test.ts` to point to the new obfuscation script locations. - Modified `package-size-budget.test.ts` to use updated paths for size budget scripts. - Changed `r2-update-metadata-contract.test.ts` to reference the new metadata script. - Updated `release-fragment-contract.test.ts` to use the new fragment contract script. - Refactored `release-storage-layout.test.ts` to point to the new storage layout script. - Added `runtime-trace.test.ts` to test runtime tracing functionality. - Updated `node-pty-native-release.test.ts` to reflect new paths for native release scripts.
53 lines
1.8 KiB
JavaScript
53 lines
1.8 KiB
JavaScript
import { access, readFile } from 'node:fs/promises'
|
|
import os from 'node:os'
|
|
import path from 'node:path'
|
|
import process from 'node:process'
|
|
|
|
export const loadReleaseEnvironment = async (root) => {
|
|
const filePath = path.join(root, '.env')
|
|
const content = await readFile(filePath, 'utf8').catch((error) => {
|
|
if (error?.code === 'ENOENT') return ''
|
|
throw error
|
|
})
|
|
for (const rawLine of content.split(/\r?\n/u)) {
|
|
const line = rawLine.trim()
|
|
if (!line || line.startsWith('#')) continue
|
|
const separator = line.indexOf('=')
|
|
if (separator < 1) throw new Error(`invalid release environment line: ${rawLine}`)
|
|
const name = line.slice(0, separator).trim()
|
|
let value = line.slice(separator + 1).trim()
|
|
if (
|
|
(value.startsWith('"') && value.endsWith('"')) ||
|
|
(value.startsWith("'") && value.endsWith("'"))
|
|
) {
|
|
value = value.slice(1, -1)
|
|
}
|
|
if (!process.env[name]) process.env[name] = value
|
|
}
|
|
|
|
if (!process.env.AWS_ACCESS_KEY_ID && process.env.R2_ACCESS_KEY_ID) {
|
|
process.env.AWS_ACCESS_KEY_ID = process.env.R2_ACCESS_KEY_ID
|
|
}
|
|
if (!process.env.AWS_SECRET_ACCESS_KEY && process.env.R2_SECRET_ACCESS_KEY) {
|
|
process.env.AWS_SECRET_ACCESS_KEY = process.env.R2_SECRET_ACCESS_KEY
|
|
}
|
|
|
|
if (process.platform === 'win32' && !process.env.NCURATOR_AWS_CLI) {
|
|
const candidates = [
|
|
process.env.ProgramFiles
|
|
? path.join(process.env.ProgramFiles, 'Amazon', 'AWSCLIV2', 'aws.exe')
|
|
: '',
|
|
path.join(os.homedir(), '.ncurator', 'release-tools', 'awscli', 'aws.exe')
|
|
].filter(Boolean)
|
|
for (const candidate of candidates) {
|
|
const exists = await access(candidate)
|
|
.then(() => true)
|
|
.catch(() => false)
|
|
if (exists) {
|
|
process.env.NCURATOR_AWS_CLI = candidate
|
|
break
|
|
}
|
|
}
|
|
}
|
|
}
|