@elinzy/cli 0.1.6 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/eslint/index.mjs +251 -0
- package/dist/commands/eslint/register.mjs +13 -0
- package/dist/constants/common.mjs +13 -1
- package/dist/constants/index.mjs +2 -2
- package/dist/helpers/createEslintConfigFile/index.mjs +29 -18
- package/dist/helpers/getArgs/index.mjs +67 -0
- package/dist/helpers/getCommands/index.mjs +12 -7
- package/dist/helpers/getConfigUrl/index.mjs +8 -3
- package/dist/helpers/getPackageManager.mjs +17 -0
- package/dist/helpers/installPackages/index.mjs +1 -1
- package/dist/index.mjs +2 -10
- package/dist/package.mjs +1 -1
- package/dist/utils/index.mjs +4 -0
- package/dist/utils/paths.mjs +7 -0
- package/package.json +6 -10
- package/dist/_virtual/_rolldown/runtime.cjs +0 -28
- package/dist/commands/eslint.cjs +0 -259
- package/dist/commands/eslint.mjs +0 -254
- package/dist/constants/common.cjs +0 -54
- package/dist/constants/index.cjs +0 -11
- package/dist/helpers/createEslintConfigFile/index.cjs +0 -47
- package/dist/helpers/getCommands/index.cjs +0 -21
- package/dist/helpers/getConfigUrl/index.cjs +0 -26
- package/dist/helpers/installPackages/index.cjs +0 -29
- package/dist/index.cjs +0 -19
- package/dist/index.d.cts +0 -1
- package/dist/package.cjs +0 -17
- package/dist/utils/functions.cjs +0 -33
package/dist/commands/eslint.cjs
DELETED
|
@@ -1,259 +0,0 @@
|
|
|
1
|
-
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
-
const require_functions = require("../utils/functions.cjs");
|
|
3
|
-
const require_common = require("../constants/common.cjs");
|
|
4
|
-
require("../constants/index.cjs");
|
|
5
|
-
const require_index$1 = require("../helpers/createEslintConfigFile/index.cjs");
|
|
6
|
-
const require_index$2 = require("../helpers/getCommands/index.cjs");
|
|
7
|
-
const require_index$3 = require("../helpers/getConfigUrl/index.cjs");
|
|
8
|
-
const require_index$4 = require("../helpers/installPackages/index.cjs");
|
|
9
|
-
let ansis = require("ansis");
|
|
10
|
-
ansis = require_runtime.__toESM(ansis, 1);
|
|
11
|
-
let node_path = require("node:path");
|
|
12
|
-
node_path = require_runtime.__toESM(node_path, 1);
|
|
13
|
-
let prompts = require("prompts");
|
|
14
|
-
prompts = require_runtime.__toESM(prompts, 1);
|
|
15
|
-
|
|
16
|
-
//#region src/commands/eslint.ts
|
|
17
|
-
const eslint = async () => {
|
|
18
|
-
process.on("SIGINT", require_functions.handleSigTerm);
|
|
19
|
-
process.on("SIGTERM", require_functions.handleSigTerm);
|
|
20
|
-
let args = {
|
|
21
|
-
config: null,
|
|
22
|
-
language: null,
|
|
23
|
-
formatter: null,
|
|
24
|
-
runtime: null,
|
|
25
|
-
strictConfig: null,
|
|
26
|
-
legacyConfig: null,
|
|
27
|
-
createEslintFile: null,
|
|
28
|
-
skipInstall: null
|
|
29
|
-
};
|
|
30
|
-
if (args.config === null) {
|
|
31
|
-
const { configBoolean } = await (0, prompts.default)({
|
|
32
|
-
type: "toggle",
|
|
33
|
-
name: "configBoolean",
|
|
34
|
-
message: "Config type?",
|
|
35
|
-
initial: require_common.defaults.config === require_common.configs.EXTENDED,
|
|
36
|
-
active: "Extended (flat config)",
|
|
37
|
-
inactive: "Legacy (.eslintrc)",
|
|
38
|
-
onState: require_functions.onPromptState
|
|
39
|
-
}, { onCancel: require_functions.onCancel });
|
|
40
|
-
const config = configBoolean ? require_common.configs.EXTENDED : require_common.configs.LEGACY;
|
|
41
|
-
args = {
|
|
42
|
-
...args,
|
|
43
|
-
config,
|
|
44
|
-
...config === require_common.configs.EXTENDED ? { legacyConfig: null } : { runtime: null }
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
if (args.language === null) {
|
|
48
|
-
const { languageBoolean } = await (0, prompts.default)({
|
|
49
|
-
type: "toggle",
|
|
50
|
-
name: "languageBoolean",
|
|
51
|
-
message: `Are you using ${ansis.default.blue("TypeScript")}?`,
|
|
52
|
-
initial: require_common.defaults.language === require_common.languages.TYPESCRIPT,
|
|
53
|
-
active: "Yes",
|
|
54
|
-
inactive: "No",
|
|
55
|
-
onState: require_functions.onPromptState
|
|
56
|
-
}, { onCancel: require_functions.onCancel });
|
|
57
|
-
args = {
|
|
58
|
-
...args,
|
|
59
|
-
language: languageBoolean ? require_common.languages.TYPESCRIPT : require_common.languages.JAVASCRIPT
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
if (args.formatter === require_common.formatters.NONE) args = {
|
|
63
|
-
...args,
|
|
64
|
-
formatter: null
|
|
65
|
-
};
|
|
66
|
-
else if (args.formatter === null) {
|
|
67
|
-
const { formatterBoolean } = await (0, prompts.default)({
|
|
68
|
-
type: "toggle",
|
|
69
|
-
name: "formatterBoolean",
|
|
70
|
-
message: `Are you using ${ansis.default.cyan("Prettier")}?`,
|
|
71
|
-
initial: require_common.defaults.formatter === require_common.formatters.PRETTIER,
|
|
72
|
-
active: "Yes",
|
|
73
|
-
inactive: "No",
|
|
74
|
-
onState: require_functions.onPromptState
|
|
75
|
-
}, { onCancel: require_functions.onCancel });
|
|
76
|
-
args = {
|
|
77
|
-
...args,
|
|
78
|
-
formatter: formatterBoolean ? require_common.formatters.PRETTIER : null
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
if (args.config === require_common.configs.EXTENDED && !args.runtime) {
|
|
82
|
-
const { runtime } = await (0, prompts.default)({
|
|
83
|
-
type: "select",
|
|
84
|
-
name: "runtime",
|
|
85
|
-
message: "Which runtime?",
|
|
86
|
-
choices: [
|
|
87
|
-
{
|
|
88
|
-
title: "Node.js",
|
|
89
|
-
description: ansis.default.green("Node.js backend or library"),
|
|
90
|
-
value: require_common.runtimes.NODE
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
title: "React",
|
|
94
|
-
description: ansis.default.cyan("React.js with JSX"),
|
|
95
|
-
value: require_common.runtimes.REACT
|
|
96
|
-
},
|
|
97
|
-
{
|
|
98
|
-
title: "Next.js",
|
|
99
|
-
description: ansis.default.blackBright("Next.js framework"),
|
|
100
|
-
value: require_common.runtimes.NEXT
|
|
101
|
-
}
|
|
102
|
-
],
|
|
103
|
-
onState: require_functions.onPromptState
|
|
104
|
-
}, { onCancel: require_functions.onCancel });
|
|
105
|
-
args = {
|
|
106
|
-
...args,
|
|
107
|
-
runtime
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
if (args.config === require_common.configs.EXTENDED) {
|
|
111
|
-
if (args.strictConfig?.includes(require_common.strictConfigs.NONE)) args = {
|
|
112
|
-
...args,
|
|
113
|
-
strictConfig: null
|
|
114
|
-
};
|
|
115
|
-
else if (!args.strictConfig) {
|
|
116
|
-
const { hasStrictConfig } = await (0, prompts.default)({
|
|
117
|
-
type: "toggle",
|
|
118
|
-
name: "hasStrictConfig",
|
|
119
|
-
message: `Add ${ansis.default.yellow("strict")} configs?`,
|
|
120
|
-
initial: require_common.defaults.strictConfig,
|
|
121
|
-
active: "Yes",
|
|
122
|
-
inactive: "No",
|
|
123
|
-
onState: require_functions.onPromptState
|
|
124
|
-
}, { onCancel: require_functions.onCancel });
|
|
125
|
-
if (hasStrictConfig) {
|
|
126
|
-
const { strictConfig } = await (0, prompts.default)({
|
|
127
|
-
type: "multiselect",
|
|
128
|
-
name: "strictConfig",
|
|
129
|
-
message: "Select strict configs:",
|
|
130
|
-
min: 1,
|
|
131
|
-
choices: [
|
|
132
|
-
{
|
|
133
|
-
title: "Import",
|
|
134
|
-
description: ansis.default.yellow("Strict import rules"),
|
|
135
|
-
value: require_common.strictConfigs.IMPORT
|
|
136
|
-
},
|
|
137
|
-
...args.runtime && [require_common.runtimes.REACT, require_common.runtimes.NEXT].includes(args.runtime) ? [{
|
|
138
|
-
title: "React",
|
|
139
|
-
description: ansis.default.cyan("Strict React rules"),
|
|
140
|
-
value: require_common.strictConfigs.REACT
|
|
141
|
-
}] : [],
|
|
142
|
-
...args.language === require_common.languages.TYPESCRIPT ? [{
|
|
143
|
-
title: "TypeScript",
|
|
144
|
-
description: ansis.default.blue("Strict TypeScript rules"),
|
|
145
|
-
value: require_common.strictConfigs.TYPESCRIPT
|
|
146
|
-
}] : []
|
|
147
|
-
],
|
|
148
|
-
onState: require_functions.onPromptState
|
|
149
|
-
}, { onCancel: require_functions.onCancel });
|
|
150
|
-
args = {
|
|
151
|
-
...args,
|
|
152
|
-
strictConfig
|
|
153
|
-
};
|
|
154
|
-
} else args = {
|
|
155
|
-
...args,
|
|
156
|
-
strictConfig: null
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
if (args.config === require_common.configs.LEGACY && !args.legacyConfig) {
|
|
161
|
-
const { legacyConfig } = await (0, prompts.default)({
|
|
162
|
-
type: "select",
|
|
163
|
-
name: "legacyConfig",
|
|
164
|
-
message: "Which legacy base?",
|
|
165
|
-
choices: [{
|
|
166
|
-
title: "Base",
|
|
167
|
-
description: ansis.default.green("@elinzy/eslint-config-extended base"),
|
|
168
|
-
value: require_common.legacyConfigs.BASE
|
|
169
|
-
}, {
|
|
170
|
-
title: "React",
|
|
171
|
-
description: ansis.default.cyan("@elinzy/eslint-config-extended react"),
|
|
172
|
-
value: require_common.legacyConfigs.REACT
|
|
173
|
-
}],
|
|
174
|
-
onState: require_functions.onPromptState
|
|
175
|
-
}, { onCancel: require_functions.onCancel });
|
|
176
|
-
args = {
|
|
177
|
-
...args,
|
|
178
|
-
legacyConfig
|
|
179
|
-
};
|
|
180
|
-
if (args.legacyConfig === require_common.legacyConfigs.REACT) {
|
|
181
|
-
const { reactHooks } = await (0, prompts.default)({
|
|
182
|
-
type: "toggle",
|
|
183
|
-
name: "reactHooks",
|
|
184
|
-
message: "Using React Hooks?",
|
|
185
|
-
initial: require_common.defaults.legacyReactHooks,
|
|
186
|
-
active: "Yes",
|
|
187
|
-
inactive: "No",
|
|
188
|
-
onState: require_functions.onPromptState
|
|
189
|
-
}, { onCancel: require_functions.onCancel });
|
|
190
|
-
args = {
|
|
191
|
-
...args,
|
|
192
|
-
legacyConfig: reactHooks ? require_common.legacyConfigs.REACT_HOOKS : require_common.legacyConfigs.REACT
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
if (args.createEslintFile === null) {
|
|
197
|
-
const { createEslintFile } = await (0, prompts.default)({
|
|
198
|
-
type: "toggle",
|
|
199
|
-
name: "createEslintFile",
|
|
200
|
-
message: `Create ${ansis.default.blue(require_common.eslintConfigName)} file?`,
|
|
201
|
-
initial: require_common.defaults.createEslintFile,
|
|
202
|
-
active: "Yes",
|
|
203
|
-
inactive: "No",
|
|
204
|
-
onState: require_functions.onPromptState
|
|
205
|
-
}, { onCancel: require_functions.onCancel });
|
|
206
|
-
args = {
|
|
207
|
-
...args,
|
|
208
|
-
createEslintFile
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
if (args.skipInstall === null) {
|
|
212
|
-
const { skipInstall } = await (0, prompts.default)({
|
|
213
|
-
type: "toggle",
|
|
214
|
-
name: "skipInstall",
|
|
215
|
-
message: "Skip package installation?",
|
|
216
|
-
initial: require_common.defaults.skipInstall,
|
|
217
|
-
active: "Yes",
|
|
218
|
-
inactive: "No",
|
|
219
|
-
onState: require_functions.onPromptState
|
|
220
|
-
}, { onCancel: require_functions.onCancel });
|
|
221
|
-
args = {
|
|
222
|
-
...args,
|
|
223
|
-
skipInstall
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
const configUrl = require_index$3.getConfigUrl({
|
|
227
|
-
config: args.config,
|
|
228
|
-
language: args.language,
|
|
229
|
-
formatter: args.formatter,
|
|
230
|
-
runtime: args.runtime,
|
|
231
|
-
strictConfig: args.strictConfig,
|
|
232
|
-
legacyConfig: args.legacyConfig
|
|
233
|
-
});
|
|
234
|
-
console.log();
|
|
235
|
-
console.log(ansis.default.cyan("Template:"), configUrl.path);
|
|
236
|
-
if (args.createEslintFile && configUrl) {
|
|
237
|
-
const outputPath = node_path.default.resolve(process.cwd(), require_common.eslintConfigName);
|
|
238
|
-
await require_index$1.createESLintConfigFile({
|
|
239
|
-
configPath: configUrl.path,
|
|
240
|
-
outputPath
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
if (args.skipInstall) {
|
|
244
|
-
const commands = require_index$2.getCommands({ formatter: args.formatter });
|
|
245
|
-
console.log();
|
|
246
|
-
console.log(ansis.default.yellow("Install manually:"));
|
|
247
|
-
console.log(ansis.default.blue(commands.join(" ")));
|
|
248
|
-
} else {
|
|
249
|
-
console.log();
|
|
250
|
-
console.log(ansis.default.blue("Installing packages..."));
|
|
251
|
-
await require_index$4.installPackages({ formatter: args.formatter });
|
|
252
|
-
console.log(ansis.default.green("Installation complete!"));
|
|
253
|
-
}
|
|
254
|
-
console.log();
|
|
255
|
-
};
|
|
256
|
-
|
|
257
|
-
//#endregion
|
|
258
|
-
exports.default = eslint;
|
|
259
|
-
exports.eslint = eslint;
|
package/dist/commands/eslint.mjs
DELETED
|
@@ -1,254 +0,0 @@
|
|
|
1
|
-
import { handleSigTerm, onCancel, onPromptState } from "../utils/functions.mjs";
|
|
2
|
-
import { configs, defaults, eslintConfigName, formatters, languages, legacyConfigs, runtimes, strictConfigs } from "../constants/common.mjs";
|
|
3
|
-
import "../constants/index.mjs";
|
|
4
|
-
import { createESLintConfigFile } from "../helpers/createEslintConfigFile/index.mjs";
|
|
5
|
-
import { getCommands } from "../helpers/getCommands/index.mjs";
|
|
6
|
-
import { getConfigUrl } from "../helpers/getConfigUrl/index.mjs";
|
|
7
|
-
import { installPackages } from "../helpers/installPackages/index.mjs";
|
|
8
|
-
import pc from "ansis";
|
|
9
|
-
import path from "node:path";
|
|
10
|
-
import prompts from "prompts";
|
|
11
|
-
|
|
12
|
-
//#region src/commands/eslint.ts
|
|
13
|
-
const eslint = async () => {
|
|
14
|
-
process.on("SIGINT", handleSigTerm);
|
|
15
|
-
process.on("SIGTERM", handleSigTerm);
|
|
16
|
-
let args = {
|
|
17
|
-
config: null,
|
|
18
|
-
language: null,
|
|
19
|
-
formatter: null,
|
|
20
|
-
runtime: null,
|
|
21
|
-
strictConfig: null,
|
|
22
|
-
legacyConfig: null,
|
|
23
|
-
createEslintFile: null,
|
|
24
|
-
skipInstall: null
|
|
25
|
-
};
|
|
26
|
-
if (args.config === null) {
|
|
27
|
-
const { configBoolean } = await prompts({
|
|
28
|
-
type: "toggle",
|
|
29
|
-
name: "configBoolean",
|
|
30
|
-
message: "Config type?",
|
|
31
|
-
initial: defaults.config === configs.EXTENDED,
|
|
32
|
-
active: "Extended (flat config)",
|
|
33
|
-
inactive: "Legacy (.eslintrc)",
|
|
34
|
-
onState: onPromptState
|
|
35
|
-
}, { onCancel });
|
|
36
|
-
const config = configBoolean ? configs.EXTENDED : configs.LEGACY;
|
|
37
|
-
args = {
|
|
38
|
-
...args,
|
|
39
|
-
config,
|
|
40
|
-
...config === configs.EXTENDED ? { legacyConfig: null } : { runtime: null }
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
if (args.language === null) {
|
|
44
|
-
const { languageBoolean } = await prompts({
|
|
45
|
-
type: "toggle",
|
|
46
|
-
name: "languageBoolean",
|
|
47
|
-
message: `Are you using ${pc.blue("TypeScript")}?`,
|
|
48
|
-
initial: defaults.language === languages.TYPESCRIPT,
|
|
49
|
-
active: "Yes",
|
|
50
|
-
inactive: "No",
|
|
51
|
-
onState: onPromptState
|
|
52
|
-
}, { onCancel });
|
|
53
|
-
args = {
|
|
54
|
-
...args,
|
|
55
|
-
language: languageBoolean ? languages.TYPESCRIPT : languages.JAVASCRIPT
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
if (args.formatter === formatters.NONE) args = {
|
|
59
|
-
...args,
|
|
60
|
-
formatter: null
|
|
61
|
-
};
|
|
62
|
-
else if (args.formatter === null) {
|
|
63
|
-
const { formatterBoolean } = await prompts({
|
|
64
|
-
type: "toggle",
|
|
65
|
-
name: "formatterBoolean",
|
|
66
|
-
message: `Are you using ${pc.cyan("Prettier")}?`,
|
|
67
|
-
initial: defaults.formatter === formatters.PRETTIER,
|
|
68
|
-
active: "Yes",
|
|
69
|
-
inactive: "No",
|
|
70
|
-
onState: onPromptState
|
|
71
|
-
}, { onCancel });
|
|
72
|
-
args = {
|
|
73
|
-
...args,
|
|
74
|
-
formatter: formatterBoolean ? formatters.PRETTIER : null
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
if (args.config === configs.EXTENDED && !args.runtime) {
|
|
78
|
-
const { runtime } = await prompts({
|
|
79
|
-
type: "select",
|
|
80
|
-
name: "runtime",
|
|
81
|
-
message: "Which runtime?",
|
|
82
|
-
choices: [
|
|
83
|
-
{
|
|
84
|
-
title: "Node.js",
|
|
85
|
-
description: pc.green("Node.js backend or library"),
|
|
86
|
-
value: runtimes.NODE
|
|
87
|
-
},
|
|
88
|
-
{
|
|
89
|
-
title: "React",
|
|
90
|
-
description: pc.cyan("React.js with JSX"),
|
|
91
|
-
value: runtimes.REACT
|
|
92
|
-
},
|
|
93
|
-
{
|
|
94
|
-
title: "Next.js",
|
|
95
|
-
description: pc.blackBright("Next.js framework"),
|
|
96
|
-
value: runtimes.NEXT
|
|
97
|
-
}
|
|
98
|
-
],
|
|
99
|
-
onState: onPromptState
|
|
100
|
-
}, { onCancel });
|
|
101
|
-
args = {
|
|
102
|
-
...args,
|
|
103
|
-
runtime
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
if (args.config === configs.EXTENDED) {
|
|
107
|
-
if (args.strictConfig?.includes(strictConfigs.NONE)) args = {
|
|
108
|
-
...args,
|
|
109
|
-
strictConfig: null
|
|
110
|
-
};
|
|
111
|
-
else if (!args.strictConfig) {
|
|
112
|
-
const { hasStrictConfig } = await prompts({
|
|
113
|
-
type: "toggle",
|
|
114
|
-
name: "hasStrictConfig",
|
|
115
|
-
message: `Add ${pc.yellow("strict")} configs?`,
|
|
116
|
-
initial: defaults.strictConfig,
|
|
117
|
-
active: "Yes",
|
|
118
|
-
inactive: "No",
|
|
119
|
-
onState: onPromptState
|
|
120
|
-
}, { onCancel });
|
|
121
|
-
if (hasStrictConfig) {
|
|
122
|
-
const { strictConfig } = await prompts({
|
|
123
|
-
type: "multiselect",
|
|
124
|
-
name: "strictConfig",
|
|
125
|
-
message: "Select strict configs:",
|
|
126
|
-
min: 1,
|
|
127
|
-
choices: [
|
|
128
|
-
{
|
|
129
|
-
title: "Import",
|
|
130
|
-
description: pc.yellow("Strict import rules"),
|
|
131
|
-
value: strictConfigs.IMPORT
|
|
132
|
-
},
|
|
133
|
-
...args.runtime && [runtimes.REACT, runtimes.NEXT].includes(args.runtime) ? [{
|
|
134
|
-
title: "React",
|
|
135
|
-
description: pc.cyan("Strict React rules"),
|
|
136
|
-
value: strictConfigs.REACT
|
|
137
|
-
}] : [],
|
|
138
|
-
...args.language === languages.TYPESCRIPT ? [{
|
|
139
|
-
title: "TypeScript",
|
|
140
|
-
description: pc.blue("Strict TypeScript rules"),
|
|
141
|
-
value: strictConfigs.TYPESCRIPT
|
|
142
|
-
}] : []
|
|
143
|
-
],
|
|
144
|
-
onState: onPromptState
|
|
145
|
-
}, { onCancel });
|
|
146
|
-
args = {
|
|
147
|
-
...args,
|
|
148
|
-
strictConfig
|
|
149
|
-
};
|
|
150
|
-
} else args = {
|
|
151
|
-
...args,
|
|
152
|
-
strictConfig: null
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
if (args.config === configs.LEGACY && !args.legacyConfig) {
|
|
157
|
-
const { legacyConfig } = await prompts({
|
|
158
|
-
type: "select",
|
|
159
|
-
name: "legacyConfig",
|
|
160
|
-
message: "Which legacy base?",
|
|
161
|
-
choices: [{
|
|
162
|
-
title: "Base",
|
|
163
|
-
description: pc.green("@elinzy/eslint-config-extended base"),
|
|
164
|
-
value: legacyConfigs.BASE
|
|
165
|
-
}, {
|
|
166
|
-
title: "React",
|
|
167
|
-
description: pc.cyan("@elinzy/eslint-config-extended react"),
|
|
168
|
-
value: legacyConfigs.REACT
|
|
169
|
-
}],
|
|
170
|
-
onState: onPromptState
|
|
171
|
-
}, { onCancel });
|
|
172
|
-
args = {
|
|
173
|
-
...args,
|
|
174
|
-
legacyConfig
|
|
175
|
-
};
|
|
176
|
-
if (args.legacyConfig === legacyConfigs.REACT) {
|
|
177
|
-
const { reactHooks } = await prompts({
|
|
178
|
-
type: "toggle",
|
|
179
|
-
name: "reactHooks",
|
|
180
|
-
message: "Using React Hooks?",
|
|
181
|
-
initial: defaults.legacyReactHooks,
|
|
182
|
-
active: "Yes",
|
|
183
|
-
inactive: "No",
|
|
184
|
-
onState: onPromptState
|
|
185
|
-
}, { onCancel });
|
|
186
|
-
args = {
|
|
187
|
-
...args,
|
|
188
|
-
legacyConfig: reactHooks ? legacyConfigs.REACT_HOOKS : legacyConfigs.REACT
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
if (args.createEslintFile === null) {
|
|
193
|
-
const { createEslintFile } = await prompts({
|
|
194
|
-
type: "toggle",
|
|
195
|
-
name: "createEslintFile",
|
|
196
|
-
message: `Create ${pc.blue(eslintConfigName)} file?`,
|
|
197
|
-
initial: defaults.createEslintFile,
|
|
198
|
-
active: "Yes",
|
|
199
|
-
inactive: "No",
|
|
200
|
-
onState: onPromptState
|
|
201
|
-
}, { onCancel });
|
|
202
|
-
args = {
|
|
203
|
-
...args,
|
|
204
|
-
createEslintFile
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
if (args.skipInstall === null) {
|
|
208
|
-
const { skipInstall } = await prompts({
|
|
209
|
-
type: "toggle",
|
|
210
|
-
name: "skipInstall",
|
|
211
|
-
message: "Skip package installation?",
|
|
212
|
-
initial: defaults.skipInstall,
|
|
213
|
-
active: "Yes",
|
|
214
|
-
inactive: "No",
|
|
215
|
-
onState: onPromptState
|
|
216
|
-
}, { onCancel });
|
|
217
|
-
args = {
|
|
218
|
-
...args,
|
|
219
|
-
skipInstall
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
const configUrl = getConfigUrl({
|
|
223
|
-
config: args.config,
|
|
224
|
-
language: args.language,
|
|
225
|
-
formatter: args.formatter,
|
|
226
|
-
runtime: args.runtime,
|
|
227
|
-
strictConfig: args.strictConfig,
|
|
228
|
-
legacyConfig: args.legacyConfig
|
|
229
|
-
});
|
|
230
|
-
console.log();
|
|
231
|
-
console.log(pc.cyan("Template:"), configUrl.path);
|
|
232
|
-
if (args.createEslintFile && configUrl) {
|
|
233
|
-
const outputPath = path.resolve(process.cwd(), eslintConfigName);
|
|
234
|
-
await createESLintConfigFile({
|
|
235
|
-
configPath: configUrl.path,
|
|
236
|
-
outputPath
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
if (args.skipInstall) {
|
|
240
|
-
const commands = getCommands({ formatter: args.formatter });
|
|
241
|
-
console.log();
|
|
242
|
-
console.log(pc.yellow("Install manually:"));
|
|
243
|
-
console.log(pc.blue(commands.join(" ")));
|
|
244
|
-
} else {
|
|
245
|
-
console.log();
|
|
246
|
-
console.log(pc.blue("Installing packages..."));
|
|
247
|
-
await installPackages({ formatter: args.formatter });
|
|
248
|
-
console.log(pc.green("Installation complete!"));
|
|
249
|
-
}
|
|
250
|
-
console.log();
|
|
251
|
-
};
|
|
252
|
-
|
|
253
|
-
//#endregion
|
|
254
|
-
export { eslint as default, eslint };
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
//#region src/constants/common.ts
|
|
2
|
-
const configs = {
|
|
3
|
-
EXTENDED: "extended",
|
|
4
|
-
LEGACY: "legacy"
|
|
5
|
-
};
|
|
6
|
-
const languages = {
|
|
7
|
-
JAVASCRIPT: "javascript",
|
|
8
|
-
TYPESCRIPT: "typescript"
|
|
9
|
-
};
|
|
10
|
-
const formatters = {
|
|
11
|
-
NONE: "none",
|
|
12
|
-
PRETTIER: "prettier"
|
|
13
|
-
};
|
|
14
|
-
const runtimes = {
|
|
15
|
-
REACT: "react",
|
|
16
|
-
NEXT: "next",
|
|
17
|
-
NODE: "node"
|
|
18
|
-
};
|
|
19
|
-
const strictConfigs = {
|
|
20
|
-
NONE: "none",
|
|
21
|
-
IMPORT: "import",
|
|
22
|
-
REACT: "react",
|
|
23
|
-
TYPESCRIPT: "typescript"
|
|
24
|
-
};
|
|
25
|
-
const legacyConfigs = {
|
|
26
|
-
BASE: "base",
|
|
27
|
-
REACT: "react",
|
|
28
|
-
REACT_HOOKS: "react-hooks"
|
|
29
|
-
};
|
|
30
|
-
const defaults = {
|
|
31
|
-
config: configs.EXTENDED,
|
|
32
|
-
language: languages.TYPESCRIPT,
|
|
33
|
-
formatter: formatters.PRETTIER,
|
|
34
|
-
strictConfig: false,
|
|
35
|
-
legacyReactHooks: true,
|
|
36
|
-
createEslintFile: true,
|
|
37
|
-
skipInstall: false
|
|
38
|
-
};
|
|
39
|
-
const subFolders = {
|
|
40
|
-
DEFAULT: "default",
|
|
41
|
-
STRICT: "strict"
|
|
42
|
-
};
|
|
43
|
-
const eslintConfigName = "eslint.config.mjs";
|
|
44
|
-
|
|
45
|
-
//#endregion
|
|
46
|
-
exports.configs = configs;
|
|
47
|
-
exports.defaults = defaults;
|
|
48
|
-
exports.eslintConfigName = eslintConfigName;
|
|
49
|
-
exports.formatters = formatters;
|
|
50
|
-
exports.languages = languages;
|
|
51
|
-
exports.legacyConfigs = legacyConfigs;
|
|
52
|
-
exports.runtimes = runtimes;
|
|
53
|
-
exports.strictConfigs = strictConfigs;
|
|
54
|
-
exports.subFolders = subFolders;
|
package/dist/constants/index.cjs
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
const require_common = require("./common.cjs");
|
|
2
|
-
|
|
3
|
-
exports.configs = require_common.configs;
|
|
4
|
-
exports.defaults = require_common.defaults;
|
|
5
|
-
exports.eslintConfigName = require_common.eslintConfigName;
|
|
6
|
-
exports.formatters = require_common.formatters;
|
|
7
|
-
exports.languages = require_common.languages;
|
|
8
|
-
exports.legacyConfigs = require_common.legacyConfigs;
|
|
9
|
-
exports.runtimes = require_common.runtimes;
|
|
10
|
-
exports.strictConfigs = require_common.strictConfigs;
|
|
11
|
-
exports.subFolders = require_common.subFolders;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
const require_runtime = require("../../_virtual/_rolldown/runtime.cjs");
|
|
2
|
-
let node_path = require("node:path");
|
|
3
|
-
node_path = require_runtime.__toESM(node_path, 1);
|
|
4
|
-
let node_fs = require("node:fs");
|
|
5
|
-
node_fs = require_runtime.__toESM(node_fs, 1);
|
|
6
|
-
let node_url = require("node:url");
|
|
7
|
-
|
|
8
|
-
//#region src/helpers/createEslintConfigFile/index.ts
|
|
9
|
-
/**
|
|
10
|
-
* Resolve templates directory from the `@elinzy/build-templates` package.
|
|
11
|
-
*/
|
|
12
|
-
const resolveTemplatesDir = () => {
|
|
13
|
-
try {
|
|
14
|
-
const pkgUrl = {}.resolve("@elinzy/build-templates/package.json");
|
|
15
|
-
const pkgPath = (0, node_url.fileURLToPath)(pkgUrl);
|
|
16
|
-
const dir = node_path.default.join(node_path.default.dirname(pkgPath), "templates");
|
|
17
|
-
if (node_fs.default.existsSync(dir)) return dir;
|
|
18
|
-
} catch {}
|
|
19
|
-
const base = __dirname;
|
|
20
|
-
const resolvePaths = [
|
|
21
|
-
node_path.default.resolve(base, "..", "..", "..", "build-templates", "templates"),
|
|
22
|
-
node_path.default.resolve(base, "..", "..", "..", "..", "build-templates", "templates"),
|
|
23
|
-
node_path.default.resolve(process.cwd(), "packages", "build-templates", "templates")
|
|
24
|
-
];
|
|
25
|
-
for (const p of resolvePaths) if (node_fs.default.existsSync(p)) return p;
|
|
26
|
-
return null;
|
|
27
|
-
};
|
|
28
|
-
const templatesDir = resolveTemplatesDir();
|
|
29
|
-
const createESLintConfigFile = async (config) => {
|
|
30
|
-
const { configPath, outputPath } = config;
|
|
31
|
-
if (!templatesDir) throw new Error("Cannot find @elinzy/build-templates package. Please ensure it is installed.");
|
|
32
|
-
const templateFile = node_path.default.join(templatesDir, configPath);
|
|
33
|
-
if (!node_fs.default.existsSync(templateFile)) {
|
|
34
|
-
console.warn(`Template not found: ${configPath}`);
|
|
35
|
-
console.warn(`Searched: ${templateFile}`);
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
const content = node_fs.default.readFileSync(templateFile, "utf8");
|
|
39
|
-
node_fs.default.writeFileSync(outputPath, content, "utf8");
|
|
40
|
-
console.log(`Created: ${outputPath}`);
|
|
41
|
-
console.log(`Template: ${baseGithubUrl}/${configPath}`);
|
|
42
|
-
};
|
|
43
|
-
const baseGithubUrl = "https://github.com/Appleec/e/tree/main/packages/build-templates/templates";
|
|
44
|
-
|
|
45
|
-
//#endregion
|
|
46
|
-
exports.baseGithubUrl = baseGithubUrl;
|
|
47
|
-
exports.createESLintConfigFile = createESLintConfigFile;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
const require_common = require("../../constants/common.cjs");
|
|
2
|
-
require("../../constants/index.cjs");
|
|
3
|
-
|
|
4
|
-
//#region src/helpers/getCommands/index.ts
|
|
5
|
-
const getCommands = (args) => {
|
|
6
|
-
const { formatter } = args;
|
|
7
|
-
const commands = [
|
|
8
|
-
"pnpm",
|
|
9
|
-
"add",
|
|
10
|
-
"-D",
|
|
11
|
-
"eslint",
|
|
12
|
-
"@eslint/compat",
|
|
13
|
-
"@eslint/js",
|
|
14
|
-
"@elinzy/eslint-config-extended"
|
|
15
|
-
];
|
|
16
|
-
if (formatter === require_common.formatters.PRETTIER) commands.push("prettier", "eslint-plugin-prettier", "eslint-config-prettier");
|
|
17
|
-
return commands;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
//#endregion
|
|
21
|
-
exports.getCommands = getCommands;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
const require_common = require("../../constants/common.cjs");
|
|
2
|
-
require("../../constants/index.cjs");
|
|
3
|
-
|
|
4
|
-
//#region src/helpers/getConfigUrl/index.ts
|
|
5
|
-
const getConfigUrl = (args) => {
|
|
6
|
-
const { config, language, formatter, strictConfig, runtime, legacyConfig } = args;
|
|
7
|
-
const isLegacy = config === require_common.configs.LEGACY;
|
|
8
|
-
const prettierText = formatter === require_common.formatters.PRETTIER ? "prettier" : null;
|
|
9
|
-
const tsOrJsText = language === require_common.languages.TYPESCRIPT ? "ts" : "js";
|
|
10
|
-
const legacyLanguage = config === require_common.configs.EXTENDED ? null : legacyConfig;
|
|
11
|
-
const strictOrDefaultText = (() => {
|
|
12
|
-
if (!strictConfig || strictConfig.length === 0) return [require_common.subFolders.DEFAULT];
|
|
13
|
-
const strictFolder = [...strictConfig].sort().join("-");
|
|
14
|
-
return [require_common.subFolders.STRICT, strictFolder];
|
|
15
|
-
})();
|
|
16
|
-
return { path: [
|
|
17
|
-
...isLegacy ? [require_common.configs.LEGACY, legacyLanguage] : [runtime],
|
|
18
|
-
prettierText,
|
|
19
|
-
tsOrJsText,
|
|
20
|
-
...strictOrDefaultText,
|
|
21
|
-
require_common.eslintConfigName
|
|
22
|
-
].filter(Boolean).join("/") };
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
//#endregion
|
|
26
|
-
exports.getConfigUrl = getConfigUrl;
|