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

[nextjs][RAV] Install pre-push-hook to root .git #1472

Merged
merged 5 commits into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Our versioning strategy is as follows:
* `[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)) ([#1444](https://github.com/Sitecore/jss/pull/1444)) ([#1468](https://github.com/Sitecore/jss/pull/1468))
([#1472](https://github.com/Sitecore/jss/pull/1472))
* `[sitecore-jss-nextjs] Add a new handling for token $siteLang(context site language) in middleware redirect ([#1454](https://github.com/Sitecore/jss/pull/1454))

### 🧹 Chores
Expand Down
5 changes: 4 additions & 1 deletion packages/create-sitecore-jss/src/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,15 @@ export const main = async (args: ParsedArgs) => {
type: 'confirm',
name: 'prePushHook',
message: 'Would you like to use the pre-push hook for linting check?',
default: false,
});

args.prePushHook = answer.prePushHook;
}
} else {
args.prePushHook = true;
if (args.prePushHook === null) {
args.prePushHook = false;
}
}

try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
import * as fs from 'fs';
import * as path from 'path';
import { promisify } from 'util';
import { exec } from 'child_process';
import chalk from 'chalk';

const installHooks = () => {
// data to be written to the file
const data = `#!/bin/sh
const installHooks = async () => {
try {
const appPath = path.join(__dirname, '..').replace(/\\/g, '/');
const { stdout } = await promisify(exec)('git rev-parse --show-toplevel');
const gitRootPath = stdout.trim();
console.log(chalk.green(`Writing data to local .git folder ${gitRootPath}...`));

const data = `#!/bin/sh
#
# pre-push hook runs our linter before we push our changes
#
# To skip this hook, use the --no-verify flag
# when pushing.
#

echo "Running lint check..."
cd ${appPath}
npm run lint`;

// \x1b[32m%s\x1b[0m - set color to green, insert the string, reset color after string is logged to console
console.log('\x1b[32m%s\x1b[0m', 'Writing to local .git folder...');

// Write the hook to the local .git folder. Using writeFile in order to catch any errors
fs.writeFile('./.git/hooks/pre-push', data, 'utf8', (err: Error) => {
if (err) {
console.log('\x1b[31m%o\x1b[0m', err);
} else {
console.log('\x1b[32m%s\x1b[0m', 'Success!');
}
});
await promisify(fs.writeFile)(`${gitRootPath}/.git/hooks/pre-push`, data, 'utf8');
console.log(chalk.green('Success'));
} catch (error) {
console.log(chalk.red(`Error installing hook: ${error}`));
}
};

installHooks();
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
import fs from 'fs';
import path from 'path';
import { promisify } from 'util';
import { exec } from 'child_process';
import chalk from 'chalk';

const installHooks = () => {
// data to be written to the file
const data = `#!/bin/sh
#
# pre-push hook runs our linter before we push our changes
#
# To skip this hook, use the --no-verify flag
# when pushing.
#
echo "Running lint check..."
npm run lint`;
const installHooks = async () => {
try {
const appPath = path.join(__dirname, '..').replace(/\\/g, '/');
const { stdout } = await promisify(exec)('git rev-parse --show-toplevel');
const gitRootPath = stdout.trim();
console.log(chalk.green(`Writing data to local .git folder ${gitRootPath}...`));

// \x1b[32m%s\x1b[0m - set color to green, insert the string, reset color after string is logged to console
console.log('\x1b[32m%s\x1b[0m', 'Writing to local .git folder...');
const data = `#!/bin/sh
#
# pre-push hook runs our linter before we push our changes
#
# To skip this hook, use the --no-verify flag
# when pushing.
#
echo "Running lint check..."
cd ${appPath}
npm run lint`;

// Write the hook to the local .git folder. Using writeFile in order to catch any errors
fs.writeFile('./.git/hooks/pre-push', data, 'utf8', err => {
if (err) {
console.log('\x1b[31m%o\x1b[0m', err);
} else {
console.log('\x1b[32m%s\x1b[0m', 'Success!');
}
});
await promisify(fs.writeFile)(`${gitRootPath}/.git/hooks/pre-push`, data, 'utf8');
console.log(chalk.green('Success'));
} catch (error) {
console.log(chalk.red(`Error installing hook: ${error}`));
}
};

installHooks();
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
const fs = require('fs');
const fs = require('fs');
const path = require('path');
const { promisify } = require('util');
const { exec } = require('child_process');
const chalk = require('chalk');

const installHooks = () => {
// data to be written to the file
const data = `#!/bin/sh
#
# pre-push hook runs our linter before we push our changes
#
# To skip this hook, use the --no-verify flag
# when pushing.
#
echo "Running lint check..."
npm run lint`;
const installHooks = async () => {
try {
const appPath = path.join(__dirname, '..').replace(/\\/g, '/');
const { stdout } = await promisify(exec)('git rev-parse --show-toplevel');
const gitRootPath = stdout.trim();
console.log(chalk.green(`Writing data to local .git folder ${gitRootPath}...`));

// \x1b[32m%s\x1b[0m - set color to green, insert the string, reset color after string is logged to console
console.log('\x1b[32m%s\x1b[0m', 'Writing to local .git folder...');
const data = `#!/bin/sh
#
# pre-push hook runs our linter before we push our changes
#
# To skip this hook, use the --no-verify flag
# when pushing.
#
echo "Running lint check..."
cd ${appPath}
npm run lint`;

// Write the hook to the local .git folder. Using writeFile in order to catch any errors
fs.writeFile('./.git/hooks/pre-push', data, 'utf8', err => {
if (err) {
console.log('\x1b[31m%o\x1b[0m', err);
} else {
console.log('\x1b[32m%s\x1b[0m', 'Success!');
}
});
await promisify(fs.writeFile)(`${gitRootPath}/.git/hooks/pre-push`, data, 'utf8');
console.log(chalk.green('Success'));
} catch (error) {
console.log(chalk.red(`Error installing hook: ${error}`));
}
};

installHooks();
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
const fs = require('fs');
const fs = require('fs');
const path = require('path');
const { promisify } = require('util');
const { exec } = require('child_process');
const chalk = require('chalk');

const installHooks = () => {
// data to be written to the file
const data = `#!/bin/sh
#
# pre-push hook runs our linter before we push our changes
#
# To skip this hook, use the --no-verify flag
# when pushing.
#
echo "Running lint check..."
npm run lint`;
const installHooks = async () => {
try {
const appPath = path.join(__dirname, '..').replace(/\\/g, '/');
const { stdout } = await promisify(exec)('git rev-parse --show-toplevel');
const gitRootPath = stdout.trim();
console.log(chalk.green(`Writing data to local .git folder ${gitRootPath}...`));

// \x1b[32m%s\x1b[0m - set color to green, insert the string, reset color after string is logged to console
console.log('\x1b[32m%s\x1b[0m', 'Writing to local .git folder...');
const data = `#!/bin/sh
#
# pre-push hook runs our linter before we push our changes
#
# To skip this hook, use the --no-verify flag
# when pushing.
#
echo "Running lint check..."
cd ${appPath}
npm run lint`;

// Write the hook to the local .git folder. Using writeFile in order to catch any errors
fs.writeFile('./.git/hooks/pre-push', data, 'utf8', (err) => {
if (err) {
console.log('\x1b[31m%o\x1b[0m', err);
} else {
console.log('\x1b[32m%s\x1b[0m', 'Success!');
}
});
await promisify(fs.writeFile)(`${gitRootPath}/.git/hooks/pre-push`, data, 'utf8');
console.log(chalk.green('Success'));
} catch (error) {
console.log(chalk.red(`Error installing hook: ${error}`));
}
};

installHooks();