@forgehive/forge-cli 0.2.14 → 0.3.0
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 +3 -1
- package/dist/tasks/auth/add.js +23 -19
- package/dist/tasks/auth/list.js +20 -16
- package/dist/tasks/auth/load.js +19 -15
- package/dist/tasks/auth/loadCurrent.js +13 -9
- package/dist/tasks/auth/remove.js +30 -26
- package/dist/tasks/auth/switch.js +19 -15
- package/dist/tasks/bundle/create.js +16 -12
- package/dist/tasks/bundle/fingerprint.d.ts +36 -0
- package/dist/tasks/bundle/fingerprint.js +164 -0
- package/dist/tasks/bundle/load.js +9 -5
- package/dist/tasks/bundle/zip.js +49 -45
- package/dist/tasks/conf/info.js +23 -19
- package/dist/tasks/conf/load.js +8 -4
- package/dist/tasks/fixture/download.js +40 -36
- package/dist/tasks/init.js +35 -31
- package/dist/tasks/runner/bundle.js +34 -30
- package/dist/tasks/runner/create.js +28 -24
- package/dist/tasks/runner/remove.js +22 -18
- package/dist/tasks/task/createTask.js +35 -28
- package/dist/tasks/task/describe.js +85 -81
- package/dist/tasks/task/download.js +63 -59
- package/dist/tasks/task/fingerprint.d.ts +26 -0
- package/dist/tasks/task/fingerprint.js +87 -0
- package/dist/tasks/task/list.js +27 -23
- package/dist/tasks/task/publish.js +72 -68
- package/dist/tasks/task/remove.js +24 -20
- package/dist/tasks/task/replay.js +94 -90
- package/dist/tasks/task/run.js +84 -79
- package/dist/test/tasks/create.test.js +6 -5
- package/dist/utils/taskAnalysis.d.ts +21 -0
- package/dist/utils/taskAnalysis.js +380 -0
- package/forge.json +12 -0
- package/logs/task:fingerprint.log +10 -0
- package/package.json +7 -7
- package/specs/fingerprint.md +380 -0
- package/src/runner.ts +3 -1
- package/src/tasks/README.md +13 -13
- package/src/tasks/auth/add.ts +3 -3
- package/src/tasks/auth/list.ts +3 -3
- package/src/tasks/auth/load.ts +3 -3
- package/src/tasks/auth/loadCurrent.ts +3 -3
- package/src/tasks/auth/remove.ts +3 -3
- package/src/tasks/auth/switch.ts +3 -3
- package/src/tasks/bundle/README.md +7 -7
- package/src/tasks/bundle/create.ts +4 -4
- package/src/tasks/bundle/fingerprint.ts +218 -0
- package/src/tasks/bundle/load.ts +4 -4
- package/src/tasks/bundle/zip.ts +3 -3
- package/src/tasks/conf/info.ts +3 -3
- package/src/tasks/conf/load.ts +3 -3
- package/src/tasks/fixture/download.ts +3 -3
- package/src/tasks/init.ts +3 -3
- package/src/tasks/runner/bundle.ts +3 -3
- package/src/tasks/runner/create.ts +3 -3
- package/src/tasks/runner/remove.ts +3 -3
- package/src/tasks/task/createTask.ts +10 -7
- package/src/tasks/task/describe.ts +3 -3
- package/src/tasks/task/download.ts +3 -3
- package/src/tasks/task/fingerprint.ts +107 -0
- package/src/tasks/task/list.ts +3 -3
- package/src/tasks/task/publish.ts +3 -3
- package/src/tasks/task/remove.ts +3 -3
- package/src/tasks/task/replay.ts +3 -3
- package/src/tasks/task/run.ts +5 -4
- package/src/test/tasks/create.test.ts +9 -9
- 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)(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
|
|
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
|
-
|
|
95
|
-
console.log('
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
|
-
|
|
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)(
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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
|
|
100
|
+
error: 'Task already exists',
|
|
113
101
|
taskPath: `${taskPath}/${fileName}`,
|
|
114
102
|
descriptor
|
|
115
103
|
};
|
|
116
104
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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);
|
package/dist/tasks/task/list.js
CHANGED
|
@@ -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)(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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)(
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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
|
-
|
|
148
|
-
|
|
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
|
});
|