@fnet/cli 0.115.0 → 0.116.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.
- package/dist/fnet/index.BZuqvTVt.js +1 -0
- package/dist/fnet/index.js +1 -1
- package/dist/fnode/index.B_0ZxySP.js +1 -0
- package/dist/fnode/{index.CoRsFBwp.js → index.D3C-8oZW.js} +1 -1
- package/dist/fnode/index.D4sPJLOP.js +1 -0
- package/dist/fnode/{index.Brxbka97.js → index.DMkgR1Dh.js} +1 -1
- package/dist/fnode/index.js +1 -1
- package/package.json +2 -1
- package/template/fnet/node/package.json.njk +1 -0
- package/template/fnet/node/src/cli/index.js.njk +308 -199
- package/template/fnode/node/package.json.njk +10 -1
- package/template/fnode/node/src/cli/index.js.njk +191 -320
- package/dist/fnet/index.PNP2oTpU.js +0 -1
- package/dist/fnode/index.6_yfJqit.js +0 -1
- package/dist/fnode/index.Dg0hAD29.js +0 -1
|
@@ -1,44 +1,58 @@
|
|
|
1
1
|
{% if atom.doc.features.cli.enabled===true %}
|
|
2
2
|
|
|
3
|
-
{
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
{
|
|
8
|
-
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
{%
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
{
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
{%
|
|
19
|
-
|
|
20
|
-
const run = async () => {
|
|
21
|
-
const args = await argv();
|
|
22
|
-
const cliMode = args['cli-mode'] || args.cli_mode || 'default';
|
|
23
|
-
|
|
24
|
-
if (cliMode === 'default') {
|
|
25
|
-
// Default mode code
|
|
26
|
-
return await Node(args);
|
|
27
|
-
}
|
|
3
|
+
{# Define macros for reusable code blocks #}
|
|
4
|
+
{% macro importMcpDependencies(format) %}
|
|
5
|
+
{% if format === 'esm' %}
|
|
6
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
7
|
+
import { ListToolsRequestSchema, CallToolRequestSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
8
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
9
|
+
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
10
|
+
import express from "express";
|
|
11
|
+
{% else %}
|
|
12
|
+
const { Server } = require("@modelcontextprotocol/sdk/server/index.js");
|
|
13
|
+
const { ListToolsRequestSchema, CallToolRequestSchema } = require("@modelcontextprotocol/sdk/types.js");
|
|
14
|
+
const { StdioServerTransport } = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
15
|
+
const { StreamableHTTPServerTransport } = require("@modelcontextprotocol/sdk/server/streamableHttp.js");
|
|
16
|
+
const express = require("express");
|
|
17
|
+
{% endif %}
|
|
18
|
+
{% endmacro %}
|
|
28
19
|
|
|
29
|
-
|
|
20
|
+
{% macro mcpModeCode(nodeFn) %}
|
|
30
21
|
if (cliMode === 'mcp') {
|
|
31
22
|
// MCP mode code
|
|
32
|
-
const server = new
|
|
33
|
-
name: "{{atom.doc.name}}",
|
|
34
|
-
version: "{{atom.doc.version}}"
|
|
23
|
+
const server = new Server({
|
|
24
|
+
name: "{{atom.doc.features.cli.mcp.name or atom.doc.name}}",
|
|
25
|
+
version: "{{atom.doc.version or '0.0.1'}}"
|
|
26
|
+
}, {
|
|
27
|
+
capabilities: {
|
|
28
|
+
tools: {}
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// Define available tools
|
|
33
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
34
|
+
return {
|
|
35
|
+
tools: [{
|
|
36
|
+
name: "{{atom.doc.features.cli.mcp.tool.name or atom.doc.name}}",
|
|
37
|
+
description: "{{atom.doc.features.cli.mcp.tool.description or atom.doc.description}}",
|
|
38
|
+
{% if atom.doc.input %}
|
|
39
|
+
inputSchema: {{atom.doc.input | dump | safe}}
|
|
40
|
+
{% else %}
|
|
41
|
+
inputSchema: {
|
|
42
|
+
type: "object",
|
|
43
|
+
properties: {},
|
|
44
|
+
additionalProperties: true
|
|
45
|
+
}
|
|
46
|
+
{% endif %}
|
|
47
|
+
}]
|
|
48
|
+
};
|
|
35
49
|
});
|
|
36
50
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
51
|
+
// Handle tool execution
|
|
52
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
53
|
+
if (request.params.name === "{{atom.doc.features.cli.mcp.tool.name or atom.doc.name}}") {
|
|
40
54
|
try {
|
|
41
|
-
const result = await
|
|
55
|
+
const result = await {{ nodeFn }}(request.params.arguments);
|
|
42
56
|
return {
|
|
43
57
|
content: [{
|
|
44
58
|
type: "text",
|
|
@@ -55,73 +69,129 @@ const run = async () => {
|
|
|
55
69
|
};
|
|
56
70
|
}
|
|
57
71
|
}
|
|
58
|
-
|
|
72
|
+
throw new Error("Tool not found");
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// Get transport type from arguments
|
|
76
|
+
const transportType = args['mcp-transport'] || args.mcp_transport || 'stdio';
|
|
77
|
+
let transport;
|
|
78
|
+
|
|
79
|
+
if (transportType === 'stdio') {
|
|
80
|
+
// Use stdio transport
|
|
81
|
+
transport = new StdioServerTransport();
|
|
82
|
+
} else if (transportType === 'sse') {
|
|
83
|
+
// Use SSE transport
|
|
84
|
+
const app = express();
|
|
85
|
+
app.use(express.json());
|
|
86
|
+
|
|
87
|
+
const port = args['cli-port'] || args.cli_port || 3000;
|
|
88
|
+
const server = app.listen(port, () => {
|
|
89
|
+
console.log(`MCP server started with SSE transport on port ${port}`);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
transport = new StreamableHTTPServerTransport({
|
|
93
|
+
sessionIdGenerator: () => Math.random().toString(36).substring(2, 15),
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
app.post('/sse', async (req, res) => {
|
|
97
|
+
await transport.handleRequest(req, res, req.body);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
app.get('/sse', async (req, res) => {
|
|
101
|
+
await transport.handleRequest(req, res);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
app.delete('/sse', async (req, res) => {
|
|
105
|
+
await transport.handleRequest(req, res);
|
|
106
|
+
});
|
|
107
|
+
} else {
|
|
108
|
+
console.error(`Unknown MCP transport type: ${transportType}`);
|
|
109
|
+
console.error(`Supported types: stdio, sse`);
|
|
110
|
+
process.exit(1);
|
|
111
|
+
}
|
|
59
112
|
|
|
60
|
-
const transport = new StdioServerTransport();
|
|
61
113
|
await server.connect(transport);
|
|
62
|
-
console.log("MCP server started with stdio transport");
|
|
63
114
|
return;
|
|
64
115
|
}
|
|
65
|
-
|
|
116
|
+
{% endmacro %}
|
|
66
117
|
|
|
67
|
-
|
|
118
|
+
{% macro httpModeCodeExpress(nodeFn) %}
|
|
68
119
|
if (cliMode === 'http') {
|
|
69
|
-
// HTTP mode code
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
try {
|
|
80
|
-
const data = JSON.parse(body);
|
|
81
|
-
const result = await Node(data);
|
|
82
|
-
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
83
|
-
res.end(JSON.stringify(result));
|
|
84
|
-
} catch (error) {
|
|
85
|
-
res.writeHead(500, { 'Content-Type': 'application/json' });
|
|
86
|
-
res.end(JSON.stringify({ error: error.message }));
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
} else {
|
|
90
|
-
res.writeHead(404);
|
|
91
|
-
res.end();
|
|
120
|
+
// HTTP mode code
|
|
121
|
+
const app = express();
|
|
122
|
+
app.use(express.json());
|
|
123
|
+
|
|
124
|
+
app.post('/{{atom.doc.features.cli.http.path or atom.doc.name}}', async (req, res) => {
|
|
125
|
+
try {
|
|
126
|
+
const result = await {{ nodeFn }}(req.body);
|
|
127
|
+
res.json(result);
|
|
128
|
+
} catch (error) {
|
|
129
|
+
res.status(500).json({ error: error.message });
|
|
92
130
|
}
|
|
93
131
|
});
|
|
94
132
|
|
|
95
133
|
const port = args['cli-port'] || args.cli_port || 3000;
|
|
96
|
-
|
|
134
|
+
app.listen(port, () => {
|
|
97
135
|
console.log(`HTTP server started on port ${port}`);
|
|
98
136
|
});
|
|
99
137
|
return;
|
|
100
138
|
}
|
|
101
|
-
|
|
139
|
+
{% endmacro %}
|
|
102
140
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
141
|
+
{% macro defaultModeExtend(nodeFn) %}
|
|
142
|
+
if (cliMode === 'default') {
|
|
143
|
+
// Default mode code
|
|
144
|
+
return await {{ nodeFn }}(args);
|
|
145
|
+
}
|
|
146
|
+
{% endmacro %}
|
|
147
|
+
|
|
148
|
+
{% macro defaultModeStandard(nodeFn) %}
|
|
149
|
+
if (cliMode === 'default') {
|
|
150
|
+
// Default mode code
|
|
151
|
+
const result = await {{ nodeFn }}(args);
|
|
152
|
+
|
|
153
|
+
if (typeof result !== 'undefined') {
|
|
154
|
+
const stdout_format = args['stdout-format'] || args.stdout_format || null;
|
|
155
|
+
|
|
156
|
+
if (stdout_format === 'json') console.log(JSON.stringify(result, null, 2));
|
|
157
|
+
else console.log(result);
|
|
158
|
+
}
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
{% endmacro %}
|
|
162
|
+
|
|
163
|
+
{% macro runWithCatch() %}
|
|
164
|
+
run()
|
|
165
|
+
.catch((error) => {
|
|
166
|
+
console.error(error.message);
|
|
167
|
+
process.exit(1);
|
|
168
|
+
});
|
|
169
|
+
{% endmacro %}
|
|
106
170
|
|
|
171
|
+
{% macro runWithThenCatch() %}
|
|
107
172
|
run()
|
|
108
173
|
.then(() => {
|
|
109
|
-
{# process.exit(0);
|
|
174
|
+
{# process.exit(0); #}
|
|
110
175
|
})
|
|
111
176
|
.catch((error) => {
|
|
112
177
|
console.error(error.message);
|
|
113
178
|
process.exit(1);
|
|
114
179
|
});
|
|
180
|
+
{% endmacro %}
|
|
115
181
|
|
|
116
|
-
{
|
|
117
|
-
|
|
182
|
+
{# Main template starts here #}
|
|
183
|
+
{% if atom.doc.features.project.format==='esm' %}
|
|
118
184
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
185
|
+
import argv from '../default/input.args.js';
|
|
186
|
+
|
|
187
|
+
{% if atom.doc.features.cli.extend===true %}
|
|
188
|
+
|
|
189
|
+
import Node from '../../../cli';
|
|
123
190
|
|
|
124
|
-
{% if atom.doc.features.cli.
|
|
191
|
+
{% if atom.doc.features.cli.mcp.enabled===true %}
|
|
192
|
+
{{ importMcpDependencies('esm') }}
|
|
193
|
+
{% elif atom.doc.features.cli.http.enabled===true %}
|
|
194
|
+
// Using express for HTTP mode
|
|
125
195
|
import express from 'express';
|
|
126
196
|
{% endif %}
|
|
127
197
|
|
|
@@ -129,89 +199,51 @@ const run = async () => {
|
|
|
129
199
|
const args = await argv();
|
|
130
200
|
const cliMode = args['cli-mode'] || args.cli_mode || 'default';
|
|
131
201
|
|
|
132
|
-
|
|
133
|
-
// Default mode code
|
|
134
|
-
const result = await Node(args);
|
|
202
|
+
{{ defaultModeExtend('Node') }}
|
|
135
203
|
|
|
136
|
-
|
|
137
|
-
|
|
204
|
+
{% if atom.doc.features.cli.mcp.enabled===true %}
|
|
205
|
+
{{ mcpModeCode('Node') }}
|
|
206
|
+
{% endif %}
|
|
138
207
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
208
|
+
{% if atom.doc.features.cli.http.enabled===true %}
|
|
209
|
+
{{ httpModeCodeBuiltIn('Node') }}
|
|
210
|
+
{% endif %}
|
|
144
211
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
const server = new McpServer({
|
|
149
|
-
name: "{{atom.doc.name}}",
|
|
150
|
-
version: "{{atom.doc.version}}"
|
|
151
|
-
});
|
|
212
|
+
console.error(`Unknown CLI mode: ${cliMode}`);
|
|
213
|
+
process.exit(1);
|
|
214
|
+
};
|
|
152
215
|
|
|
153
|
-
|
|
154
|
-
"{{atom.doc.name}}",
|
|
155
|
-
async (toolArgs) => {
|
|
156
|
-
try {
|
|
157
|
-
const result = await Node(toolArgs);
|
|
158
|
-
return {
|
|
159
|
-
content: [{
|
|
160
|
-
type: "text",
|
|
161
|
-
text: JSON.stringify(result)
|
|
162
|
-
}]
|
|
163
|
-
};
|
|
164
|
-
} catch (error) {
|
|
165
|
-
return {
|
|
166
|
-
content: [{
|
|
167
|
-
type: "text",
|
|
168
|
-
text: `Error: ${error.message}`
|
|
169
|
-
}],
|
|
170
|
-
isError: true
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
);
|
|
216
|
+
{{ runWithThenCatch() }}
|
|
175
217
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
console.log("MCP server started with stdio transport");
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
{% endif %}
|
|
218
|
+
{% else %}
|
|
219
|
+
import Node from '../../../src';
|
|
182
220
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
221
|
+
{% if atom.doc.features.cli.mcp.enabled===true %}
|
|
222
|
+
{{ importMcpDependencies('esm') }}
|
|
223
|
+
{% elif atom.doc.features.cli.http.enabled===true %}
|
|
224
|
+
// Using express for HTTP mode
|
|
225
|
+
import express from 'express';
|
|
226
|
+
{% endif %}
|
|
188
227
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
res.json(result);
|
|
193
|
-
} catch (error) {
|
|
194
|
-
res.status(500).json({ error: error.message });
|
|
195
|
-
}
|
|
196
|
-
});
|
|
228
|
+
const run = async () => {
|
|
229
|
+
const args = await argv();
|
|
230
|
+
const cliMode = args['cli-mode'] || args.cli_mode || 'default';
|
|
197
231
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
232
|
+
{{ defaultModeStandard('Node') }}
|
|
233
|
+
|
|
234
|
+
{% if atom.doc.features.cli.mcp.enabled===true %}
|
|
235
|
+
{{ mcpModeCode('Node') }}
|
|
236
|
+
{% endif %}
|
|
237
|
+
|
|
238
|
+
{% if atom.doc.features.cli.http.enabled===true %}
|
|
239
|
+
{{ httpModeCodeExpress('Node') }}
|
|
204
240
|
{% endif %}
|
|
205
241
|
|
|
206
242
|
console.error(`Unknown CLI mode: ${cliMode}`);
|
|
207
243
|
process.exit(1);
|
|
208
244
|
};
|
|
209
245
|
|
|
210
|
-
|
|
211
|
-
.catch((error) => {
|
|
212
|
-
console.error(error.message);
|
|
213
|
-
process.exit(1);
|
|
214
|
-
});
|
|
246
|
+
{{ runWithCatch() }}
|
|
215
247
|
{% endif %}
|
|
216
248
|
|
|
217
249
|
{% elif atom.doc.features.project.format==='cjs' %}
|
|
@@ -223,222 +255,61 @@ const argv = require('../default/input.args.js');
|
|
|
223
255
|
const Node = require('../../../cli');
|
|
224
256
|
|
|
225
257
|
{% if atom.doc.features.cli.mcp.enabled===true %}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
{% if atom.doc.features.cli.http.enabled===true %}
|
|
231
|
-
// Using Node.js built-in http module instead of express
|
|
258
|
+
{{ importMcpDependencies('cjs') }}
|
|
259
|
+
{% elif atom.doc.features.cli.http.enabled===true %}
|
|
260
|
+
// Using express for HTTP mode
|
|
261
|
+
const express = require('express');
|
|
232
262
|
{% endif %}
|
|
233
263
|
|
|
234
264
|
const run = async () => {
|
|
235
265
|
const args = await argv();
|
|
236
266
|
const cliMode = args['cli-mode'] || args.cli_mode || 'default';
|
|
237
267
|
|
|
238
|
-
|
|
239
|
-
// Default mode code
|
|
240
|
-
return await Node(args);
|
|
241
|
-
}
|
|
268
|
+
{{ defaultModeExtend('Node') }}
|
|
242
269
|
|
|
243
270
|
{% if atom.doc.features.cli.mcp.enabled===true %}
|
|
244
|
-
|
|
245
|
-
// MCP mode code
|
|
246
|
-
const server = new McpServer({
|
|
247
|
-
name: "{{atom.doc.name}}",
|
|
248
|
-
version: "{{atom.doc.version}}"
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
server.tool(
|
|
252
|
-
"{{atom.doc.name}}",
|
|
253
|
-
async (toolArgs) => {
|
|
254
|
-
try {
|
|
255
|
-
const result = await Node(toolArgs);
|
|
256
|
-
return {
|
|
257
|
-
content: [{
|
|
258
|
-
type: "text",
|
|
259
|
-
text: JSON.stringify(result)
|
|
260
|
-
}]
|
|
261
|
-
};
|
|
262
|
-
} catch (error) {
|
|
263
|
-
return {
|
|
264
|
-
content: [{
|
|
265
|
-
type: "text",
|
|
266
|
-
text: `Error: ${error.message}`
|
|
267
|
-
}],
|
|
268
|
-
isError: true
|
|
269
|
-
};
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
);
|
|
273
|
-
|
|
274
|
-
const transport = new StdioServerTransport();
|
|
275
|
-
await server.connect(transport);
|
|
276
|
-
console.log("MCP server started with stdio transport");
|
|
277
|
-
return;
|
|
278
|
-
}
|
|
271
|
+
{{ mcpModeCode('Node') }}
|
|
279
272
|
{% endif %}
|
|
280
273
|
|
|
281
274
|
{% if atom.doc.features.cli.http.enabled===true %}
|
|
282
|
-
|
|
283
|
-
// HTTP mode code using built-in http module
|
|
284
|
-
const http = require('http');
|
|
285
|
-
|
|
286
|
-
const server = http.createServer((req, res) => {
|
|
287
|
-
if (req.method === 'POST' && req.url === '/{{atom.doc.name}}') {
|
|
288
|
-
let body = '';
|
|
289
|
-
req.on('data', chunk => {
|
|
290
|
-
body += chunk.toString();
|
|
291
|
-
});
|
|
292
|
-
req.on('end', async () => {
|
|
293
|
-
try {
|
|
294
|
-
const data = JSON.parse(body);
|
|
295
|
-
const result = await Node(data);
|
|
296
|
-
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
297
|
-
res.end(JSON.stringify(result));
|
|
298
|
-
} catch (error) {
|
|
299
|
-
res.writeHead(500, { 'Content-Type': 'application/json' });
|
|
300
|
-
res.end(JSON.stringify({ error: error.message }));
|
|
301
|
-
}
|
|
302
|
-
});
|
|
303
|
-
} else {
|
|
304
|
-
res.writeHead(404);
|
|
305
|
-
res.end();
|
|
306
|
-
}
|
|
307
|
-
});
|
|
308
|
-
|
|
309
|
-
const port = args['cli-port'] || args.cli_port || 3000;
|
|
310
|
-
server.listen(port, () => {
|
|
311
|
-
console.log(`HTTP server started on port ${port}`);
|
|
312
|
-
});
|
|
313
|
-
return;
|
|
314
|
-
}
|
|
275
|
+
{{ httpModeCodeBuiltIn('Node') }}
|
|
315
276
|
{% endif %}
|
|
316
277
|
|
|
317
278
|
console.error(`Unknown CLI mode: ${cliMode}`);
|
|
318
279
|
process.exit(1);
|
|
319
280
|
};
|
|
320
281
|
|
|
321
|
-
|
|
322
|
-
.then(() => {
|
|
323
|
-
{# process.exit(0); #}
|
|
324
|
-
})
|
|
325
|
-
.catch((error) => {
|
|
326
|
-
console.error(error.message);
|
|
327
|
-
process.exit(1);
|
|
328
|
-
});
|
|
282
|
+
{{ runWithThenCatch() }}
|
|
329
283
|
|
|
330
284
|
{% else %}
|
|
331
285
|
const Node = require('../../../src');
|
|
332
286
|
|
|
333
287
|
{% if atom.doc.features.cli.mcp.enabled===true %}
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
{% if atom.doc.features.cli.http.enabled===true %}
|
|
339
|
-
// Using Node.js built-in http module instead of express
|
|
288
|
+
{{ importMcpDependencies('cjs') }}
|
|
289
|
+
{% elif atom.doc.features.cli.http.enabled===true %}
|
|
290
|
+
// Using express for HTTP mode
|
|
291
|
+
const express = require('express');
|
|
340
292
|
{% endif %}
|
|
341
293
|
|
|
342
294
|
const run = async () => {
|
|
343
295
|
const args = await argv();
|
|
344
296
|
const cliMode = args['cli-mode'] || args.cli_mode || 'default';
|
|
345
297
|
|
|
346
|
-
|
|
347
|
-
// Default mode code
|
|
348
|
-
const result = await Node(args);
|
|
349
|
-
|
|
350
|
-
if (typeof result !== 'undefined') {
|
|
351
|
-
const stdout_format = args['stdout-format'] || args.stdout_format || null;
|
|
352
|
-
|
|
353
|
-
if (stdout_format === 'json') console.log(JSON.stringify(result, null, 2));
|
|
354
|
-
else console.log(result);
|
|
355
|
-
}
|
|
356
|
-
return;
|
|
357
|
-
}
|
|
298
|
+
{{ defaultModeStandard('Node') }}
|
|
358
299
|
|
|
359
300
|
{% if atom.doc.features.cli.mcp.enabled===true %}
|
|
360
|
-
|
|
361
|
-
// MCP mode code
|
|
362
|
-
const server = new McpServer({
|
|
363
|
-
name: "{{atom.doc.name}}",
|
|
364
|
-
version: "{{atom.doc.version}}"
|
|
365
|
-
});
|
|
366
|
-
|
|
367
|
-
server.tool(
|
|
368
|
-
"{{atom.doc.name}}",
|
|
369
|
-
async (toolArgs) => {
|
|
370
|
-
try {
|
|
371
|
-
const result = await Node(toolArgs);
|
|
372
|
-
return {
|
|
373
|
-
content: [{
|
|
374
|
-
type: "text",
|
|
375
|
-
text: JSON.stringify(result)
|
|
376
|
-
}]
|
|
377
|
-
};
|
|
378
|
-
} catch (error) {
|
|
379
|
-
return {
|
|
380
|
-
content: [{
|
|
381
|
-
type: "text",
|
|
382
|
-
text: `Error: ${error.message}`
|
|
383
|
-
}],
|
|
384
|
-
isError: true
|
|
385
|
-
};
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
);
|
|
389
|
-
|
|
390
|
-
const transport = new StdioServerTransport();
|
|
391
|
-
await server.connect(transport);
|
|
392
|
-
console.log("MCP server started with stdio transport");
|
|
393
|
-
return;
|
|
394
|
-
}
|
|
301
|
+
{{ mcpModeCode('Node') }}
|
|
395
302
|
{% endif %}
|
|
396
303
|
|
|
397
304
|
{% if atom.doc.features.cli.http.enabled===true %}
|
|
398
|
-
|
|
399
|
-
// HTTP mode code using built-in http module
|
|
400
|
-
const http = require('http');
|
|
401
|
-
|
|
402
|
-
const server = http.createServer((req, res) => {
|
|
403
|
-
if (req.method === 'POST' && req.url === '/{{atom.doc.name}}') {
|
|
404
|
-
let body = '';
|
|
405
|
-
req.on('data', chunk => {
|
|
406
|
-
body += chunk.toString();
|
|
407
|
-
});
|
|
408
|
-
req.on('end', async () => {
|
|
409
|
-
try {
|
|
410
|
-
const data = JSON.parse(body);
|
|
411
|
-
const result = await Node(data);
|
|
412
|
-
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
413
|
-
res.end(JSON.stringify(result));
|
|
414
|
-
} catch (error) {
|
|
415
|
-
res.writeHead(500, { 'Content-Type': 'application/json' });
|
|
416
|
-
res.end(JSON.stringify({ error: error.message }));
|
|
417
|
-
}
|
|
418
|
-
});
|
|
419
|
-
} else {
|
|
420
|
-
res.writeHead(404);
|
|
421
|
-
res.end();
|
|
422
|
-
}
|
|
423
|
-
});
|
|
424
|
-
|
|
425
|
-
const port = args['cli-port'] || args.cli_port || 3000;
|
|
426
|
-
server.listen(port, () => {
|
|
427
|
-
console.log(`HTTP server started on port ${port}`);
|
|
428
|
-
});
|
|
429
|
-
return;
|
|
430
|
-
}
|
|
305
|
+
{{ httpModeCodeExpress('Node') }}
|
|
431
306
|
{% endif %}
|
|
432
307
|
|
|
433
308
|
console.error(`Unknown CLI mode: ${cliMode}`);
|
|
434
309
|
process.exit(1);
|
|
435
310
|
};
|
|
436
311
|
|
|
437
|
-
|
|
438
|
-
.catch((error) => {
|
|
439
|
-
console.error(error.message);
|
|
440
|
-
process.exit(1);
|
|
441
|
-
});
|
|
312
|
+
{{ runWithCatch() }}
|
|
442
313
|
{% endif %}
|
|
443
314
|
|
|
444
315
|
{% endif %}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import e from"node:path";import t from"node:fs";import o from"@fnet/yaml";import r from"yaml";import{r as i}from"./index.js";import"node:url";import"yargs";import"chalk";import"node:util";import"tree-kill";import"node:child_process";import"@fnet/config";import"node:os";import"@flownet/lib-render-templates-dir";import"@fnet/shelljs";import"nunjucks";import"lodash.clonedeep";import"isobject";import"redis";import"@flownet/lib-is-redis-online";import"node:crypto";import"@flownet/lib-atom-api-js";import"lodash.merge";import"@flownet/lib-parse-imports-js";import"@fnet/npm-list-versions";import"@fnet/npm-pick-versions";import"object-hash";import"ajv/dist/2020.js";import"ajv/dist/standalone/index.js";import"ajv-formats";import"@flownet/lib-parse-node-url";import"bpmn-moddle";import"dagre";import"@fnet/expression";import"@fnet/list-files";import"@fnet/key-value-transformer";import"lodash.pick";import"lodash.omit";import"@fnet/prompt";import"fs";import"path";import"@fnet/shell-flow";async function n(n){if(n.id)return{id:n.id,buildId:n.buildId,mode:n.mode,protocol:n.protocol||"ac:",templateDir:i("./template/fnode/node"),projectDir:e.resolve(process.cwd(),`./.output/${n.id}`),tags:n.ftag};try{const s=await async function({tags:i}){let n=function(o){const r=e.resolve(o,"node.yaml"),i=e.resolve(o,"fnode.yaml");if(t.existsSync(i))return i;if(t.existsSync(r))try{const e=t.readFileSync(r,"utf8");return t.writeFileSync(i,e,"utf8"),t.unlinkSync(r),console.log(`Migrated node.yaml to fnode.yaml in ${o}`),i}catch(e){return console.error(`Error migrating node.yaml to fnode.yaml: ${e.message}`),r}return i}(process.cwd());if(!t.existsSync(n))throw new Error("fnode.yaml file not found in current directory.");const{raw:s,parsed:m}=await o({file:n,tags:i}),p=e.dirname(n);m.features=m.features||{};const l=m.features;l.runtime=l.runtime||{},l.runtime.type=l.runtime.type||"node","python"===l.runtime.type?l.runtime.template=l.runtime.template||"python":"bun"===l.runtime.type?l.runtime.template=l.runtime.template||"bun":l.runtime.template=l.runtime.template||"node";const a={libraryAtom:{doc:{...m},fileName:"index"},projectDir:p,projectFilePath:n,projectFileContent:s,projectFileParsed:m,runtime:l.runtime};let c=e.resolve(p,"fnet/targets.yaml");if(!t.existsSync(c)&&(c=e.resolve(p,"node.devops.yaml"),t.existsSync(c))){const o=e.resolve(p,"fnet");t.existsSync(o)||t.mkdirSync(o),t.copyFileSync(c,e.resolve(p,"fnet/targets.yaml")),t.unlinkSync(c)}if(t.existsSync(c)){const{raw:e,parsed:n}=await o({file:c,tags:i}),s=r.parseDocument(e);a.devops={filePath:c,fileContent:e,yamlDocument:s,doc:{...n},type:"library.deploy",save:async()=>{t.writeFileSync(a.devops.filePath,s.toString())}}}const d=e.resolve(p,"readme.md");if(t.existsSync(d)){const e=t.readFileSync(d,"utf8");a.readme={filePath:d,fileContent:e,doc:{content:e,"content-type":"markdown"},type:"wiki"}}return a}({tags:n.ftag});return{buildId:n.buildId,mode:n.mode,protocol:n.protocol||"local:",templateDir:i(`./template/fnode/${s.runtime.template}`),projectDir:e.resolve(s.projectDir,"./.workspace"),projectSrcDir:e.resolve(s.projectDir,"./src"),project:s,tags:n.ftag}}catch(e){return console.warn(`Warning: Could not load project: ${e.message}`),{projectDir:process.cwd(),tags:n.ftag}}}export{n as createContext};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import e from"node:path";import t from"node:fs";import o from"@fnet/yaml";import r from"yaml";import{r as i}from"./index.js";import"node:url";import"yargs";import"chalk";import"@fnet/config";import"node:util";import"tree-kill";import"node:child_process";import"node:os";import"@flownet/lib-render-templates-dir";import"@fnet/shelljs";import"@fnet/prompt";import"fs";import"path";import"@fnet/shell-flow";async function n(n){if(n.id)return{id:n.id,buildId:n.buildId,mode:n.mode,protocol:n.protocol||"ac:",templateDir:i("./template/fnet/node"),coreDir:i("./template/fnet/core"),projectDir:e.resolve(process.cwd(),`./.output/${n.id}`),tags:n.ftag};try{const s=await async function({tags:i}){let n=(s=process.cwd(),e.resolve(s,"fnet.yaml"));var s;if(!t.existsSync(n))throw new Error("fnet.yaml file not found in current directory.");const{raw:l,parsed:a}=await o({file:n,tags:i}),c=e.dirname(n);a.features=a.features||{};const p=a.features;let m;if(p.runtime=p.runtime||{},p.runtime.type=p.runtime.type||"node","object"==typeof a.flows)m=a.flows;else{let r="flow.main.yaml";t.existsSync(e.join(c,"fnet","flows.yaml"))&&(r=e.join("fnet","flows.yaml"));const n=a.main||r;let s=e.resolve(c,n);if(t.existsSync(s)){const{parsed:e}=await o({file:s,tags:i});m=e}else m={main:{steps:[]}}}const f={workflowAtom:{doc:{...a,content:m}},projectDir:c,projectFilePath:n,projectFileContent:l,projectFileParsed:a,runtime:p.runtime};let d=e.resolve(c,"fnet/targets.yaml");if(t.existsSync(d)){const{raw:e,parsed:n}=await o({file:d,tags:i}),s=r.parseDocument(e);f.devops={filePath:d,fileContent:e,yamlDocument:s,doc:{...n},type:"workflow.deploy",save:async()=>{t.writeFileSync(f.devops.filePath,s.toString())}}}const u=e.resolve(c,"readme.md");if(t.existsSync(u)){const e=t.readFileSync(u,"utf8");f.readme={filePath:u,fileContent:e,doc:{content:e,"content-type":"markdown"},type:"wiki"}}return f}({tags:n.ftag});return{buildId:n.buildId,mode:n.mode,protocol:n.protocol||"local:",templateDir:i("./template/fnet/node"),coreDir:i("./template/fnet/core"),projectDir:e.resolve(s.projectDir,"./.workspace"),projectSrcDir:e.resolve(s.projectDir,"./src"),project:s,tags:n.ftag}}catch(e){return console.warn(`Warning: Could not load project: ${e.message}`),{projectDir:process.cwd(),tags:n.ftag}}}export{n as createContext};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import e from"lodash.merge";import s from"node:fs";import t from"node:path";import a from"@flownet/lib-render-templates-dir";import n from"nunjucks";import o from"@flownet/lib-parse-imports-js";import r from"@fnet/npm-pick-versions";import c from"object-hash";import i from"ajv/dist/2020.js";import p from"ajv/dist/standalone/index.js";import l from"ajv-formats";import f from"@fnet/shelljs";import{w as d}from"./index.js";function u({feature:s,features:t,packageDevDependencies:a}){const{name:n,packages:o,options:r,extraCheck:c,explicit:i}=s,p=`${n}_enabled`,l=t.rollup_output||{},f=Object.keys(l);let d=r||{};const u=t[n]?.options;u&&(d=e(d,u));const m=!t[n]||!1===t[n]?.enabled;f.forEach((e=>{const s=t.rollup_output[e];if(s){if(Reflect.has(s,n)){if(m||!s[n]||!1===s[n]?.enabled)return void delete s[n];!0===s[n]&&(s[n]={enabled:!0,options:d})}else{if(m||i||!1===t[p])return;s[n]={enabled:!0}}s[n]=s[n]||{},s[n].options={...d,...s[n].options}}}));let g=f.some((e=>!0===t.rollup_output[e][n]?.enabled));c&&(g=c()&&g),t[p]=g,g&&o.forEach((e=>a.push({package:e[0],version:e[1]})))}function m(e){const{atom:s,packageDevDependencies:t}=e;u({feature:{name:"string",packages:[["rollup-plugin-string","^3"]]},features:s.doc.features,packageDevDependencies:t})}function g(e){const{atom:s,packageDevDependencies:t}=e;u({feature:{name:"image",packages:[["@rollup/plugin-image","^3"]]},features:s.doc.features,packageDevDependencies:t})}function k(e){const{atom:s,packageDevDependencies:t}=e;u({feature:{name:"json",packages:[["@rollup/plugin-json","^6"]]},features:s.doc.features,packageDevDependencies:t})}function j(e){const{atom:s,packageDevDependencies:t}=e,a=s.doc.features,n={};!0===a.app?.enabled&&(n.targets=n.targets||[],n.targets.push({src:"./src/app/index.html",dest:a.app.dir}),Reflect.has(a.app,"copy")||Reflect.has(a,"copy")||(a.copy=!0)),u({feature:{name:"copy",packages:[["rollup-plugin-copy","^3"],["chokidar","^3"]],options:n},features:a,packageDevDependencies:t})}function v(e){const{atom:s,packageDevDependencies:t}=e,a=s.doc.features,n=a.css&&!1!==a.css.enabled;let o=[];if(n){o.push(["rollup-plugin-postcss","^4"]),o.push(["sass","^1.66"]);(a.css?.options?.plugins||[]).forEach((e=>{switch(e.name){case"postcss-import":o.push(["postcss-import","^15"]);break;case"postcss-url":o.push(["postcss-url","^10"]);break;case"postcss-preset-env":o.push(["postcss-preset-env","^9"]);break;case"autoprefixer":o.push(["autoprefixer","^10"]);break;case"cssnano":o.push(["cssnano","^6"])}}))}u({feature:{name:"css",packages:o},features:a,packageDevDependencies:t})}async function D({atom:e,setProgress:n,context:o,packageDependencies:r}){if(!0!==e.doc.features.app.enabled)return;await n({message:"Creating app folder"});const c={atom:e,packageDependencies:r,ts:Date.now()},i=o.templateDir,p=t.resolve(o.projectDir,"src/app");s.existsSync(p)||s.mkdirSync(p,{recursive:!0});let l=["index.js.njk"];!1!==e.doc.features.app.html&&l.push("index.html.njk"),await a({pattern:l,dir:t.resolve(i,"src/app"),outDir:p,context:c})}async function h({projectDir:e,name:a,setProgress:n,count:o=1}){let i;const p=c(["npm-pick-versions",a,o]),l=t.join(e,".cache"),f=t.join(l,p+".json");return s.existsSync(f)?(n&&n(`Picking npm version of ${a} from cache ...`),i=JSON.parse(s.readFileSync(f,"utf8"))):(n&&n(`Picking npm version of ${a} ...`),i=await r({name:a,count:o}),s.mkdirSync(l,{recursive:!0}),s.writeFileSync(f,JSON.stringify(i),"utf8")),i}async function w({atom:e,context:a,packageDependencies:r,packageDevDependencies:c,setProgress:i}){await i({message:"Creating package.json."});r.filter((e=>!0===e.dev)).forEach((e=>{c.find((s=>s.package===e.package))||c.push(e);const s=r.findIndex((s=>s.package===e.package));r.splice(s,1)}));const p=r.find((e=>"react"===e.package)),l=r.find((e=>"react-dom"===e.package));p&&!l?r.push({package:"react-dom",version:p.version}):p&&l&&(l.version=p.version),p&&e.doc.features.react_version>=17&&(r.find((e=>"@emotion/react"===e.package))||r.push({package:"@emotion/react",version:"^11"}),r.find((e=>"@emotion/styled"===e.package))||r.push({package:"@emotion/styled",version:"^11"}));const f=[];!0===e.doc.features.app.enabled&&f.push({file:t.resolve(a.projectDir,"src/app/index.js"),dev:!1!==e.doc.features.app.dev}),!0===e.doc.features.cli.enabled&&f.push({file:t.resolve(a.projectDir,"src/cli/index.js"),dev:!1!==e.doc.features.cli.dev});for await(const e of f){const t=e.file;if(!s.existsSync(t))throw new Error(`App file not found: ${t}`);const n=(await o({file:t,recursive:!0})).all;for await(const s of n){if("npm"!==s.type)continue;if(r.find((e=>e.package===s.package)))continue;if(c.find((e=>e.package===s.package)))continue;const t=await h({name:s.package,projectDir:a.projectDir,setProgress:i});(!0===e.dev?c:r).push({package:s.package,subpath:s.subpath,version:t.minorRange,type:"npm"})}}const d={atom:e,packageDependencies:r,packageDevDependencies:c},u=a.templateDir,m=n.compile(s.readFileSync(t.resolve(u,"package.json.njk"),"utf8"),n.configure(u)).render(d),g=a.projectDir,k=t.resolve(g,"package.json");s.writeFileSync(k,m,"utf8");const j=t.resolve(a.project.projectDir,"fnet");if(s.existsSync(j)){const e=t.resolve(a.projectDir,"fnet");s.existsSync(e)||s.mkdirSync(e);const n=s.readdirSync(j);for(const a of n){const n=t.resolve(j,a);if(!s.lstatSync(n).isFile())continue;const o=t.resolve(e,a);s.copyFileSync(n,o)}}}async function y({atom:e,setProgress:n,context:o,packageDependencies:r}){if(!0!==e.doc.features.cli.enabled)return;await n({message:"Creating cli."});const c={atom:e,packageDependencies:r},i=o.templateDir,p=t.resolve(o.projectDir,"src/cli");s.existsSync(p)||s.mkdirSync(p,{recursive:!0}),await a({pattern:["index.js.njk"],dir:t.resolve(i,"src/cli"),outDir:p,context:c})}async function b({atom:e,setProgress:a,context:o,njEnv:r}){if(!0!==e.doc.features.cli.enabled)return;await a({message:"Creating input args."});let c={};if(c=e.doc.input?e.doc.input:{type:"object",properties:{},required:[]},e.doc.features.cli.fargs&&!1!==e.doc.features.cli.fargs?.enabled){const s=e.doc.features.cli.fargs,t={type:"string",description:"Config name to load args",hidden:!1},a={type:"array",description:"Tags to filter the config",hidden:!1};Reflect.has(s,"default")&&(t.default=s.default),c.properties&&(c.properties.fargs=t,c.properties.ftag=a)}const f={options:c,imports:[],atom:e},d=o.templateDir,u=n.compile(s.readFileSync(t.resolve(d,"src/default/input.args.js.njk"),"utf8"),r).render(f),m=o.projectDir,g=t.resolve(m,"src/default/input.args.js");s.writeFileSync(g,u,"utf8");const k=new i({allErrors:!0,useDefaults:!0,formats:{},strict:!1,code:{esm:!0,lines:!0,optimize:!1,source:!0}});l(k);const j=k.compile(c),v=p(k,j);s.writeFileSync(t.resolve(m,"src/default/validate_input.js"),v,"utf8")}async function x({atom:e,setProgress:a,context:o,packageDependencies:r}){await a({message:"Creating tsconfig.json."});const c={atom:e,packageDependencies:r},i=o.templateDir,p=n.compile(s.readFileSync(t.resolve(i,"tsconfig.json.njk"),"utf8"),n.configure(i)).render(c),l=o.projectDir,f=t.resolve(l,"tsconfig.json");s.writeFileSync(f,p,"utf8")}async function S({setProgress:e,context:s}){const a=s.projectDir;await e({message:"Prettifiying source files."});let n=t.join("src","**","*");if(d("bun")){const e=await f(`prettier --write ${n} *.{js,cjs,mjs,json,yaml,html} --no-error-on-unmatched-pattern`,{cwd:a});if(0!==e.code)throw new Error(e.stderr)}else{const e=await f(`prettier --write ${n} *.{js,cjs,mjs,json,yaml,html} --no-error-on-unmatched-pattern`,{cwd:a});if(0!==e.code)throw new Error(e.stderr)}}async function P({setProgress:e,atom:s,context:t}){const a=t.projectDir;if(await e({message:"Installing npm packages."}),d("bun")){if(0!==(await f(`bun install ${s.doc.features.npm_install_flags}`,{cwd:a})).code)throw new Error("Couldnt install npm packages.")}else{if(0!==(await f(`npm install ${s.doc.features.npm_install_flags}`,{cwd:a})).code)throw new Error("Couldnt install npm packages.")}}async function E({setProgress:e,context:s}){const t=s.projectDir;await e({message:"Building main project."});if(0!==(await f("npm run build",{cwd:t})).code)throw new Error("Couldnt build project.")}export{j as a,k as b,m as c,g as d,x as e,u as f,b as g,y as h,v as i,D as j,w as k,S as l,P as m,h as p,E as r};
|