diff --git a/README.md b/README.md index e751f77..14a4958 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,11 @@ To override binary download URL: $ CYPRESS_MOON_BINARY=https://company.example.com/download/cypress-moon npm install @aerokube/cypress-moon --save-dev ``` +or use a .npmrc config with your own mirror: +` +CYPRESS_MOON_MIRROR=https://company.example.com/download/cypress-moon +` + To use binary already present on the file system: ``` diff --git a/lib/index.js b/lib/index.js index fcbe024..4b85e81 100644 --- a/lib/index.js +++ b/lib/index.js @@ -33,7 +33,8 @@ async function cypressMoon() { const outputPath = path.join(dest, binName); await fs.promises.mkdir(dest, {recursive: true}); - const binaryUrlOverride = process.env.CYPRESS_MOON_BINARY; + const cypressMoonMirror = process.env.npm_config_CYPRESS_MOON_MIRROR; + const binaryUrlOverride = process.env.CYPRESS_MOON_BINARY const binaryUrlIsLocalPath = await fileExists(binaryUrlOverride); if (binaryUrlIsLocalPath) { console.log(`Using local binary from ${binaryUrlOverride}...`); @@ -41,9 +42,14 @@ async function cypressMoon() { } const exists = await fileExists(outputPath); if (!exists) { - const url = binaryUrlOverride ? - binaryUrlOverride : - `https://github.com/aerokube/moon/releases/download/${moonVersion}/${binName}`; + let url + if (cypressMoonMirror) { + url = `${cypressMoonMirror}/${moonVersion}/${binName}` + } else if (binaryUrlOverride) { + url = binaryUrlOverride + } else { + url = `https://github.com/aerokube/moon/releases/download/${moonVersion}/${binName}`; + } console.log(`Downloading binary from ${url}...`); await downloadFile(url, outputPath); await fs.promises.chmod(outputPath, 0o755);