Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/commands/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ export async function init () {
// Write the new package json back
await writeProjectPackageJSON(newPackage);

// Ask for config the remote origin url
changeRemoteUrl(projectInfo.answer, projectInfo.name);

// Reset git and make first commit
resetGit(projectInfo.name);
}
Expand All @@ -39,8 +42,10 @@ async function promptProjectInfo () {
const folderName = paths.project.split('/').pop();
const name = await askDefault(`Name [${folderName}]: `, folderName || '');
const license = await askDefault('License [MIT]: ', 'MIT');
const projectUrl = getProjectUrl(name);
const answer = await askDefault(`Remote origin url "${projectUrl}"? [Y]`, 'Y');
close();
return {name, license};
return {name, license, answer};
}

// Get a string with the users git info, like "Hernan Rajchert <[email protected]>"
Expand All @@ -64,3 +69,20 @@ function resetGit (projectName: string) {
exec('git add .');
exec(`git commit -m "chore(general): Initialize ${projectName}"`);
}

function getProjectUrl (projectName: string) {
const username = getGitUserInfo().name;
return `https://github.com/${username}/${projectName}.git`;
}

function changeRemoteUrl (answer: string, projectName: string) {
if (answer.toLowerCase() === 'y' || answer.toLowerCase() === 'yes') {
execChangeRemoteUrl(projectName);
}
}

// Execute the command for changing the remote origin url
function execChangeRemoteUrl (projectName: string) {
const projectUrl = getProjectUrl(projectName);
exec(`git remote add origin ${projectUrl}`);
}