meocli 0.0.3 → 0.0.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/README.md +20 -9
- package/dist/commands/pr/index.d.ts +4 -4
- package/dist/commands/pr/index.js +59 -25
- package/dist/consts/prettierrc.d.ts +4 -1
- package/dist/consts/prettierrc.js +4 -4
- package/oclif.manifest.json +7 -17
- package/package.json +3 -1
- package/dist/consts/prettierrc.tmp.d.ts +0 -3
- package/dist/consts/prettierrc.tmp.js +0 -54
package/README.md
CHANGED
|
@@ -9,6 +9,7 @@ A new CLI generated with oclif
|
|
|
9
9
|
<!-- toc -->
|
|
10
10
|
* [meocli](#meocli)
|
|
11
11
|
* [Dev](#dev)
|
|
12
|
+
* [Publish](#publish)
|
|
12
13
|
* [Usage](#usage)
|
|
13
14
|
* [Commands](#commands)
|
|
14
15
|
<!-- tocstop -->
|
|
@@ -16,9 +17,19 @@ A new CLI generated with oclif
|
|
|
16
17
|
# Dev
|
|
17
18
|
|
|
18
19
|
```sh-session
|
|
20
|
+
<!-- demo -->
|
|
19
21
|
$ pnpm run dev hello world
|
|
20
22
|
$ pnpm run prod hello world
|
|
21
23
|
$ pnpm run dev hello foo -f bar
|
|
24
|
+
<!-- prettier -->
|
|
25
|
+
$ pnpm run dev pr ./tmp/test.svg
|
|
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
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
# Publish
|
|
31
|
+
|
|
32
|
+
```sh-session
|
|
22
33
|
$ pnpm login
|
|
23
34
|
$ pnpm build
|
|
24
35
|
$ pnpm publish
|
|
@@ -32,7 +43,7 @@ $ npm install -g meocli
|
|
|
32
43
|
$ me COMMAND
|
|
33
44
|
running command...
|
|
34
45
|
$ me (--version)
|
|
35
|
-
meocli/0.0.
|
|
46
|
+
meocli/0.0.5 win32-x64 node-v24.12.0
|
|
36
47
|
$ me --help [COMMAND]
|
|
37
48
|
USAGE
|
|
38
49
|
$ me COMMAND
|
|
@@ -80,7 +91,7 @@ EXAMPLES
|
|
|
80
91
|
hello friend from oclif! (./src/commands/hello/index.ts)
|
|
81
92
|
```
|
|
82
93
|
|
|
83
|
-
_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.5/src/commands/hello/index.ts)_
|
|
84
95
|
|
|
85
96
|
## `me hello world`
|
|
86
97
|
|
|
@@ -98,7 +109,7 @@ EXAMPLES
|
|
|
98
109
|
hello world! (./src/commands/hello/world.ts)
|
|
99
110
|
```
|
|
100
111
|
|
|
101
|
-
_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.5/src/commands/hello/world.ts)_
|
|
102
113
|
|
|
103
114
|
## `me help [COMMAND]`
|
|
104
115
|
|
|
@@ -416,16 +427,16 @@ Use Prettier to format file
|
|
|
416
427
|
|
|
417
428
|
```
|
|
418
429
|
USAGE
|
|
419
|
-
$ me pr FILEPATH [-c <value>] [--ignore
|
|
430
|
+
$ me pr FILEPATH [-c <value>] [--ignore <value>]
|
|
420
431
|
|
|
421
432
|
ARGUMENTS
|
|
422
433
|
FILEPATH file path that need to be formatted by Prettier
|
|
423
434
|
|
|
424
435
|
FLAGS
|
|
425
|
-
-c, --config=<value>
|
|
426
|
-
|
|
427
|
-
--
|
|
428
|
-
|
|
436
|
+
-c, --config=<value> [default: built_in] built_in:使用内置规则(默认值), 传入路径则是使用自定义配置,
|
|
437
|
+
auto:自动检测config file
|
|
438
|
+
--ignore=<value> [default: built_in] built_in:使用内置规则(默认值), 传入路径则是使用自定义规则,
|
|
439
|
+
auto:自动检测ignore file
|
|
429
440
|
|
|
430
441
|
DESCRIPTION
|
|
431
442
|
Use Prettier to format file
|
|
@@ -436,5 +447,5 @@ EXAMPLES
|
|
|
436
447
|
$ me pr ./src/file.ts --config ./.prettierrc.yaml
|
|
437
448
|
```
|
|
438
449
|
|
|
439
|
-
_See code: [src/commands/pr/index.ts](https://github.com/meme2046/meocli/blob/v0.0.
|
|
450
|
+
_See code: [src/commands/pr/index.ts](https://github.com/meme2046/meocli/blob/v0.0.5/src/commands/pr/index.ts)_
|
|
440
451
|
<!-- commandsstop -->
|
|
@@ -6,13 +6,13 @@ export default class Prettier extends Command {
|
|
|
6
6
|
static description: string;
|
|
7
7
|
static examples: string[];
|
|
8
8
|
static flags: {
|
|
9
|
-
config: import("@oclif/core/interfaces").OptionFlag<string
|
|
10
|
-
|
|
11
|
-
'no-config': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
12
|
-
'no-ignore': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
9
|
+
config: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
|
+
ignore: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
13
11
|
};
|
|
14
12
|
run(): Promise<void>;
|
|
15
13
|
private detectPackageManager;
|
|
16
14
|
private findProjectPrettierConfig;
|
|
17
15
|
private findProjectPrettierIgnore;
|
|
16
|
+
private replacePluginArgs;
|
|
17
|
+
private resolvePluginPaths;
|
|
18
18
|
}
|
|
@@ -5,7 +5,7 @@ import { existsSync } from 'node:fs';
|
|
|
5
5
|
import { platform } from 'node:os';
|
|
6
6
|
import { dirname, join } from 'node:path';
|
|
7
7
|
import { fileURLToPath } from 'node:url';
|
|
8
|
-
import { DEFAULT_ARGS } from '../../consts/prettierrc.js';
|
|
8
|
+
import { DEFAULT_ARGS, DEFAULT_PLUGINS } from '../../consts/prettierrc.js';
|
|
9
9
|
export default class Prettier extends Command {
|
|
10
10
|
static args = {
|
|
11
11
|
filePath: Args.string({
|
|
@@ -21,27 +21,28 @@ export default class Prettier extends Command {
|
|
|
21
21
|
static flags = {
|
|
22
22
|
config: Flags.string({
|
|
23
23
|
char: 'c',
|
|
24
|
-
|
|
25
|
-
description: '
|
|
24
|
+
default: 'built_in',
|
|
25
|
+
description: 'built_in:使用内置规则(默认值), 传入路径则是使用自定义配置, auto:自动检测config file',
|
|
26
26
|
required: false,
|
|
27
27
|
}),
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
ignore: Flags.string({
|
|
29
|
+
default: 'built_in',
|
|
30
|
+
description: 'built_in:使用内置规则(默认值), 传入路径则是使用自定义规则, auto:自动检测ignore file',
|
|
30
31
|
required: false,
|
|
31
32
|
}),
|
|
32
|
-
'no-config': Flags.boolean({
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}),
|
|
36
|
-
'no-ignore': Flags.boolean({
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}),
|
|
33
|
+
// 'no-config': Flags.boolean({
|
|
34
|
+
// default: false,
|
|
35
|
+
// description: 'Disable config file detection',
|
|
36
|
+
// }),
|
|
37
|
+
// 'no-ignore': Flags.boolean({
|
|
38
|
+
// default: false,
|
|
39
|
+
// description: 'Disable ignore file detection',
|
|
40
|
+
// }),
|
|
40
41
|
};
|
|
41
42
|
async run() {
|
|
42
43
|
const { args, flags } = await this.parse(Prettier);
|
|
43
44
|
const { filePath } = args;
|
|
44
|
-
const { config,
|
|
45
|
+
const { config, ignore } = flags;
|
|
45
46
|
// 检查文件是否存在
|
|
46
47
|
if (!existsSync(filePath)) {
|
|
47
48
|
this.error(`file『${filePath}』not found`);
|
|
@@ -53,23 +54,21 @@ export default class Prettier extends Command {
|
|
|
53
54
|
const __filename = fileURLToPath(import.meta.url);
|
|
54
55
|
const __dirname = dirname(__filename);
|
|
55
56
|
const projectRoot = join(__dirname, '../../../'); // 回到项目根目录
|
|
56
|
-
// let prettierBin = join(projectRoot, 'node_modules', 'prettier', 'node_modules', '.bin', 'prettier')
|
|
57
57
|
let prettierBin = join(projectRoot, 'node_modules', '.bin', 'prettier');
|
|
58
58
|
if (platform() === 'win32') {
|
|
59
59
|
prettierBin += '.cmd';
|
|
60
60
|
}
|
|
61
|
-
// this.log(prettierBin)
|
|
62
61
|
if (!existsSync(prettierBin)) {
|
|
63
62
|
this.error(`prettier not found`);
|
|
64
63
|
return;
|
|
65
64
|
}
|
|
66
65
|
// 根据包管理器类型构建参数
|
|
67
66
|
let prettierArgs = ['--write', filePath];
|
|
68
|
-
if (
|
|
69
|
-
prettierArgs.unshift('--ignore-path', '');
|
|
67
|
+
if (ignore === 'built_in') {
|
|
68
|
+
prettierArgs.unshift('--ignore-path', join(projectRoot, '.prettierignore'));
|
|
70
69
|
}
|
|
71
|
-
else if (
|
|
72
|
-
prettierArgs.unshift('--ignore-path',
|
|
70
|
+
else if (existsSync(ignore)) {
|
|
71
|
+
prettierArgs.unshift('--ignore-path', ignore);
|
|
73
72
|
}
|
|
74
73
|
else {
|
|
75
74
|
const projectIgnore = this.findProjectPrettierIgnore();
|
|
@@ -77,10 +76,14 @@ export default class Prettier extends Command {
|
|
|
77
76
|
prettierArgs.unshift('--ignore-path', projectIgnore);
|
|
78
77
|
}
|
|
79
78
|
}
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
const resolvedPluginArgs = this.resolvePluginPaths(DEFAULT_PLUGINS, projectRoot);
|
|
80
|
+
const argsWithResolvedPlugins = this.replacePluginArgs(DEFAULT_ARGS, resolvedPluginArgs);
|
|
81
|
+
const completeArgs = [...argsWithResolvedPlugins, ...prettierArgs];
|
|
82
|
+
if (config === 'built_in') {
|
|
83
|
+
// 为插件参数使用绝对路径,避免全局安装时找不到插件
|
|
84
|
+
prettierArgs = completeArgs;
|
|
82
85
|
}
|
|
83
|
-
else if (
|
|
86
|
+
else if (existsSync(config)) {
|
|
84
87
|
prettierArgs.unshift('--config', config);
|
|
85
88
|
}
|
|
86
89
|
else {
|
|
@@ -90,10 +93,12 @@ export default class Prettier extends Command {
|
|
|
90
93
|
prettierArgs.unshift('--config', projectConfig);
|
|
91
94
|
}
|
|
92
95
|
else {
|
|
93
|
-
|
|
96
|
+
// 为插件参数使用绝对路径,避免全局安装时找不到插件
|
|
97
|
+
prettierArgs = completeArgs;
|
|
94
98
|
}
|
|
95
99
|
}
|
|
96
|
-
|
|
100
|
+
this.log(prettierBin);
|
|
101
|
+
this.log(JSON.stringify(prettierArgs));
|
|
97
102
|
// this.log(`Formatting file: ${filePath}`)
|
|
98
103
|
const { stderr, stdout } = await execa(prettierBin, prettierArgs, {
|
|
99
104
|
env: { ...process.env },
|
|
@@ -136,4 +141,33 @@ export default class Prettier extends Command {
|
|
|
136
141
|
}
|
|
137
142
|
return null;
|
|
138
143
|
}
|
|
144
|
+
// 替换默认参数中的插件路径
|
|
145
|
+
replacePluginArgs(defaultArgs, resolvedPluginPaths) {
|
|
146
|
+
const newArgs = [];
|
|
147
|
+
for (let i = 0; i < defaultArgs.length; i++) {
|
|
148
|
+
if (defaultArgs[i] === '--plugin' && i + 1 < defaultArgs.length) {
|
|
149
|
+
// 跳过这个 '--plugin' 标记和它的值,稍后替换
|
|
150
|
+
i++; // 跳过下一个值(插件名称)
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
newArgs.push(defaultArgs[i]);
|
|
154
|
+
}
|
|
155
|
+
// 添加解析后的插件路径
|
|
156
|
+
for (const pluginPath of resolvedPluginPaths) {
|
|
157
|
+
newArgs.push('--plugin', pluginPath);
|
|
158
|
+
}
|
|
159
|
+
return newArgs;
|
|
160
|
+
}
|
|
161
|
+
// 将插件名称转换为绝对路径
|
|
162
|
+
resolvePluginPaths(plugins, projectRoot) {
|
|
163
|
+
return plugins.map((plugin) => {
|
|
164
|
+
// 查找插件的实际路径
|
|
165
|
+
const pluginPath = join(projectRoot, 'node_modules', plugin.name, plugin.main);
|
|
166
|
+
if (existsSync(pluginPath)) {
|
|
167
|
+
return pluginPath;
|
|
168
|
+
}
|
|
169
|
+
// 如果插件路径不存在,则返回原始名称(让 prettier 自己处理)
|
|
170
|
+
return plugin.name;
|
|
171
|
+
});
|
|
172
|
+
}
|
|
139
173
|
}
|
|
@@ -67,10 +67,10 @@ export const DEFAULT_ARGS = [
|
|
|
67
67
|
];
|
|
68
68
|
// 默认的 Prettier 插件列表
|
|
69
69
|
export const DEFAULT_PLUGINS = [
|
|
70
|
-
'@prettier/plugin-xml',
|
|
71
|
-
'prettier-plugin-toml',
|
|
72
|
-
'prettier-plugin-
|
|
73
|
-
'prettier-plugin-
|
|
70
|
+
{ main: 'src/plugin.js', name: '@prettier/plugin-xml' },
|
|
71
|
+
{ main: 'lib/index.cjs', name: 'prettier-plugin-toml' },
|
|
72
|
+
{ main: 'lib/index.cjs', name: 'prettier-plugin-sh' },
|
|
73
|
+
{ main: 'dist/index', name: 'prettier-plugin-nginx' },
|
|
74
74
|
];
|
|
75
75
|
// 默认的忽略模式
|
|
76
76
|
export const DEFAULT_IGNORE_PATTERNS = [
|
package/oclif.manifest.json
CHANGED
|
@@ -81,32 +81,22 @@
|
|
|
81
81
|
"flags": {
|
|
82
82
|
"config": {
|
|
83
83
|
"char": "c",
|
|
84
|
-
"description": "
|
|
84
|
+
"description": "built_in:使用内置规则(默认值), 传入路径则是使用自定义配置, auto:自动检测config file",
|
|
85
85
|
"name": "config",
|
|
86
86
|
"required": false,
|
|
87
|
+
"default": "built_in",
|
|
87
88
|
"hasDynamicHelp": false,
|
|
88
89
|
"multiple": false,
|
|
89
90
|
"type": "option"
|
|
90
91
|
},
|
|
91
|
-
"ignore
|
|
92
|
-
"description": "
|
|
93
|
-
"name": "ignore
|
|
92
|
+
"ignore": {
|
|
93
|
+
"description": "built_in:使用内置规则(默认值), 传入路径则是使用自定义规则, auto:自动检测ignore file",
|
|
94
|
+
"name": "ignore",
|
|
94
95
|
"required": false,
|
|
96
|
+
"default": "built_in",
|
|
95
97
|
"hasDynamicHelp": false,
|
|
96
98
|
"multiple": false,
|
|
97
99
|
"type": "option"
|
|
98
|
-
},
|
|
99
|
-
"no-config": {
|
|
100
|
-
"description": "Disable config file detection",
|
|
101
|
-
"name": "no-config",
|
|
102
|
-
"allowNo": false,
|
|
103
|
-
"type": "boolean"
|
|
104
|
-
},
|
|
105
|
-
"no-ignore": {
|
|
106
|
-
"description": "Disable ignore file detection",
|
|
107
|
-
"name": "no-ignore",
|
|
108
|
-
"allowNo": false,
|
|
109
|
-
"type": "boolean"
|
|
110
100
|
}
|
|
111
101
|
},
|
|
112
102
|
"hasDynamicHelp": false,
|
|
@@ -126,5 +116,5 @@
|
|
|
126
116
|
]
|
|
127
117
|
}
|
|
128
118
|
},
|
|
129
|
-
"version": "0.0.
|
|
119
|
+
"version": "0.0.5"
|
|
130
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.
|
|
4
|
+
"version": "0.0.5",
|
|
5
5
|
"author": "meme2046",
|
|
6
6
|
"bin": {
|
|
7
7
|
"me": "./bin/run.js"
|
|
@@ -68,6 +68,8 @@
|
|
|
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",
|
|
71
73
|
"dev": "node --no-deprecation --no-warnings --loader ts-node/esm --disable-warning=ExperimentalWarning bin/dev.js",
|
|
72
74
|
"prod": "node bin/run.js",
|
|
73
75
|
"prettier": "prettier",
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
export const DEFAULT_ARGS = [
|
|
2
|
-
'--arrow-parens=always',
|
|
3
|
-
'--bracket-same-line=false',
|
|
4
|
-
'--object-wrap=preserve',
|
|
5
|
-
'--experimental-operator-position=end',
|
|
6
|
-
'--no-experimental-ternaries',
|
|
7
|
-
'--single-quote=false',
|
|
8
|
-
'--jsx-single-quote=false',
|
|
9
|
-
'--quote-props=as-needed',
|
|
10
|
-
'--trailing-comma=all',
|
|
11
|
-
'--single-attribute-per-line=false',
|
|
12
|
-
'--html-whitespace-sensitivity=css',
|
|
13
|
-
'--vue-indent-script-and-style=false',
|
|
14
|
-
'--prose-wrap=preserve',
|
|
15
|
-
'--end-of-line=lf',
|
|
16
|
-
'--insert-pragma=false',
|
|
17
|
-
'--print-width=80',
|
|
18
|
-
'--require-pragma=false',
|
|
19
|
-
'--tab-width=2',
|
|
20
|
-
'--use-tabs=false',
|
|
21
|
-
'--embedded-language-formatting=auto',
|
|
22
|
-
// plugins
|
|
23
|
-
'--plugin=@prettier/plugin-xml',
|
|
24
|
-
'--plugin=prettier-plugin-toml',
|
|
25
|
-
'--plugin=prettier-plugin-sh',
|
|
26
|
-
'--plugin=prettier-plugin-nginx',
|
|
27
|
-
// xml
|
|
28
|
-
'--xml-whitespace-sensitivity=strict',
|
|
29
|
-
'--xml-sort-attributes-by-key=true',
|
|
30
|
-
'--xml-self-closing-space=true',
|
|
31
|
-
// toml
|
|
32
|
-
'--indent-entries=true',
|
|
33
|
-
'--reorder-keys=true',
|
|
34
|
-
// nginx
|
|
35
|
-
'--wrap-parameters=false',
|
|
36
|
-
'--continuation-indent=2',
|
|
37
|
-
];
|
|
38
|
-
// 默认的 Prettier 插件列表
|
|
39
|
-
export const DEFAULT_PLUGINS = [
|
|
40
|
-
'@prettier/plugin-xml',
|
|
41
|
-
'prettier-plugin-toml',
|
|
42
|
-
'prettier-plugin-nginx',
|
|
43
|
-
'prettier-plugin-sh',
|
|
44
|
-
];
|
|
45
|
-
// 默认的忽略模式
|
|
46
|
-
export const DEFAULT_IGNORE_PATTERNS = [
|
|
47
|
-
'node_modules/',
|
|
48
|
-
'dist/',
|
|
49
|
-
'build/',
|
|
50
|
-
'.nyc_output/',
|
|
51
|
-
'coverage/',
|
|
52
|
-
'.next/',
|
|
53
|
-
'out/',
|
|
54
|
-
];
|