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

Added binPrefix option, to support running via Bazel #653

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 3 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
8 changes: 6 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export interface Logger {

export interface Options {
dryRun: boolean;
binPrefix: string;
gtsRootDir: string;
targetRootDir: string;
yes: boolean;
Expand Down Expand Up @@ -69,6 +70,7 @@ const cli = meow({
-n, --no Assume a no answer for every prompt.
--dry-run Don't make any actual changes.
--yarn Use yarn instead of npm.
--bin-prefix Directory containing node_modules. Used for running eslint.

Examples
$ gts init -y
Expand All @@ -81,6 +83,7 @@ const cli = meow({
yes: {type: 'boolean', alias: 'y'},
no: {type: 'boolean', alias: 'n'},
dryRun: {type: 'boolean'},
binPrefix: {type: 'string'},
yarn: {type: 'boolean'},
},
});
Expand Down Expand Up @@ -115,6 +118,7 @@ export async function run(verb: string, files: string[]): Promise<boolean> {

const options = {
dryRun: cli.flags.dryRun || false,
binPrefix: cli.flags.binPrefix || '.',
// Paths are relative to the transpiled output files.
gtsRootDir: path.resolve(__dirname, '../..'),
targetRootDir: process.cwd(),
Expand Down Expand Up @@ -145,7 +149,7 @@ export async function run(verb: string, files: string[]): Promise<boolean> {
case 'lint':
case 'check': {
try {
await execa('node', ['./node_modules/eslint/bin/eslint', ...flags], {
await execa('node', [options.binPrefix + '/node_modules/eslint/bin/eslint', ...flags], {
stdio: 'inherit',
});
return true;
Expand All @@ -158,7 +162,7 @@ export async function run(verb: string, files: string[]): Promise<boolean> {
try {
await execa(
'node',
['./node_modules/eslint/bin/eslint', fixFlag, ...flags],
[options.binPrefix + '/node_modules/eslint/bin/eslint', fixFlag, ...flags],
{
stdio: 'inherit',
}
Expand Down