@miloya/oc-minimax-status 0.1.2 → 0.1.4

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.
Files changed (3) hide show
  1. package/bin/init.js +8 -3
  2. package/index.js +41 -0
  3. package/package.json +1 -1
package/bin/init.js CHANGED
@@ -28,9 +28,14 @@ function getCommandDir() {
28
28
  return path.join(home, ".config", "opencode", "commands");
29
29
  }
30
30
 
31
- function getPackageDir() {
32
- return process.cwd();
33
- }
31
+ function getPackageDir() {
32
+ // When running postinstall for global install, use npm_package_json env var
33
+ const pkgJson = process.env.npm_package_json;
34
+ if (pkgJson) {
35
+ return path.dirname(pkgJson);
36
+ }
37
+ return process.cwd();
38
+ }
34
39
 
35
40
  function updateOpencodeConfig() {
36
41
  const configPath = getOpencodeConfigPath();
package/index.js CHANGED
@@ -10,12 +10,53 @@ import { tool } from "@opencode-ai/plugin";
10
10
  import axios from "axios";
11
11
  import fs from "fs";
12
12
  import path from "path";
13
+ import { fileURLToPath } from "url";
13
14
 
14
15
  const CONFIG_PATH = path.join(
15
16
  process.env.HOME || process.env.USERPROFILE,
16
17
  ".minimax-config.json"
17
18
  );
18
19
 
20
+ function syncPluginFiles() {
21
+ try {
22
+ const pkgDir = path.dirname(fileURLToPath(import.meta.url));
23
+ const home = process.env.HOME || process.env.USERPROFILE;
24
+ const plugins = path.join(home, ".config", "opencode", "plugins");
25
+ const commands = path.join(home, ".config", "opencode", "commands");
26
+
27
+ // Copy index.js to plugins
28
+ const srcIndex = path.join(pkgDir, "index.js");
29
+ const destIndex = path.join(plugins, "oc-minimax-status.js");
30
+ if (fs.existsSync(srcIndex)) {
31
+ if (!fs.existsSync(plugins)) {
32
+ fs.mkdirSync(plugins, { recursive: true });
33
+ }
34
+ fs.copyFileSync(srcIndex, destIndex);
35
+ }
36
+
37
+ // Copy commands
38
+ const srcCmdDir = path.join(pkgDir, "commands");
39
+ if (fs.existsSync(srcCmdDir)) {
40
+ if (!fs.existsSync(commands)) {
41
+ fs.mkdirSync(commands, { recursive: true });
42
+ }
43
+ const files = fs.readdirSync(srcCmdDir);
44
+ for (const file of files) {
45
+ if (file.endsWith(".md")) {
46
+ fs.copyFileSync(
47
+ path.join(srcCmdDir, file),
48
+ path.join(commands, file)
49
+ );
50
+ }
51
+ }
52
+ }
53
+ } catch (e) {
54
+ // Silent fail
55
+ }
56
+ }
57
+
58
+ syncPluginFiles();
59
+
19
60
  function getCredentials() {
20
61
  try {
21
62
  if (fs.existsSync(CONFIG_PATH)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@miloya/oc-minimax-status",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "MiniMax Coding Plan 用量查询插件 for OpenCode - 一键安装自动配置",
5
5
  "main": "index.js",
6
6
  "type": "module",