meocli 0.1.1 → 0.1.3
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/README.md +50 -22
- package/dist/commands/hello/world.d.ts +1 -1
- package/dist/commands/hello/world.js +4 -3
- package/dist/commands/prettier/index.d.ts +1 -4
- package/dist/commands/prettier/index.js +57 -86
- package/dist/commands/prettier/reset.d.ts +10 -0
- package/dist/commands/prettier/reset.js +41 -0
- package/dist/lib/commonjs.d.ts +2 -0
- package/dist/lib/commonjs.js +3 -0
- package/dist/lib/resolve.d.ts +9 -0
- package/dist/lib/resolve.js +39 -0
- package/oclif.manifest.json +35 -3
- package/package.json +6 -4
package/README.md
CHANGED
|
@@ -9,9 +9,9 @@ A new CLI generated with oclif
|
|
|
9
9
|
<!-- toc -->
|
|
10
10
|
* [meocli](#meocli)
|
|
11
11
|
* [Dev](#dev)
|
|
12
|
-
* [
|
|
12
|
+
* [Prettier](#prettier)
|
|
13
|
+
* [Prettier.Vscode](#prettiervscode)
|
|
13
14
|
* [Publish](#publish)
|
|
14
|
-
* [Vscode](#vscode)
|
|
15
15
|
* [Usage](#usage)
|
|
16
16
|
* [Commands](#commands)
|
|
17
17
|
<!-- tocstop -->
|
|
@@ -32,27 +32,19 @@ $ pnpm run dev prettier ./tmp/test.json --config=auto --ignore=auto
|
|
|
32
32
|
$ pnpm run dev prettier ./tmp/test.svg --config=built_in --ignore=auto
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
-
#
|
|
35
|
+
# Prettier
|
|
36
36
|
|
|
37
37
|
```sh-session
|
|
38
38
|
$ pnpm install -g meocli
|
|
39
|
-
$ me --
|
|
39
|
+
$ me prettier --help
|
|
40
|
+
$ me prettier reset --verbose # 重置Prettier配置
|
|
40
41
|
$ me prettier ./test.svg --verbose # 使用prettier格式化文件
|
|
41
|
-
$ me hello world
|
|
42
|
-
$ me hello foo -f bar
|
|
43
42
|
```
|
|
44
43
|
|
|
45
|
-
#
|
|
46
|
-
|
|
47
|
-
```sh-session
|
|
48
|
-
$ pnpm login
|
|
49
|
-
$ pnpm build
|
|
50
|
-
$ pnpm publish
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
# Vscode
|
|
44
|
+
# Prettier.Vscode
|
|
54
45
|
|
|
55
46
|
1. `pnpm install -g meocli`
|
|
47
|
+
|
|
56
48
|
2. 配合vscode插件:[emeraldwalk.RunOnSave](https://marketplace.visualstudio.com/items?itemName=emeraldwalk.RunOnSave) 保存时自动格式化
|
|
57
49
|
3. 配置 `.vscode/settings.json` 添加 `"emeraldwalk.runonsave"` 节点,以下为参考配置⤵︎
|
|
58
50
|
|
|
@@ -97,12 +89,26 @@ $ pnpm publish
|
|
|
97
89
|
"match": "Dockerfile$",
|
|
98
90
|
"isAsync": true,
|
|
99
91
|
"cmd": "me prettier ${file}"
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
// nushell
|
|
95
|
+
"match": "\\.(nu)$",
|
|
96
|
+
"isAsync": true,
|
|
97
|
+
"cmd": "topiary format ${file}"
|
|
100
98
|
}
|
|
101
99
|
]
|
|
102
100
|
}
|
|
103
101
|
}
|
|
104
102
|
```
|
|
105
103
|
|
|
104
|
+
# Publish
|
|
105
|
+
|
|
106
|
+
```sh-session
|
|
107
|
+
$ pnpm login
|
|
108
|
+
$ pnpm build
|
|
109
|
+
$ pnpm publish
|
|
110
|
+
```
|
|
111
|
+
|
|
106
112
|
# Usage
|
|
107
113
|
|
|
108
114
|
<!-- usage -->
|
|
@@ -111,7 +117,7 @@ $ npm install -g meocli
|
|
|
111
117
|
$ me COMMAND
|
|
112
118
|
running command...
|
|
113
119
|
$ me (--version)
|
|
114
|
-
meocli/0.1.
|
|
120
|
+
meocli/0.1.3 win32-x64 node-v24.12.0
|
|
115
121
|
$ me --help [COMMAND]
|
|
116
122
|
USAGE
|
|
117
123
|
$ me COMMAND
|
|
@@ -136,6 +142,7 @@ USAGE
|
|
|
136
142
|
* [`me plugins unlink [PLUGIN]`](#me-plugins-unlink-plugin)
|
|
137
143
|
* [`me plugins update`](#me-plugins-update)
|
|
138
144
|
* [`me prettier FILEPATH`](#me-prettier-filepath)
|
|
145
|
+
* [`me prettier reset`](#me-prettier-reset)
|
|
139
146
|
|
|
140
147
|
## `me hello PERSON`
|
|
141
148
|
|
|
@@ -159,7 +166,7 @@ EXAMPLES
|
|
|
159
166
|
hello friend from oclif! (./src/commands/hello/index.ts)
|
|
160
167
|
```
|
|
161
168
|
|
|
162
|
-
_See code: [src/commands/hello/index.ts](https://github.com/meme2046/meocli/blob/v0.1.
|
|
169
|
+
_See code: [src/commands/hello/index.ts](https://github.com/meme2046/meocli/blob/v0.1.3/src/commands/hello/index.ts)_
|
|
163
170
|
|
|
164
171
|
## `me hello world`
|
|
165
172
|
|
|
@@ -177,7 +184,7 @@ EXAMPLES
|
|
|
177
184
|
hello world! (./src/commands/hello/world.ts)
|
|
178
185
|
```
|
|
179
186
|
|
|
180
|
-
_See code: [src/commands/hello/world.ts](https://github.com/meme2046/meocli/blob/v0.1.
|
|
187
|
+
_See code: [src/commands/hello/world.ts](https://github.com/meme2046/meocli/blob/v0.1.3/src/commands/hello/world.ts)_
|
|
181
188
|
|
|
182
189
|
## `me help [COMMAND]`
|
|
183
190
|
|
|
@@ -491,7 +498,7 @@ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/
|
|
|
491
498
|
|
|
492
499
|
## `me prettier FILEPATH`
|
|
493
500
|
|
|
494
|
-
Use Prettier to format file
|
|
501
|
+
Use Prettier to format file,集成:『@prettier/plugin-xml、prettier-plugin-toml、prettier-plugin-sh』、prettier-plugin-nginx
|
|
495
502
|
|
|
496
503
|
```
|
|
497
504
|
USAGE
|
|
@@ -508,13 +515,34 @@ FLAGS
|
|
|
508
515
|
auto:自动检测ignore file
|
|
509
516
|
|
|
510
517
|
DESCRIPTION
|
|
511
|
-
Use Prettier to format
|
|
518
|
+
Use Prettier to format
|
|
519
|
+
file,集成:『@prettier/plugin-xml、prettier-plugin-toml、prettier-plugin-sh』、prettier-plugin-nginx
|
|
512
520
|
|
|
513
521
|
EXAMPLES
|
|
514
|
-
$ me prettier ./tests/test.
|
|
522
|
+
$ me prettier ./tests/test.svg
|
|
515
523
|
|
|
516
524
|
$ me prettier ./src/file.ts --config ./.prettierrc.yaml
|
|
517
525
|
```
|
|
518
526
|
|
|
519
|
-
_See code: [src/commands/prettier/index.ts](https://github.com/meme2046/meocli/blob/v0.1.
|
|
527
|
+
_See code: [src/commands/prettier/index.ts](https://github.com/meme2046/meocli/blob/v0.1.3/src/commands/prettier/index.ts)_
|
|
528
|
+
|
|
529
|
+
## `me prettier reset`
|
|
530
|
+
|
|
531
|
+
reset prettier config and ignore file,『~/.meocli/.prettierrc.yaml, ~/.meocli/.prettierignore』
|
|
532
|
+
|
|
533
|
+
```
|
|
534
|
+
USAGE
|
|
535
|
+
$ me prettier reset [-v]
|
|
536
|
+
|
|
537
|
+
FLAGS
|
|
538
|
+
-v, --verbose Show verbose output
|
|
539
|
+
|
|
540
|
+
DESCRIPTION
|
|
541
|
+
reset prettier config and ignore file,『~/.meocli/.prettierrc.yaml, ~/.meocli/.prettierignore』
|
|
542
|
+
|
|
543
|
+
EXAMPLES
|
|
544
|
+
$ me prettier reset --verbose
|
|
545
|
+
```
|
|
546
|
+
|
|
547
|
+
_See code: [src/commands/prettier/reset.ts](https://github.com/meme2046/meocli/blob/v0.1.3/src/commands/prettier/reset.ts)_
|
|
520
548
|
<!-- commandsstop -->
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Command } from
|
|
1
|
+
import { Command } from "@oclif/core";
|
|
2
2
|
export default class World extends Command {
|
|
3
3
|
static args = {};
|
|
4
|
-
static description =
|
|
4
|
+
static description = "Say hello world";
|
|
5
5
|
static examples = [
|
|
6
6
|
`<%= config.bin %> <%= command.id %>
|
|
7
7
|
hello world! (./src/commands/hello/world.ts)
|
|
@@ -9,6 +9,7 @@ hello world! (./src/commands/hello/world.ts)
|
|
|
9
9
|
];
|
|
10
10
|
static flags = {};
|
|
11
11
|
async run() {
|
|
12
|
-
this.
|
|
12
|
+
await this.parse(World);
|
|
13
|
+
this.log("hello world! (./src/commands/hello/world.ts)");
|
|
13
14
|
}
|
|
14
15
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Command } from
|
|
1
|
+
import { Command } from "@oclif/core";
|
|
2
2
|
export default class Prettier extends Command {
|
|
3
3
|
static args: {
|
|
4
4
|
filePath: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
@@ -15,7 +15,4 @@ export default class Prettier extends Command {
|
|
|
15
15
|
private findProjectPrettierConfig;
|
|
16
16
|
private findProjectPrettierIgnore;
|
|
17
17
|
private replacePluginArgs;
|
|
18
|
-
private resolvePlugin;
|
|
19
|
-
private resolvePluginArgs;
|
|
20
|
-
private resolvePluginPaths;
|
|
21
18
|
}
|
|
@@ -1,41 +1,40 @@
|
|
|
1
|
-
import { Args, Command, Flags } from
|
|
2
|
-
import { execa } from
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { toYamlFile } from
|
|
10
|
-
const require = createRequire(import.meta.url);
|
|
1
|
+
import { Args, Command, Flags } from "@oclif/core";
|
|
2
|
+
import { execa } from "execa";
|
|
3
|
+
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { homedir } from "node:os";
|
|
5
|
+
import { dirname, join } from "node:path";
|
|
6
|
+
import { DEFAULT_CONFIG, DEFAULT_IGNORE_PATTERNS, } from "../../consts/prettierrc.js";
|
|
7
|
+
import { require } from "../../lib/commonjs.js";
|
|
8
|
+
import { resolvePaths } from "../../lib/resolve.js";
|
|
9
|
+
import { toYamlFile } from "../../lib/to-yaml-file.js";
|
|
11
10
|
export default class Prettier extends Command {
|
|
12
11
|
static args = {
|
|
13
12
|
filePath: Args.string({
|
|
14
|
-
description:
|
|
13
|
+
description: "file path that need to be formatted by Prettier",
|
|
15
14
|
required: true,
|
|
16
15
|
}),
|
|
17
16
|
};
|
|
18
|
-
static description =
|
|
17
|
+
static description = "Use Prettier to format file,集成:『@prettier/plugin-xml、prettier-plugin-toml、prettier-plugin-sh』、prettier-plugin-nginx";
|
|
19
18
|
static examples = [
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
"<%= config.bin %> <%= command.id %> ./tests/test.svg",
|
|
20
|
+
"<%= config.bin %> <%= command.id %> ./src/file.ts --config ./.prettierrc.yaml",
|
|
22
21
|
];
|
|
23
22
|
static flags = {
|
|
24
23
|
config: Flags.string({
|
|
25
|
-
char:
|
|
26
|
-
default:
|
|
27
|
-
description:
|
|
24
|
+
char: "c",
|
|
25
|
+
default: "built_in",
|
|
26
|
+
description: "built_in:使用内置规则(默认值), 传入路径则是使用自定义配置, auto:自动检测config file",
|
|
28
27
|
required: false,
|
|
29
28
|
}),
|
|
30
29
|
ignore: Flags.string({
|
|
31
|
-
default:
|
|
32
|
-
description:
|
|
30
|
+
default: "built_in",
|
|
31
|
+
description: "built_in:使用内置规则(默认值), 传入路径则是使用自定义规则, auto:自动检测ignore file",
|
|
33
32
|
required: false,
|
|
34
33
|
}),
|
|
35
34
|
verbose: Flags.boolean({
|
|
36
|
-
char:
|
|
35
|
+
char: "v",
|
|
37
36
|
default: false,
|
|
38
|
-
description:
|
|
37
|
+
description: "Show verbose output",
|
|
39
38
|
}),
|
|
40
39
|
// 'no-config': Flags.boolean({
|
|
41
40
|
// default: false,
|
|
@@ -51,8 +50,8 @@ export default class Prettier extends Command {
|
|
|
51
50
|
const { filePath } = args;
|
|
52
51
|
const { config, ignore, verbose } = flags;
|
|
53
52
|
if (verbose) {
|
|
54
|
-
process.env.DEBUG =
|
|
55
|
-
require(
|
|
53
|
+
process.env.DEBUG = "oclif:me:prettier";
|
|
54
|
+
require("debug").enable(process.env.DEBUG);
|
|
56
55
|
}
|
|
57
56
|
// 检查文件是否存在
|
|
58
57
|
if (!existsSync(filePath)) {
|
|
@@ -61,8 +60,8 @@ export default class Prettier extends Command {
|
|
|
61
60
|
}
|
|
62
61
|
// 检测当前使用的包管理器
|
|
63
62
|
// const packageManager = this.detectPackageManager()
|
|
64
|
-
const prettierMain = require.resolve(
|
|
65
|
-
const prettierBin = join(dirname(prettierMain),
|
|
63
|
+
const prettierMain = require.resolve("prettier");
|
|
64
|
+
const prettierBin = join(dirname(prettierMain), "./bin/prettier.cjs");
|
|
66
65
|
// 获取 prettier 可执行文件的路径
|
|
67
66
|
// const __filename = fileURLToPath(import.meta.url)
|
|
68
67
|
// const __dirname = dirname(__filename)
|
|
@@ -82,54 +81,56 @@ export default class Prettier extends Command {
|
|
|
82
81
|
mkdirSync(meocliPath);
|
|
83
82
|
}
|
|
84
83
|
if (!existsSync(ignorePath)) {
|
|
85
|
-
writeFileSync(ignorePath, DEFAULT_IGNORE_PATTERNS.join(
|
|
84
|
+
writeFileSync(ignorePath, DEFAULT_IGNORE_PATTERNS.join("\n"), {
|
|
85
|
+
encoding: "utf8",
|
|
86
|
+
});
|
|
86
87
|
}
|
|
87
88
|
if (!existsSync(configPath)) {
|
|
88
|
-
DEFAULT_CONFIG.plugins =
|
|
89
|
-
this.debug(
|
|
89
|
+
DEFAULT_CONFIG.plugins = resolvePaths(DEFAULT_CONFIG.plugins);
|
|
90
|
+
this.debug("prettier config:", DEFAULT_CONFIG);
|
|
90
91
|
toYamlFile(configPath, DEFAULT_CONFIG);
|
|
91
92
|
}
|
|
92
93
|
// 根据包管理器类型构建参数
|
|
93
|
-
const prettierArgs = [
|
|
94
|
-
if (ignore ===
|
|
95
|
-
prettierArgs.unshift(
|
|
94
|
+
const prettierArgs = ["--no-color", "--write", filePath];
|
|
95
|
+
if (ignore === "built_in") {
|
|
96
|
+
prettierArgs.unshift("--ignore-path", ignorePath);
|
|
96
97
|
}
|
|
97
98
|
else if (existsSync(ignore)) {
|
|
98
|
-
prettierArgs.unshift(
|
|
99
|
+
prettierArgs.unshift("--ignore-path", ignore);
|
|
99
100
|
}
|
|
100
101
|
else {
|
|
101
102
|
const projectIgnore = this.findProjectPrettierIgnore();
|
|
102
103
|
if (projectIgnore) {
|
|
103
|
-
prettierArgs.unshift(
|
|
104
|
+
prettierArgs.unshift("--ignore-path", projectIgnore);
|
|
104
105
|
}
|
|
105
106
|
else {
|
|
106
|
-
prettierArgs.unshift(
|
|
107
|
+
prettierArgs.unshift("--ignore-path", ignorePath);
|
|
107
108
|
}
|
|
108
109
|
}
|
|
109
110
|
// const resolvedPluginArgs = this.resolvePluginPaths(DEFAULT_PLUGINS, projectRoot)
|
|
110
111
|
// const argsWithResolvedPlugins = this.replacePluginArgs(DEFAULT_ARGS, resolvedPluginArgs)
|
|
111
112
|
// const pluginArgs = this.resolvePluginArgs(DEFAULT_PLUGINS)
|
|
112
113
|
// const completeArgs = [...DEFAULT_ARGS, ...pluginArgs, ...prettierArgs]
|
|
113
|
-
if (config ===
|
|
114
|
+
if (config === "built_in") {
|
|
114
115
|
// 为插件参数使用绝对路径,避免全局安装时找不到插件
|
|
115
|
-
prettierArgs.unshift(
|
|
116
|
+
prettierArgs.unshift("--config", configPath);
|
|
116
117
|
}
|
|
117
118
|
else if (existsSync(config)) {
|
|
118
|
-
prettierArgs.unshift(
|
|
119
|
+
prettierArgs.unshift("--config", config);
|
|
119
120
|
}
|
|
120
121
|
else {
|
|
121
122
|
// 否则尝试查找项目中的配置文件
|
|
122
123
|
const projectConfig = this.findProjectPrettierConfig();
|
|
123
124
|
if (projectConfig) {
|
|
124
|
-
prettierArgs.unshift(
|
|
125
|
+
prettierArgs.unshift("--config", projectConfig);
|
|
125
126
|
}
|
|
126
127
|
else {
|
|
127
128
|
// 为插件参数使用绝对路径,避免全局安装时找不到插件
|
|
128
|
-
prettierArgs.unshift(
|
|
129
|
+
prettierArgs.unshift("--config", configPath);
|
|
129
130
|
}
|
|
130
131
|
}
|
|
131
|
-
this.debug(
|
|
132
|
-
this.debug(
|
|
132
|
+
this.debug("prettier path:", prettierBin);
|
|
133
|
+
this.debug("args:", JSON.stringify(prettierArgs));
|
|
133
134
|
// this.log(`Formatting file: ${filePath}`)
|
|
134
135
|
const { stderr, stdout } = await execa(prettierBin, prettierArgs, {
|
|
135
136
|
env: { ...process.env },
|
|
@@ -144,18 +145,24 @@ export default class Prettier extends Command {
|
|
|
144
145
|
}
|
|
145
146
|
detectPackageManager() {
|
|
146
147
|
// 检查项目根目录是否存在 pnpm-lock.yaml 来判断是否使用 pnpm
|
|
147
|
-
if (existsSync(join(process.cwd(),
|
|
148
|
-
return
|
|
148
|
+
if (existsSync(join(process.cwd(), "pnpm-lock.yaml"))) {
|
|
149
|
+
return "pnpx";
|
|
149
150
|
}
|
|
150
151
|
// 检查是否存在 yarn.lock 来判断是否使用 yarn
|
|
151
|
-
if (existsSync(join(process.cwd(),
|
|
152
|
-
return
|
|
152
|
+
if (existsSync(join(process.cwd(), "yarn.lock"))) {
|
|
153
|
+
return "yarn";
|
|
153
154
|
}
|
|
154
155
|
// 默认使用 npm
|
|
155
|
-
return
|
|
156
|
+
return "npx";
|
|
156
157
|
}
|
|
157
158
|
findProjectPrettierConfig() {
|
|
158
|
-
const possibleConfigs = [
|
|
159
|
+
const possibleConfigs = [
|
|
160
|
+
".prettierrc",
|
|
161
|
+
".prettierrc.json",
|
|
162
|
+
".prettierrc.yaml",
|
|
163
|
+
".prettierrc.yml",
|
|
164
|
+
".prettierrc.js",
|
|
165
|
+
];
|
|
159
166
|
for (const configFile of possibleConfigs) {
|
|
160
167
|
if (existsSync(configFile)) {
|
|
161
168
|
return configFile;
|
|
@@ -164,7 +171,7 @@ export default class Prettier extends Command {
|
|
|
164
171
|
return null;
|
|
165
172
|
}
|
|
166
173
|
findProjectPrettierIgnore() {
|
|
167
|
-
const possibleIgnoreFiles = [
|
|
174
|
+
const possibleIgnoreFiles = [".prettierignore", ".gitignore"];
|
|
168
175
|
for (const ignoreFile of possibleIgnoreFiles) {
|
|
169
176
|
if (existsSync(ignoreFile)) {
|
|
170
177
|
return ignoreFile;
|
|
@@ -176,7 +183,7 @@ export default class Prettier extends Command {
|
|
|
176
183
|
replacePluginArgs(defaultArgs, resolvedPluginPaths) {
|
|
177
184
|
const newArgs = [];
|
|
178
185
|
for (let i = 0; i < defaultArgs.length; i++) {
|
|
179
|
-
if (defaultArgs[i] ===
|
|
186
|
+
if (defaultArgs[i] === "--plugin" && i + 1 < defaultArgs.length) {
|
|
180
187
|
// 跳过这个 '--plugin' 标记和它的值,稍后替换
|
|
181
188
|
i++; // 跳过下一个值(插件名称)
|
|
182
189
|
continue;
|
|
@@ -185,44 +192,8 @@ export default class Prettier extends Command {
|
|
|
185
192
|
}
|
|
186
193
|
// 添加解析后的插件路径
|
|
187
194
|
for (const pluginPath of resolvedPluginPaths) {
|
|
188
|
-
newArgs.push(
|
|
195
|
+
newArgs.push("--plugin", pluginPath);
|
|
189
196
|
}
|
|
190
197
|
return newArgs;
|
|
191
198
|
}
|
|
192
|
-
resolvePlugin(plugins) {
|
|
193
|
-
return plugins.map((plugin) => {
|
|
194
|
-
// 尝试查找插件的实际路径
|
|
195
|
-
const pluginPath = require.resolve(plugin);
|
|
196
|
-
if (existsSync(pluginPath)) {
|
|
197
|
-
return pluginPath;
|
|
198
|
-
}
|
|
199
|
-
// 如果插件路径不存在,则返回原始名称(让 prettier 自己处理)
|
|
200
|
-
return plugin;
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
resolvePluginArgs(plugins) {
|
|
204
|
-
const pluginArgs = [];
|
|
205
|
-
for (const plugin of plugins) {
|
|
206
|
-
const pluginPath = require.resolve(plugin.name);
|
|
207
|
-
if (existsSync(pluginPath)) {
|
|
208
|
-
pluginArgs.push('--plugin', pluginPath);
|
|
209
|
-
}
|
|
210
|
-
else {
|
|
211
|
-
pluginArgs.push('--plugin', plugin.name);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
return pluginArgs;
|
|
215
|
-
}
|
|
216
|
-
// 将插件名称转换为绝对路径
|
|
217
|
-
resolvePluginPaths(plugins, projectRoot) {
|
|
218
|
-
return plugins.map((plugin) => {
|
|
219
|
-
// 查找插件的实际路径
|
|
220
|
-
const pluginPath = join(projectRoot, 'node_modules', plugin.name, plugin.main);
|
|
221
|
-
if (existsSync(pluginPath)) {
|
|
222
|
-
return pluginPath;
|
|
223
|
-
}
|
|
224
|
-
// 如果插件路径不存在,则返回原始名称(让 prettier 自己处理)
|
|
225
|
-
return plugin.name;
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
199
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Command } from "@oclif/core";
|
|
2
|
+
export default class Reset extends Command {
|
|
3
|
+
static args: {};
|
|
4
|
+
static description: string;
|
|
5
|
+
static examples: string[];
|
|
6
|
+
static flags: {
|
|
7
|
+
verbose: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
8
|
+
};
|
|
9
|
+
run(): Promise<void>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Command, Flags } from "@oclif/core";
|
|
2
|
+
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { DEFAULT_CONFIG, DEFAULT_IGNORE_PATTERNS, } from "../../consts/prettierrc.js";
|
|
5
|
+
import { require } from "../../lib/commonjs.js";
|
|
6
|
+
import { resolvePaths } from "../../lib/resolve.js";
|
|
7
|
+
import { toYamlFile } from "../../lib/to-yaml-file.js";
|
|
8
|
+
export default class Reset extends Command {
|
|
9
|
+
static args = {};
|
|
10
|
+
static description = "reset prettier config and ignore file,『~/.meocli/.prettierrc.yaml, ~/.meocli/.prettierignore』";
|
|
11
|
+
static examples = [`<%= config.bin %> <%= command.id %> --verbose`];
|
|
12
|
+
static flags = {
|
|
13
|
+
verbose: Flags.boolean({
|
|
14
|
+
char: "v",
|
|
15
|
+
default: false,
|
|
16
|
+
description: "Show verbose output",
|
|
17
|
+
}),
|
|
18
|
+
};
|
|
19
|
+
async run() {
|
|
20
|
+
const { flags } = await this.parse(Reset);
|
|
21
|
+
const { verbose } = flags;
|
|
22
|
+
if (verbose) {
|
|
23
|
+
process.env.DEBUG = "oclif:me:prettier:reset";
|
|
24
|
+
require("debug").enable(process.env.DEBUG);
|
|
25
|
+
}
|
|
26
|
+
const meocliPath = `${homedir}/.meocli`;
|
|
27
|
+
const ignorePath = `${meocliPath}/.prettierignore`;
|
|
28
|
+
const configPath = `${meocliPath}/.prettierrc.yaml`;
|
|
29
|
+
if (!existsSync(meocliPath)) {
|
|
30
|
+
mkdirSync(meocliPath);
|
|
31
|
+
}
|
|
32
|
+
writeFileSync(ignorePath, DEFAULT_IGNORE_PATTERNS.join("\n"), {
|
|
33
|
+
encoding: "utf8",
|
|
34
|
+
});
|
|
35
|
+
this.debug("Prettier ignore >:", DEFAULT_IGNORE_PATTERNS);
|
|
36
|
+
DEFAULT_CONFIG.plugins = resolvePaths(DEFAULT_CONFIG.plugins);
|
|
37
|
+
this.debug("Prettier config >:", DEFAULT_CONFIG);
|
|
38
|
+
toYamlFile(configPath, DEFAULT_CONFIG);
|
|
39
|
+
this.log("✔ Prettier config and ignore file reset success!");
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare function resolvePaths(names: string[]): string[];
|
|
2
|
+
export declare function resolvePluginArgs(plugins: {
|
|
3
|
+
main: string;
|
|
4
|
+
name: string;
|
|
5
|
+
}[]): string[];
|
|
6
|
+
export declare function resolvePluginPaths(plugins: {
|
|
7
|
+
main: string;
|
|
8
|
+
name: string;
|
|
9
|
+
}[], projectRoot: string): string[];
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { require } from "./commonjs.js";
|
|
4
|
+
export function resolvePaths(names) {
|
|
5
|
+
return names.map((name) => {
|
|
6
|
+
// 尝试查找插件的实际路径
|
|
7
|
+
const rPath = require.resolve(name);
|
|
8
|
+
if (existsSync(rPath)) {
|
|
9
|
+
return rPath;
|
|
10
|
+
}
|
|
11
|
+
// 如果插件路径不存在,则返回原始名称(让 prettier 自己处理)
|
|
12
|
+
return name;
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
export function resolvePluginArgs(plugins) {
|
|
16
|
+
const pluginArgs = [];
|
|
17
|
+
for (const plugin of plugins) {
|
|
18
|
+
const pluginPath = require.resolve(plugin.name);
|
|
19
|
+
if (existsSync(pluginPath)) {
|
|
20
|
+
pluginArgs.push("--plugin", pluginPath);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
pluginArgs.push("--plugin", plugin.name);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return pluginArgs;
|
|
27
|
+
}
|
|
28
|
+
// 将插件名称转换为绝对路径
|
|
29
|
+
export function resolvePluginPaths(plugins, projectRoot) {
|
|
30
|
+
return plugins.map((plugin) => {
|
|
31
|
+
// 查找插件的实际路径
|
|
32
|
+
const pluginPath = join(projectRoot, "node_modules", plugin.name, plugin.main);
|
|
33
|
+
if (existsSync(pluginPath)) {
|
|
34
|
+
return pluginPath;
|
|
35
|
+
}
|
|
36
|
+
// 如果插件路径不存在,则返回原始名称(让 prettier 自己处理)
|
|
37
|
+
return plugin.name;
|
|
38
|
+
});
|
|
39
|
+
}
|
package/oclif.manifest.json
CHANGED
|
@@ -73,9 +73,9 @@
|
|
|
73
73
|
"required": true
|
|
74
74
|
}
|
|
75
75
|
},
|
|
76
|
-
"description": "Use Prettier to format file",
|
|
76
|
+
"description": "Use Prettier to format file,集成:『@prettier/plugin-xml、prettier-plugin-toml、prettier-plugin-sh』、prettier-plugin-nginx",
|
|
77
77
|
"examples": [
|
|
78
|
-
"<%= config.bin %> <%= command.id %> ./tests/test.
|
|
78
|
+
"<%= config.bin %> <%= command.id %> ./tests/test.svg",
|
|
79
79
|
"<%= config.bin %> <%= command.id %> ./src/file.ts --config ./.prettierrc.yaml"
|
|
80
80
|
],
|
|
81
81
|
"flags": {
|
|
@@ -121,7 +121,39 @@
|
|
|
121
121
|
"prettier",
|
|
122
122
|
"index.js"
|
|
123
123
|
]
|
|
124
|
+
},
|
|
125
|
+
"prettier:reset": {
|
|
126
|
+
"aliases": [],
|
|
127
|
+
"args": {},
|
|
128
|
+
"description": "reset prettier config and ignore file,『~/.meocli/.prettierrc.yaml, ~/.meocli/.prettierignore』",
|
|
129
|
+
"examples": [
|
|
130
|
+
"<%= config.bin %> <%= command.id %> --verbose"
|
|
131
|
+
],
|
|
132
|
+
"flags": {
|
|
133
|
+
"verbose": {
|
|
134
|
+
"char": "v",
|
|
135
|
+
"description": "Show verbose output",
|
|
136
|
+
"name": "verbose",
|
|
137
|
+
"allowNo": false,
|
|
138
|
+
"type": "boolean"
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
"hasDynamicHelp": false,
|
|
142
|
+
"hiddenAliases": [],
|
|
143
|
+
"id": "prettier:reset",
|
|
144
|
+
"pluginAlias": "meocli",
|
|
145
|
+
"pluginName": "meocli",
|
|
146
|
+
"pluginType": "core",
|
|
147
|
+
"strict": true,
|
|
148
|
+
"enableJsonFlag": false,
|
|
149
|
+
"isESM": true,
|
|
150
|
+
"relativePath": [
|
|
151
|
+
"dist",
|
|
152
|
+
"commands",
|
|
153
|
+
"prettier",
|
|
154
|
+
"reset.js"
|
|
155
|
+
]
|
|
124
156
|
}
|
|
125
157
|
},
|
|
126
|
-
"version": "0.1.
|
|
158
|
+
"version": "0.1.3"
|
|
127
159
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "meocli",
|
|
3
|
-
"description": "
|
|
4
|
-
"version": "0.1.
|
|
3
|
+
"description": "node CLI generated with oclif, Integrate Prettier",
|
|
4
|
+
"version": "0.1.3",
|
|
5
5
|
"author": "meme2046",
|
|
6
6
|
"bin": {
|
|
7
7
|
"me": "./bin/run.js"
|
|
@@ -49,7 +49,9 @@
|
|
|
49
49
|
],
|
|
50
50
|
"homepage": "https://github.com/meme2046/meocli",
|
|
51
51
|
"keywords": [
|
|
52
|
-
"oclif"
|
|
52
|
+
"oclif",
|
|
53
|
+
"prettier",
|
|
54
|
+
"formatting"
|
|
53
55
|
],
|
|
54
56
|
"license": "MIT",
|
|
55
57
|
"main": "dist/index.js",
|
|
@@ -73,7 +75,7 @@
|
|
|
73
75
|
"types": "dist/index.d.ts",
|
|
74
76
|
"scripts": {
|
|
75
77
|
"ncu": "ncu --target minor --reject webpack,shx",
|
|
76
|
-
"dev": "node --no-deprecation --no-warnings --loader ts-node/esm
|
|
78
|
+
"dev": "node --no-deprecation --no-warnings --disable-warning=ExperimentalWarning --loader ts-node/esm bin/dev.js",
|
|
77
79
|
"prod": "node bin/run.js",
|
|
78
80
|
"build": "shx rm -rf dist && tsc -b",
|
|
79
81
|
"lint": "eslint",
|