meocli 0.0.6 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -6
- package/dist/commands/pr/index.d.ts +2 -0
- package/dist/commands/pr/index.js +42 -15
- package/dist/consts/prettierrc.js +8 -8
- package/oclif.manifest.json +8 -1
- package/package.json +2 -3
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ $ pnpm run dev hello world
|
|
|
22
22
|
$ pnpm run prod hello world
|
|
23
23
|
$ pnpm run dev hello foo -f bar
|
|
24
24
|
<!-- prettier -->
|
|
25
|
-
$ pnpm run dev pr ./tmp/test.svg
|
|
25
|
+
$ pnpm run dev pr ./tmp/test.svg --verbose
|
|
26
26
|
$ pnpm run dev pr ./tmp/test.json --config=auto --ignore=auto
|
|
27
27
|
$ pnpm run dev pr ./tmp/test.svg --config=built_in --ignore=auto
|
|
28
28
|
```
|
|
@@ -43,7 +43,7 @@ $ npm install -g meocli
|
|
|
43
43
|
$ me COMMAND
|
|
44
44
|
running command...
|
|
45
45
|
$ me (--version)
|
|
46
|
-
meocli/0.0.
|
|
46
|
+
meocli/0.0.8 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.
|
|
94
|
+
_See code: [src/commands/hello/index.ts](https://github.com/meme2046/meocli/blob/v0.0.8/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.
|
|
112
|
+
_See code: [src/commands/hello/world.ts](https://github.com/meme2046/meocli/blob/v0.0.8/src/commands/hello/world.ts)_
|
|
113
113
|
|
|
114
114
|
## `me help [COMMAND]`
|
|
115
115
|
|
|
@@ -427,7 +427,7 @@ Use Prettier to format file
|
|
|
427
427
|
|
|
428
428
|
```
|
|
429
429
|
USAGE
|
|
430
|
-
$ me pr FILEPATH [-c <value>] [--ignore <value>]
|
|
430
|
+
$ me pr FILEPATH [-c <value>] [--ignore <value>] [-v]
|
|
431
431
|
|
|
432
432
|
ARGUMENTS
|
|
433
433
|
FILEPATH file path that need to be formatted by Prettier
|
|
@@ -435,6 +435,7 @@ ARGUMENTS
|
|
|
435
435
|
FLAGS
|
|
436
436
|
-c, --config=<value> [default: built_in] built_in:使用内置规则(默认值), 传入路径则是使用自定义配置,
|
|
437
437
|
auto:自动检测config file
|
|
438
|
+
-v, --verbose Show verbose output
|
|
438
439
|
--ignore=<value> [default: built_in] built_in:使用内置规则(默认值), 传入路径则是使用自定义规则,
|
|
439
440
|
auto:自动检测ignore file
|
|
440
441
|
|
|
@@ -447,5 +448,5 @@ EXAMPLES
|
|
|
447
448
|
$ me pr ./src/file.ts --config ./.prettierrc.yaml
|
|
448
449
|
```
|
|
449
450
|
|
|
450
|
-
_See code: [src/commands/pr/index.ts](https://github.com/meme2046/meocli/blob/v0.0.
|
|
451
|
+
_See code: [src/commands/pr/index.ts](https://github.com/meme2046/meocli/blob/v0.0.8/src/commands/pr/index.ts)_
|
|
451
452
|
<!-- commandsstop -->
|
|
@@ -8,11 +8,13 @@ export default class Prettier extends Command {
|
|
|
8
8
|
static flags: {
|
|
9
9
|
config: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
10
|
ignore: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
|
+
verbose: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
11
12
|
};
|
|
12
13
|
run(): Promise<void>;
|
|
13
14
|
private detectPackageManager;
|
|
14
15
|
private findProjectPrettierConfig;
|
|
15
16
|
private findProjectPrettierIgnore;
|
|
16
17
|
private replacePluginArgs;
|
|
18
|
+
private resolvePluginArgs;
|
|
17
19
|
private resolvePluginPaths;
|
|
18
20
|
}
|
|
@@ -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 {
|
|
5
|
+
import { createRequire } from 'node:module';
|
|
6
6
|
import { dirname, join } from 'node:path';
|
|
7
|
-
import {
|
|
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({
|
|
@@ -30,6 +31,11 @@ export default class Prettier extends Command {
|
|
|
30
31
|
description: 'built_in:使用内置规则(默认值), 传入路径则是使用自定义规则, auto:自动检测ignore file',
|
|
31
32
|
required: false,
|
|
32
33
|
}),
|
|
34
|
+
verbose: Flags.boolean({
|
|
35
|
+
char: 'v',
|
|
36
|
+
default: false,
|
|
37
|
+
description: 'Show verbose output',
|
|
38
|
+
}),
|
|
33
39
|
// 'no-config': Flags.boolean({
|
|
34
40
|
// default: false,
|
|
35
41
|
// description: 'Disable config file detection',
|
|
@@ -42,7 +48,11 @@ export default class Prettier extends Command {
|
|
|
42
48
|
async run() {
|
|
43
49
|
const { args, flags } = await this.parse(Prettier);
|
|
44
50
|
const { filePath } = args;
|
|
45
|
-
const { config, ignore } = flags;
|
|
51
|
+
const { config, ignore, verbose } = flags;
|
|
52
|
+
if (verbose) {
|
|
53
|
+
process.env.DEBUG = 'oclif:me:pr';
|
|
54
|
+
require('debug').enable(process.env.DEBUG);
|
|
55
|
+
}
|
|
46
56
|
// 检查文件是否存在
|
|
47
57
|
if (!existsSync(filePath)) {
|
|
48
58
|
this.error(`file『${filePath}』not found`);
|
|
@@ -50,14 +60,16 @@ export default class Prettier extends Command {
|
|
|
50
60
|
}
|
|
51
61
|
// 检测当前使用的包管理器
|
|
52
62
|
// const packageManager = this.detectPackageManager()
|
|
63
|
+
const prettierMain = require.resolve('prettier');
|
|
64
|
+
const prettierBin = join(dirname(prettierMain), './bin/prettier.cjs');
|
|
53
65
|
// 获取 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
|
-
|
|
60
|
-
}
|
|
66
|
+
// const __filename = fileURLToPath(import.meta.url)
|
|
67
|
+
// const __dirname = dirname(__filename)
|
|
68
|
+
// const projectRoot = join(__dirname, '../../../') // 回到项目根目录
|
|
69
|
+
// let prettierBin = join(projectRoot, 'node_modules', '.bin', 'prettier')
|
|
70
|
+
// if (platform() === 'win32') {
|
|
71
|
+
// prettierBin += '.cmd'
|
|
72
|
+
// }
|
|
61
73
|
if (!existsSync(prettierBin)) {
|
|
62
74
|
this.error(`prettier not found`);
|
|
63
75
|
return;
|
|
@@ -65,6 +77,7 @@ export default class Prettier extends Command {
|
|
|
65
77
|
// 根据包管理器类型构建参数
|
|
66
78
|
let prettierArgs = ['--write', filePath];
|
|
67
79
|
if (ignore === 'built_in') {
|
|
80
|
+
const projectRoot = cwd();
|
|
68
81
|
prettierArgs.unshift('--ignore-path', join(projectRoot, '.prettierignore'));
|
|
69
82
|
}
|
|
70
83
|
else if (existsSync(ignore)) {
|
|
@@ -76,9 +89,10 @@ export default class Prettier extends Command {
|
|
|
76
89
|
prettierArgs.unshift('--ignore-path', projectIgnore);
|
|
77
90
|
}
|
|
78
91
|
}
|
|
79
|
-
const resolvedPluginArgs = this.resolvePluginPaths(DEFAULT_PLUGINS, projectRoot)
|
|
80
|
-
const argsWithResolvedPlugins = this.replacePluginArgs(DEFAULT_ARGS, resolvedPluginArgs)
|
|
81
|
-
const
|
|
92
|
+
// const resolvedPluginArgs = this.resolvePluginPaths(DEFAULT_PLUGINS, projectRoot)
|
|
93
|
+
// const argsWithResolvedPlugins = this.replacePluginArgs(DEFAULT_ARGS, resolvedPluginArgs)
|
|
94
|
+
const pluginArgs = this.resolvePluginArgs(DEFAULT_PLUGINS);
|
|
95
|
+
const completeArgs = [...DEFAULT_ARGS, ...pluginArgs, ...prettierArgs];
|
|
82
96
|
if (config === 'built_in') {
|
|
83
97
|
// 为插件参数使用绝对路径,避免全局安装时找不到插件
|
|
84
98
|
prettierArgs = completeArgs;
|
|
@@ -97,8 +111,8 @@ export default class Prettier extends Command {
|
|
|
97
111
|
prettierArgs = completeArgs;
|
|
98
112
|
}
|
|
99
113
|
}
|
|
100
|
-
this.
|
|
101
|
-
this.
|
|
114
|
+
this.debug('prettier path:', prettierBin);
|
|
115
|
+
this.debug('args:', JSON.stringify(prettierArgs));
|
|
102
116
|
// this.log(`Formatting file: ${filePath}`)
|
|
103
117
|
const { stderr, stdout } = await execa(prettierBin, prettierArgs, {
|
|
104
118
|
env: { ...process.env },
|
|
@@ -158,6 +172,19 @@ export default class Prettier extends Command {
|
|
|
158
172
|
}
|
|
159
173
|
return newArgs;
|
|
160
174
|
}
|
|
175
|
+
resolvePluginArgs(plugins) {
|
|
176
|
+
const pluginArgs = [];
|
|
177
|
+
for (const plugin of plugins) {
|
|
178
|
+
const pluginPath = require.resolve(plugin.name);
|
|
179
|
+
if (existsSync(pluginPath)) {
|
|
180
|
+
pluginArgs.push('--plugin', pluginPath);
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
pluginArgs.push('--plugin', plugin.name);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return pluginArgs;
|
|
187
|
+
}
|
|
161
188
|
// 将插件名称转换为绝对路径
|
|
162
189
|
resolvePluginPaths(plugins, projectRoot) {
|
|
163
190
|
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',
|
package/oclif.manifest.json
CHANGED
|
@@ -97,6 +97,13 @@
|
|
|
97
97
|
"hasDynamicHelp": false,
|
|
98
98
|
"multiple": false,
|
|
99
99
|
"type": "option"
|
|
100
|
+
},
|
|
101
|
+
"verbose": {
|
|
102
|
+
"char": "v",
|
|
103
|
+
"description": "Show verbose output",
|
|
104
|
+
"name": "verbose",
|
|
105
|
+
"allowNo": false,
|
|
106
|
+
"type": "boolean"
|
|
100
107
|
}
|
|
101
108
|
},
|
|
102
109
|
"hasDynamicHelp": false,
|
|
@@ -116,5 +123,5 @@
|
|
|
116
123
|
]
|
|
117
124
|
}
|
|
118
125
|
},
|
|
119
|
-
"version": "0.0.
|
|
126
|
+
"version": "0.0.8"
|
|
120
127
|
}
|
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.
|
|
4
|
+
"version": "0.0.8",
|
|
5
5
|
"author": "meme2046",
|
|
6
6
|
"bin": {
|
|
7
7
|
"me": "./bin/run.js"
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"@oclif/plugin-help": "^6",
|
|
13
13
|
"@oclif/plugin-plugins": "^5",
|
|
14
14
|
"@prettier/plugin-xml": "^3.4.2",
|
|
15
|
+
"debug": "^4.4.3",
|
|
15
16
|
"execa": "^9.6.1",
|
|
16
17
|
"prettier": "^3.7.4",
|
|
17
18
|
"prettier-plugin-nginx": "^1.0.3",
|
|
@@ -68,8 +69,6 @@
|
|
|
68
69
|
"repository": "meme2046/meocli",
|
|
69
70
|
"types": "dist/index.d.ts",
|
|
70
71
|
"scripts": {
|
|
71
|
-
"lk": "pnpm link --global",
|
|
72
|
-
"ulk": "pnpm unlink --global meocli",
|
|
73
72
|
"dev": "node --no-deprecation --no-warnings --loader ts-node/esm --disable-warning=ExperimentalWarning bin/dev.js",
|
|
74
73
|
"prod": "node bin/run.js",
|
|
75
74
|
"prettier": "prettier",
|