meocli 0.0.0 → 0.0.1
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 +34 -7
- package/dist/commands/hello/world.js +0 -1
- package/dist/commands/prettier/index.d.ts +14 -0
- package/dist/commands/prettier/index.js +81 -0
- package/dist/lib/env.d.ts +1 -0
- package/dist/lib/env.js +3 -0
- package/dist/lib/sleep.d.ts +1 -0
- package/dist/lib/sleep.js +3 -0
- package/oclif.manifest.json +53 -1
- package/package.json +8 -2
package/README.md
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
#
|
|
1
|
+
# meocli
|
|
2
2
|
|
|
3
3
|
A new CLI generated with oclif
|
|
4
4
|
|
|
5
5
|
[](https://oclif.io)
|
|
6
|
-
[](https://npmjs.org/package/meocli)
|
|
7
|
+
[](https://npmjs.org/package/meocli)
|
|
8
8
|
|
|
9
9
|
<!-- toc -->
|
|
10
|
-
* [
|
|
10
|
+
* [meocli](#meocli)
|
|
11
11
|
* [Dev](#dev)
|
|
12
12
|
* [Usage](#usage)
|
|
13
13
|
* [Commands](#commands)
|
|
@@ -32,7 +32,7 @@ $ npm install -g meocli
|
|
|
32
32
|
$ me COMMAND
|
|
33
33
|
running command...
|
|
34
34
|
$ me (--version)
|
|
35
|
-
meocli/0.0.
|
|
35
|
+
meocli/0.0.1 win32-x64 node-v24.12.0
|
|
36
36
|
$ me --help [COMMAND]
|
|
37
37
|
USAGE
|
|
38
38
|
$ me COMMAND
|
|
@@ -56,6 +56,7 @@ USAGE
|
|
|
56
56
|
* [`me plugins uninstall [PLUGIN]`](#me-plugins-uninstall-plugin)
|
|
57
57
|
* [`me plugins unlink [PLUGIN]`](#me-plugins-unlink-plugin)
|
|
58
58
|
* [`me plugins update`](#me-plugins-update)
|
|
59
|
+
* [`me prettier FILEPATH`](#me-prettier-filepath)
|
|
59
60
|
|
|
60
61
|
## `me hello PERSON`
|
|
61
62
|
|
|
@@ -79,7 +80,7 @@ EXAMPLES
|
|
|
79
80
|
hello friend from oclif! (./src/commands/hello/index.ts)
|
|
80
81
|
```
|
|
81
82
|
|
|
82
|
-
_See code: [src/commands/hello/index.ts](https://github.com/meme2046/meocli/blob/v0.0.
|
|
83
|
+
_See code: [src/commands/hello/index.ts](https://github.com/meme2046/meocli/blob/v0.0.1/src/commands/hello/index.ts)_
|
|
83
84
|
|
|
84
85
|
## `me hello world`
|
|
85
86
|
|
|
@@ -97,7 +98,7 @@ EXAMPLES
|
|
|
97
98
|
hello world! (./src/commands/hello/world.ts)
|
|
98
99
|
```
|
|
99
100
|
|
|
100
|
-
_See code: [src/commands/hello/world.ts](https://github.com/meme2046/meocli/blob/v0.0.
|
|
101
|
+
_See code: [src/commands/hello/world.ts](https://github.com/meme2046/meocli/blob/v0.0.1/src/commands/hello/world.ts)_
|
|
101
102
|
|
|
102
103
|
## `me help [COMMAND]`
|
|
103
104
|
|
|
@@ -408,4 +409,30 @@ DESCRIPTION
|
|
|
408
409
|
```
|
|
409
410
|
|
|
410
411
|
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.54/src/commands/plugins/update.ts)_
|
|
412
|
+
|
|
413
|
+
## `me prettier FILEPATH`
|
|
414
|
+
|
|
415
|
+
Use Prettier to format file
|
|
416
|
+
|
|
417
|
+
```
|
|
418
|
+
USAGE
|
|
419
|
+
$ me prettier FILEPATH [-c <value>] [-i <value>]
|
|
420
|
+
|
|
421
|
+
ARGUMENTS
|
|
422
|
+
FILEPATH file path that need to be formatted by Prettier
|
|
423
|
+
|
|
424
|
+
FLAGS
|
|
425
|
+
-c, --config=<value> [default: ./src/files/.prettierrc.yaml] Prettier config file path
|
|
426
|
+
-i, --ignore=<value> [default: ./src/files/.prettierignore] Prettier ignore file path
|
|
427
|
+
|
|
428
|
+
DESCRIPTION
|
|
429
|
+
Use Prettier to format file
|
|
430
|
+
|
|
431
|
+
EXAMPLES
|
|
432
|
+
$ me prettier ./tests/test.json
|
|
433
|
+
|
|
434
|
+
$ me prettier ./src/file.ts --config ./.prettierrc.yaml
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
_See code: [src/commands/prettier/index.ts](https://github.com/meme2046/meocli/blob/v0.0.1/src/commands/prettier/index.ts)_
|
|
411
438
|
<!-- commandsstop -->
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
export default class Prettier extends Command {
|
|
3
|
+
static args: {
|
|
4
|
+
filePath: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
5
|
+
};
|
|
6
|
+
static description: string;
|
|
7
|
+
static examples: string[];
|
|
8
|
+
static flags: {
|
|
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>;
|
|
11
|
+
};
|
|
12
|
+
run(): Promise<void>;
|
|
13
|
+
private detectPackageManager;
|
|
14
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { Args, Command, Flags } from '@oclif/core';
|
|
2
|
+
import { spawn } from 'node:child_process';
|
|
3
|
+
import { existsSync } from 'node:fs';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
export default class Prettier extends Command {
|
|
6
|
+
static args = {
|
|
7
|
+
filePath: Args.string({
|
|
8
|
+
description: 'file path that need to be formatted by Prettier',
|
|
9
|
+
required: true,
|
|
10
|
+
}),
|
|
11
|
+
};
|
|
12
|
+
static description = 'Use Prettier to format file';
|
|
13
|
+
static examples = [
|
|
14
|
+
'<%= config.bin %> <%= command.id %> ./tests/test.json',
|
|
15
|
+
'<%= config.bin %> <%= command.id %> ./src/file.ts --config ./.prettierrc.yaml',
|
|
16
|
+
];
|
|
17
|
+
static flags = {
|
|
18
|
+
config: Flags.string({
|
|
19
|
+
char: 'c',
|
|
20
|
+
default: './src/files/.prettierrc.yaml',
|
|
21
|
+
description: 'Prettier config file path',
|
|
22
|
+
required: false,
|
|
23
|
+
}),
|
|
24
|
+
ignore: Flags.string({
|
|
25
|
+
char: 'i',
|
|
26
|
+
default: './src/files/.prettierignore',
|
|
27
|
+
description: 'Prettier ignore file path',
|
|
28
|
+
required: false,
|
|
29
|
+
}),
|
|
30
|
+
};
|
|
31
|
+
async run() {
|
|
32
|
+
const { args, flags } = await this.parse(Prettier);
|
|
33
|
+
const { filePath } = args;
|
|
34
|
+
const { config, ignore } = flags;
|
|
35
|
+
// 检测当前使用的包管理器
|
|
36
|
+
const packageManager = this.detectPackageManager();
|
|
37
|
+
// 根据包管理器类型构建参数
|
|
38
|
+
const prettierArgs = [
|
|
39
|
+
'prettier',
|
|
40
|
+
'--write',
|
|
41
|
+
filePath,
|
|
42
|
+
...(config ? [`--config=${config}`] : []),
|
|
43
|
+
...(ignore ? [`--ignore-path=${ignore}`] : []),
|
|
44
|
+
];
|
|
45
|
+
// this.log(`Formatting file: ${filePath}`)
|
|
46
|
+
// 返回一个 Promise 以等待子进程完成
|
|
47
|
+
await new Promise((resolve, reject) => {
|
|
48
|
+
const prettierProcess = spawn(packageManager, prettierArgs, {
|
|
49
|
+
env: { ...process.env }, // 确保子进程继承当前环境变量
|
|
50
|
+
shell: false, // 设置为 false 以避免安全警告
|
|
51
|
+
stdio: 'inherit',
|
|
52
|
+
});
|
|
53
|
+
prettierProcess.on('close', (code) => {
|
|
54
|
+
if (code === 0) {
|
|
55
|
+
this.log(`Successfully formatted ${filePath}`);
|
|
56
|
+
resolve(null);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
reject(new Error(`Prettier exited with code ${code}`));
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
prettierProcess.on('error', (error) => {
|
|
63
|
+
reject(error);
|
|
64
|
+
});
|
|
65
|
+
}).catch((error) => {
|
|
66
|
+
this.error(`Error executing prettier: ${error.message}`);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
detectPackageManager() {
|
|
70
|
+
// 检查项目根目录是否存在 pnpm-lock.yaml 来判断是否使用 pnpm
|
|
71
|
+
if (existsSync(join(process.cwd(), 'pnpm-lock.yaml'))) {
|
|
72
|
+
return 'pnpx';
|
|
73
|
+
}
|
|
74
|
+
// 检查是否存在 yarn.lock 来判断是否使用 yarn
|
|
75
|
+
if (existsSync(join(process.cwd(), 'yarn.lock'))) {
|
|
76
|
+
return 'yarn';
|
|
77
|
+
}
|
|
78
|
+
// 默认使用 npm
|
|
79
|
+
return 'npx';
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getEnv(name: string): string;
|
package/dist/lib/env.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const sleep: (ms: number) => Promise<unknown>;
|
package/oclif.manifest.json
CHANGED
|
@@ -63,7 +63,59 @@
|
|
|
63
63
|
"hello",
|
|
64
64
|
"world.js"
|
|
65
65
|
]
|
|
66
|
+
},
|
|
67
|
+
"prettier": {
|
|
68
|
+
"aliases": [],
|
|
69
|
+
"args": {
|
|
70
|
+
"filePath": {
|
|
71
|
+
"description": "file path that need to be formatted by Prettier",
|
|
72
|
+
"name": "filePath",
|
|
73
|
+
"required": true
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
"description": "Use Prettier to format file",
|
|
77
|
+
"examples": [
|
|
78
|
+
"<%= config.bin %> <%= command.id %> ./tests/test.json",
|
|
79
|
+
"<%= config.bin %> <%= command.id %> ./src/file.ts --config ./.prettierrc.yaml"
|
|
80
|
+
],
|
|
81
|
+
"flags": {
|
|
82
|
+
"config": {
|
|
83
|
+
"char": "c",
|
|
84
|
+
"description": "Prettier config file path",
|
|
85
|
+
"name": "config",
|
|
86
|
+
"required": false,
|
|
87
|
+
"default": "./src/files/.prettierrc.yaml",
|
|
88
|
+
"hasDynamicHelp": false,
|
|
89
|
+
"multiple": false,
|
|
90
|
+
"type": "option"
|
|
91
|
+
},
|
|
92
|
+
"ignore": {
|
|
93
|
+
"char": "i",
|
|
94
|
+
"description": "Prettier ignore file path",
|
|
95
|
+
"name": "ignore",
|
|
96
|
+
"required": false,
|
|
97
|
+
"default": "./src/files/.prettierignore",
|
|
98
|
+
"hasDynamicHelp": false,
|
|
99
|
+
"multiple": false,
|
|
100
|
+
"type": "option"
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
"hasDynamicHelp": false,
|
|
104
|
+
"hiddenAliases": [],
|
|
105
|
+
"id": "prettier",
|
|
106
|
+
"pluginAlias": "meocli",
|
|
107
|
+
"pluginName": "meocli",
|
|
108
|
+
"pluginType": "core",
|
|
109
|
+
"strict": true,
|
|
110
|
+
"enableJsonFlag": false,
|
|
111
|
+
"isESM": true,
|
|
112
|
+
"relativePath": [
|
|
113
|
+
"dist",
|
|
114
|
+
"commands",
|
|
115
|
+
"prettier",
|
|
116
|
+
"index.js"
|
|
117
|
+
]
|
|
66
118
|
}
|
|
67
119
|
},
|
|
68
|
-
"version": "0.0.
|
|
120
|
+
"version": "0.0.1"
|
|
69
121
|
}
|
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.1",
|
|
5
5
|
"author": "meme2046",
|
|
6
6
|
"bin": {
|
|
7
7
|
"me": "./bin/run.js"
|
|
@@ -10,7 +10,12 @@
|
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@oclif/core": "^4",
|
|
12
12
|
"@oclif/plugin-help": "^6",
|
|
13
|
-
"@oclif/plugin-plugins": "^5"
|
|
13
|
+
"@oclif/plugin-plugins": "^5",
|
|
14
|
+
"@prettier/plugin-xml": "^3.4.2",
|
|
15
|
+
"prettier": "^3.7.4",
|
|
16
|
+
"prettier-plugin-nginx": "^1.0.3",
|
|
17
|
+
"prettier-plugin-sh": "^0.18.0",
|
|
18
|
+
"prettier-plugin-toml": "^2.0.6"
|
|
14
19
|
},
|
|
15
20
|
"devDependencies": {
|
|
16
21
|
"@eslint/compat": "^1",
|
|
@@ -64,6 +69,7 @@
|
|
|
64
69
|
"scripts": {
|
|
65
70
|
"dev": "node bin/dev.js",
|
|
66
71
|
"prod": "node bin/run.js",
|
|
72
|
+
"prettier": "prettier",
|
|
67
73
|
"build": "shx rm -rf dist && tsc -b",
|
|
68
74
|
"lint": "eslint",
|
|
69
75
|
"posttest": "pnpm run lint",
|