@forgehive/forge-cli 0.3.8 → 0.3.9

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/dist/runner.js CHANGED
@@ -24,6 +24,7 @@ const create_1 = require("./tasks/runner/create");
24
24
  const remove_2 = require("./tasks/runner/remove");
25
25
  const bundle_1 = require("./tasks/runner/bundle");
26
26
  const download_2 = require("./tasks/fixture/download");
27
+ const download_3 = require("./tasks/docs/download");
27
28
  const add_1 = require("./tasks/auth/add");
28
29
  const switch_1 = require("./tasks/auth/switch");
29
30
  const list_2 = require("./tasks/auth/list");
@@ -56,6 +57,8 @@ runner.load('runner:remove', remove_2.remove);
56
57
  runner.load('runner:bundle', bundle_1.bundle);
57
58
  // Fixture commands
58
59
  runner.load('fixture:download', download_2.download);
60
+ // Docs commands
61
+ runner.load('docs:download', download_3.download);
59
62
  // Auth commands
60
63
  runner.load('auth:add', add_1.add);
61
64
  runner.load('auth:switch', switch_1.switchProfile);
@@ -146,6 +149,12 @@ runner.setHandler(async (data) => {
146
149
  profileName: action
147
150
  });
148
151
  }
152
+ else if (taskName === 'docs:download') {
153
+ const { path } = args;
154
+ result = await task.run({
155
+ path
156
+ });
157
+ }
149
158
  else {
150
159
  result = await task.run(args);
151
160
  if (taskName === 'info') {
@@ -0,0 +1,20 @@
1
+ export declare const download: import("@forgehive/task").TaskInstanceType<(argv: {
2
+ path?: string | undefined;
3
+ }, boundaries: import("@forgehive/task").WrappedBoundaries<{
4
+ fetchFile: (url: string) => Promise<string>;
5
+ getCurrentWorkingDirectory: () => Promise<string>;
6
+ createDirectory: (dirPath: string) => Promise<void>;
7
+ writeFile: (filePath: string, content: string) => Promise<void>;
8
+ checkFileExists: (filePath: string) => Promise<boolean>;
9
+ }>) => Promise<{
10
+ success: boolean;
11
+ filePath: string;
12
+ targetPath: string;
13
+ size: number;
14
+ }>, {
15
+ fetchFile: (url: string) => Promise<string>;
16
+ getCurrentWorkingDirectory: () => Promise<string>;
17
+ createDirectory: (dirPath: string) => Promise<void>;
18
+ writeFile: (filePath: string, content: string) => Promise<void>;
19
+ checkFileExists: (filePath: string) => Promise<boolean>;
20
+ }>;
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ // TASK: download
3
+ // Run this task with:
4
+ // forge task:run docs:download
5
+ // forge task:run docs:download --path="custom/path/forge.md"
6
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
+ if (k2 === undefined) k2 = k;
8
+ var desc = Object.getOwnPropertyDescriptor(m, k);
9
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
+ desc = { enumerable: true, get: function() { return m[k]; } };
11
+ }
12
+ Object.defineProperty(o, k2, desc);
13
+ }) : (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ o[k2] = m[k];
16
+ }));
17
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
18
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
19
+ }) : function(o, v) {
20
+ o["default"] = v;
21
+ });
22
+ var __importStar = (this && this.__importStar) || (function () {
23
+ var ownKeys = function(o) {
24
+ ownKeys = Object.getOwnPropertyNames || function (o) {
25
+ var ar = [];
26
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
27
+ return ar;
28
+ };
29
+ return ownKeys(o);
30
+ };
31
+ return function (mod) {
32
+ if (mod && mod.__esModule) return mod;
33
+ var result = {};
34
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
35
+ __setModuleDefault(result, mod);
36
+ return result;
37
+ };
38
+ })();
39
+ var __importDefault = (this && this.__importDefault) || function (mod) {
40
+ return (mod && mod.__esModule) ? mod : { "default": mod };
41
+ };
42
+ Object.defineProperty(exports, "__esModule", { value: true });
43
+ exports.download = void 0;
44
+ const task_1 = require("@forgehive/task");
45
+ const schema_1 = require("@forgehive/schema");
46
+ const path_1 = __importDefault(require("path"));
47
+ const name = 'docs:download';
48
+ const description = 'Download the ForgeHive LLM guide from GitHub to local project';
49
+ const LLM_GUIDE_URL = 'https://raw.githubusercontent.com/forge-and-hive/forge-mono-repo/refs/heads/main/docs/llm.md';
50
+ const schema = new schema_1.Schema({
51
+ path: schema_1.Schema.string().optional()
52
+ });
53
+ const boundaries = {
54
+ fetchFile: async (url) => {
55
+ const response = await fetch(url);
56
+ if (!response.ok) {
57
+ throw new Error(`Failed to fetch file: ${response.status} ${response.statusText}`);
58
+ }
59
+ return await response.text();
60
+ },
61
+ getCurrentWorkingDirectory: async () => {
62
+ return process.cwd();
63
+ },
64
+ createDirectory: async (dirPath) => {
65
+ const fs = await Promise.resolve().then(() => __importStar(require('fs/promises')));
66
+ await fs.mkdir(dirPath, { recursive: true });
67
+ },
68
+ writeFile: async (filePath, content) => {
69
+ const fs = await Promise.resolve().then(() => __importStar(require('fs/promises')));
70
+ await fs.writeFile(filePath, content, 'utf-8');
71
+ },
72
+ checkFileExists: async (filePath) => {
73
+ const fs = await Promise.resolve().then(() => __importStar(require('fs/promises')));
74
+ try {
75
+ await fs.access(filePath);
76
+ return true;
77
+ }
78
+ catch {
79
+ return false;
80
+ }
81
+ }
82
+ };
83
+ exports.download = (0, task_1.createTask)({
84
+ name,
85
+ description,
86
+ schema,
87
+ boundaries,
88
+ fn: async function ({ path: customPath }, { fetchFile, getCurrentWorkingDirectory, createDirectory, writeFile, checkFileExists }) {
89
+ // Determine the target path
90
+ const targetPath = customPath || 'docs/forge.md';
91
+ const cwd = await getCurrentWorkingDirectory();
92
+ const fullPath = path_1.default.resolve(cwd, targetPath);
93
+ const dirPath = path_1.default.dirname(fullPath);
94
+ console.log(`Downloading ForgeHive LLM guide to: ${targetPath}`);
95
+ // Check if file already exists
96
+ const fileExists = await checkFileExists(fullPath);
97
+ if (fileExists) {
98
+ console.log(`Warning: File already exists at ${targetPath}. It will be overwritten.`);
99
+ }
100
+ // Download the file content
101
+ const content = await fetchFile(LLM_GUIDE_URL);
102
+ // Create directory if it doesn't exist
103
+ await createDirectory(dirPath);
104
+ // Write the file
105
+ await writeFile(fullPath, content);
106
+ console.log(`✅ Successfully downloaded ForgeHive LLM guide to ${targetPath}`);
107
+ return {
108
+ success: true,
109
+ filePath: fullPath,
110
+ targetPath,
111
+ size: content.length
112
+ };
113
+ }
114
+ });
package/forge.json CHANGED
@@ -114,6 +114,10 @@
114
114
  "task:invoke": {
115
115
  "path": "src/tasks/task/invoke.ts",
116
116
  "handler": "invoke"
117
+ },
118
+ "docs:download": {
119
+ "path": "src/tasks/docs/download.ts",
120
+ "handler": "download"
117
121
  }
118
122
  },
119
123
  "runners": {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forgehive/forge-cli",
3
- "version": "0.3.8",
3
+ "version": "0.3.9",
4
4
  "description": "TypeScript CLI application",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -29,9 +29,9 @@
29
29
  "minimist": "^1.2.8",
30
30
  "@forgehive/hive-sdk": "0.1.2",
31
31
  "@forgehive/record-tape": "0.2.5",
32
- "@forgehive/schema": "0.1.4",
32
+ "@forgehive/task": "0.2.5",
33
33
  "@forgehive/runner": "0.2.5",
34
- "@forgehive/task": "0.2.5"
34
+ "@forgehive/schema": "0.1.4"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@types/archiver": "^6.0.3",
package/src/runner.ts CHANGED
@@ -27,6 +27,8 @@ import { bundle as bundleRunner } from './tasks/runner/bundle'
27
27
 
28
28
  import { download as downloadFixture } from './tasks/fixture/download'
29
29
 
30
+ import { download as downloadDocs } from './tasks/docs/download'
31
+
30
32
  import { add as addProfile } from './tasks/auth/add'
31
33
  import { switchProfile } from './tasks/auth/switch'
32
34
  import { list as listProfiles } from './tasks/auth/list'
@@ -70,6 +72,9 @@ runner.load('runner:bundle', bundleRunner)
70
72
  // Fixture commands
71
73
  runner.load('fixture:download', downloadFixture)
72
74
 
75
+ // Docs commands
76
+ runner.load('docs:download', downloadDocs)
77
+
73
78
  // Auth commands
74
79
  runner.load('auth:add', addProfile)
75
80
  runner.load('auth:switch', switchProfile)
@@ -164,6 +169,12 @@ runner.setHandler(async (data: ParsedArgs): Promise<unknown> => {
164
169
  result = await task.run({
165
170
  profileName: action
166
171
  })
172
+ } else if (taskName === 'docs:download') {
173
+ const { path } = args as { path?: string }
174
+
175
+ result = await task.run({
176
+ path
177
+ })
167
178
  } else {
168
179
  result = await task.run(args)
169
180
 
@@ -0,0 +1,87 @@
1
+ // TASK: download
2
+ // Run this task with:
3
+ // forge task:run docs:download
4
+ // forge task:run docs:download --path="custom/path/forge.md"
5
+
6
+ import { createTask } from '@forgehive/task'
7
+ import { Schema } from '@forgehive/schema'
8
+ import path from 'path'
9
+
10
+ const name = 'docs:download'
11
+ const description = 'Download the ForgeHive LLM guide from GitHub to local project'
12
+
13
+ const LLM_GUIDE_URL = 'https://raw.githubusercontent.com/forge-and-hive/forge-mono-repo/refs/heads/main/docs/llm.md'
14
+
15
+ const schema = new Schema({
16
+ path: Schema.string().optional()
17
+ })
18
+
19
+ const boundaries = {
20
+ fetchFile: async (url: string): Promise<string> => {
21
+ const response = await fetch(url)
22
+ if (!response.ok) {
23
+ throw new Error(`Failed to fetch file: ${response.status} ${response.statusText}`)
24
+ }
25
+ return await response.text()
26
+ },
27
+ getCurrentWorkingDirectory: async (): Promise<string> => {
28
+ return process.cwd()
29
+ },
30
+ createDirectory: async (dirPath: string): Promise<void> => {
31
+ const fs = await import('fs/promises')
32
+ await fs.mkdir(dirPath, { recursive: true })
33
+ },
34
+ writeFile: async (filePath: string, content: string): Promise<void> => {
35
+ const fs = await import('fs/promises')
36
+ await fs.writeFile(filePath, content, 'utf-8')
37
+ },
38
+ checkFileExists: async (filePath: string): Promise<boolean> => {
39
+ const fs = await import('fs/promises')
40
+ try {
41
+ await fs.access(filePath)
42
+ return true
43
+ } catch {
44
+ return false
45
+ }
46
+ }
47
+ }
48
+
49
+ export const download = createTask({
50
+ name,
51
+ description,
52
+ schema,
53
+ boundaries,
54
+ fn: async function ({ path: customPath }, { fetchFile, getCurrentWorkingDirectory, createDirectory, writeFile, checkFileExists }) {
55
+ // Determine the target path
56
+ const targetPath = customPath || 'docs/forge.md'
57
+ const cwd = await getCurrentWorkingDirectory()
58
+ const fullPath = path.resolve(cwd, targetPath)
59
+ const dirPath = path.dirname(fullPath)
60
+
61
+ console.log(`Downloading ForgeHive LLM guide to: ${targetPath}`)
62
+
63
+ // Check if file already exists
64
+ const fileExists = await checkFileExists(fullPath)
65
+ if (fileExists) {
66
+ console.log(`Warning: File already exists at ${targetPath}. It will be overwritten.`)
67
+ }
68
+
69
+ // Download the file content
70
+ const content = await fetchFile(LLM_GUIDE_URL)
71
+
72
+ // Create directory if it doesn't exist
73
+ await createDirectory(dirPath)
74
+
75
+ // Write the file
76
+ await writeFile(fullPath, content)
77
+
78
+ console.log(`✅ Successfully downloaded ForgeHive LLM guide to ${targetPath}`)
79
+
80
+ return {
81
+ success: true,
82
+ filePath: fullPath,
83
+ targetPath,
84
+ size: content.length
85
+ }
86
+ }
87
+ })