fix(core): update
This commit is contained in:
73
ts/mod_commit/index.ts
Normal file
73
ts/mod_commit/index.ts
Normal file
@@ -0,0 +1,73 @@
|
||||
// this file contains code to create commits in a consistent way
|
||||
|
||||
import * as plugins from './mod.plugins.js';
|
||||
import * as paths from '../paths.js';
|
||||
import { logger } from '../gitzone.logging.js';
|
||||
|
||||
export const run = async (argvArg: any) => {
|
||||
const commitInteract = new plugins.smartinteract.SmartInteract();
|
||||
commitInteract.addQuestions([
|
||||
{
|
||||
type: 'list',
|
||||
name: `commitType`,
|
||||
message: `Choose TYPE of the commit:`,
|
||||
choices: [`fix`, `feat`, `BREAKING CHANGE`],
|
||||
default: `fix`,
|
||||
},
|
||||
{
|
||||
type: 'input',
|
||||
name: `commitScope`,
|
||||
message: `What is the SCOPE of the commit:`,
|
||||
default: `core`,
|
||||
},
|
||||
{
|
||||
type: `input`,
|
||||
name: `commitDescription`,
|
||||
message: `What is the DESCRIPTION of the commit?`,
|
||||
default: `update`,
|
||||
},
|
||||
{
|
||||
type: 'confirm',
|
||||
name: `pushToOrigin`,
|
||||
message: `Do you want to push this version now?`,
|
||||
default: true,
|
||||
},
|
||||
]);
|
||||
const answerBucket = await commitInteract.runQueue();
|
||||
const commitString = createCommitStringFromAnswerBucket(answerBucket);
|
||||
const commitVersionType = (() => {
|
||||
switch (answerBucket.getAnswerFor('commitType')) {
|
||||
case 'fix':
|
||||
return 'patch';
|
||||
case 'feat':
|
||||
return 'minor';
|
||||
case 'BREAKING CHANGE':
|
||||
return 'major';
|
||||
}
|
||||
})();
|
||||
|
||||
logger.log('info', `OK! Creating commit with message '${commitString}'`);
|
||||
const smartshellInstance = new plugins.smartshell.Smartshell({
|
||||
executor: 'bash',
|
||||
sourceFilePaths: [],
|
||||
});
|
||||
|
||||
logger.log('info', `Baking commitinfo into code`);
|
||||
const commitInfo = new plugins.commitinfo.CommitInfo(paths.cwd, commitVersionType);
|
||||
await commitInfo.writeIntoPotentialDirs();
|
||||
|
||||
logger.log('info', `Staging files for commit:`);
|
||||
await smartshellInstance.exec(`git add -A`);
|
||||
await smartshellInstance.exec(`git commit -m "${commitString}"`);
|
||||
await smartshellInstance.exec(`npm version ${commitVersionType}`);
|
||||
if (answerBucket.getAnswerFor('pushToOrigin') && !(process.env.CI === 'true')) {
|
||||
await smartshellInstance.exec(`git push origin master --follow-tags`);
|
||||
}
|
||||
};
|
||||
|
||||
const createCommitStringFromAnswerBucket = (answerBucket: plugins.smartinteract.AnswerBucket) => {
|
||||
const commitType = answerBucket.getAnswerFor('commitType');
|
||||
const commitScope = answerBucket.getAnswerFor('commitScope');
|
||||
const commitDescription = answerBucket.getAnswerFor('commitDescription');
|
||||
return `${commitType}(${commitScope}): ${commitDescription}`;
|
||||
};
|
7
ts/mod_commit/mod.plugins.ts
Normal file
7
ts/mod_commit/mod.plugins.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
export * from '../plugins.js';
|
||||
|
||||
import * as commitinfo from '@push.rocks/commitinfo';
|
||||
import * as smartinteract from '@push.rocks/smartinteract';
|
||||
import * as smartshell from '@push.rocks/smartshell';
|
||||
|
||||
export { commitinfo, smartinteract, smartshell };
|
Reference in New Issue
Block a user