diff --git a/CHANGELOG.md b/CHANGELOG.md index 108ae30b83..add54c6ddd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,7 +26,7 @@ Our versioning strategy is as follows: * `[templates/nextjs-sxa]` Add custom template for _jss scaffold_ ([#1420](https://github.com/Sitecore/jss/pull/1420)) * `[sitecore-jss-react]` `[sitecore-jss-nextjs]` FEaaS component will render 'staged' variant for editing and preview and 'published' variant for live site by default, unless variant is overriden via rendering parameters. ([#1433](https://github.com/Sitecore/jss/pull/1433)) * `[templates/nextjs]` `[templates/angular]` `[templates/react]` `[templates/vue]` Pre-push hook for lint check ([#1427](https://github.com/Sitecore/jss/pull/1427)) -([#1442](https://github.com/Sitecore/jss/pull/1442)) +([#1442](https://github.com/Sitecore/jss/pull/1442)) ([#1444](https://github.com/Sitecore/jss/pull/1444)) ### 🧹 Chores diff --git a/packages/create-sitecore-jss/src/common/processes/install.test.ts b/packages/create-sitecore-jss/src/common/processes/install.test.ts index 6ff938822c..7f2c3bb6ae 100644 --- a/packages/create-sitecore-jss/src/common/processes/install.test.ts +++ b/packages/create-sitecore-jss/src/common/processes/install.test.ts @@ -12,7 +12,6 @@ describe('install', () => { let isDevEnvironment: SinonStub; let openPackageJson: SinonStub; let log: SinonStub; - const execStub = sinon.stub(childProcess, 'exec'); beforeEach(() => { run = sinon.stub(cmd, 'run'); @@ -152,6 +151,8 @@ describe('install', () => { }); describe('installPrePushHook', () => { + const execStub = sinon.stub(childProcess, 'exec'); + it('should run exec function', () => { const destination = './some/path'; @@ -175,12 +176,16 @@ describe('install', () => { ); }); - it('should log a warning message if there is an error', () => { + it('should log a warning message if there is an error', async () => { const destination = './some/path'; const error = new Error('some error'); execStub.yields(error); - installPrePushHook(destination); + try { + await installPrePushHook(destination); + } catch (err) { + expect(err).to.equal(error); + } expect(log).to.have.been.calledWith( chalk.yellow(`Warning: Pre-push hook may not be working due to error ${error}`) diff --git a/packages/create-sitecore-jss/src/common/processes/install.ts b/packages/create-sitecore-jss/src/common/processes/install.ts index eff0c21d62..16f22207ea 100644 --- a/packages/create-sitecore-jss/src/common/processes/install.ts +++ b/packages/create-sitecore-jss/src/common/processes/install.ts @@ -66,12 +66,18 @@ export const lintFix = (projectFolder: string, silent?: boolean) => { * @param {string} destination path to the app folder * @param {boolean} [silent] suppress logs */ -export const installPrePushHook = (destination: string, silent?: boolean) => { +export const installPrePushHook = async (destination: string, silent?: boolean) => { silent || console.log(chalk.cyan('Installing pre-push hook...')); - exec(`cd ${destination} && git init && npm run install-pre-push-hook`, (err) => { - if (err) { - console.log(chalk.yellow(`Warning: Pre-push hook may not be working due to error ${err}`)); - } + await new Promise((resolve, reject) => { + exec(`cd ${destination} && git init && npm run install-pre-push-hook`, (err) => { + if (err) { + console.log(chalk.yellow(`Warning: Pre-push hook may not be working due to error ${err}`)); + reject(err); + } else { + silent || console.log(chalk.cyan('Pre-push hook installed successfully!')); + resolve(); + } + }); }); }; diff --git a/packages/create-sitecore-jss/src/init-runner.ts b/packages/create-sitecore-jss/src/init-runner.ts index 9c01c3318d..b9b4fdf610 100644 --- a/packages/create-sitecore-jss/src/init-runner.ts +++ b/packages/create-sitecore-jss/src/init-runner.ts @@ -50,7 +50,7 @@ export const initRunner = async (initializers: string[], args: BaseArgs) => { // install pre-push hook if user opts-in if (args.prePushHook) { - installPrePushHook(args.destination, args.silent); + await installPrePushHook(args.destination, args.silent); } if (!args.silent) { diff --git a/packages/create-sitecore-jss/src/templates/angular/scripts/install-pre-push-hook.ts b/packages/create-sitecore-jss/src/templates/angular/scripts/install-pre-push-hook.ts index b9f4f46f11..1893652e2f 100644 --- a/packages/create-sitecore-jss/src/templates/angular/scripts/install-pre-push-hook.ts +++ b/packages/create-sitecore-jss/src/templates/angular/scripts/install-pre-push-hook.ts @@ -1,4 +1,4 @@ -import fs from 'fs'; +import * as fs from 'fs'; const installHooks = () => { // data to be written to the file