Skip to content

Commit

Permalink
Make requests
Browse files Browse the repository at this point in the history
  • Loading branch information
usulpro committed May 29, 2024
1 parent 4fadd1e commit 6d63690
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions .env.initial
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
REPO_ID=807741852
51 changes: 51 additions & 0 deletions src/rollout-tools/local/cli.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -132,6 +180,9 @@ const main = async () => {
),
);

// Check for .env.initial and copy variables to .env
copyInitialEnvVariables();

// Step 1: Vercel login
console.log(
colorText(
Expand Down
1 change: 1 addition & 0 deletions src/rollout-tools/local/services.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ export async function getVercelProjects() {
);

if (response.status.toString().startsWith('4')) {
console.error(response.status);
throw new Error('Error getVercelProjects');
}

Expand Down

0 comments on commit 6d63690

Please sign in to comment.