-
Notifications
You must be signed in to change notification settings - Fork 0
/
editorconfig
executable file
·99 lines (85 loc) · 2.04 KB
/
editorconfig
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
97
98
99
#!/usr/bin/env node
const readline = require("readline");
const fs = require("fs");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
const askQuestion = async (question) => {
return new Promise((resolve) => {
rl.question(question, (answer) => {
resolve(answer.trim());
});
});
};
const isYes = async (question) => {
const answer = await askQuestion(`${question}? (Y/n): `);
return answer === "" || answer === "y" || answer === "yes";
};
const askQuestions = async () => {
const indentStyle = (await isYes("Use tabs for the indentStyle?"))
? "tab"
: "space";
const isJsProject = await isYes("is this a Javascript based project?");
const isTsProject = isJsProject
? await isYes("is this a Typescript based project?")
: isJsProject;
const isScssProject = await isYes("is this a SCSS based project?");
generateEditorConfig({
indentStyle,
isJsProject,
isTsProject,
isScssProject,
});
};
askQuestions();
const generateEditorConfig = ({
indentStyle,
isJsProject,
isTsProject,
isScssProject,
}) => {
const editorConfig = `
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# http://editorconfig.org
root = true
[*]
indent_style = ${indentStyle}
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.${isJsProject ? "{md,mdx}" : "md"}]
indent_size = 4
trim_trailing_whitespace = false
max_line_length = 80
[*.${isScssProject ? "{css,scss}" : "css"}]
indent_size = 4
max_line_length = 80
[*.{${
isJsProject
? isTsProject
? "html,js,ts,vue,tsx"
: "html,cjs,vue,jsx"
: "html"
}}]
indent_size = 4
max_line_length = 80
${
isJsProject
? ""
: `[*.{xml,phtml,php}]
indent_size = 4
max_line_length = 120
[{composer,auth}.json]
indent_size = 4
`
}`;
fs.writeFile(".editorconfig", editorConfig, (err) => {
if (err) throw err;
console.log(".editorconfig file created.");
rl.close();
});
};