Skip to content

Commit

Permalink
feat(index): run git commands if working directory is a git repo
Browse files Browse the repository at this point in the history
  • Loading branch information
remarkablemark committed Jun 5, 2020
1 parent 210db34 commit 14a61d8
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ process.on('exit', code => {
*/
log(`${name} v${version}`);

/**
* Check if current working directory is git repository.
*/
let isGitRepository = true;
try {
exec(`git -C ${cwd} rev-parse`);
} catch (err) {
isGitRepository = false;
}

/**
* Check if `package.json` exists.
*/
Expand All @@ -74,7 +84,7 @@ const devDependencies = [
'standard-version'
];
exec(`npm install --save-dev ${devDependencies.join(' ')}`);
exec('git add package.json');
isGitRepository && exec('git add package.json');

/**
* Copy files.
Expand All @@ -86,15 +96,16 @@ readdirSync(filesPath).forEach(filename => {
const destination = resolve(cwd, filename);
log(`Copying \`${filename}\`...`);
copyFileSync(source, destination);
exec(`git add ${filename}`);
isGitRepository && exec(`git add ${filename}`);
});

/**
* Commit changes.
*/
log('Committing changes...');
exec(
'git commit -m "chore: run `conventional-release-setup`" -m "https://github.com/remarkablemark/conventional-release-setup"'
);
isGitRepository &&
exec(
'git commit -m "chore: run `conventional-release-setup`" -m "https://github.com/remarkablemark/conventional-release-setup"'
);

log(`${name} done`);

0 comments on commit 14a61d8

Please sign in to comment.