@gitton-dev/cli 0.0.2

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 ADDED
@@ -0,0 +1,49 @@
1
+ # @gitton-dev/cli
2
+
3
+ CLI tool for managing Gitton plugins.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install -g @gitton-dev/cli
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Install a plugin
14
+
15
+ ```bash
16
+ # Install by full package name
17
+ gitton install @gitton-dev/plugin-github-actions
18
+
19
+ # Or use shorthand (automatically expands to @gitton-dev/plugin-{name})
20
+ gitton install github-actions
21
+ ```
22
+
23
+ ### List installed plugins
24
+
25
+ ```bash
26
+ gitton list
27
+ ```
28
+
29
+ ### Uninstall a plugin
30
+
31
+ ```bash
32
+ gitton uninstall github-actions
33
+ ```
34
+
35
+ ## Options
36
+
37
+ - `--dev` - Use development plugins directory (for plugin developers)
38
+
39
+ ## Plugin Directory
40
+
41
+ Plugins are installed to:
42
+
43
+ - **macOS**: `~/Library/Application Support/gitton/plugins/`
44
+ - **Windows**: `%APPDATA%/gitton/plugins/`
45
+ - **Linux**: `~/.config/gitton/plugins/`
46
+
47
+ ## License
48
+
49
+ MIT
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
package/dist/index.js ADDED
@@ -0,0 +1,207 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/index.ts
4
+ import { Command } from "commander";
5
+
6
+ // src/commands/install.ts
7
+ import pacote from "pacote";
8
+ import path from "path";
9
+ import fs from "fs/promises";
10
+ import os from "os";
11
+ import chalk from "chalk";
12
+ function getPluginsDir(isDev) {
13
+ const platform = os.platform();
14
+ const homeDir = os.homedir();
15
+ let appDataDir;
16
+ if (platform === "darwin") {
17
+ appDataDir = path.join(homeDir, "Library", "Application Support", "gitton");
18
+ } else if (platform === "win32") {
19
+ appDataDir = path.join(process.env.APPDATA || path.join(homeDir, "AppData", "Roaming"), "gitton");
20
+ } else {
21
+ appDataDir = path.join(homeDir, ".config", "gitton");
22
+ }
23
+ return path.join(appDataDir, isDev ? "plugins-dev" : "plugins");
24
+ }
25
+ async function install(packageName, options) {
26
+ const pluginsDir = getPluginsDir(options.dev ?? false);
27
+ console.log(chalk.blue(`Installing ${packageName}...`));
28
+ try {
29
+ await fs.mkdir(pluginsDir, { recursive: true });
30
+ let fullPackageName = packageName;
31
+ if (!packageName.startsWith("@") && !packageName.includes("/")) {
32
+ fullPackageName = `@gitton-dev/plugin-${packageName}`;
33
+ }
34
+ console.log(chalk.gray(`Fetching ${fullPackageName}...`));
35
+ const manifest = await pacote.manifest(fullPackageName, { fullMetadata: true });
36
+ const pluginDir = path.join(pluginsDir, manifest.name.replace("/", "-"));
37
+ const gittonConfig = manifest.gitton;
38
+ if (!gittonConfig) {
39
+ console.error(chalk.red(`Error: ${fullPackageName} is not a valid Gitton plugin (missing "gitton" field in package.json)`));
40
+ process.exit(1);
41
+ }
42
+ await fs.rm(pluginDir, { recursive: true, force: true });
43
+ console.log(chalk.gray(`Extracting to ${pluginDir}...`));
44
+ await pacote.extract(fullPackageName, pluginDir);
45
+ console.log(chalk.green(`\u2713 Installed ${manifest.name}@${manifest.version}`));
46
+ console.log(chalk.gray(` Location: ${pluginDir}`));
47
+ console.log(chalk.gray(` Display Name: ${gittonConfig.displayName}`));
48
+ if (gittonConfig.permissions?.length > 0) {
49
+ console.log(chalk.gray(` Permissions: ${gittonConfig.permissions.join(", ")}`));
50
+ }
51
+ console.log("");
52
+ console.log(chalk.yellow("Note: Restart Gitton to load the plugin."));
53
+ } catch (error) {
54
+ if (error.code === "E404") {
55
+ console.error(chalk.red(`Error: Package "${packageName}" not found on npm`));
56
+ if (!packageName.startsWith("@gitton-dev/")) {
57
+ console.log(chalk.gray(`Did you mean @gitton-dev/plugin-${packageName}?`));
58
+ }
59
+ } else {
60
+ console.error(chalk.red(`Error: ${error.message}`));
61
+ }
62
+ process.exit(1);
63
+ }
64
+ }
65
+
66
+ // src/commands/list.ts
67
+ import path2 from "path";
68
+ import fs2 from "fs/promises";
69
+ import os2 from "os";
70
+ import chalk2 from "chalk";
71
+ function getPluginsDir2(isDev) {
72
+ const platform = os2.platform();
73
+ const homeDir = os2.homedir();
74
+ let appDataDir;
75
+ if (platform === "darwin") {
76
+ appDataDir = path2.join(homeDir, "Library", "Application Support", "gitton");
77
+ } else if (platform === "win32") {
78
+ appDataDir = path2.join(process.env.APPDATA || path2.join(homeDir, "AppData", "Roaming"), "gitton");
79
+ } else {
80
+ appDataDir = path2.join(homeDir, ".config", "gitton");
81
+ }
82
+ return path2.join(appDataDir, isDev ? "plugins-dev" : "plugins");
83
+ }
84
+ async function list(options) {
85
+ const pluginsDir = getPluginsDir2(options.dev ?? false);
86
+ console.log(chalk2.blue(`Plugins directory: ${pluginsDir}`));
87
+ console.log("");
88
+ try {
89
+ const entries = await fs2.readdir(pluginsDir, { withFileTypes: true });
90
+ const plugins = [];
91
+ for (const entry of entries) {
92
+ if (!entry.isDirectory()) continue;
93
+ if (entry.name.startsWith(".") || entry.name.startsWith("_")) continue;
94
+ const packageJsonPath = path2.join(pluginsDir, entry.name, "package.json");
95
+ try {
96
+ const content = await fs2.readFile(packageJsonPath, "utf-8");
97
+ const pkg = JSON.parse(content);
98
+ if (pkg.gitton) {
99
+ plugins.push({
100
+ name: pkg.name,
101
+ version: pkg.version,
102
+ displayName: pkg.gitton.displayName || pkg.name,
103
+ description: pkg.gitton.description || pkg.description || ""
104
+ });
105
+ }
106
+ } catch {
107
+ }
108
+ }
109
+ if (plugins.length === 0) {
110
+ console.log(chalk2.gray("No plugins installed."));
111
+ console.log("");
112
+ console.log("Install plugins with:");
113
+ console.log(chalk2.cyan(" gitton install <package-name>"));
114
+ console.log("");
115
+ console.log("Example:");
116
+ console.log(chalk2.cyan(" gitton install github-actions"));
117
+ return;
118
+ }
119
+ console.log(`Found ${plugins.length} plugin(s):`);
120
+ console.log("");
121
+ for (const plugin of plugins) {
122
+ console.log(chalk2.green(` ${plugin.displayName}`));
123
+ console.log(chalk2.gray(` ${plugin.name}@${plugin.version}`));
124
+ if (plugin.description) {
125
+ console.log(chalk2.gray(` ${plugin.description}`));
126
+ }
127
+ console.log("");
128
+ }
129
+ } catch (error) {
130
+ if (error.code === "ENOENT") {
131
+ console.log(chalk2.gray("No plugins installed."));
132
+ } else {
133
+ console.error(chalk2.red(`Error: ${error.message}`));
134
+ process.exit(1);
135
+ }
136
+ }
137
+ }
138
+
139
+ // src/commands/uninstall.ts
140
+ import path3 from "path";
141
+ import fs3 from "fs/promises";
142
+ import os3 from "os";
143
+ import chalk3 from "chalk";
144
+ function getPluginsDir3(isDev) {
145
+ const platform = os3.platform();
146
+ const homeDir = os3.homedir();
147
+ let appDataDir;
148
+ if (platform === "darwin") {
149
+ appDataDir = path3.join(homeDir, "Library", "Application Support", "gitton");
150
+ } else if (platform === "win32") {
151
+ appDataDir = path3.join(process.env.APPDATA || path3.join(homeDir, "AppData", "Roaming"), "gitton");
152
+ } else {
153
+ appDataDir = path3.join(homeDir, ".config", "gitton");
154
+ }
155
+ return path3.join(appDataDir, isDev ? "plugins-dev" : "plugins");
156
+ }
157
+ async function uninstall(packageName, options) {
158
+ const pluginsDir = getPluginsDir3(options.dev ?? false);
159
+ let searchName = packageName;
160
+ if (!packageName.startsWith("@") && !packageName.includes("/")) {
161
+ searchName = `@gitton-dev/plugin-${packageName}`;
162
+ }
163
+ const pluginDirName = searchName.replace("/", "-");
164
+ const pluginDir = path3.join(pluginsDir, pluginDirName);
165
+ try {
166
+ await fs3.access(pluginDir);
167
+ try {
168
+ const packageJsonPath = path3.join(pluginDir, "package.json");
169
+ const content = await fs3.readFile(packageJsonPath, "utf-8");
170
+ const pkg = JSON.parse(content);
171
+ console.log(chalk3.blue(`Uninstalling ${pkg.gitton?.displayName || pkg.name}...`));
172
+ } catch {
173
+ console.log(chalk3.blue(`Uninstalling ${searchName}...`));
174
+ }
175
+ await fs3.rm(pluginDir, { recursive: true, force: true });
176
+ console.log(chalk3.green(`\u2713 Uninstalled ${searchName}`));
177
+ console.log("");
178
+ console.log(chalk3.yellow("Note: Restart Gitton to apply changes."));
179
+ } catch (error) {
180
+ if (error.code === "ENOENT") {
181
+ console.error(chalk3.red(`Error: Plugin "${packageName}" is not installed`));
182
+ console.log("");
183
+ console.log("Installed plugins:");
184
+ try {
185
+ const entries = await fs3.readdir(pluginsDir, { withFileTypes: true });
186
+ for (const entry of entries) {
187
+ if (entry.isDirectory() && !entry.name.startsWith(".")) {
188
+ console.log(chalk3.gray(` - ${entry.name}`));
189
+ }
190
+ }
191
+ } catch {
192
+ console.log(chalk3.gray(" (none)"));
193
+ }
194
+ } else {
195
+ console.error(chalk3.red(`Error: ${error.message}`));
196
+ }
197
+ process.exit(1);
198
+ }
199
+ }
200
+
201
+ // src/index.ts
202
+ var program = new Command();
203
+ program.name("gitton").description("CLI tool for managing Gitton plugins").version("0.0.1");
204
+ program.command("install <package>").alias("i").description("Install a Gitton plugin from npm").option("--dev", "Install to development plugins directory").action(install);
205
+ program.command("uninstall <package>").alias("rm").description("Uninstall a Gitton plugin").option("--dev", "Uninstall from development plugins directory").action(uninstall);
206
+ program.command("list").alias("ls").description("List installed Gitton plugins").option("--dev", "List plugins from development directory").action(list);
207
+ program.parse();
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@gitton-dev/cli",
3
+ "version": "0.0.2",
4
+ "description": "CLI tool for managing Gitton plugins",
5
+ "type": "module",
6
+ "bin": {
7
+ "gitton": "./dist/index.js"
8
+ },
9
+ "files": [
10
+ "dist"
11
+ ],
12
+ "keywords": [
13
+ "gitton",
14
+ "gitton-plugin",
15
+ "cli"
16
+ ],
17
+ "author": "godai",
18
+ "license": "MIT",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git@github.com:gitton-dev/gitton-plugins.git",
22
+ "directory": "packages/cli"
23
+ },
24
+ "bugs": {
25
+ "url": "https://github.com/gitton-dev/gitton-plugins/issues"
26
+ },
27
+ "homepage": "https://jsers.dev/service/gitton",
28
+ "dependencies": {
29
+ "commander": "^13.1.0",
30
+ "pacote": "^21.0.0",
31
+ "chalk": "^5.4.1"
32
+ },
33
+ "devDependencies": {
34
+ "@types/node": "^22.13.4",
35
+ "@types/pacote": "^11.1.8",
36
+ "tsup": "^8.4.0",
37
+ "typescript": "^5.7.3"
38
+ },
39
+ "scripts": {
40
+ "build": "tsup src/index.ts --format esm --dts --clean",
41
+ "dev": "tsup src/index.ts --format esm --watch",
42
+ "clean": "rm -rf dist"
43
+ }
44
+ }