@airuleshub/cli 1.0.0 → 1.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.
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from "commander";
3
+ import { installRule } from "../src/commands/install.js";
4
+ const program = new Command();
5
+ program.name("airuleshub").description("Install AI rules from airuleshub.com");
6
+ program
7
+ .command("install <slug>")
8
+ .option("-f, --format <type>", "md or txt")
9
+ .action(installRule);
10
+ program.parse();
@@ -0,0 +1,8 @@
1
+ export async function fetchRule(slug) {
2
+ const BASE_URL = process.env.VITE_APP_URL || 'https://airuleshub.com';
3
+ const res = await fetch(`${BASE_URL}/api/rules/${slug}`);
4
+ if (!res.ok) {
5
+ throw new Error('Rule not found');
6
+ }
7
+ return res.json();
8
+ }
@@ -0,0 +1,38 @@
1
+ import fs from 'fs-extra';
2
+ import inquirer from 'inquirer';
3
+ import { fetchRule } from '../api/rules.js';
4
+ import { writeRule, getRulePath } from '../fs/writer.js';
5
+ export async function installRule(slug, options) {
6
+ console.log(`📦 Installing rule: ${slug}`);
7
+ const rule = await fetchRule(slug);
8
+ const format = options.format
9
+ ? options.format
10
+ : (await inquirer.prompt([
11
+ {
12
+ type: 'list',
13
+ name: 'format',
14
+ message: '📄 Choose file format:',
15
+ choices: [
16
+ { name: 'Markdown (.md)', value: 'md' },
17
+ { name: 'Text (.txt)', value: 'txt' },
18
+ ],
19
+ default: 'md',
20
+ },
21
+ ])).format;
22
+ const filePath = getRulePath(slug, format);
23
+ if (await fs.pathExists(filePath)) {
24
+ const { overwrite } = await inquirer.prompt([
25
+ {
26
+ type: 'confirm',
27
+ name: 'overwrite',
28
+ message: '⚠️ File already exists. Overwrite?',
29
+ default: false,
30
+ },
31
+ ]);
32
+ if (!overwrite) {
33
+ console.log('❌ Installation cancelled.');
34
+ return;
35
+ }
36
+ }
37
+ await writeRule(rule, format ?? 'md');
38
+ }
@@ -0,0 +1,14 @@
1
+ import fs from 'fs-extra';
2
+ import path from 'path';
3
+ import { renderTemplate } from '../template.js';
4
+ export const RULES_DIR = 'airules';
5
+ export function getRulePath(slug, format) {
6
+ return path.join(process.cwd(), RULES_DIR, `${slug}.${format}`);
7
+ }
8
+ export async function writeRule(rule, format) {
9
+ const baseDir = path.join(process.cwd(), RULES_DIR);
10
+ await fs.ensureDir(baseDir);
11
+ const filePath = getRulePath(rule.slug, format);
12
+ await fs.writeFile(filePath, renderTemplate(rule));
13
+ console.log(`✅ Installed: ${RULES_DIR}/${rule.slug}.${format}`);
14
+ }
@@ -0,0 +1,11 @@
1
+ export function renderTemplate(rule) {
2
+ return `
3
+ # ${rule.title}
4
+
5
+ Source: https://airuleshub.com/rules/${rule.slug}
6
+
7
+ ---
8
+
9
+ ${rule.content}
10
+ `.trim();
11
+ }
package/package.json CHANGED
@@ -1,10 +1,12 @@
1
1
  {
2
2
  "name": "@airuleshub/cli",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "main": "index.js",
7
7
  "scripts": {
8
+ "build": "tsc",
9
+ "prepublishOnly": "npm run build",
8
10
  "test": "echo \"Error: no test specified\" && exit 1"
9
11
  },
10
12
  "bin": {