launch-express
Version:
CLI tool to setup a new Launch Express project
57 lines (54 loc) • 2.16 kB
JavaScript
import chalk from 'chalk';
import { outro, spinner } from '@clack/prompts';
import { execSync } from 'child_process';
import { REPO_URL } from '../utils.js';
export function showHelp() {
console.log(`
${chalk.dim('Update your current project with the latest changes from the template.')}
${chalk.yellow('Usage:')}
npx launch-express update
${chalk.yellow('Note:')}
This command should be run from your project's root directory.
It will merge the latest changes from the template while preserving your modifications.
`);
process.exit(0);
}
export async function execute() {
// Check if we're in a git repository
try {
execSync('git rev-parse --is-inside-work-tree', { stdio: 'ignore' });
}
catch (error) {
outro(chalk.red('Error: Not a git repository. Please run this command from your project root directory.'));
process.exit(1);
}
const s = spinner();
s.start('Updating your project');
try {
// Add the template repository as a remote
execSync(`git remote add template ${REPO_URL} 2>/dev/null || git remote set-url template ${REPO_URL}`);
// Fetch the latest changes
execSync('git fetch template');
// Merge the changes with --allow-unrelated-histories
try {
execSync('git merge template/main --allow-unrelated-histories -m "Merge updates from template"');
}
catch (error) {
s.stop('Merge conflicts detected');
outro(chalk.yellow('\nPlease resolve the conflicts manually:'));
console.log(chalk.blue('1. Fix the conflicts in the affected files'));
console.log(chalk.blue('2. git add .'));
console.log(chalk.blue('3. git commit -m "Resolve merge conflicts"'));
process.exit(1);
}
// Remove the template remote
execSync('git remote remove template');
s.stop('Project updated successfully!');
outro(chalk.green('Your project has been updated to the latest version.'));
}
catch (error) {
s.stop('Failed to update project');
console.error(error);
process.exit(1);
}
}