-
-
Notifications
You must be signed in to change notification settings - Fork 20
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
7b8a80e
commit 449f0e1
Showing
49 changed files
with
542 additions
and
1,501 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 4 | ||
trim_trailing_whitespace = true | ||
end_of_line = lf | ||
insert_final_newline = 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,20 +3,19 @@ | |
* @author 唯然<[email protected]> | ||
*/ | ||
import process from "process"; | ||
import path from "path"; | ||
import { writeFile } from "fs/promises"; | ||
import { isPackageTypeModule } from "./utils/npm-utils.js"; | ||
|
||
/** | ||
* | ||
*/ | ||
export class ConfigGenerator { | ||
constructor(options) { | ||
constructor(options = {}) { | ||
this.cwd = options.cwd || process.cwd(); | ||
this.answers = options.answers || {}; | ||
this.result = { | ||
devDependencies: [], | ||
configPath: "", | ||
devDependencies: ["eslint"], | ||
configFilename: "eslint.config.js", | ||
configContent: "" | ||
}; | ||
} | ||
|
@@ -33,37 +32,53 @@ export class ConfigGenerator { | |
} | ||
|
||
calc() { | ||
const isModule = isPackageTypeModule(); | ||
const isModule = isPackageTypeModule(this.cwd); | ||
|
||
this.result.configPath = path.join(this.cwd, isModule ? "eslint.config.js" : "eslint.config.mjs"); | ||
this.result.configFilename = isModule ? "eslint.config.js" : "eslint.config.mjs"; | ||
|
||
let importContent = ""; | ||
let exportContent = ""; | ||
|
||
if (this.answers.purpose === "syntax") { | ||
|
||
// ? | ||
} else if (this.answers.purpose === "problem") { | ||
this.result.devDependencies.push("@eslint/js"); | ||
importContent += `import pluginJs from "@eslint/js";\n`; | ||
exportContent += " pluginJs.configs.recommended,\n"; | ||
} else if (this.answers.purpose === "style") { | ||
|
||
// TODO: style | ||
} | ||
|
||
if (this.answers.module === "commonjs") { | ||
exportContent = ` {languageOption:{sourceType: "commonjs"}},\n${exportContent}`; | ||
} | ||
|
||
// TODO: we may need to use "@eslint/eslintrc" as these plugins have not support flat configs yet? | ||
if (this.answers.typescript) { | ||
this.result.devDependencies.push("@typescript-eslint/eslint-plugin"); | ||
importContent += "import PluginTs from '@typescript-eslint/eslint-plugin';\n"; | ||
exportContent += "PluginTs.configs.recommended,"; | ||
importContent += `import pluginTs from "@typescript-eslint/eslint-plugin";\n`; | ||
exportContent += " pluginTs.configs.recommended,\n"; | ||
} | ||
|
||
if (this.answers.framework === "vue") { | ||
this.result.devDependencies.push("eslint-plugin-vue"); | ||
importContent += "import PluginVue from 'eslint-plugin-vue';\n"; | ||
exportContent += "PluginVue.configs.recommended,"; | ||
importContent += `import pluginVue from "eslint-plugin-vue";\n`; | ||
exportContent += " pluginVue.configs.recommended,\n"; | ||
} | ||
|
||
if (this.answers.framework === "react") { | ||
this.result.devDependencies.push("eslint-plugin-react"); | ||
importContent += "import PluginReact from 'eslint-plugin-react';\n"; | ||
exportContent += "PluginReact.configs.recommended,"; | ||
importContent += `import pluginReact from "eslint-plugin-react";\n`; | ||
exportContent += " pluginReact.configs.recommended,\n"; | ||
} | ||
|
||
this.result.configContent = `${importContent}export default [${exportContent}];`; | ||
this.result.configContent = `${importContent}export default [\n${exportContent}];`; | ||
} | ||
|
||
async output() { | ||
await writeFile(this.result.configPath, this.result.configContent); | ||
await writeFile(this.result.configFilename, this.result.configContent); | ||
|
||
// TODO: install this.result.devDependencies | ||
// TODO: is peerDependencies still needed? | ||
|
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.