@fnet/cli 0.115.0 → 0.116.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/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 +303 -199
- package/template/fnode/node/package.json.njk +10 -1
- package/template/fnode/node/src/cli/index.js.njk +189 -311
- 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
|
+
}
|
|
35
30
|
});
|
|
36
31
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
+
};
|
|
49
|
+
});
|
|
50
|
+
|
|
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,132 @@ 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-type'] || args.mcp_transport_type || 'stdio';
|
|
77
|
+
let transport;
|
|
78
|
+
|
|
79
|
+
if (transportType === 'stdio') {
|
|
80
|
+
// Use stdio transport
|
|
81
|
+
transport = new StdioServerTransport();
|
|
82
|
+
console.log("MCP server started with stdio transport");
|
|
83
|
+
} else if (transportType === 'http') {
|
|
84
|
+
// Use HTTP transport
|
|
85
|
+
const app = express();
|
|
86
|
+
app.use(express.json());
|
|
87
|
+
|
|
88
|
+
const port = args['cli-port'] || args.cli_port || 3000;
|
|
89
|
+
const server = app.listen(port, () => {
|
|
90
|
+
console.log(`MCP server started with HTTP transport on port ${port}`);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
transport = new StreamableHTTPServerTransport({
|
|
94
|
+
sessionIdGenerator: () => Math.random().toString(36).substring(2, 15),
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
app.post('/mcp', async (req, res) => {
|
|
98
|
+
await transport.handleRequest(req, res, req.body);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
app.get('/mcp', async (req, res) => {
|
|
102
|
+
await transport.handleRequest(req, res);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
app.delete('/mcp', async (req, res) => {
|
|
106
|
+
await transport.handleRequest(req, res);
|
|
107
|
+
});
|
|
108
|
+
} else {
|
|
109
|
+
console.error(`Unknown MCP transport type: ${transportType}`);
|
|
110
|
+
console.error(`Supported types: stdio, http`);
|
|
111
|
+
process.exit(1);
|
|
112
|
+
}
|
|
59
113
|
|
|
60
|
-
const transport = new StdioServerTransport();
|
|
61
114
|
await server.connect(transport);
|
|
62
|
-
console.log("MCP server started with stdio transport");
|
|
63
115
|
return;
|
|
64
116
|
}
|
|
65
|
-
|
|
117
|
+
{% endmacro %}
|
|
66
118
|
|
|
67
|
-
|
|
119
|
+
{% macro httpModeCodeExpress(nodeFn) %}
|
|
68
120
|
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();
|
|
121
|
+
// HTTP mode code
|
|
122
|
+
const app = express();
|
|
123
|
+
app.use(express.json());
|
|
124
|
+
|
|
125
|
+
app.post('/{{atom.doc.features.cli.http.path or atom.doc.name}}', async (req, res) => {
|
|
126
|
+
try {
|
|
127
|
+
const result = await {{ nodeFn }}(req.body);
|
|
128
|
+
res.json(result);
|
|
129
|
+
} catch (error) {
|
|
130
|
+
res.status(500).json({ error: error.message });
|
|
92
131
|
}
|
|
93
132
|
});
|
|
94
133
|
|
|
95
134
|
const port = args['cli-port'] || args.cli_port || 3000;
|
|
96
|
-
|
|
135
|
+
app.listen(port, () => {
|
|
97
136
|
console.log(`HTTP server started on port ${port}`);
|
|
98
137
|
});
|
|
99
138
|
return;
|
|
100
139
|
}
|
|
101
|
-
|
|
140
|
+
{% endmacro %}
|
|
102
141
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
142
|
+
{% macro defaultModeExtend(nodeFn) %}
|
|
143
|
+
if (cliMode === 'default') {
|
|
144
|
+
// Default mode code
|
|
145
|
+
return await {{ nodeFn }}(args);
|
|
146
|
+
}
|
|
147
|
+
{% endmacro %}
|
|
148
|
+
|
|
149
|
+
{% macro defaultModeStandard(nodeFn) %}
|
|
150
|
+
if (cliMode === 'default') {
|
|
151
|
+
// Default mode code
|
|
152
|
+
const result = await {{ nodeFn }}(args);
|
|
153
|
+
|
|
154
|
+
if (typeof result !== 'undefined') {
|
|
155
|
+
const stdout_format = args['stdout-format'] || args.stdout_format || null;
|
|
156
|
+
|
|
157
|
+
if (stdout_format === 'json') console.log(JSON.stringify(result, null, 2));
|
|
158
|
+
else console.log(result);
|
|
159
|
+
}
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
{% endmacro %}
|
|
106
163
|
|
|
164
|
+
{% macro runWithCatch() %}
|
|
165
|
+
run()
|
|
166
|
+
.catch((error) => {
|
|
167
|
+
console.error(error.message);
|
|
168
|
+
process.exit(1);
|
|
169
|
+
});
|
|
170
|
+
{% endmacro %}
|
|
171
|
+
|
|
172
|
+
{% macro runWithThenCatch() %}
|
|
107
173
|
run()
|
|
108
174
|
.then(() => {
|
|
109
|
-
{# process.exit(0);
|
|
175
|
+
{# process.exit(0); #}
|
|
110
176
|
})
|
|
111
177
|
.catch((error) => {
|
|
112
178
|
console.error(error.message);
|
|
113
179
|
process.exit(1);
|
|
114
180
|
});
|
|
181
|
+
{% endmacro %}
|
|
115
182
|
|
|
116
|
-
{
|
|
117
|
-
|
|
183
|
+
{# Main template starts here #}
|
|
184
|
+
{% if atom.doc.features.project.format==='esm' %}
|
|
185
|
+
|
|
186
|
+
import argv from '../default/input.args.js';
|
|
187
|
+
|
|
188
|
+
{% if atom.doc.features.cli.extend===true %}
|
|
189
|
+
|
|
190
|
+
import Node from '../../../cli';
|
|
118
191
|
|
|
119
192
|
{% if atom.doc.features.cli.mcp.enabled===true %}
|
|
120
|
-
|
|
121
|
-
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
193
|
+
{{ importMcpDependencies('esm') }}
|
|
122
194
|
{% endif %}
|
|
123
195
|
|
|
124
196
|
{% if atom.doc.features.cli.http.enabled===true %}
|
|
197
|
+
// Using express for HTTP mode
|
|
125
198
|
import express from 'express';
|
|
126
199
|
{% endif %}
|
|
127
200
|
|
|
@@ -129,89 +202,52 @@ const run = async () => {
|
|
|
129
202
|
const args = await argv();
|
|
130
203
|
const cliMode = args['cli-mode'] || args.cli_mode || 'default';
|
|
131
204
|
|
|
132
|
-
|
|
133
|
-
// Default mode code
|
|
134
|
-
const result = await Node(args);
|
|
205
|
+
{{ defaultModeExtend('Node') }}
|
|
135
206
|
|
|
136
|
-
|
|
137
|
-
|
|
207
|
+
{% if atom.doc.features.cli.mcp.enabled===true %}
|
|
208
|
+
{{ mcpModeCode('Node') }}
|
|
209
|
+
{% endif %}
|
|
138
210
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
211
|
+
{% if atom.doc.features.cli.http.enabled===true %}
|
|
212
|
+
{{ httpModeCodeBuiltIn('Node') }}
|
|
213
|
+
{% endif %}
|
|
144
214
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
const server = new McpServer({
|
|
149
|
-
name: "{{atom.doc.name}}",
|
|
150
|
-
version: "{{atom.doc.version}}"
|
|
151
|
-
});
|
|
215
|
+
console.error(`Unknown CLI mode: ${cliMode}`);
|
|
216
|
+
process.exit(1);
|
|
217
|
+
};
|
|
152
218
|
|
|
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
|
-
);
|
|
219
|
+
{{ runWithThenCatch() }}
|
|
175
220
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
console.log("MCP server started with stdio transport");
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
{% endif %}
|
|
221
|
+
{% else %}
|
|
222
|
+
import Node from '../../../src';
|
|
182
223
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
const app = express();
|
|
187
|
-
app.use(express.json());
|
|
224
|
+
{% if atom.doc.features.cli.mcp.enabled===true %}
|
|
225
|
+
{{ importMcpDependencies('esm') }}
|
|
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
|
+
{% if atom.doc.features.cli.http.enabled===true %}
|
|
229
|
+
import express from 'express';
|
|
230
|
+
{% endif %}
|
|
197
231
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
232
|
+
const run = async () => {
|
|
233
|
+
const args = await argv();
|
|
234
|
+
const cliMode = args['cli-mode'] || args.cli_mode || 'default';
|
|
235
|
+
|
|
236
|
+
{{ defaultModeStandard('Node') }}
|
|
237
|
+
|
|
238
|
+
{% if atom.doc.features.cli.mcp.enabled===true %}
|
|
239
|
+
{{ mcpModeCode('Node') }}
|
|
240
|
+
{% endif %}
|
|
241
|
+
|
|
242
|
+
{% if atom.doc.features.cli.http.enabled===true %}
|
|
243
|
+
{{ httpModeCodeExpress('Node') }}
|
|
204
244
|
{% endif %}
|
|
205
245
|
|
|
206
246
|
console.error(`Unknown CLI mode: ${cliMode}`);
|
|
207
247
|
process.exit(1);
|
|
208
248
|
};
|
|
209
249
|
|
|
210
|
-
|
|
211
|
-
.catch((error) => {
|
|
212
|
-
console.error(error.message);
|
|
213
|
-
process.exit(1);
|
|
214
|
-
});
|
|
250
|
+
{{ runWithCatch() }}
|
|
215
251
|
{% endif %}
|
|
216
252
|
|
|
217
253
|
{% elif atom.doc.features.project.format==='cjs' %}
|
|
@@ -223,222 +259,64 @@ const argv = require('../default/input.args.js');
|
|
|
223
259
|
const Node = require('../../../cli');
|
|
224
260
|
|
|
225
261
|
{% if atom.doc.features.cli.mcp.enabled===true %}
|
|
226
|
-
|
|
227
|
-
const { StdioServerTransport } = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
262
|
+
{{ importMcpDependencies('cjs') }}
|
|
228
263
|
{% endif %}
|
|
229
264
|
|
|
230
265
|
{% if atom.doc.features.cli.http.enabled===true %}
|
|
231
|
-
// Using
|
|
266
|
+
// Using express for HTTP mode
|
|
267
|
+
const express = require('express');
|
|
232
268
|
{% endif %}
|
|
233
269
|
|
|
234
270
|
const run = async () => {
|
|
235
271
|
const args = await argv();
|
|
236
272
|
const cliMode = args['cli-mode'] || args.cli_mode || 'default';
|
|
237
273
|
|
|
238
|
-
|
|
239
|
-
// Default mode code
|
|
240
|
-
return await Node(args);
|
|
241
|
-
}
|
|
274
|
+
{{ defaultModeExtend('Node') }}
|
|
242
275
|
|
|
243
276
|
{% 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
|
-
}
|
|
277
|
+
{{ mcpModeCode('Node') }}
|
|
279
278
|
{% endif %}
|
|
280
279
|
|
|
281
280
|
{% 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
|
-
}
|
|
281
|
+
{{ httpModeCodeBuiltIn('Node') }}
|
|
315
282
|
{% endif %}
|
|
316
283
|
|
|
317
284
|
console.error(`Unknown CLI mode: ${cliMode}`);
|
|
318
285
|
process.exit(1);
|
|
319
286
|
};
|
|
320
287
|
|
|
321
|
-
|
|
322
|
-
.then(() => {
|
|
323
|
-
{# process.exit(0); #}
|
|
324
|
-
})
|
|
325
|
-
.catch((error) => {
|
|
326
|
-
console.error(error.message);
|
|
327
|
-
process.exit(1);
|
|
328
|
-
});
|
|
288
|
+
{{ runWithThenCatch() }}
|
|
329
289
|
|
|
330
290
|
{% else %}
|
|
331
291
|
const Node = require('../../../src');
|
|
332
292
|
|
|
333
293
|
{% if atom.doc.features.cli.mcp.enabled===true %}
|
|
334
|
-
|
|
335
|
-
const { StdioServerTransport } = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
294
|
+
{{ importMcpDependencies('cjs') }}
|
|
336
295
|
{% endif %}
|
|
337
296
|
|
|
338
297
|
{% if atom.doc.features.cli.http.enabled===true %}
|
|
339
|
-
|
|
298
|
+
const express = require('express');
|
|
340
299
|
{% endif %}
|
|
341
300
|
|
|
342
301
|
const run = async () => {
|
|
343
302
|
const args = await argv();
|
|
344
303
|
const cliMode = args['cli-mode'] || args.cli_mode || 'default';
|
|
345
304
|
|
|
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
|
-
}
|
|
305
|
+
{{ defaultModeStandard('Node') }}
|
|
358
306
|
|
|
359
307
|
{% 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
|
-
}
|
|
308
|
+
{{ mcpModeCode('Node') }}
|
|
395
309
|
{% endif %}
|
|
396
310
|
|
|
397
311
|
{% 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
|
-
}
|
|
312
|
+
{{ httpModeCodeExpress('Node') }}
|
|
431
313
|
{% endif %}
|
|
432
314
|
|
|
433
315
|
console.error(`Unknown CLI mode: ${cliMode}`);
|
|
434
316
|
process.exit(1);
|
|
435
317
|
};
|
|
436
318
|
|
|
437
|
-
|
|
438
|
-
.catch((error) => {
|
|
439
|
-
console.error(error.message);
|
|
440
|
-
process.exit(1);
|
|
441
|
-
});
|
|
319
|
+
{{ runWithCatch() }}
|
|
442
320
|
{% endif %}
|
|
443
321
|
|
|
444
322
|
{% 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};
|