-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8e8fb4a
commit 4736a40
Showing
11 changed files
with
143 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { BaseContext } from "clipanion"; | ||
|
||
export type FrolintContext = BaseContext & { | ||
cwd: string; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Command } from "clipanion"; | ||
import { FrolintContext } from "../Context"; | ||
|
||
export class DefaultCommand extends Command<FrolintContext> { | ||
public static usage = Command.Usage({ | ||
description: "apply ESLint and Prettier", | ||
}); | ||
|
||
@Command.Path() | ||
public async execute() { | ||
console.log("Hello world"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Command } from "clipanion"; | ||
import { FrolintContext } from "../Context"; | ||
|
||
export class HelpCommand extends Command<FrolintContext> { | ||
@Command.Path("--help") | ||
@Command.Path("-h") | ||
public async execute() { | ||
this.context.stdout.write(this.cli.usage(null)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Command } from "clipanion"; | ||
import { FrolintContext } from "../Context"; | ||
import { gitExists, isInsideGitRepository } from "../utils"; | ||
|
||
export class InstallCommand extends Command<FrolintContext> { | ||
public static usage = Command.Usage({ | ||
description: "install git pre-commit hook for frolint", | ||
details: ` | ||
This command will insert the pre-commit hook script into .git/hooks/pre-commit. If there is no .git/hooks/pre-commit, this command will create the script file. | ||
`, | ||
}); | ||
|
||
@Command.Path("install") | ||
public async execute() { | ||
if (!gitExists()) { | ||
return; | ||
} | ||
|
||
if (!isInsideGitRepository(this.context.cwd)) { | ||
return; | ||
} | ||
|
||
this.context.stdout.write("Install"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Command } from "clipanion"; | ||
import { FrolintContext } from "../Context"; | ||
import { gitExists, isInsideGitRepository } from "../utils"; | ||
|
||
export class UninstallCommand extends Command<FrolintContext> { | ||
public static usage = Command.Usage({ | ||
description: "uninstall git pre-commit hook for frolint", | ||
details: ` | ||
This command will remove the pre-commit hook script from .git/hooks/pre-commit. | ||
`, | ||
}); | ||
|
||
@Command.Path("uninstall") | ||
public async execute() { | ||
if (!gitExists()) { | ||
return; | ||
} | ||
|
||
if (!isInsideGitRepository(this.context.cwd)) { | ||
return; | ||
} | ||
|
||
this.context.stdout.write("Uninstall"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export { DefaultCommand } from "./DefaultCommand"; | ||
export { HelpCommand } from "./HelpCommand"; | ||
export { InstallCommand } from "./InstallCommand"; | ||
export { UninstallCommand } from "./UninstallCommand"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,23 @@ | ||
console.log("hello world"); | ||
import { Cli } from "clipanion"; | ||
import { DefaultCommand, HelpCommand, InstallCommand, UninstallCommand } from "./commands"; | ||
import { FrolintContext } from "./Context"; | ||
const pkg = require("../package.json"); | ||
|
||
const cli = new Cli<FrolintContext>({ | ||
binaryLabel: "FROntend LINt Tool", | ||
binaryName: "frolint", | ||
binaryVersion: pkg.version, | ||
}); | ||
|
||
cli.register(DefaultCommand); | ||
cli.register(HelpCommand); | ||
cli.register(InstallCommand); | ||
cli.register(UninstallCommand); | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
cli.runExit(process.argv.slice(2), { | ||
stdin: process.stdin, | ||
stdout: process.stdout, | ||
stderr: process.stderr, | ||
cwd: process.cwd(), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { execSync } from "child_process"; | ||
import { sync as commandExistsSync } from "command-exists"; | ||
|
||
export function isInsideGitRepository(cwd?: string) { | ||
try { | ||
return Boolean( | ||
execSync("git rev-parse --is-inside-work-tree", { cwd }) | ||
.toString() | ||
.trim() | ||
); | ||
} catch (err) { | ||
return false; | ||
} | ||
} | ||
|
||
export function gitExists() { | ||
return commandExistsSync("git"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es5", | ||
"target": "es2017", | ||
"module": "commonjs", | ||
"strict": true, | ||
"noImplicitAny": true, | ||
"moduleResolution": "node", | ||
"allowSyntheticDefaultImports": true, | ||
"esModuleInterop": true, | ||
"experimentalDecorators": true | ||
"experimentalDecorators": true, | ||
"resolveJsonModule": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters