@forgehive/forge-cli 0.2.14 → 0.3.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.
Files changed (67) hide show
  1. package/dist/runner.js +3 -1
  2. package/dist/tasks/auth/add.js +23 -19
  3. package/dist/tasks/auth/list.js +20 -16
  4. package/dist/tasks/auth/load.js +19 -15
  5. package/dist/tasks/auth/loadCurrent.js +13 -9
  6. package/dist/tasks/auth/remove.js +30 -26
  7. package/dist/tasks/auth/switch.js +19 -15
  8. package/dist/tasks/bundle/create.js +16 -12
  9. package/dist/tasks/bundle/fingerprint.d.ts +36 -0
  10. package/dist/tasks/bundle/fingerprint.js +164 -0
  11. package/dist/tasks/bundle/load.js +9 -5
  12. package/dist/tasks/bundle/zip.js +49 -45
  13. package/dist/tasks/conf/info.js +23 -19
  14. package/dist/tasks/conf/load.js +8 -4
  15. package/dist/tasks/fixture/download.js +40 -36
  16. package/dist/tasks/init.js +35 -31
  17. package/dist/tasks/runner/bundle.js +34 -30
  18. package/dist/tasks/runner/create.js +28 -24
  19. package/dist/tasks/runner/remove.js +22 -18
  20. package/dist/tasks/task/createTask.js +35 -28
  21. package/dist/tasks/task/describe.js +85 -81
  22. package/dist/tasks/task/download.js +63 -59
  23. package/dist/tasks/task/fingerprint.d.ts +26 -0
  24. package/dist/tasks/task/fingerprint.js +87 -0
  25. package/dist/tasks/task/list.js +27 -23
  26. package/dist/tasks/task/publish.js +72 -68
  27. package/dist/tasks/task/remove.js +24 -20
  28. package/dist/tasks/task/replay.js +94 -90
  29. package/dist/tasks/task/run.js +78 -79
  30. package/dist/test/tasks/create.test.js +6 -5
  31. package/dist/utils/taskAnalysis.d.ts +21 -0
  32. package/dist/utils/taskAnalysis.js +380 -0
  33. package/forge.json +12 -0
  34. package/logs/task:fingerprint.log +10 -0
  35. package/package.json +7 -7
  36. package/specs/fingerprint.md +380 -0
  37. package/src/runner.ts +3 -1
  38. package/src/tasks/README.md +13 -13
  39. package/src/tasks/auth/add.ts +3 -3
  40. package/src/tasks/auth/list.ts +3 -3
  41. package/src/tasks/auth/load.ts +3 -3
  42. package/src/tasks/auth/loadCurrent.ts +3 -3
  43. package/src/tasks/auth/remove.ts +3 -3
  44. package/src/tasks/auth/switch.ts +3 -3
  45. package/src/tasks/bundle/README.md +7 -7
  46. package/src/tasks/bundle/create.ts +4 -4
  47. package/src/tasks/bundle/fingerprint.ts +218 -0
  48. package/src/tasks/bundle/load.ts +4 -4
  49. package/src/tasks/bundle/zip.ts +3 -3
  50. package/src/tasks/conf/info.ts +3 -3
  51. package/src/tasks/conf/load.ts +3 -3
  52. package/src/tasks/fixture/download.ts +3 -3
  53. package/src/tasks/init.ts +3 -3
  54. package/src/tasks/runner/bundle.ts +3 -3
  55. package/src/tasks/runner/create.ts +3 -3
  56. package/src/tasks/runner/remove.ts +3 -3
  57. package/src/tasks/task/createTask.ts +10 -7
  58. package/src/tasks/task/describe.ts +3 -3
  59. package/src/tasks/task/download.ts +3 -3
  60. package/src/tasks/task/fingerprint.ts +107 -0
  61. package/src/tasks/task/list.ts +3 -3
  62. package/src/tasks/task/publish.ts +3 -3
  63. package/src/tasks/task/remove.ts +3 -3
  64. package/src/tasks/task/replay.ts +3 -3
  65. package/src/tasks/task/run.ts +12 -18
  66. package/src/test/tasks/create.test.ts +9 -9
  67. package/src/utils/taskAnalysis.ts +419 -0
@@ -34,93 +34,97 @@ const boundaries = {
34
34
  return buildsPath;
35
35
  }
36
36
  };
37
- exports.describe = (0, task_1.createTask)(schema, boundaries, async function ({ descriptorName }, { loadConf, bundleCreate, bundleLoad, ensureBuildsFolder }) {
38
- // Load forge configuration
39
- const forge = await loadConf({});
40
- const taskDescriptor = forge.tasks[descriptorName];
41
- if (taskDescriptor === undefined) {
42
- throw new Error(`Task "${descriptorName}" is not defined in forge.json`);
43
- }
44
- // Prepare paths
45
- const entryPoint = path_1.default.join(process.cwd(), taskDescriptor.path);
46
- const buildsPath = await ensureBuildsFolder();
47
- const outputFile = path_1.default.join(buildsPath, `${descriptorName}.js`);
48
- // Bundle the task
49
- await bundleCreate({
50
- entryPoint,
51
- outputFile
52
- });
53
- // Load the bundled task
54
- const bundle = await bundleLoad({
55
- bundlePath: outputFile
56
- });
57
- // Get the task handler
58
- const task = bundle[taskDescriptor.handler];
59
- if (!task) {
60
- throw new Error(`Handler "${taskDescriptor.handler}" not found in bundle`);
61
- }
62
- console.log('===============================================');
63
- console.log(`Task: ${descriptorName}`);
64
- console.log('===============================================');
65
- console.log(`Path: ${taskDescriptor.path}`);
66
- console.log(`Handler: ${taskDescriptor.handler}`);
67
- // Get task description
68
- const taskDescription = task.getDescription?.() || 'No description available';
69
- console.log(`Description: ${taskDescription}`);
70
- console.log('');
71
- console.log('Schema:');
72
- console.log('-------');
73
- // Get schema information
74
- const taskSchema = task.getSchema?.();
75
- if (taskSchema && taskSchema.shape) {
76
- const schemaKeys = Object.keys(taskSchema.shape);
77
- if (schemaKeys.length === 0) {
78
- console.log(' No schema parameters defined');
37
+ exports.describe = (0, task_1.createTask)({
38
+ schema,
39
+ boundaries,
40
+ fn: async function ({ descriptorName }, { loadConf, bundleCreate, bundleLoad, ensureBuildsFolder }) {
41
+ // Load forge configuration
42
+ const forge = await loadConf({});
43
+ const taskDescriptor = forge.tasks[descriptorName];
44
+ if (taskDescriptor === undefined) {
45
+ throw new Error(`Task "${descriptorName}" is not defined in forge.json`);
46
+ }
47
+ // Prepare paths
48
+ const entryPoint = path_1.default.join(process.cwd(), taskDescriptor.path);
49
+ const buildsPath = await ensureBuildsFolder();
50
+ const outputFile = path_1.default.join(buildsPath, `${descriptorName}.js`);
51
+ // Bundle the task
52
+ await bundleCreate({
53
+ entryPoint,
54
+ outputFile
55
+ });
56
+ // Load the bundled task
57
+ const bundle = await bundleLoad({
58
+ bundlePath: outputFile
59
+ });
60
+ // Get the task handler
61
+ const task = bundle[taskDescriptor.handler];
62
+ if (!task) {
63
+ throw new Error(`Handler "${taskDescriptor.handler}" not found in bundle`);
64
+ }
65
+ console.log('===============================================');
66
+ console.log(`Task: ${descriptorName}`);
67
+ console.log('===============================================');
68
+ console.log(`Path: ${taskDescriptor.path}`);
69
+ console.log(`Handler: ${taskDescriptor.handler}`);
70
+ // Get task description
71
+ const taskDescription = task.getDescription?.() || 'No description available';
72
+ console.log(`Description: ${taskDescription}`);
73
+ console.log('');
74
+ console.log('Schema:');
75
+ console.log('-------');
76
+ // Get schema information
77
+ const taskSchema = task.getSchema?.();
78
+ if (taskSchema && taskSchema.shape) {
79
+ const schemaKeys = Object.keys(taskSchema.shape);
80
+ if (schemaKeys.length === 0) {
81
+ console.log(' No schema parameters defined');
82
+ }
83
+ else {
84
+ schemaKeys.forEach(key => {
85
+ const field = taskSchema.shape[key];
86
+ const fieldType = field.type || 'unknown';
87
+ const fieldDescription = field.description || '';
88
+ if (fieldDescription) {
89
+ console.log(` • ${key} (${fieldType}): ${fieldDescription}`);
90
+ }
91
+ else {
92
+ console.log(` • ${key} (${fieldType})`);
93
+ }
94
+ });
95
+ }
79
96
  }
80
97
  else {
81
- schemaKeys.forEach(key => {
82
- const field = taskSchema.shape[key];
83
- const fieldType = field.type || 'unknown';
84
- const fieldDescription = field.description || '';
85
- if (fieldDescription) {
86
- console.log(` • ${key} (${fieldType}): ${fieldDescription}`);
87
- }
88
- else {
89
- console.log(` • ${key} (${fieldType})`);
90
- }
91
- });
98
+ console.log(' No schema information available');
92
99
  }
93
- }
94
- else {
95
- console.log(' No schema information available');
96
- }
97
- console.log('');
98
- console.log('Boundaries:');
99
- console.log('-----------');
100
- // Get boundaries information
101
- const taskBoundaries = task.getBoundaries?.();
102
- if (taskBoundaries) {
103
- const boundaryKeys = Object.keys(taskBoundaries);
104
- if (boundaryKeys.length === 0) {
105
- console.log(' No boundaries defined');
100
+ console.log('');
101
+ console.log('Boundaries:');
102
+ console.log('-----------');
103
+ // Get boundaries information
104
+ const taskBoundaries = task.getBoundaries?.();
105
+ if (taskBoundaries) {
106
+ const boundaryKeys = Object.keys(taskBoundaries);
107
+ if (boundaryKeys.length === 0) {
108
+ console.log(' No boundaries defined');
109
+ }
110
+ else {
111
+ boundaryKeys.forEach(boundaryName => {
112
+ console.log(` ${boundaryName}`);
113
+ });
114
+ }
106
115
  }
107
116
  else {
108
- boundaryKeys.forEach(boundaryName => {
109
- console.log(` • ${boundaryName}`);
110
- });
117
+ console.log(' No boundary information available');
111
118
  }
119
+ console.log('===============================================');
120
+ return {
121
+ name: descriptorName,
122
+ path: taskDescriptor.path,
123
+ handler: taskDescriptor.handler,
124
+ description: taskDescription,
125
+ schema: taskSchema?.shape || {},
126
+ boundaries: taskBoundaries ? Object.keys(taskBoundaries) : []
127
+ };
112
128
  }
113
- else {
114
- console.log(' No boundary information available');
115
- }
116
- console.log('===============================================');
117
- return {
118
- name: descriptorName,
119
- path: taskDescriptor.path,
120
- handler: taskDescriptor.handler,
121
- description: taskDescription,
122
- schema: taskSchema?.shape || {},
123
- boundaries: taskBoundaries ? Object.keys(taskBoundaries) : []
124
- };
125
129
  });
126
130
  exports.describe.setDescription(description);
@@ -78,50 +78,53 @@ const boundaries = {
78
78
  }
79
79
  }
80
80
  };
81
- exports.download = (0, task_1.createTask)(schema, boundaries, async function ({ descriptorName, uuid }, { downloadTask, getCwd, parseTaskName, persistTask, loadConf, persistConf, checkTaskExists, loadCurrentProfile }) {
82
- console.log(`Attempting to download task with descriptor: ${descriptorName} and uuid: ${uuid}`);
83
- // Parse descriptor name to get task details
84
- const { taskName, fileName, descriptor, dir } = await parseTaskName(descriptorName);
85
- const profile = await loadCurrentProfile({});
86
- const cwd = await getCwd();
87
- const forge = await loadConf({});
88
- let taskPath = forge.paths.tasks;
89
- if (dir !== undefined) {
90
- taskPath = path_1.default.join(taskPath, dir);
91
- }
92
- // Check if task already exists
93
- const taskExists = await checkTaskExists(taskPath, fileName);
94
- if (taskExists) {
95
- console.log(`Task ${descriptor} already exists at ${taskPath}/${fileName}`);
96
- return {
97
- error: 'Task already exists',
98
- taskPath: `${taskPath}/${fileName}`,
99
- descriptor
100
- };
101
- }
102
- // Download from hive api server
103
- let response;
104
- try {
105
- response = await downloadTask(uuid, profile);
106
- }
107
- catch (e) {
108
- const error = e;
109
- console.error('Error downloading task:', error.message, error.status);
110
- if (error.status === 404) {
81
+ exports.download = (0, task_1.createTask)({
82
+ schema,
83
+ boundaries,
84
+ fn: async function ({ descriptorName, uuid }, { downloadTask, getCwd, parseTaskName, persistTask, loadConf, persistConf, checkTaskExists, loadCurrentProfile }) {
85
+ console.log(`Attempting to download task with descriptor: ${descriptorName} and uuid: ${uuid}`);
86
+ // Parse descriptor name to get task details
87
+ const { taskName, fileName, descriptor, dir } = await parseTaskName(descriptorName);
88
+ const profile = await loadCurrentProfile({});
89
+ const cwd = await getCwd();
90
+ const forge = await loadConf({});
91
+ let taskPath = forge.paths.tasks;
92
+ if (dir !== undefined) {
93
+ taskPath = path_1.default.join(taskPath, dir);
94
+ }
95
+ // Check if task already exists
96
+ const taskExists = await checkTaskExists(taskPath, fileName);
97
+ if (taskExists) {
98
+ console.log(`Task ${descriptor} already exists at ${taskPath}/${fileName}`);
111
99
  return {
112
- error: 'Task not found',
100
+ error: 'Task already exists',
113
101
  taskPath: `${taskPath}/${fileName}`,
114
102
  descriptor
115
103
  };
116
104
  }
117
- return {
118
- error: 'Failed to download task',
119
- message: error.message,
120
- taskPath: `${taskPath}/${fileName}`,
121
- descriptor
122
- };
123
- }
124
- console.log(`
105
+ // Download from hive api server
106
+ let response;
107
+ try {
108
+ response = await downloadTask(uuid, profile);
109
+ }
110
+ catch (e) {
111
+ const error = e;
112
+ console.error('Error downloading task:', error.message, error.status);
113
+ if (error.status === 404) {
114
+ return {
115
+ error: 'Task not found',
116
+ taskPath: `${taskPath}/${fileName}`,
117
+ descriptor
118
+ };
119
+ }
120
+ return {
121
+ error: 'Failed to download task',
122
+ message: error.message,
123
+ taskPath: `${taskPath}/${fileName}`,
124
+ descriptor
125
+ };
126
+ }
127
+ console.log(`
125
128
  ==================================================
126
129
  Starting task download!
127
130
  Creating: ${taskName}
@@ -129,25 +132,26 @@ exports.download = (0, task_1.createTask)(schema, boundaries, async function ({
129
132
  Into: ${taskPath}
130
133
  ==================================================
131
134
  `);
132
- console.log('Writing task file:', taskPath, fileName);
133
- console.log('Handler:', response.handler);
134
- console.log('Source code:', response.sourceCode);
135
- // Persist task with cwd
136
- await persistTask(taskPath, fileName, response.sourceCode, cwd);
137
- // Update forge.json with the new task
138
- if (forge.tasks === undefined) {
139
- forge.tasks = {};
135
+ console.log('Writing task file:', taskPath, fileName);
136
+ console.log('Handler:', response.handler);
137
+ console.log('Source code:', response.sourceCode);
138
+ // Persist task with cwd
139
+ await persistTask(taskPath, fileName, response.sourceCode, cwd);
140
+ // Update forge.json with the new task
141
+ if (forge.tasks === undefined) {
142
+ forge.tasks = {};
143
+ }
144
+ forge.tasks[descriptor] = {
145
+ path: `${taskPath}/${fileName}`,
146
+ handler: response.handler
147
+ };
148
+ console.log('Forge:', forge);
149
+ await persistConf(forge, cwd);
150
+ return {
151
+ taskPath,
152
+ fileName,
153
+ descriptor,
154
+ handler: response.handler
155
+ };
140
156
  }
141
- forge.tasks[descriptor] = {
142
- path: `${taskPath}/${fileName}`,
143
- handler: response.handler
144
- };
145
- console.log('Forge:', forge);
146
- await persistConf(forge, cwd);
147
- return {
148
- taskPath,
149
- fileName,
150
- descriptor,
151
- handler: response.handler
152
- };
153
157
  });
@@ -0,0 +1,26 @@
1
+ import { TaskFingerprintOutput } from '../../utils/taskAnalysis';
2
+ export declare const fingerprint: import("@forgehive/task").TaskInstanceType<(argv: {
3
+ descriptorName: string;
4
+ }, boundaries: import("@forgehive/task").WrappedBoundaries<{
5
+ getCwd: () => Promise<string>;
6
+ loadConf: (args: {}) => Promise<Promise<import("../types").ForgeConf>>;
7
+ readFile: (filePath: string) => Promise<string>;
8
+ writeFile: (filePath: string, content: string) => Promise<void>;
9
+ ensureForgeFolder: () => Promise<string>;
10
+ }>) => Promise<{
11
+ taskName: string;
12
+ fingerprint: TaskFingerprintOutput;
13
+ fingerprintFile: string;
14
+ analysis: {
15
+ inputSchemaProps: string[];
16
+ boundaryCount: number;
17
+ hasDescription: boolean;
18
+ outputType: string;
19
+ };
20
+ }>, {
21
+ getCwd: () => Promise<string>;
22
+ loadConf: (args: {}) => Promise<Promise<import("../types").ForgeConf>>;
23
+ readFile: (filePath: string) => Promise<string>;
24
+ writeFile: (filePath: string, content: string) => Promise<void>;
25
+ ensureForgeFolder: () => Promise<string>;
26
+ }>;
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ // TASK: fingerprint
3
+ // Run this task with:
4
+ // forge task:run task:fingerprint --descriptorName task-name
5
+ var __importDefault = (this && this.__importDefault) || function (mod) {
6
+ return (mod && mod.__esModule) ? mod : { "default": mod };
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.fingerprint = void 0;
10
+ const task_1 = require("@forgehive/task");
11
+ const schema_1 = require("@forgehive/schema");
12
+ const promises_1 = __importDefault(require("fs/promises"));
13
+ const path_1 = __importDefault(require("path"));
14
+ const os_1 = __importDefault(require("os"));
15
+ const load_1 = require("../conf/load");
16
+ const taskAnalysis_1 = require("../../utils/taskAnalysis");
17
+ const description = 'Analyze a specific task and generate detailed fingerprint without bundling';
18
+ const schema = new schema_1.Schema({
19
+ descriptorName: schema_1.Schema.string()
20
+ });
21
+ const boundaries = {
22
+ getCwd: async () => {
23
+ return process.cwd();
24
+ },
25
+ loadConf: load_1.load.asBoundary(),
26
+ readFile: async (filePath) => {
27
+ return promises_1.default.readFile(filePath, 'utf-8');
28
+ },
29
+ writeFile: async (filePath, content) => {
30
+ return promises_1.default.writeFile(filePath, content);
31
+ },
32
+ ensureForgeFolder: async () => {
33
+ const forgePath = path_1.default.join(os_1.default.homedir(), '.forge');
34
+ try {
35
+ await promises_1.default.access(forgePath);
36
+ }
37
+ catch {
38
+ await promises_1.default.mkdir(forgePath, { recursive: true });
39
+ }
40
+ return forgePath;
41
+ }
42
+ };
43
+ exports.fingerprint = (0, task_1.createTask)({
44
+ schema,
45
+ boundaries,
46
+ fn: async function ({ descriptorName }, { getCwd, loadConf, readFile, writeFile, ensureForgeFolder }) {
47
+ const cwd = await getCwd();
48
+ const forgeJson = await loadConf({});
49
+ const taskDescriptor = forgeJson.tasks[descriptorName];
50
+ if (taskDescriptor === undefined) {
51
+ throw new Error(`Task "${descriptorName}" is not defined in forge.json`);
52
+ }
53
+ const filePath = path_1.default.join(cwd, taskDescriptor.path);
54
+ const forgePath = await ensureForgeFolder();
55
+ const fingerprintFile = path_1.default.join(forgePath, `${descriptorName}.task-fingerprint.json`);
56
+ console.log(`Analyzing task: ${descriptorName}`);
57
+ console.log(`Task file: ${filePath}`);
58
+ // Read and analyze the task file using the utility function
59
+ const sourceCode = await readFile(filePath);
60
+ const taskFingerprint = (0, taskAnalysis_1.analyzeTaskFile)(sourceCode, filePath);
61
+ if (!taskFingerprint) {
62
+ throw new Error('Could not extract fingerprint from task file: ' + filePath);
63
+ }
64
+ // Create analysis result - clean output without extra fields
65
+ const analysis = {
66
+ taskFingerprint
67
+ };
68
+ // Write fingerprint to file
69
+ await writeFile(fingerprintFile, JSON.stringify(analysis, null, 2));
70
+ console.log('Task fingerprint generated successfully');
71
+ console.log(`Input properties: ${Object.keys(taskFingerprint.inputSchema.properties).join(', ')}`);
72
+ console.log(`Boundaries: ${taskFingerprint.boundaries.join(', ')}`);
73
+ console.log(`Fingerprint saved to: ${fingerprintFile}`);
74
+ return {
75
+ taskName: descriptorName,
76
+ fingerprint: taskFingerprint,
77
+ fingerprintFile,
78
+ analysis: {
79
+ inputSchemaProps: Object.keys(taskFingerprint.inputSchema.properties),
80
+ boundaryCount: taskFingerprint.boundaries.length,
81
+ hasDescription: !!taskFingerprint.description,
82
+ outputType: taskFingerprint.outputType.type
83
+ }
84
+ };
85
+ }
86
+ });
87
+ exports.fingerprint.setDescription(description);
@@ -14,29 +14,33 @@ const schema = new schema_1.Schema({
14
14
  const boundaries = {
15
15
  loadConf: load_1.load.asBoundary()
16
16
  };
17
- exports.list = (0, task_1.createTask)(schema, boundaries, async function (argv, { loadConf }) {
18
- // Load forge configuration
19
- const forge = await loadConf({});
20
- console.log('Available tasks:');
21
- console.log('===============================================');
22
- const tasks = forge.tasks;
23
- const taskNames = Object.keys(tasks).sort();
24
- if (taskNames.length === 0) {
25
- console.log('No tasks found in forge.json');
26
- return { taskCount: 0, tasks: [] };
17
+ exports.list = (0, task_1.createTask)({
18
+ schema,
19
+ boundaries,
20
+ fn: async function (argv, { loadConf }) {
21
+ // Load forge configuration
22
+ const forge = await loadConf({});
23
+ console.log('Available tasks:');
24
+ console.log('===============================================');
25
+ const tasks = forge.tasks;
26
+ const taskNames = Object.keys(tasks).sort();
27
+ if (taskNames.length === 0) {
28
+ console.log('No tasks found in forge.json');
29
+ return { taskCount: 0, tasks: [] };
30
+ }
31
+ // Find the longest task name for alignment
32
+ const maxNameLength = Math.max(...taskNames.map(name => name.length));
33
+ taskNames.forEach((taskName) => {
34
+ const task = tasks[taskName];
35
+ const paddedName = taskName.padEnd(maxNameLength + 1);
36
+ console.log(`• ${paddedName} - ${task.path}`);
37
+ });
38
+ console.log('===============================================');
39
+ console.log('Total tasks: ', taskNames.length);
40
+ console.log('===============================================');
41
+ return {
42
+ taskCount: taskNames.length
43
+ };
27
44
  }
28
- // Find the longest task name for alignment
29
- const maxNameLength = Math.max(...taskNames.map(name => name.length));
30
- taskNames.forEach((taskName) => {
31
- const task = tasks[taskName];
32
- const paddedName = taskName.padEnd(maxNameLength + 1);
33
- console.log(`• ${paddedName} - ${task.path}`);
34
- });
35
- console.log('===============================================');
36
- console.log('Total tasks: ', taskNames.length);
37
- console.log('===============================================');
38
- return {
39
- taskCount: taskNames.length
40
- };
41
45
  });
42
46
  exports.list.setDescription(description);
@@ -77,74 +77,78 @@ const boundaries = {
77
77
  return buildsPath;
78
78
  }
79
79
  };
80
- exports.publish = (0, task_1.createTask)(schema, boundaries, async function ({ descriptorName }, { getCwd, ensureBuildsFolder, loadConf, bundleCreate, bundleLoad, bundleZip, readFileUtf8, readFileBinary, publishTask, loadCurrentProfile, uploadBundleWithPresignedUrl }) {
81
- const cwd = await getCwd();
82
- const forgeJson = await loadConf({});
83
- const profile = await loadCurrentProfile({});
84
- const taskDescriptor = forgeJson.tasks[descriptorName];
85
- const projectName = forgeJson.project.name;
86
- if (taskDescriptor === undefined) {
87
- throw new Error('Task is not defined on forge.json');
88
- }
89
- const entryPoint = path_1.default.join(cwd, taskDescriptor.path);
90
- const buildsPath = await ensureBuildsFolder();
91
- const outputFile = path_1.default.join(buildsPath, `${descriptorName}.js`);
92
- const zipFile = `${descriptorName}.zip`;
93
- // Bundle the task
94
- await bundleCreate({
95
- entryPoint,
96
- outputFile
97
- });
98
- console.log('Bundle created...');
99
- // Zip the bundle
100
- await bundleZip({
101
- dir: buildsPath,
102
- input: `${descriptorName}.js`,
103
- output: zipFile
104
- });
105
- console.log('Bundle zipped...');
106
- // Load the bundled task
107
- const bundle = await bundleLoad({
108
- bundlePath: outputFile
109
- });
110
- // Get the task handler
111
- const task = bundle[taskDescriptor.handler];
112
- const description = task.getDescription() ?? '';
113
- const schema = task.getSchema() || new schema_1.Schema({});
114
- const boundaries = Object.keys(task.getBoundaries()) || [];
115
- const schemaDescriptor = schema.describe();
116
- // Read the task file content
117
- const sourceCode = await readFileUtf8(entryPoint);
118
- // Read the zipped bundle instead of the raw bundle
119
- const zipPath = path_1.default.join(buildsPath, zipFile);
120
- const bundleContent = await readFileBinary(zipPath);
121
- // Get bundle size
122
- const bundleSize = bundleContent.length;
123
- // First, publish task metadata and get presigned URL for bundle upload
124
- const data = {
125
- ...taskDescriptor,
126
- taskName: descriptorName,
127
- handler: taskDescriptor.handler,
128
- projectName,
129
- description,
130
- schemaDescriptor: JSON.stringify(schemaDescriptor),
131
- boundaries,
132
- sourceCode,
133
- bundleSize
134
- };
135
- // Publish metadata to hive api server
136
- console.log(`Publishing metadata and source code to ${profile.url}...`);
137
- const publishResponse = await publishTask(data, profile);
138
- // Upload zipped bundle using the presigned URL
139
- if (publishResponse.bundleUploadUrl) {
140
- console.log('Uploading zipped bundle...');
141
- await uploadBundleWithPresignedUrl(publishResponse.bundleUploadUrl, bundleContent);
142
- return {
143
- descriptor: taskDescriptor,
144
- publish: true
80
+ exports.publish = (0, task_1.createTask)({
81
+ schema,
82
+ boundaries,
83
+ fn: async function ({ descriptorName }, { getCwd, ensureBuildsFolder, loadConf, bundleCreate, bundleLoad, bundleZip, readFileUtf8, readFileBinary, publishTask, loadCurrentProfile, uploadBundleWithPresignedUrl }) {
84
+ const cwd = await getCwd();
85
+ const forgeJson = await loadConf({});
86
+ const profile = await loadCurrentProfile({});
87
+ const taskDescriptor = forgeJson.tasks[descriptorName];
88
+ const projectName = forgeJson.project.name;
89
+ if (taskDescriptor === undefined) {
90
+ throw new Error('Task is not defined on forge.json');
91
+ }
92
+ const entryPoint = path_1.default.join(cwd, taskDescriptor.path);
93
+ const buildsPath = await ensureBuildsFolder();
94
+ const outputFile = path_1.default.join(buildsPath, `${descriptorName}.js`);
95
+ const zipFile = `${descriptorName}.zip`;
96
+ // Bundle the task
97
+ await bundleCreate({
98
+ entryPoint,
99
+ outputFile
100
+ });
101
+ console.log('Bundle created...');
102
+ // Zip the bundle
103
+ await bundleZip({
104
+ dir: buildsPath,
105
+ input: `${descriptorName}.js`,
106
+ output: zipFile
107
+ });
108
+ console.log('Bundle zipped...');
109
+ // Load the bundled task
110
+ const bundle = await bundleLoad({
111
+ bundlePath: outputFile
112
+ });
113
+ // Get the task handler
114
+ const task = bundle[taskDescriptor.handler];
115
+ const description = task.getDescription() ?? '';
116
+ const schema = task.getSchema() || new schema_1.Schema({});
117
+ const boundaries = Object.keys(task.getBoundaries()) || [];
118
+ const schemaDescriptor = schema.describe();
119
+ // Read the task file content
120
+ const sourceCode = await readFileUtf8(entryPoint);
121
+ // Read the zipped bundle instead of the raw bundle
122
+ const zipPath = path_1.default.join(buildsPath, zipFile);
123
+ const bundleContent = await readFileBinary(zipPath);
124
+ // Get bundle size
125
+ const bundleSize = bundleContent.length;
126
+ // First, publish task metadata and get presigned URL for bundle upload
127
+ const data = {
128
+ ...taskDescriptor,
129
+ taskName: descriptorName,
130
+ handler: taskDescriptor.handler,
131
+ projectName,
132
+ description,
133
+ schemaDescriptor: JSON.stringify(schemaDescriptor),
134
+ boundaries,
135
+ sourceCode,
136
+ bundleSize
145
137
  };
146
- }
147
- else {
148
- throw new Error('Bundle upload failed');
138
+ // Publish metadata to hive api server
139
+ console.log(`Publishing metadata and source code to ${profile.url}...`);
140
+ const publishResponse = await publishTask(data, profile);
141
+ // Upload zipped bundle using the presigned URL
142
+ if (publishResponse.bundleUploadUrl) {
143
+ console.log('Uploading zipped bundle...');
144
+ await uploadBundleWithPresignedUrl(publishResponse.bundleUploadUrl, bundleContent);
145
+ return {
146
+ descriptor: taskDescriptor,
147
+ publish: true
148
+ };
149
+ }
150
+ else {
151
+ throw new Error('Bundle upload failed');
152
+ }
149
153
  }
150
154
  });