Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pre-push-hook] Fix error when initializing angular app #1444

Merged
merged 8 commits into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -152,6 +151,8 @@ describe('install', () => {
});

describe('installPrePushHook', () => {
const execStub = sinon.stub(childProcess, 'exec');

it('should run exec function', () => {
const destination = './some/path';

Expand All @@ -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}`)
Expand Down
16 changes: 11 additions & 5 deletions packages/create-sitecore-jss/src/common/processes/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>((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();
}
});
});
};
2 changes: 1 addition & 1 deletion packages/create-sitecore-jss/src/init-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fs from 'fs';
import * as fs from 'fs';

const installHooks = () => {
// data to be written to the file
Expand Down