@elinzy/cli 0.0.0-stage → 0.1.5
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/LICENSE +21 -0
- package/README.md +43 -2
- package/dist/_virtual/_rolldown/runtime.cjs +28 -0
- package/dist/commands/eslint.cjs +259 -0
- package/dist/commands/eslint.mjs +254 -0
- package/dist/constants/common.cjs +54 -0
- package/dist/constants/common.mjs +46 -0
- package/dist/constants/index.cjs +11 -0
- package/dist/constants/index.mjs +3 -0
- package/dist/helpers/createEslintConfigFile/index.cjs +39 -0
- package/dist/helpers/createEslintConfigFile/index.mjs +35 -0
- package/dist/helpers/getCommands/index.cjs +21 -0
- package/dist/helpers/getCommands/index.mjs +21 -0
- package/dist/helpers/getConfigUrl/index.cjs +26 -0
- package/dist/helpers/getConfigUrl/index.mjs +26 -0
- package/dist/helpers/installPackages/index.cjs +29 -0
- package/dist/helpers/installPackages/index.mjs +27 -0
- package/dist/index.cjs +19 -0
- package/dist/index.d.cts +1 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.mjs +20 -0
- package/dist/package.cjs +17 -0
- package/dist/package.mjs +6 -0
- package/dist/utils/functions.cjs +33 -0
- package/dist/utils/functions.mjs +28 -0
- package/package.json +64 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Appleex
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,44 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @elinzy/cli
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A general-purpose CLI toolkit for the `@elinzy/e` ecosystem.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```shell
|
|
8
|
+
# Project dependency
|
|
9
|
+
npm install -D @elinzy/cli
|
|
10
|
+
|
|
11
|
+
# Global
|
|
12
|
+
npm install -g @elinzy/cli
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Commands
|
|
16
|
+
|
|
17
|
+
### `e eslint`
|
|
18
|
+
|
|
19
|
+
Interactive ESLint config scaffolding. Generates an `eslint.config.mjs` with `@elinzy/eslint-config-extended` presets.
|
|
20
|
+
|
|
21
|
+
```shell
|
|
22
|
+
e eslint
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
The wizard will guide you through:
|
|
26
|
+
|
|
27
|
+
1. Config type — Extended (flat config) or Legacy (.eslintrc compat)
|
|
28
|
+
2. Language — TypeScript or JavaScript
|
|
29
|
+
3. Formatter — Prettier or none
|
|
30
|
+
4. Runtime — Node.js / React / Next.js
|
|
31
|
+
5. Strict configs — Import / React / TypeScript
|
|
32
|
+
6. Create file — writes `eslint.config.mjs` to current directory
|
|
33
|
+
7. Skip install — optionally skip `pnpm add` for dependencies
|
|
34
|
+
|
|
35
|
+
### `e --help`
|
|
36
|
+
|
|
37
|
+
```shell
|
|
38
|
+
e --help # Show all commands
|
|
39
|
+
e eslint --help # Show eslint subcommand options
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## License
|
|
43
|
+
|
|
44
|
+
[MIT](https://github.com/Appleec/e/blob/main/LICENSE)
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
13
|
+
__defProp(to, key, {
|
|
14
|
+
get: ((k) => from[k]).bind(null, key),
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
23
|
+
value: mod,
|
|
24
|
+
enumerable: true
|
|
25
|
+
}) : target, mod));
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
exports.__toESM = __toESM;
|
|
@@ -0,0 +1,259 @@
|
|
|
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;
|
|
@@ -0,0 +1,254 @@
|
|
|
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 };
|
|
@@ -0,0 +1,54 @@
|
|
|
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;
|
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
export { configs, defaults, eslintConfigName, formatters, languages, legacyConfigs, runtimes, strictConfigs, subFolders };
|
|
@@ -0,0 +1,11 @@
|
|
|
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;
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
|
|
7
|
+
//#region src/helpers/createEslintConfigFile/index.ts
|
|
8
|
+
/**
|
|
9
|
+
* Resolve templates directory from the `@elinzy/build-templates` package.
|
|
10
|
+
* Uses import.meta.resolve to find the package, then reads templates locally.
|
|
11
|
+
*/
|
|
12
|
+
const templatesDir = (() => {
|
|
13
|
+
const resolvePaths = [
|
|
14
|
+
node_path.default.resolve(__dirname, "..", "..", "..", "build-templates", "templates"),
|
|
15
|
+
node_path.default.resolve(__dirname, "..", "..", "..", "..", "build-templates", "templates"),
|
|
16
|
+
node_path.default.resolve(process.cwd(), "packages", "build-templates", "templates")
|
|
17
|
+
];
|
|
18
|
+
for (const p of resolvePaths) if (node_fs.default.existsSync(p)) return p;
|
|
19
|
+
return null;
|
|
20
|
+
})();
|
|
21
|
+
const createESLintConfigFile = async (config) => {
|
|
22
|
+
const { configPath, outputPath } = config;
|
|
23
|
+
if (!templatesDir) throw new Error("Cannot find @elinzy/build-templates package. Please ensure it is installed.");
|
|
24
|
+
const templateFile = node_path.default.join(templatesDir, configPath);
|
|
25
|
+
if (!node_fs.default.existsSync(templateFile)) {
|
|
26
|
+
console.warn(`Template not found: ${configPath}`);
|
|
27
|
+
console.warn(`Searched: ${templateFile}`);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const content = node_fs.default.readFileSync(templateFile, "utf8");
|
|
31
|
+
node_fs.default.writeFileSync(outputPath, content, "utf8");
|
|
32
|
+
console.log(`Created: ${outputPath}`);
|
|
33
|
+
console.log(`Template: ${baseGithubUrl}/${configPath}`);
|
|
34
|
+
};
|
|
35
|
+
const baseGithubUrl = "https://github.com/Appleec/e/tree/main/packages/build-templates/templates";
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
exports.baseGithubUrl = baseGithubUrl;
|
|
39
|
+
exports.createESLintConfigFile = createESLintConfigFile;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
|
|
4
|
+
//#region src/helpers/createEslintConfigFile/index.ts
|
|
5
|
+
/**
|
|
6
|
+
* Resolve templates directory from the `@elinzy/build-templates` package.
|
|
7
|
+
* Uses import.meta.resolve to find the package, then reads templates locally.
|
|
8
|
+
*/
|
|
9
|
+
const templatesDir = (() => {
|
|
10
|
+
const resolvePaths = [
|
|
11
|
+
path.resolve(import.meta.dirname, "..", "..", "..", "build-templates", "templates"),
|
|
12
|
+
path.resolve(import.meta.dirname, "..", "..", "..", "..", "build-templates", "templates"),
|
|
13
|
+
path.resolve(process.cwd(), "packages", "build-templates", "templates")
|
|
14
|
+
];
|
|
15
|
+
for (const p of resolvePaths) if (fs.existsSync(p)) return p;
|
|
16
|
+
return null;
|
|
17
|
+
})();
|
|
18
|
+
const createESLintConfigFile = async (config) => {
|
|
19
|
+
const { configPath, outputPath } = config;
|
|
20
|
+
if (!templatesDir) throw new Error("Cannot find @elinzy/build-templates package. Please ensure it is installed.");
|
|
21
|
+
const templateFile = path.join(templatesDir, configPath);
|
|
22
|
+
if (!fs.existsSync(templateFile)) {
|
|
23
|
+
console.warn(`Template not found: ${configPath}`);
|
|
24
|
+
console.warn(`Searched: ${templateFile}`);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const content = fs.readFileSync(templateFile, "utf8");
|
|
28
|
+
fs.writeFileSync(outputPath, content, "utf8");
|
|
29
|
+
console.log(`Created: ${outputPath}`);
|
|
30
|
+
console.log(`Template: ${baseGithubUrl}/${configPath}`);
|
|
31
|
+
};
|
|
32
|
+
const baseGithubUrl = "https://github.com/Appleec/e/tree/main/packages/build-templates/templates";
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
export { baseGithubUrl, createESLintConfigFile };
|
|
@@ -0,0 +1,21 @@
|
|
|
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;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { formatters } from "../../constants/common.mjs";
|
|
2
|
+
import "../../constants/index.mjs";
|
|
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 === formatters.PRETTIER) commands.push("prettier", "eslint-plugin-prettier", "eslint-config-prettier");
|
|
17
|
+
return commands;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
export { getCommands };
|
|
@@ -0,0 +1,26 @@
|
|
|
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;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { configs, eslintConfigName, formatters, languages, subFolders } from "../../constants/common.mjs";
|
|
2
|
+
import "../../constants/index.mjs";
|
|
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 === configs.LEGACY;
|
|
8
|
+
const prettierText = formatter === formatters.PRETTIER ? "prettier" : null;
|
|
9
|
+
const tsOrJsText = language === languages.TYPESCRIPT ? "ts" : "js";
|
|
10
|
+
const legacyLanguage = config === configs.EXTENDED ? null : legacyConfig;
|
|
11
|
+
const strictOrDefaultText = (() => {
|
|
12
|
+
if (!strictConfig || strictConfig.length === 0) return [subFolders.DEFAULT];
|
|
13
|
+
const strictFolder = [...strictConfig].sort().join("-");
|
|
14
|
+
return [subFolders.STRICT, strictFolder];
|
|
15
|
+
})();
|
|
16
|
+
return { path: [
|
|
17
|
+
...isLegacy ? [configs.LEGACY, legacyLanguage] : [runtime],
|
|
18
|
+
prettierText,
|
|
19
|
+
tsOrJsText,
|
|
20
|
+
...strictOrDefaultText,
|
|
21
|
+
eslintConfigName
|
|
22
|
+
].filter(Boolean).join("/") };
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
export { getConfigUrl };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const require_runtime = require("../../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_index = require("../getCommands/index.cjs");
|
|
3
|
+
let cross_spawn = require("cross-spawn");
|
|
4
|
+
cross_spawn = require_runtime.__toESM(cross_spawn, 1);
|
|
5
|
+
|
|
6
|
+
//#region src/helpers/installPackages/index.ts
|
|
7
|
+
const installPackages = async (args) => {
|
|
8
|
+
const [packageManager, ...commands] = require_index.getCommands(args);
|
|
9
|
+
return new Promise((resolve, reject) => {
|
|
10
|
+
(0, cross_spawn.default)(packageManager, commands, {
|
|
11
|
+
stdio: "inherit",
|
|
12
|
+
env: {
|
|
13
|
+
...process.env,
|
|
14
|
+
ADBLOCK: "1",
|
|
15
|
+
NODE_ENV: "development",
|
|
16
|
+
DISABLE_OPENCOLLECTIVE: "1"
|
|
17
|
+
}
|
|
18
|
+
}).on("close", (code) => {
|
|
19
|
+
if (code !== 0) {
|
|
20
|
+
reject(new Error(`${packageManager} ${commands.join(" ")}`, { cause: "package-failed" }));
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
resolve();
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
exports.installPackages = installPackages;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { getCommands } from "../getCommands/index.mjs";
|
|
2
|
+
import spawn from "cross-spawn";
|
|
3
|
+
|
|
4
|
+
//#region src/helpers/installPackages/index.ts
|
|
5
|
+
const installPackages = async (args) => {
|
|
6
|
+
const [packageManager, ...commands] = getCommands(args);
|
|
7
|
+
return new Promise((resolve, reject) => {
|
|
8
|
+
spawn(packageManager, commands, {
|
|
9
|
+
stdio: "inherit",
|
|
10
|
+
env: {
|
|
11
|
+
...process.env,
|
|
12
|
+
ADBLOCK: "1",
|
|
13
|
+
NODE_ENV: "development",
|
|
14
|
+
DISABLE_OPENCOLLECTIVE: "1"
|
|
15
|
+
}
|
|
16
|
+
}).on("close", (code) => {
|
|
17
|
+
if (code !== 0) {
|
|
18
|
+
reject(new Error(`${packageManager} ${commands.join(" ")}`, { cause: "package-failed" }));
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
resolve();
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
export { installPackages };
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const require_functions = require("./utils/functions.cjs");
|
|
3
|
+
const require_package = require("./package.cjs");
|
|
4
|
+
const require_eslint = require("./commands/eslint.cjs");
|
|
5
|
+
let commander = require("commander");
|
|
6
|
+
|
|
7
|
+
//#region src/index.ts
|
|
8
|
+
const program = new commander.Command().name(require_package.name).version(require_package.version, "-v, --version", "Output the current version.").helpOption("-h, --help", "Display help message.");
|
|
9
|
+
program.command("eslint").description("Interactive ESLint config scaffold").action(async () => {
|
|
10
|
+
try {
|
|
11
|
+
await require_eslint.default();
|
|
12
|
+
} catch (error) {
|
|
13
|
+
if (error instanceof Error) require_functions.exit(error);
|
|
14
|
+
else console.error(error);
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
program.parse();
|
|
18
|
+
|
|
19
|
+
//#endregion
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { exit } from "./utils/functions.mjs";
|
|
3
|
+
import { name, version } from "./package.mjs";
|
|
4
|
+
import eslint from "./commands/eslint.mjs";
|
|
5
|
+
import { Command } from "commander";
|
|
6
|
+
|
|
7
|
+
//#region src/index.ts
|
|
8
|
+
const program = new Command().name(name).version(version, "-v, --version", "Output the current version.").helpOption("-h, --help", "Display help message.");
|
|
9
|
+
program.command("eslint").description("Interactive ESLint config scaffold").action(async () => {
|
|
10
|
+
try {
|
|
11
|
+
await eslint();
|
|
12
|
+
} catch (error) {
|
|
13
|
+
if (error instanceof Error) exit(error);
|
|
14
|
+
else console.error(error);
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
program.parse();
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
export { };
|
package/dist/package.cjs
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region package.json
|
|
2
|
+
var name = "@elinzy/cli";
|
|
3
|
+
var version = "0.1.5";
|
|
4
|
+
|
|
5
|
+
//#endregion
|
|
6
|
+
Object.defineProperty(exports, "name", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return name;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "version", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return version;
|
|
16
|
+
}
|
|
17
|
+
});
|
package/dist/package.mjs
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
let ansis = require("ansis");
|
|
3
|
+
ansis = require_runtime.__toESM(ansis, 1);
|
|
4
|
+
|
|
5
|
+
//#region src/utils/functions.ts
|
|
6
|
+
const handleSigTerm = () => process.exit(0);
|
|
7
|
+
const onPromptState = (state) => {
|
|
8
|
+
if (state.aborted) {
|
|
9
|
+
process.stdout.write("\x1B[?25h");
|
|
10
|
+
process.stdout.write("\n");
|
|
11
|
+
process.exit(1);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
const onCancel = () => {
|
|
15
|
+
console.error("Exiting, bye bye.");
|
|
16
|
+
process.exit(1);
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Run Function Catch Block
|
|
20
|
+
* @see https://github.com/vercel/next.js/blob/canary/packages/create-next-app/index.ts#L499
|
|
21
|
+
*/
|
|
22
|
+
const exit = (error) => {
|
|
23
|
+
console.log("Aborting installation.");
|
|
24
|
+
if (error.cause === "package-failed") console.log(`${ansis.default.red(error.message)} has failed.`);
|
|
25
|
+
else console.log(`${ansis.default.red("Unexpected error. Please report it as a bug:")}\n`, error);
|
|
26
|
+
process.exit(1);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
exports.exit = exit;
|
|
31
|
+
exports.handleSigTerm = handleSigTerm;
|
|
32
|
+
exports.onCancel = onCancel;
|
|
33
|
+
exports.onPromptState = onPromptState;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import pc from "ansis";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/functions.ts
|
|
4
|
+
const handleSigTerm = () => process.exit(0);
|
|
5
|
+
const onPromptState = (state) => {
|
|
6
|
+
if (state.aborted) {
|
|
7
|
+
process.stdout.write("\x1B[?25h");
|
|
8
|
+
process.stdout.write("\n");
|
|
9
|
+
process.exit(1);
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
const onCancel = () => {
|
|
13
|
+
console.error("Exiting, bye bye.");
|
|
14
|
+
process.exit(1);
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Run Function Catch Block
|
|
18
|
+
* @see https://github.com/vercel/next.js/blob/canary/packages/create-next-app/index.ts#L499
|
|
19
|
+
*/
|
|
20
|
+
const exit = (error) => {
|
|
21
|
+
console.log("Aborting installation.");
|
|
22
|
+
if (error.cause === "package-failed") console.log(`${pc.red(error.message)} has failed.`);
|
|
23
|
+
else console.log(`${pc.red("Unexpected error. Please report it as a bug:")}\n`, error);
|
|
24
|
+
process.exit(1);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
export { exit, handleSigTerm, onCancel, onPromptState };
|
package/package.json
CHANGED
|
@@ -1,6 +1,67 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elinzy/cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.5",
|
|
4
|
+
"description": "A collection of common scripts and commands for e",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"types": "./dist/index.d.cts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.mjs",
|
|
11
|
+
"require": "./dist/index.cjs"
|
|
12
|
+
},
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public",
|
|
20
|
+
"registry": "https://registry.npmjs.org/"
|
|
21
|
+
},
|
|
22
|
+
"bin": {
|
|
23
|
+
"cli": "./dist/index.mjs"
|
|
24
|
+
},
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "https://github.com/Appleec/e.git",
|
|
28
|
+
"directory": "packages/cli"
|
|
29
|
+
},
|
|
30
|
+
"keywords": [
|
|
31
|
+
"e",
|
|
32
|
+
"cli"
|
|
33
|
+
],
|
|
34
|
+
"author": "Appleec <771992522@qq.com>",
|
|
35
|
+
"license": "MIT",
|
|
36
|
+
"bugs": {
|
|
37
|
+
"url": "https://github.com/Appleec/e/issues"
|
|
38
|
+
},
|
|
39
|
+
"homepage": "https://github.com/Appleec/e#readme",
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"ansis": "^3.17.0",
|
|
42
|
+
"commander": "^14.0.3",
|
|
43
|
+
"conventional-changelog": "^6.0.0",
|
|
44
|
+
"cross-spawn": "^7.0.6",
|
|
45
|
+
"nanospinner": "^1.2.2",
|
|
46
|
+
"node-fetch": "3.3.2",
|
|
47
|
+
"package-manager-detector": "1.6.0",
|
|
48
|
+
"prompts": "^2.4.2",
|
|
49
|
+
"semver": "^7.7.1",
|
|
50
|
+
"@elinzy/core": "^0.1.2",
|
|
51
|
+
"@elinzy/build-templates": "0.1.0",
|
|
52
|
+
"@elinzy/logger": "1.0.0"
|
|
53
|
+
},
|
|
54
|
+
"engines": {
|
|
55
|
+
"node": "^18.18.0 || ^20.9.0 || >=21.1.0"
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"tsdown": "^0.23.1"
|
|
59
|
+
},
|
|
60
|
+
"module": "./dist/index.mjs",
|
|
61
|
+
"scripts": {
|
|
62
|
+
"dev": "tsx src/index.ts",
|
|
63
|
+
"build": "tsdown",
|
|
64
|
+
"typecheck": "tsc --noEmit",
|
|
65
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
66
|
+
}
|
|
6
67
|
}
|