-
-
Notifications
You must be signed in to change notification settings - Fork 50
/
index.js
50 lines (43 loc) · 1.82 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**
* @fileoverview Main generator (delegates to rule or plugin generator)
* @author Kevin Partington
* @copyright jQuery Foundation and other contributors, https://jquery.org/
* MIT License
*/
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
import Generator from "yeoman-generator";
import RuleGenerator from "../rule/index.js";
import PluginGenerator from "../plugin/index.js";
import { fileURLToPath } from "node:url";
import path from "node:path";
/* eslint-disable no-underscore-dangle -- cjs convention */
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const RULE_GENERATOR_PATH = path.join(__dirname, "..", "rule", "index.js");
const PLUGIN_GENERATOR_PATH = path.join(__dirname, "..", "plugin", "index.js");
/* eslint-enable no-underscore-dangle -- cjs convention*/
//------------------------------------------------------------------------------
// Constructor
//------------------------------------------------------------------------------
/**
* Represents a generator for creating ESLint plugins/rules.
*/
export default class extends Generator {
async prompting() {
const answers = await this.prompt({
type: "list",
name: "outputType",
message: "Do you want to generate a rule or a plugin?",
choices: ["Rule", "Plugin"],
default: "Rule"
});
if (answers.outputType === "Rule") {
this.composeWith({ Generator: RuleGenerator, path: RULE_GENERATOR_PATH });
} else if (answers.outputType === "Plugin") {
this.composeWith({ Generator: PluginGenerator, path: PLUGIN_GENERATOR_PATH });
} else {
throw new Error("Unhandled generator type.");
}
}
}