-
-
Notifications
You must be signed in to change notification settings - Fork 50
/
index.js
96 lines (80 loc) · 2.81 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/**
* @fileoverview Rule generator
* @author Nicholas C. Zakas
* @copyright jQuery Foundation and other contributors, https://jquery.org/
* MIT License
*/
"use strict";
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
const util = require("util");
const mkdirp = require("mkdirp");
const yeoman = require("yeoman-generator");
const validators = require("../lib/validators");
//------------------------------------------------------------------------------
// Helpers
//------------------------------------------------------------------------------
const isPluginId = validators.isPluginId;
const isRequired = validators.isRequired;
//------------------------------------------------------------------------------
// Constructor
//------------------------------------------------------------------------------
const ESLintPluginGenerator = module.exports = function ESLintPluginGenerator() {
yeoman.Base.apply(this, arguments); // eslint-disable-line prefer-rest-params
};
util.inherits(ESLintPluginGenerator, yeoman.Base);
ESLintPluginGenerator.prototype.askFor = function askFor() {
const cb = this.async();
const prompts = [{
type: "input",
name: "userName",
message: "What is your name?"
}, {
type: "input",
name: "pluginId",
message: "What is the plugin ID?",
validate: isPluginId
}, {
type: "input",
name: "desc",
message: "Type a short description of this plugin:",
validate: isRequired
}, {
type: "confirm",
name: "hasRules",
message: "Does this plugin contain custom ESLint rules?",
default: true
}, {
type: "confirm",
name: "hasProcessors",
message: "Does this plugin contain one or more processors?",
default: false
}];
this.prompt(prompts, props => {
this.pluginId = props.pluginId.replace("eslint-plugin-", "");
this.hasRules = props.hasRules;
this.hasProcessors = props.hasProcessors;
this.desc = props.desc;
this.userName = props.userName;
this.year = (new Date()).getFullYear();
cb();
});
};
ESLintPluginGenerator.prototype.generate = function generate() {
mkdirp.sync("lib");
mkdirp.sync("tests");
mkdirp.sync("tests/lib");
this.template("_.eslintrc.js", ".eslintrc.js");
this.template("_plugin.js", "lib/index.js");
this.template("_package.json", "package.json");
this.template("_README.md", "README.md");
if (this.hasRules) {
mkdirp.sync("lib/rules");
mkdirp.sync("tests/lib/rules");
}
if (this.hasProcessors) {
mkdirp.sync("lib/processors");
mkdirp.sync("tests/lib/processors");
}
};