Comparing version 0.1.0-alpha.6 to 0.1.0-alpha.7
#! /usr/bin/env node | ||
import { cosmiconfig } from "cosmiconfig"; | ||
import path from "path"; | ||
import yargs from "yargs"; | ||
import { runReporters, runRules } from "../core/index.js"; | ||
@@ -9,13 +10,20 @@ import { noFilter } from "../filter/noFilter.js"; | ||
import { resolvePackage } from "./resolvePackage.js"; | ||
main().catch((err) => { | ||
console.error(err); | ||
process.exit(1); | ||
}); | ||
async function main() { | ||
var _a; | ||
const explorer = cosmiconfig("akitainu"); | ||
const searchResult = await explorer.search(); | ||
yargs(process.argv.slice(2)) | ||
.command("$0 [configfile]", "Run akitainu", (yargs) => { | ||
return yargs.positional("configfile", { | ||
type: "string", | ||
}); | ||
}, (argv) => { | ||
const configFile = argv.configfile; | ||
main(configFile).catch((err) => { | ||
console.error(err); | ||
process.exit(1); | ||
}); | ||
}) | ||
.help().argv; | ||
async function main(configFile) { | ||
const { configDir, config: rawConfig } = await loadConfig(configFile); | ||
const config = { | ||
...getDefaultConfig(searchResult ? path.dirname(searchResult.filepath) : process.cwd()), | ||
...((_a = searchResult === null || searchResult === void 0 ? void 0 : searchResult.config) !== null && _a !== void 0 ? _a : {}), | ||
...getDefaultConfig(configDir), | ||
...rawConfig, | ||
}; | ||
@@ -38,2 +46,15 @@ const [rules, reporters] = await Promise.all([ | ||
} | ||
async function loadConfig(configFile) { | ||
var _a; | ||
const explorer = cosmiconfig("akitainu"); | ||
const searchResult = configFile === undefined | ||
? await explorer.search() | ||
: await explorer.load(configFile); | ||
return { | ||
configDir: searchResult | ||
? path.dirname(searchResult.filepath) | ||
: process.cwd(), | ||
config: (_a = searchResult === null || searchResult === void 0 ? void 0 : searchResult.config) !== null && _a !== void 0 ? _a : {}, | ||
}; | ||
} | ||
function getRules(config) { | ||
@@ -40,0 +61,0 @@ return Promise.all(config.rules.map(async (rule) => ({ |
@@ -6,2 +6,3 @@ import chalk from "chalk"; | ||
async run({ errors }) { | ||
console.log(`Found ${errors.length || "no"} error${errors.length > 1 ? "s" : ""}.\n`); | ||
for (const { checker, code, message, location } of errors) { | ||
@@ -8,0 +9,0 @@ const loc = !location |
{ | ||
"name": "akitainu", | ||
"version": "0.1.0-alpha.6", | ||
"version": "0.1.0-alpha.7", | ||
"description": "Gradual code linting tool", | ||
@@ -31,2 +31,3 @@ "main": "dist/index.js", | ||
"@types/jest": "^26.0.22", | ||
"@types/yargs": "^15.0.13", | ||
"babel-jest": "^26.6.3", | ||
@@ -38,4 +39,5 @@ "jest": "^27.0.0-next.9", | ||
"chalk": "^4.1.0", | ||
"cosmiconfig": "^7.0.0" | ||
"cosmiconfig": "^7.0.0", | ||
"yargs": "^16.2.0" | ||
} | ||
} |
@@ -5,2 +5,3 @@ #! /usr/bin/env node | ||
import path from "path"; | ||
import yargs from "yargs"; | ||
import { Checker } from "../checker/index.js"; | ||
@@ -17,15 +18,26 @@ import { runReporters, runRules } from "../core/index.js"; | ||
main().catch((err) => { | ||
console.error(err); | ||
process.exit(1); | ||
}); | ||
yargs(process.argv.slice(2)) | ||
.command( | ||
"$0 [configfile]", | ||
"Run akitainu", | ||
(yargs) => { | ||
return yargs.positional("configfile", { | ||
type: "string", | ||
}); | ||
}, | ||
(argv) => { | ||
const configFile = argv.configfile; | ||
main(configFile).catch((err) => { | ||
console.error(err); | ||
process.exit(1); | ||
}); | ||
} | ||
) | ||
.help().argv; | ||
async function main() { | ||
const explorer = cosmiconfig("akitainu"); | ||
const searchResult = await explorer.search(); | ||
async function main(configFile: string | undefined) { | ||
const { configDir, config: rawConfig } = await loadConfig(configFile); | ||
const config: CliConfig = { | ||
...getDefaultConfig( | ||
searchResult ? path.dirname(searchResult.filepath) : process.cwd() | ||
), | ||
...(searchResult?.config ?? {}), | ||
...getDefaultConfig(configDir), | ||
...rawConfig, | ||
}; | ||
@@ -52,2 +64,16 @@ const [rules, reporters] = await Promise.all([ | ||
async function loadConfig(configFile: string | undefined) { | ||
const explorer = cosmiconfig("akitainu"); | ||
const searchResult = | ||
configFile === undefined | ||
? await explorer.search() | ||
: await explorer.load(configFile); | ||
return { | ||
configDir: searchResult | ||
? path.dirname(searchResult.filepath) | ||
: process.cwd(), | ||
config: searchResult?.config ?? {}, | ||
}; | ||
} | ||
function getRules(config: CliConfig): Promise<Rule[]> { | ||
@@ -54,0 +80,0 @@ return Promise.all( |
@@ -13,2 +13,5 @@ import chalk from "chalk"; | ||
async run({ errors }) { | ||
console.log( | ||
`Found ${errors.length || "no"} error${errors.length > 1 ? "s" : ""}.\n` | ||
); | ||
for (const { checker, code, message, location } of errors) { | ||
@@ -15,0 +18,0 @@ const loc = !location |
Sorry, the diff of this file is not supported yet
39091
1110
3
8
+ Addedyargs@^16.2.0
+ Addedansi-regex@5.0.1(transitive)
+ Addedcliui@7.0.4(transitive)
+ Addedemoji-regex@8.0.0(transitive)
+ Addedescalade@3.2.0(transitive)
+ Addedget-caller-file@2.0.5(transitive)
+ Addedis-fullwidth-code-point@3.0.0(transitive)
+ Addedrequire-directory@2.1.1(transitive)
+ Addedstring-width@4.2.3(transitive)
+ Addedstrip-ansi@6.0.1(transitive)
+ Addedwrap-ansi@7.0.0(transitive)
+ Addedy18n@5.0.8(transitive)
+ Addedyargs@16.2.0(transitive)
+ Addedyargs-parser@20.2.9(transitive)