meocli 0.0.5 → 0.0.7

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
@@ -43,7 +43,7 @@ $ npm install -g meocli
43
43
  $ me COMMAND
44
44
  running command...
45
45
  $ me (--version)
46
- meocli/0.0.5 win32-x64 node-v24.12.0
46
+ meocli/0.0.7 win32-x64 node-v24.12.0
47
47
  $ me --help [COMMAND]
48
48
  USAGE
49
49
  $ me COMMAND
@@ -91,7 +91,7 @@ EXAMPLES
91
91
  hello friend from oclif! (./src/commands/hello/index.ts)
92
92
  ```
93
93
 
94
- _See code: [src/commands/hello/index.ts](https://github.com/meme2046/meocli/blob/v0.0.5/src/commands/hello/index.ts)_
94
+ _See code: [src/commands/hello/index.ts](https://github.com/meme2046/meocli/blob/v0.0.7/src/commands/hello/index.ts)_
95
95
 
96
96
  ## `me hello world`
97
97
 
@@ -109,7 +109,7 @@ EXAMPLES
109
109
  hello world! (./src/commands/hello/world.ts)
110
110
  ```
111
111
 
112
- _See code: [src/commands/hello/world.ts](https://github.com/meme2046/meocli/blob/v0.0.5/src/commands/hello/world.ts)_
112
+ _See code: [src/commands/hello/world.ts](https://github.com/meme2046/meocli/blob/v0.0.7/src/commands/hello/world.ts)_
113
113
 
114
114
  ## `me help [COMMAND]`
115
115
 
@@ -447,5 +447,5 @@ EXAMPLES
447
447
  $ me pr ./src/file.ts --config ./.prettierrc.yaml
448
448
  ```
449
449
 
450
- _See code: [src/commands/pr/index.ts](https://github.com/meme2046/meocli/blob/v0.0.5/src/commands/pr/index.ts)_
450
+ _See code: [src/commands/pr/index.ts](https://github.com/meme2046/meocli/blob/v0.0.7/src/commands/pr/index.ts)_
451
451
  <!-- commandsstop -->
@@ -14,5 +14,6 @@ export default class Prettier extends Command {
14
14
  private findProjectPrettierConfig;
15
15
  private findProjectPrettierIgnore;
16
16
  private replacePluginArgs;
17
+ private resolvePluginArgs;
17
18
  private resolvePluginPaths;
18
19
  }
@@ -2,10 +2,11 @@ import { Args, Command, Flags } from '@oclif/core';
2
2
  import { execa } from 'execa';
3
3
  // import {spawn} from 'node:child_process'
4
4
  import { existsSync } from 'node:fs';
5
- import { platform } from 'node:os';
5
+ import { createRequire } from 'node:module';
6
6
  import { dirname, join } from 'node:path';
7
- import { fileURLToPath } from 'node:url';
7
+ import { cwd } from 'node:process';
8
8
  import { DEFAULT_ARGS, DEFAULT_PLUGINS } from '../../consts/prettierrc.js';
9
+ const require = createRequire(import.meta.url);
9
10
  export default class Prettier extends Command {
10
11
  static args = {
11
12
  filePath: Args.string({
@@ -50,14 +51,16 @@ export default class Prettier extends Command {
50
51
  }
51
52
  // 检测当前使用的包管理器
52
53
  // const packageManager = this.detectPackageManager()
54
+ const prettierMain = require.resolve('prettier');
55
+ const prettierBin = join(dirname(prettierMain), './bin/prettier.cjs');
53
56
  // 获取 prettier 可执行文件的路径
54
- const __filename = fileURLToPath(import.meta.url);
55
- const __dirname = dirname(__filename);
56
- const projectRoot = join(__dirname, '../../../'); // 回到项目根目录
57
- let prettierBin = join(projectRoot, 'node_modules', '.bin', 'prettier');
58
- if (platform() === 'win32') {
59
- prettierBin += '.cmd';
60
- }
57
+ // const __filename = fileURLToPath(import.meta.url)
58
+ // const __dirname = dirname(__filename)
59
+ // const projectRoot = join(__dirname, '../../../') // 回到项目根目录
60
+ // let prettierBin = join(projectRoot, 'node_modules', '.bin', 'prettier')
61
+ // if (platform() === 'win32') {
62
+ // prettierBin += '.cmd'
63
+ // }
61
64
  if (!existsSync(prettierBin)) {
62
65
  this.error(`prettier not found`);
63
66
  return;
@@ -65,6 +68,7 @@ export default class Prettier extends Command {
65
68
  // 根据包管理器类型构建参数
66
69
  let prettierArgs = ['--write', filePath];
67
70
  if (ignore === 'built_in') {
71
+ const projectRoot = cwd();
68
72
  prettierArgs.unshift('--ignore-path', join(projectRoot, '.prettierignore'));
69
73
  }
70
74
  else if (existsSync(ignore)) {
@@ -76,9 +80,10 @@ export default class Prettier extends Command {
76
80
  prettierArgs.unshift('--ignore-path', projectIgnore);
77
81
  }
78
82
  }
79
- const resolvedPluginArgs = this.resolvePluginPaths(DEFAULT_PLUGINS, projectRoot);
80
- const argsWithResolvedPlugins = this.replacePluginArgs(DEFAULT_ARGS, resolvedPluginArgs);
81
- const completeArgs = [...argsWithResolvedPlugins, ...prettierArgs];
83
+ // const resolvedPluginArgs = this.resolvePluginPaths(DEFAULT_PLUGINS, projectRoot)
84
+ // const argsWithResolvedPlugins = this.replacePluginArgs(DEFAULT_ARGS, resolvedPluginArgs)
85
+ const pluginArgs = this.resolvePluginArgs(DEFAULT_PLUGINS);
86
+ const completeArgs = [...DEFAULT_ARGS, ...pluginArgs, ...prettierArgs];
82
87
  if (config === 'built_in') {
83
88
  // 为插件参数使用绝对路径,避免全局安装时找不到插件
84
89
  prettierArgs = completeArgs;
@@ -97,8 +102,8 @@ export default class Prettier extends Command {
97
102
  prettierArgs = completeArgs;
98
103
  }
99
104
  }
100
- this.log(prettierBin);
101
- this.log(JSON.stringify(prettierArgs));
105
+ this.debug(prettierBin);
106
+ this.debug(JSON.stringify(prettierArgs));
102
107
  // this.log(`Formatting file: ${filePath}`)
103
108
  const { stderr, stdout } = await execa(prettierBin, prettierArgs, {
104
109
  env: { ...process.env },
@@ -158,6 +163,19 @@ export default class Prettier extends Command {
158
163
  }
159
164
  return newArgs;
160
165
  }
166
+ resolvePluginArgs(plugins) {
167
+ const pluginArgs = [];
168
+ for (const plugin of plugins) {
169
+ const pluginPath = require.resolve(plugin.name);
170
+ if (existsSync(pluginPath)) {
171
+ pluginArgs.push('--plugin', pluginPath);
172
+ }
173
+ else {
174
+ pluginArgs.push('--plugin', plugin.name);
175
+ }
176
+ }
177
+ return pluginArgs;
178
+ }
161
179
  // 将插件名称转换为绝对路径
162
180
  resolvePluginPaths(plugins, projectRoot) {
163
181
  return plugins.map((plugin) => {
@@ -39,14 +39,14 @@ export const DEFAULT_ARGS = [
39
39
  '--embedded-language-formatting',
40
40
  'auto',
41
41
  // plugins
42
- '--plugin',
43
- '@prettier/plugin-xml',
44
- '--plugin',
45
- 'prettier-plugin-toml',
46
- '--plugin',
47
- 'prettier-plugin-sh',
48
- '--plugin',
49
- 'prettier-plugin-nginx',
42
+ // '--plugin',
43
+ // '@prettier/plugin-xml',
44
+ // '--plugin',
45
+ // 'prettier-plugin-toml',
46
+ // '--plugin',
47
+ // 'prettier-plugin-sh',
48
+ // '--plugin',
49
+ // 'prettier-plugin-nginx',
50
50
  // xml
51
51
  '--xml-whitespace-sensitivity',
52
52
  'strict',
@@ -70,7 +70,7 @@ export const DEFAULT_PLUGINS = [
70
70
  { main: 'src/plugin.js', name: '@prettier/plugin-xml' },
71
71
  { main: 'lib/index.cjs', name: 'prettier-plugin-toml' },
72
72
  { main: 'lib/index.cjs', name: 'prettier-plugin-sh' },
73
- { main: 'dist/index', name: 'prettier-plugin-nginx' },
73
+ { main: 'dist/index.js', name: 'prettier-plugin-nginx' },
74
74
  ];
75
75
  // 默认的忽略模式
76
76
  export const DEFAULT_IGNORE_PATTERNS = [
@@ -116,5 +116,5 @@
116
116
  ]
117
117
  }
118
118
  },
119
- "version": "0.0.5"
119
+ "version": "0.0.7"
120
120
  }
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.0.5",
4
+ "version": "0.0.7",
5
5
  "author": "meme2046",
6
6
  "bin": {
7
7
  "me": "./bin/run.js"
@@ -68,8 +68,6 @@
68
68
  "repository": "meme2046/meocli",
69
69
  "types": "dist/index.d.ts",
70
70
  "scripts": {
71
- "lk": "pnpm link --global",
72
- "ulk": "pnpm unlink --global meocli",
73
71
  "dev": "node --no-deprecation --no-warnings --loader ts-node/esm --disable-warning=ExperimentalWarning bin/dev.js",
74
72
  "prod": "node bin/run.js",
75
73
  "prettier": "prettier",