Skip to content

Commit

Permalink
Update rollout CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
usulpro committed Jun 17, 2024
1 parent 9964d6e commit a461827
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
14 changes: 14 additions & 0 deletions src/rollout-tools/local/cli.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ const promptForToken = async (tokenName, promptMessage) => {

const promptForProjectName = async () => {
const env = loadEnvVariables();
if (!env['PROJECT_NAME'] && env['REPO_NAME']) {
try {
const name = env['REPO_NAME'].split('/').at(-1);
if (name) {
env['PROJECT_NAME'] = name;
}
} catch (e) {}
}
if (env['PROJECT_NAME']) {
const { useCurrent } = await inquirer.prompt({
type: 'confirm',
Expand Down Expand Up @@ -175,6 +183,12 @@ const main = async () => {
console.log(
'2. After logging in, create an API access token at: https://vercel.com/account/tokens',
);
console.log(
colorText(
'3. Note that you have to choose a team when generating a token. Select that team on the next step',
'red',
),
);
console.log(colorText('The token will be saved in the .env file.', 'dim'));
const vercelToken = await promptForToken(
'VERCEL_PERSONAL_AUTH_TOKEN',
Expand Down
10 changes: 3 additions & 7 deletions src/rollout-tools/local/localFlow.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -162,27 +162,23 @@ export async function localFlow({ inputs, secrets }) {
}

// Step 5: Fill the dataset with data from prod-copy.tar.gz
const step5Spinner = ora(
'Filling the dataset with data from prod-copy.tar.gz...',
).start();
console.log('\nFilling the dataset with data from prod-copy.tar.gz...\n');
try {
await new Promise((resolve, reject) => {
exec(
`SANITY_AUTH_TOKEN=${secrets.SANITY_AUTH_TOKEN} npx sanity dataset import initial-data.tar.gz ${sanityDatasetName}`,
(error, stdout, stderr) => {
if (error) {
console.error(`Error importing dataset: ${stderr}`);
step5Spinner.fail('Failed to fill the dataset with data.');
return reject(error);
}
console.log(`Dataset imported: ${stdout}`);
step5Spinner.succeed('Dataset filled with data.');
console.log(`\n\nDataset imported: ${stdout}`);
resolve();
},
);
});
} catch (error) {
step5Spinner.fail('Failed to fill the dataset with data.');
console.error('Failed to fill the dataset with data.');
throw error;
}

Expand Down
3 changes: 0 additions & 3 deletions src/rollout-tools/local/services.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export async function createSanityProject(projectName) {
}

const data = await response.json();
console.log('🚀 ~ Sanity Project', JSON.stringify(data));
spinner.succeed('Sanity project created successfully! ✅');
return data.id;
} catch (error) {
Expand Down Expand Up @@ -143,14 +142,12 @@ export async function createVercelProject({

if (response.status.toString().startsWith('4')) {
spinner.fail('Failed to create Vercel project.');
console.log('Body:', body);
const message = await response.json();
console.error(message);
throw new Error('Error createVercelProject');
}

const data = await response.json();
console.log('🚀 Vercel Project:', JSON.stringify(data, null, 2));
spinner.succeed('Vercel project created successfully! ✅');
return {
projectId: data.id,
Expand Down

0 comments on commit a461827

Please sign in to comment.