meocli 0.1.0 → 0.1.2

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 CHANGED
@@ -9,6 +9,8 @@ A new CLI generated with oclif
9
9
  <!-- toc -->
10
10
  * [meocli](#meocli)
11
11
  * [Dev](#dev)
12
+ * [Prettier](#prettier)
13
+ * [Prettier.Vscode](#prettiervscode)
12
14
  * [Publish](#publish)
13
15
  * [Usage](#usage)
14
16
  * [Commands](#commands)
@@ -17,14 +19,86 @@ A new CLI generated with oclif
17
19
  # Dev
18
20
 
19
21
  ```sh-session
22
+ <!-- pnpm exec -->
23
+ $ pnpm ncu # 检查更新
24
+ $ pnpm ncu -u # 升级更新
20
25
  <!-- demo -->
21
26
  $ pnpm run dev hello world
22
27
  $ pnpm run prod hello world
23
28
  $ pnpm run dev hello foo -f bar
24
29
  <!-- prettier -->
25
- $ pnpm run dev pr ./tmp/test.svg --verbose
26
- $ pnpm run dev pr ./tmp/test.json --config=auto --ignore=auto
27
- $ pnpm run dev pr ./tmp/test.svg --config=built_in --ignore=auto
30
+ $ pnpm run dev prettier ./tmp/test.svg --verbose
31
+ $ pnpm run dev prettier ./tmp/test.json --config=auto --ignore=auto
32
+ $ pnpm run dev prettier ./tmp/test.svg --config=built_in --ignore=auto
33
+ ```
34
+
35
+ # Prettier
36
+
37
+ ```sh-session
38
+ $ pnpm install -g meocli
39
+ $ me prettier --help
40
+ $ me prettier reset --verbose # 重置Prettier配置
41
+ $ me prettier ./test.svg --verbose # 使用prettier格式化文件
42
+ ```
43
+
44
+ # Prettier.Vscode
45
+
46
+ 1. `pnpm install -g meocli`
47
+
48
+ 2. 配合vscode插件:[emeraldwalk.RunOnSave](https://marketplace.visualstudio.com/items?itemName=emeraldwalk.RunOnSave) 保存时自动格式化
49
+ 3. 配置 `.vscode/settings.json` 添加 `"emeraldwalk.runonsave"` 节点,以下为参考配置⤵︎
50
+
51
+ ```json
52
+ {
53
+ "emeraldwalk.runonsave": {
54
+ "commands": [
55
+ {
56
+ // prettier
57
+ "match": "\\.(ts|js|json|html|css|graphql|gql|yaml|yml|md)$",
58
+ "notMatch": "node_modules/*$",
59
+ "isAsync": true,
60
+ "cmd": "me prettier ${file}"
61
+ },
62
+ {
63
+ // @prettier/plugin-xml
64
+ "match": "\\.(xml|svg)$",
65
+ "isAsync": true,
66
+ "cmd": "me prettier ${file}"
67
+ },
68
+ {
69
+ // prettier-plugin-toml
70
+ "match": "\\.(toml)$",
71
+ "isAsync": true,
72
+ "cmd": "me prettier ${file}"
73
+ },
74
+ {
75
+ // prettier-plugin-nginx
76
+ "match": "\\.(nginx)$",
77
+ "isAsync": true,
78
+ "cmd": "me prettier ${file}"
79
+ },
80
+ {
81
+ // prettier-plugin-sh
82
+ "match": "\\.(sh|env|Dockerfile|properties|gitignore|dockerignore|prettierignore)$",
83
+ "notMatch": "\\.(nu)$",
84
+ "isAsync": true,
85
+ "cmd": "me prettier ${file}"
86
+ },
87
+ {
88
+ // no-dot-ext
89
+ "match": "Dockerfile$",
90
+ "isAsync": true,
91
+ "cmd": "me prettier ${file}"
92
+ },
93
+ {
94
+ // nushell
95
+ "match": "\\.(nu)$",
96
+ "isAsync": true,
97
+ "cmd": "topiary format ${file}"
98
+ }
99
+ ]
100
+ }
101
+ }
28
102
  ```
29
103
 
30
104
  # Publish
@@ -43,7 +117,7 @@ $ npm install -g meocli
43
117
  $ me COMMAND
44
118
  running command...
45
119
  $ me (--version)
46
- meocli/0.1.0 win32-x64 node-v24.12.0
120
+ meocli/0.1.2 win32-x64 node-v24.12.0
47
121
  $ me --help [COMMAND]
48
122
  USAGE
49
123
  $ me COMMAND
@@ -67,7 +141,8 @@ USAGE
67
141
  * [`me plugins uninstall [PLUGIN]`](#me-plugins-uninstall-plugin)
68
142
  * [`me plugins unlink [PLUGIN]`](#me-plugins-unlink-plugin)
69
143
  * [`me plugins update`](#me-plugins-update)
70
- * [`me pr FILEPATH`](#me-pr-filepath)
144
+ * [`me prettier FILEPATH`](#me-prettier-filepath)
145
+ * [`me prettier reset`](#me-prettier-reset)
71
146
 
72
147
  ## `me hello PERSON`
73
148
 
@@ -91,7 +166,7 @@ EXAMPLES
91
166
  hello friend from oclif! (./src/commands/hello/index.ts)
92
167
  ```
93
168
 
94
- _See code: [src/commands/hello/index.ts](https://github.com/meme2046/meocli/blob/v0.1.0/src/commands/hello/index.ts)_
169
+ _See code: [src/commands/hello/index.ts](https://github.com/meme2046/meocli/blob/v0.1.2/src/commands/hello/index.ts)_
95
170
 
96
171
  ## `me hello world`
97
172
 
@@ -109,7 +184,7 @@ EXAMPLES
109
184
  hello world! (./src/commands/hello/world.ts)
110
185
  ```
111
186
 
112
- _See code: [src/commands/hello/world.ts](https://github.com/meme2046/meocli/blob/v0.1.0/src/commands/hello/world.ts)_
187
+ _See code: [src/commands/hello/world.ts](https://github.com/meme2046/meocli/blob/v0.1.2/src/commands/hello/world.ts)_
113
188
 
114
189
  ## `me help [COMMAND]`
115
190
 
@@ -421,13 +496,13 @@ DESCRIPTION
421
496
 
422
497
  _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.54/src/commands/plugins/update.ts)_
423
498
 
424
- ## `me pr FILEPATH`
499
+ ## `me prettier FILEPATH`
425
500
 
426
- Use Prettier to format file
501
+ Use Prettier to format file,集成:『@prettier/plugin-xml、prettier-plugin-toml、prettier-plugin-sh』、prettier-plugin-nginx
427
502
 
428
503
  ```
429
504
  USAGE
430
- $ me pr FILEPATH [-c <value>] [--ignore <value>] [-v]
505
+ $ me prettier FILEPATH [-c <value>] [--ignore <value>] [-v]
431
506
 
432
507
  ARGUMENTS
433
508
  FILEPATH file path that need to be formatted by Prettier
@@ -440,13 +515,34 @@ FLAGS
440
515
  auto:自动检测ignore file
441
516
 
442
517
  DESCRIPTION
443
- Use Prettier to format file
518
+ Use Prettier to format
519
+ file,集成:『@prettier/plugin-xml、prettier-plugin-toml、prettier-plugin-sh』、prettier-plugin-nginx
444
520
 
445
521
  EXAMPLES
446
- $ me pr ./tests/test.json
522
+ $ me prettier ./tests/test.svg
523
+
524
+ $ me prettier ./src/file.ts --config ./.prettierrc.yaml
525
+ ```
526
+
527
+ _See code: [src/commands/prettier/index.ts](https://github.com/meme2046/meocli/blob/v0.1.2/src/commands/prettier/index.ts)_
528
+
529
+ ## `me prettier reset`
447
530
 
448
- $ me pr ./src/file.ts --config ./.prettierrc.yaml
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
449
545
  ```
450
546
 
451
- _See code: [src/commands/pr/index.ts](https://github.com/meme2046/meocli/blob/v0.1.0/src/commands/pr/index.ts)_
547
+ _See code: [src/commands/prettier/reset.ts](https://github.com/meme2046/meocli/blob/v0.1.2/src/commands/prettier/reset.ts)_
452
548
  <!-- commandsstop -->
@@ -1,4 +1,4 @@
1
- import { Command } from '@oclif/core';
1
+ import { Command } from "@oclif/core";
2
2
  export default class World extends Command {
3
3
  static args: {};
4
4
  static description: string;
@@ -1,7 +1,7 @@
1
- import { Command } from '@oclif/core';
1
+ import { Command } from "@oclif/core";
2
2
  export default class World extends Command {
3
3
  static args = {};
4
- static description = 'Say hello world';
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.log('hello world! (./src/commands/hello/world.ts)');
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 '@oclif/core';
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 '@oclif/core';
2
- import { execa } from 'execa';
3
- // import {spawn} from 'node:child_process'
4
- import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
5
- import { createRequire } from 'node:module';
6
- import { homedir } from 'node:os';
7
- import { dirname, join } from 'node:path';
8
- import { DEFAULT_CONFIG, DEFAULT_IGNORE_PATTERNS } from '../../consts/prettierrc.js';
9
- import { toYamlFile } from '../../lib/to-yaml-file.js';
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: 'file path that need to be formatted by Prettier',
13
+ description: "file path that need to be formatted by Prettier",
15
14
  required: true,
16
15
  }),
17
16
  };
18
- static description = 'Use Prettier to format file';
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
- '<%= config.bin %> <%= command.id %> ./tests/test.json',
21
- '<%= config.bin %> <%= command.id %> ./src/file.ts --config ./.prettierrc.yaml',
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: 'c',
26
- default: 'built_in',
27
- description: 'built_in:使用内置规则(默认值), 传入路径则是使用自定义配置, auto:自动检测config file',
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: 'built_in',
32
- description: 'built_in:使用内置规则(默认值), 传入路径则是使用自定义规则, auto:自动检测ignore file',
30
+ default: "built_in",
31
+ description: "built_in:使用内置规则(默认值), 传入路径则是使用自定义规则, auto:自动检测ignore file",
33
32
  required: false,
34
33
  }),
35
34
  verbose: Flags.boolean({
36
- char: 'v',
35
+ char: "v",
37
36
  default: false,
38
- description: 'Show verbose output',
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 = 'oclif:me:pr';
55
- require('debug').enable(process.env.DEBUG);
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('prettier');
65
- const prettierBin = join(dirname(prettierMain), './bin/prettier.cjs');
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('\n'), { encoding: 'utf8' });
84
+ writeFileSync(ignorePath, DEFAULT_IGNORE_PATTERNS.join("\n"), {
85
+ encoding: "utf8",
86
+ });
86
87
  }
87
88
  if (!existsSync(configPath)) {
88
- DEFAULT_CONFIG.plugins = this.resolvePlugin(DEFAULT_CONFIG.plugins);
89
- this.debug('prettier config:', DEFAULT_CONFIG);
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 = ['--no-color', '--write', filePath];
94
- if (ignore === 'built_in') {
95
- prettierArgs.unshift('--ignore-path', ignorePath);
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('--ignore-path', ignore);
99
+ prettierArgs.unshift("--ignore-path", ignore);
99
100
  }
100
101
  else {
101
102
  const projectIgnore = this.findProjectPrettierIgnore();
102
103
  if (projectIgnore) {
103
- prettierArgs.unshift('--ignore-path', projectIgnore);
104
+ prettierArgs.unshift("--ignore-path", projectIgnore);
104
105
  }
105
106
  else {
106
- prettierArgs.unshift('--ignore-path', ignorePath);
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 === 'built_in') {
114
+ if (config === "built_in") {
114
115
  // 为插件参数使用绝对路径,避免全局安装时找不到插件
115
- prettierArgs.unshift('--config', configPath);
116
+ prettierArgs.unshift("--config", configPath);
116
117
  }
117
118
  else if (existsSync(config)) {
118
- prettierArgs.unshift('--config', config);
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('--config', projectConfig);
125
+ prettierArgs.unshift("--config", projectConfig);
125
126
  }
126
127
  else {
127
128
  // 为插件参数使用绝对路径,避免全局安装时找不到插件
128
- prettierArgs.unshift('--config', configPath);
129
+ prettierArgs.unshift("--config", configPath);
129
130
  }
130
131
  }
131
- this.debug('prettier path:', prettierBin);
132
- this.debug('args:', JSON.stringify(prettierArgs));
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(), 'pnpm-lock.yaml'))) {
148
- return 'pnpx';
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(), 'yarn.lock'))) {
152
- return 'yarn';
152
+ if (existsSync(join(process.cwd(), "yarn.lock"))) {
153
+ return "yarn";
153
154
  }
154
155
  // 默认使用 npm
155
- return 'npx';
156
+ return "npx";
156
157
  }
157
158
  findProjectPrettierConfig() {
158
- const possibleConfigs = ['.prettierrc', '.prettierrc.json', '.prettierrc.yaml', '.prettierrc.yml', '.prettierrc.js'];
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 = ['.prettierignore', '.gitignore'];
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] === '--plugin' && i + 1 < defaultArgs.length) {
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('--plugin', pluginPath);
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
+ }
@@ -117,4 +117,5 @@ export const DEFAULT_IGNORE_PATTERNS = [
117
117
  'coverage/',
118
118
  '.next/',
119
119
  'out/',
120
+ '*.nu',
120
121
  ];
@@ -0,0 +1,2 @@
1
+ declare const _require: NodeJS.Require;
2
+ export { _require as require };
@@ -0,0 +1,3 @@
1
+ import { createRequire } from "node:module";
2
+ const _require = createRequire(import.meta.url);
3
+ export { _require as require };
@@ -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
+ }
@@ -64,7 +64,7 @@
64
64
  "world.js"
65
65
  ]
66
66
  },
67
- "pr": {
67
+ "prettier": {
68
68
  "aliases": [],
69
69
  "args": {
70
70
  "filePath": {
@@ -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.json",
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": {
@@ -108,7 +108,7 @@
108
108
  },
109
109
  "hasDynamicHelp": false,
110
110
  "hiddenAliases": [],
111
- "id": "pr",
111
+ "id": "prettier",
112
112
  "pluginAlias": "meocli",
113
113
  "pluginName": "meocli",
114
114
  "pluginType": "core",
@@ -118,10 +118,42 @@
118
118
  "relativePath": [
119
119
  "dist",
120
120
  "commands",
121
- "pr",
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.0"
158
+ "version": "0.1.2"
127
159
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "meocli",
3
3
  "description": "A new CLI generated with oclif",
4
- "version": "0.1.0",
4
+ "version": "0.1.2",
5
5
  "author": "meme2046",
6
6
  "bin": {
7
7
  "me": "./bin/run.js"
@@ -15,7 +15,8 @@
15
15
  "debug": "^4.4.3",
16
16
  "execa": "^9.6.1",
17
17
  "js-yaml": "^4.1.1",
18
- "prettier": "^3.7.4",
18
+ "npm-check-updates": "^19.3.1",
19
+ "prettier": "^3.8.0",
19
20
  "prettier-plugin-nginx": "^1.0.3",
20
21
  "prettier-plugin-sh": "^0.18.0",
21
22
  "prettier-plugin-toml": "^2.0.6"
@@ -71,9 +72,9 @@
71
72
  "repository": "meme2046/meocli",
72
73
  "types": "dist/index.d.ts",
73
74
  "scripts": {
74
- "dev": "node --no-deprecation --no-warnings --loader ts-node/esm --disable-warning=ExperimentalWarning bin/dev.js",
75
+ "ncu": "ncu --target minor --reject webpack,shx",
76
+ "dev": "node --no-deprecation --no-warnings --disable-warning=ExperimentalWarning --loader ts-node/esm bin/dev.js",
75
77
  "prod": "node bin/run.js",
76
- "prettier": "prettier",
77
78
  "build": "shx rm -rf dist && tsc -b",
78
79
  "lint": "eslint",
79
80
  "posttest": "pnpm run lint",