diff --git a/.env.initial b/.env.initial new file mode 100644 index 0000000..c1dfcc3 --- /dev/null +++ b/.env.initial @@ -0,0 +1 @@ +REPO_ID=807741852 diff --git a/src/rollout-tools/local/cli.mjs b/src/rollout-tools/local/cli.mjs index de81f83..b676d0e 100755 --- a/src/rollout-tools/local/cli.mjs +++ b/src/rollout-tools/local/cli.mjs @@ -31,6 +31,54 @@ const appendOrUpdateEnv = (key, value) => { fs.writeFileSync(envFilePath, envLines.join('\n') + '\n'); }; +// Helper function to copy variables from .env.initial to .env +const copyInitialEnvVariables = () => { + const initialEnvFilePath = '.env.initial'; + const envFilePath = '.env'; + + if (fs.existsSync(initialEnvFilePath)) { + const initialEnvContent = fs.readFileSync(initialEnvFilePath, 'utf8'); + const initialEnvLines = initialEnvContent + .split('\n') + .filter((line) => line.trim() !== ''); // Remove empty lines + + const envContent = fs.existsSync(envFilePath) + ? fs.readFileSync(envFilePath, 'utf8') + : ''; + const envLines = envContent + .split('\n') + .filter((line) => line.trim() !== ''); // Remove empty lines + + const envVariables = new Map( + envLines.map((line) => { + const [key, value] = line.split('='); + return [key?.trim(), value?.trim()]; + }), + ); + + initialEnvLines.forEach((line) => { + const [key, value] = line.split('='); + if (!envVariables.has(key?.trim())) { + envVariables.set(key?.trim(), value?.trim()); + } + }); + + const updatedEnvContent = Array.from(envVariables) + .map(([key, value]) => `${key}=${value}`) + .join('\n'); + + fs.writeFileSync(envFilePath, updatedEnvContent + '\n'); + } else { + console.log( + colorText( + 'The .env.initial file is missing. This file is automatically generated when creating a new repository from the GitHub template. Please wait for the action to complete and update your branch afterward. The file should appear in the project root.', + 'red', + ), + ); + process.exit(1); + } +}; + // Helper function for coloring text const colorText = (text, color) => { const colors = { @@ -132,6 +180,9 @@ const main = async () => { ), ); + // Check for .env.initial and copy variables to .env + copyInitialEnvVariables(); + // Step 1: Vercel login console.log( colorText( diff --git a/src/rollout-tools/local/services.mjs b/src/rollout-tools/local/services.mjs index 4830228..0341f55 100644 --- a/src/rollout-tools/local/services.mjs +++ b/src/rollout-tools/local/services.mjs @@ -174,6 +174,7 @@ export async function getVercelProjects() { ); if (response.status.toString().startsWith('4')) { + console.error(response.status); throw new Error('Error getVercelProjects'); }