@fnet/cli 0.2.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/fbin/index.js +2 -0
- package/dist/fnet/index.-SGbq2cI.js +1 -0
- package/dist/fnet/index.B0TQiWy6.js +1 -0
- package/dist/fnet/index.B5XE4ChJ.js +1 -0
- package/dist/fnet/index.Bft2w7m3.js +1 -0
- package/dist/fnet/index.BuYxdKtK.js +1 -0
- package/dist/fnet/index.C2S9JYhS.js +1 -0
- package/dist/fnet/index.C7saWH6d.js +1 -0
- package/dist/fnet/index.CDct_kkF.js +1 -0
- package/dist/fnet/index.CMC8mlye.js +1 -0
- package/dist/fnet/index.CmMM-Ek9.js +1 -0
- package/dist/fnet/index.CuMyez3E.js +1 -0
- package/dist/fnet/index.CzAV0S36.js +1 -0
- package/dist/fnet/index.D2N9YZmA.js +1 -0
- package/dist/fnet/index.D3p7pncT.js +1 -0
- package/dist/fnet/index.DG8TqL-1.js +1 -0
- package/dist/fnet/index.DI3yyTtl.js +1 -0
- package/dist/fnet/index.DWpw12No.js +1 -0
- package/dist/fnet/index.DrwlOzAe.js +1 -0
- package/dist/fnet/index.Q-CYRcna.js +1 -0
- package/dist/fnet/index.W6RYgypK.js +1 -0
- package/dist/fnet/index.js +2 -0
- package/dist/fnet/index.rSKuKke7.js +1 -0
- package/dist/fnet/index.xd8c7XMr.js +1 -0
- package/dist/fnode/index.-SGbq2cI.js +1 -0
- package/dist/fnode/index.1IxoA5DY.js +1 -0
- package/dist/fnode/index.B5XE4ChJ.js +1 -0
- package/dist/fnode/index.Bft2w7m3.js +1 -0
- package/dist/fnode/index.BuYxdKtK.js +1 -0
- package/dist/fnode/index.C2S9JYhS.js +1 -0
- package/dist/fnode/index.C7saWH6d.js +1 -0
- package/dist/fnode/index.CDct_kkF.js +1 -0
- package/dist/fnode/index.CJ4EhqPO.js +1 -0
- package/dist/fnode/index.CMC8mlye.js +1 -0
- package/dist/fnode/index.CmMM-Ek9.js +1 -0
- package/dist/fnode/index.CuMyez3E.js +1 -0
- package/dist/fnode/index.CzAV0S36.js +1 -0
- package/dist/fnode/index.D2N9YZmA.js +1 -0
- package/dist/fnode/index.D3p7pncT.js +1 -0
- package/dist/fnode/index.DG8TqL-1.js +1 -0
- package/dist/fnode/index.DI3yyTtl.js +1 -0
- package/dist/fnode/index.DWpw12No.js +1 -0
- package/dist/fnode/index.DrwlOzAe.js +1 -0
- package/dist/fnode/index.N_a5FdgA.js +1 -0
- package/dist/fnode/index.Q-CYRcna.js +1 -0
- package/dist/fnode/index.UNoFg95r.js +1 -0
- package/dist/fnode/index.W6RYgypK.js +1 -0
- package/dist/fnode/index.js +2 -0
- package/dist/fnode/index.tq-9YxMP.js +1 -0
- package/dist/fnode/index.xd8c7XMr.js +1 -0
- package/dist/frun/index.js +2 -0
- package/dist/fservice/index.js +2 -0
- package/package.json +89 -0
- package/readme.md +251 -0
- package/template/fnet/core/assert.js +6 -0
- package/template/fnet/core/message.js +3 -0
- package/template/fnet/core/object.js +47 -0
- package/template/fnet/core/print.js +1 -0
- package/template/fnet/core/sleep.js +5 -0
- package/template/fnet/node/.gitignore.njk +9 -0
- package/template/fnet/node/build.js.njk +153 -0
- package/template/fnet/node/package.json.njk +118 -0
- package/template/fnet/node/readme.md.njk +21 -0
- package/template/fnet/node/rollup.config.mjs.njk +498 -0
- package/template/fnet/node/src/app/index.html.njk +67 -0
- package/template/fnet/node/src/app/index.js.njk +36 -0
- package/template/fnet/node/src/cli/index.js.njk +319 -0
- package/template/fnet/node/src/default/blocks/assign.js.njk +53 -0
- package/template/fnet/node/src/default/blocks/call.js.njk +156 -0
- package/template/fnet/node/src/default/blocks/for.js.njk +87 -0
- package/template/fnet/node/src/default/blocks/form.js.njk +69 -0
- package/template/fnet/node/src/default/blocks/modules.js.njk +57 -0
- package/template/fnet/node/src/default/blocks/new.js.njk +87 -0
- package/template/fnet/node/src/default/blocks/next.js.njk +37 -0
- package/template/fnet/node/src/default/blocks/output.js.njk +53 -0
- package/template/fnet/node/src/default/blocks/raise.js.njk +31 -0
- package/template/fnet/node/src/default/blocks/return.js.njk +33 -0
- package/template/fnet/node/src/default/blocks/signal.js.njk +37 -0
- package/template/fnet/node/src/default/blocks/steps.js.njk +63 -0
- package/template/fnet/node/src/default/blocks/switch.js.njk +79 -0
- package/template/fnet/node/src/default/blocks/tryexcept.js.njk +74 -0
- package/template/fnet/node/src/default/blocks/wait.js.njk +34 -0
- package/template/fnet/node/src/default/engine.js.njk +79 -0
- package/template/fnet/node/src/default/input.args.js.njk +122 -0
- package/template/fnet/node/src/default/macros/block-assign.js.njk +3 -0
- package/template/fnet/node/src/default/macros/block-body-header.js.njk +7 -0
- package/template/fnet/node/src/default/macros/block-entry-args.js.njk +2 -0
- package/template/fnet/node/src/default/macros/block-footer.js.njk +3 -0
- package/template/fnet/node/src/default/macros/block-header.js.njk +14 -0
- package/template/fnet/node/src/default/macros/block-library-header.js.njk +43 -0
- package/template/fnet/node/src/default/macros/block-modules-header.js.njk +8 -0
- package/template/fnet/node/src/default/macros/block-modules.js.njk +29 -0
- package/template/fnet/node/src/default/macros/block-next-header.js.njk +6 -0
- package/template/fnet/node/src/default/macros/block-next.js.njk +21 -0
- package/template/fnet/node/src/default/macros/block-run-footer.js.njk +7 -0
- package/template/fnet/node/src/default/macros/block-run-form.js.njk +32 -0
- package/template/fnet/node/src/default/macros/block-run-header.js.njk +31 -0
- package/template/fnet/node/src/default/macros/block-signal.js.njk +3 -0
- package/template/fnet/node/src/default/macros/page.js.njk +8 -0
- package/template/fnet/node/src/default/macros/workflow-header.js.njk +7 -0
- package/template/fnet/node/src/default/workflow.js.njk +123 -0
- package/template/fnet/node/tsconfig.json.njk +16 -0
- package/template/fnet/project/.gitignore.njk +7 -0
- package/template/fnet/project/.vscode/launch.json.njk +41 -0
- package/template/fnet/project/.vscode/tasks.json.njk +46 -0
- package/template/fnet/project/fnet/flows.yaml.njk +4 -0
- package/template/fnet/project/fnet/targets.yaml.njk +7 -0
- package/template/fnet/project/fnet.yaml.njk +3 -0
- package/template/fnode/node/.gitignore.njk +9 -0
- package/template/fnode/node/build.js.njk +149 -0
- package/template/fnode/node/package.json.njk +120 -0
- package/template/fnode/node/readme.md.njk +21 -0
- package/template/fnode/node/rollup.config.mjs.njk +498 -0
- package/template/fnode/node/src/app/index-js-with-react-host.njk +50 -0
- package/template/fnode/node/src/app/index-js-without-react-host.njk +23 -0
- package/template/fnode/node/src/app/index.html.njk +67 -0
- package/template/fnode/node/src/app/index.js.njk +9 -0
- package/template/fnode/node/src/cli/index.js.njk +403 -0
- package/template/fnode/node/src/default/engine.js.njk +17 -0
- package/template/fnode/node/src/default/input.args.js.njk +122 -0
- package/template/fnode/node/tsconfig.json.njk +16 -0
- package/template/fnode/project/.gitignore.njk +11 -0
- package/template/fnode/project/.vscode/launch.json.njk +78 -0
- package/template/fnode/project/.vscode/tasks.json.njk +46 -0
- package/template/fnode/project/fnet/targets.yaml.njk +25 -0
- package/template/fnode/project/fnode.yaml.njk +12 -0
- package/template/fnode/python/.gitignore.njk +7 -0
- package/template/fnode/python/package.json.njk +4 -0
- package/template/fnode/python/pyproject.toml.njk +3 -0
- package/template/fnode/python/readme.md.njk +12 -0
- package/template/fnode/python/setup.py.njk +19 -0
- package/template/fnode/python/src/cli/index.py.njk +25 -0
- package/template/schemas/to-npm.yaml +14 -0
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
{% if atom.doc.features.cli.enabled===true %}
|
|
2
|
+
|
|
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 %}
|
|
19
|
+
|
|
20
|
+
{% macro mcpModeCode(nodeFn) %}
|
|
21
|
+
if (cliMode === 'mcp') {
|
|
22
|
+
// MCP mode code
|
|
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
|
+
inputSchema: inputSchema
|
|
39
|
+
}]
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// Handle tool execution
|
|
44
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
45
|
+
if (request.params.name === "{{atom.doc.features.cli.mcp.tool.name or atom.doc.name}}") {
|
|
46
|
+
try {
|
|
47
|
+
const result = await {{ nodeFn }}(request.params.arguments);
|
|
48
|
+
return {
|
|
49
|
+
content: [{
|
|
50
|
+
type: "text",
|
|
51
|
+
text: JSON.stringify(result)
|
|
52
|
+
}]
|
|
53
|
+
};
|
|
54
|
+
} catch (error) {
|
|
55
|
+
return {
|
|
56
|
+
content: [{
|
|
57
|
+
type: "text",
|
|
58
|
+
text: `Error: ${error.message}`
|
|
59
|
+
}],
|
|
60
|
+
isError: true
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
throw new Error("Tool not found");
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// Get transport type from arguments
|
|
68
|
+
const transportType = args['mcp-transport'] || args.mcp_transport || 'stdio';
|
|
69
|
+
let transport;
|
|
70
|
+
|
|
71
|
+
if (transportType === 'stdio') {
|
|
72
|
+
// Use stdio transport
|
|
73
|
+
transport = new StdioServerTransport();
|
|
74
|
+
} else if (transportType === 'http') {
|
|
75
|
+
// Use Streamable HTTP transport (official transport as of MCP 2025-03-26)
|
|
76
|
+
const app = express();
|
|
77
|
+
app.use(express.json());
|
|
78
|
+
|
|
79
|
+
const port = args['cli-port'] || args.cli_port || 3000;
|
|
80
|
+
const host = args['cli-host'] || args.cli_host || '0.0.0.0';
|
|
81
|
+
const mcpEndpoint = '/mcp';
|
|
82
|
+
const verbose = args['cli-verbose'] || args.cli_verbose || false;
|
|
83
|
+
|
|
84
|
+
// Verbose logging helper
|
|
85
|
+
const log = (...args) => {
|
|
86
|
+
if (verbose) {
|
|
87
|
+
console.log('[MCP]', new Date().toISOString(), ...args);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// Map to store transports by session ID
|
|
92
|
+
const transports = {};
|
|
93
|
+
|
|
94
|
+
// Handle POST requests for client-to-server communication
|
|
95
|
+
app.post(mcpEndpoint, async (req, res) => {
|
|
96
|
+
// Check for existing session ID
|
|
97
|
+
const sessionId = req.get('Mcp-Session-Id');
|
|
98
|
+
|
|
99
|
+
log('POST request received');
|
|
100
|
+
log('Session ID:', sessionId || 'none');
|
|
101
|
+
log('Request body:', JSON.stringify(req.body, null, 2));
|
|
102
|
+
|
|
103
|
+
let transport;
|
|
104
|
+
|
|
105
|
+
if (sessionId && transports[sessionId]) {
|
|
106
|
+
// Reuse existing transport
|
|
107
|
+
log('Reusing existing transport for session:', sessionId);
|
|
108
|
+
transport = transports[sessionId];
|
|
109
|
+
} else if (!sessionId && req.body && (req.body.method === 'initialize' ||
|
|
110
|
+
(Array.isArray(req.body) && req.body.some(item => item.method === 'initialize')))) {
|
|
111
|
+
// New initialization request
|
|
112
|
+
log('Creating new transport for initialization');
|
|
113
|
+
transport = new StreamableHTTPServerTransport({
|
|
114
|
+
sessionIdGenerator: () => {
|
|
115
|
+
// Generate cryptographically secure session ID
|
|
116
|
+
return require('crypto').randomBytes(16).toString('hex');
|
|
117
|
+
},
|
|
118
|
+
onsessioninitialized: (sessionId) => {
|
|
119
|
+
// Store the transport by session ID
|
|
120
|
+
log('Session initialized:', sessionId);
|
|
121
|
+
transports[sessionId] = transport;
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
// Clean up transport when closed
|
|
126
|
+
transport.onclose = () => {
|
|
127
|
+
if (transport.sessionId) {
|
|
128
|
+
log('Transport closed, cleaning up session:', transport.sessionId);
|
|
129
|
+
delete transports[transport.sessionId];
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
// Connect to the MCP server
|
|
134
|
+
await server.connect(transport);
|
|
135
|
+
log('Server connected to transport');
|
|
136
|
+
} else {
|
|
137
|
+
// Invalid request
|
|
138
|
+
log('Invalid request - no valid session ID');
|
|
139
|
+
return res.status(400).json({
|
|
140
|
+
jsonrpc: '2.0',
|
|
141
|
+
error: {
|
|
142
|
+
code: -32000,
|
|
143
|
+
message: 'Bad Request: No valid session ID provided'
|
|
144
|
+
},
|
|
145
|
+
id: null
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Handle the request
|
|
150
|
+
log('Handling request with transport');
|
|
151
|
+
await transport.handleRequest(req, res, req.body);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
// Reusable handler for GET and DELETE requests
|
|
155
|
+
const handleSessionRequest = async (req, res) => {
|
|
156
|
+
const sessionId = req.get('Mcp-Session-Id');
|
|
157
|
+
log(`${req.method} request received for session:`, sessionId || 'none');
|
|
158
|
+
|
|
159
|
+
if (!sessionId || !transports[sessionId]) {
|
|
160
|
+
log('Invalid or missing session ID');
|
|
161
|
+
return res.status(400).send('Invalid or missing session ID');
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const transport = transports[sessionId];
|
|
165
|
+
log('Handling request with existing transport');
|
|
166
|
+
await transport.handleRequest(req, res);
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
// Handle GET requests for server-to-client notifications via SSE
|
|
170
|
+
app.get(mcpEndpoint, handleSessionRequest);
|
|
171
|
+
|
|
172
|
+
// Handle DELETE requests for session termination
|
|
173
|
+
app.delete(mcpEndpoint, handleSessionRequest);
|
|
174
|
+
|
|
175
|
+
app.listen(port, host, () => {
|
|
176
|
+
console.log(`MCP server started with Streamable HTTP transport`);
|
|
177
|
+
console.log(`Endpoint: http://${host}:${port}${mcpEndpoint}`);
|
|
178
|
+
console.log(`Listening on ${host}:${port}`);
|
|
179
|
+
if (verbose) {
|
|
180
|
+
console.log(`Verbose logging enabled`);
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
return;
|
|
185
|
+
} else {
|
|
186
|
+
console.error(`Unknown MCP transport type: ${transportType}`);
|
|
187
|
+
console.error(`Supported types: stdio, http`);
|
|
188
|
+
process.exit(1);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
await server.connect(transport);
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
{% endmacro %}
|
|
195
|
+
|
|
196
|
+
{% macro httpModeCodeExpress(nodeFn) %}
|
|
197
|
+
if (cliMode === 'http') {
|
|
198
|
+
// HTTP mode code
|
|
199
|
+
const app = express();
|
|
200
|
+
app.use(express.json());
|
|
201
|
+
|
|
202
|
+
app.post('/{{atom.doc.features.cli.http.path or atom.doc.name}}', async (req, res) => {
|
|
203
|
+
try {
|
|
204
|
+
const result = await {{ nodeFn }}(req.body);
|
|
205
|
+
res.json(result);
|
|
206
|
+
} catch (error) {
|
|
207
|
+
res.status(500).json({ error: error.message });
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
const port = args['cli-port'] || args.cli_port || 3000;
|
|
212
|
+
app.listen(port, () => {
|
|
213
|
+
console.log(`HTTP server started on port ${port}`);
|
|
214
|
+
});
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
{% endmacro %}
|
|
218
|
+
|
|
219
|
+
{% macro defaultModeExtend(nodeFn) %}
|
|
220
|
+
if (cliMode === 'default') {
|
|
221
|
+
// Default mode code
|
|
222
|
+
return await {{ nodeFn }}(await argv());
|
|
223
|
+
}
|
|
224
|
+
{% endmacro %}
|
|
225
|
+
|
|
226
|
+
{% macro defaultModeStandard(nodeFn) %}
|
|
227
|
+
if (cliMode === 'default') {
|
|
228
|
+
// Default mode code
|
|
229
|
+
const result = await {{ nodeFn }}(await argv());
|
|
230
|
+
|
|
231
|
+
if (typeof result !== 'undefined') {
|
|
232
|
+
const stdout_format = args['stdout-format'] || args.stdout_format || null;
|
|
233
|
+
|
|
234
|
+
if (stdout_format === 'json') console.log(JSON.stringify(result, null, 2));
|
|
235
|
+
else console.log(result);
|
|
236
|
+
}
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
{% endmacro %}
|
|
240
|
+
|
|
241
|
+
{% macro runWithCatch() %}
|
|
242
|
+
run()
|
|
243
|
+
.catch((error) => {
|
|
244
|
+
console.error(error.message);
|
|
245
|
+
process.exit(1);
|
|
246
|
+
});
|
|
247
|
+
{% endmacro %}
|
|
248
|
+
|
|
249
|
+
{% macro runWithThenCatch() %}
|
|
250
|
+
run()
|
|
251
|
+
.then(() => {
|
|
252
|
+
{# process.exit(0); #}
|
|
253
|
+
})
|
|
254
|
+
.catch((error) => {
|
|
255
|
+
console.error(error.message);
|
|
256
|
+
process.exit(1);
|
|
257
|
+
});
|
|
258
|
+
{% endmacro %}
|
|
259
|
+
|
|
260
|
+
{# Main template starts here #}
|
|
261
|
+
{% if atom.doc.features.project.format==='esm' %}
|
|
262
|
+
|
|
263
|
+
import argv from '../default/input.args.js';
|
|
264
|
+
import { schema as inputSchema } from '../default/validate_input.js';
|
|
265
|
+
|
|
266
|
+
{% if atom.doc.features.cli.extend===true %}
|
|
267
|
+
|
|
268
|
+
import Node from '../../../cli';
|
|
269
|
+
|
|
270
|
+
{% if atom.doc.features.cli.mcp.enabled===true %}
|
|
271
|
+
{{ importMcpDependencies('esm') }}
|
|
272
|
+
{% elif atom.doc.features.cli.http.enabled===true %}
|
|
273
|
+
// Using express for HTTP mode
|
|
274
|
+
import express from 'express';
|
|
275
|
+
{% endif %}
|
|
276
|
+
import argsParser from 'yargs-parser';
|
|
277
|
+
|
|
278
|
+
const run = async () => {
|
|
279
|
+
const args = argsParser(process.argv.slice(2));
|
|
280
|
+
const cliMode = args['cli-mode'] || args.cli_mode || 'default';
|
|
281
|
+
|
|
282
|
+
{{ defaultModeExtend('Node') }}
|
|
283
|
+
|
|
284
|
+
{% if atom.doc.features.cli.mcp.enabled===true %}
|
|
285
|
+
{{ mcpModeCode('Node') }}
|
|
286
|
+
{% endif %}
|
|
287
|
+
|
|
288
|
+
{% if atom.doc.features.cli.http.enabled===true %}
|
|
289
|
+
{{ httpModeCodeBuiltIn('Node') }}
|
|
290
|
+
{% endif %}
|
|
291
|
+
|
|
292
|
+
console.error(`Unknown CLI mode: ${cliMode}`);
|
|
293
|
+
process.exit(1);
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
{{ runWithThenCatch() }}
|
|
297
|
+
|
|
298
|
+
{% else %}
|
|
299
|
+
import Node from '../../../src';
|
|
300
|
+
|
|
301
|
+
{% if atom.doc.features.cli.mcp.enabled===true %}
|
|
302
|
+
{{ importMcpDependencies('esm') }}
|
|
303
|
+
{% elif atom.doc.features.cli.http.enabled===true %}
|
|
304
|
+
// Using express for HTTP mode
|
|
305
|
+
import express from 'express';
|
|
306
|
+
{% endif %}
|
|
307
|
+
|
|
308
|
+
import argsParser from 'yargs-parser';
|
|
309
|
+
|
|
310
|
+
const run = async () => {
|
|
311
|
+
const args = argsParser(process.argv.slice(2));
|
|
312
|
+
const cliMode = args['cli-mode'] || args.cli_mode || 'default';
|
|
313
|
+
|
|
314
|
+
{{ defaultModeStandard('Node') }}
|
|
315
|
+
|
|
316
|
+
{% if atom.doc.features.cli.mcp.enabled===true %}
|
|
317
|
+
{{ mcpModeCode('Node') }}
|
|
318
|
+
{% endif %}
|
|
319
|
+
|
|
320
|
+
{% if atom.doc.features.cli.http.enabled===true %}
|
|
321
|
+
{{ httpModeCodeExpress('Node') }}
|
|
322
|
+
{% endif %}
|
|
323
|
+
|
|
324
|
+
console.error(`Unknown CLI mode: ${cliMode}`);
|
|
325
|
+
process.exit(1);
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
{{ runWithCatch() }}
|
|
329
|
+
{% endif %}
|
|
330
|
+
|
|
331
|
+
{% elif atom.doc.features.project.format==='cjs' %}
|
|
332
|
+
|
|
333
|
+
const argv = require('../default/input.args.js');
|
|
334
|
+
|
|
335
|
+
{% if atom.doc.features.cli.extend===true %}
|
|
336
|
+
|
|
337
|
+
const Node = require('../../../cli');
|
|
338
|
+
|
|
339
|
+
{% if atom.doc.features.cli.mcp.enabled===true %}
|
|
340
|
+
{{ importMcpDependencies('cjs') }}
|
|
341
|
+
{% elif atom.doc.features.cli.http.enabled===true %}
|
|
342
|
+
// Using express for HTTP mode
|
|
343
|
+
const express = require('express');
|
|
344
|
+
{% endif %}
|
|
345
|
+
|
|
346
|
+
const argsParser = require('yargs-parser');
|
|
347
|
+
|
|
348
|
+
const run = async () => {
|
|
349
|
+
const args = argsParser(process.argv.slice(2));
|
|
350
|
+
const cliMode = args['cli-mode'] || args.cli_mode || 'default';
|
|
351
|
+
|
|
352
|
+
{{ defaultModeExtend('Node') }}
|
|
353
|
+
|
|
354
|
+
{% if atom.doc.features.cli.mcp.enabled===true %}
|
|
355
|
+
{{ mcpModeCode('Node') }}
|
|
356
|
+
{% endif %}
|
|
357
|
+
|
|
358
|
+
{% if atom.doc.features.cli.http.enabled===true %}
|
|
359
|
+
{{ httpModeCodeBuiltIn('Node') }}
|
|
360
|
+
{% endif %}
|
|
361
|
+
|
|
362
|
+
console.error(`Unknown CLI mode: ${cliMode}`);
|
|
363
|
+
process.exit(1);
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
{{ runWithThenCatch() }}
|
|
367
|
+
|
|
368
|
+
{% else %}
|
|
369
|
+
const Node = require('../../../src');
|
|
370
|
+
|
|
371
|
+
{% if atom.doc.features.cli.mcp.enabled===true %}
|
|
372
|
+
{{ importMcpDependencies('cjs') }}
|
|
373
|
+
{% elif atom.doc.features.cli.http.enabled===true %}
|
|
374
|
+
// Using express for HTTP mode
|
|
375
|
+
const express = require('express');
|
|
376
|
+
{% endif %}
|
|
377
|
+
|
|
378
|
+
const argsParser = require('yargs-parser');
|
|
379
|
+
|
|
380
|
+
const run = async () => {
|
|
381
|
+
const args = argsParser(process.argv.slice(2));
|
|
382
|
+
const cliMode = args['cli-mode'] || args.cli_mode || 'default';
|
|
383
|
+
|
|
384
|
+
{{ defaultModeStandard('Node') }}
|
|
385
|
+
|
|
386
|
+
{% if atom.doc.features.cli.mcp.enabled===true %}
|
|
387
|
+
{{ mcpModeCode('Node') }}
|
|
388
|
+
{% endif %}
|
|
389
|
+
|
|
390
|
+
{% if atom.doc.features.cli.http.enabled===true %}
|
|
391
|
+
{{ httpModeCodeExpress('Node') }}
|
|
392
|
+
{% endif %}
|
|
393
|
+
|
|
394
|
+
console.error(`Unknown CLI mode: ${cliMode}`);
|
|
395
|
+
process.exit(1);
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
{{ runWithCatch() }}
|
|
399
|
+
{% endif %}
|
|
400
|
+
|
|
401
|
+
{% endif %}
|
|
402
|
+
|
|
403
|
+
{% endif %}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{% if atom.doc.features.project.format === 'esm' %}
|
|
2
|
+
{% if atom.relativePath %}
|
|
3
|
+
export * from "{{atom.relativePath}}";
|
|
4
|
+
export { default } from "{{atom.relativePath}}";
|
|
5
|
+
{% else %}
|
|
6
|
+
export * from "../libs/{{atom.id or atom.doc.name}}";
|
|
7
|
+
export { default } from "../libs/{{atom.id or atom.doc.name}}";
|
|
8
|
+
{% endif %}
|
|
9
|
+
{% elif atom.doc.features.project.format === 'cjs' %}
|
|
10
|
+
{% if atom.relativePath %}
|
|
11
|
+
const moduleExports = require("{{atom.relativePath}}");
|
|
12
|
+
module.exports = { ...moduleExports, default: moduleExports.default || moduleExports };
|
|
13
|
+
{% else %}
|
|
14
|
+
const moduleExports = require("../libs/{{atom.id or atom.doc.name}}");
|
|
15
|
+
module.exports = { ...moduleExports, default: moduleExports.default || moduleExports };
|
|
16
|
+
{% endif %}
|
|
17
|
+
{% endif %}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
{% if atom.doc.features.project.format === 'esm' %}
|
|
2
|
+
import fnetArgs from '@fnet/args';
|
|
3
|
+
import validate,{schema as inputSchema} from "./validate_input";
|
|
4
|
+
|
|
5
|
+
{% elif atom.doc.features.project.format === 'cjs' %}
|
|
6
|
+
const fnetArgs = require('@fnet/args');
|
|
7
|
+
const validate,{schema as inputSchema} = require("./validate_input");
|
|
8
|
+
{% endif %}
|
|
9
|
+
|
|
10
|
+
{% if atom.doc.features.cli.fargs and atom.doc.features.cli.fargs?.enabled !== false %}
|
|
11
|
+
|
|
12
|
+
const get_fargs = (argv) => {
|
|
13
|
+
const fargsIndex = argv.indexOf('--fargs');
|
|
14
|
+
if (fargsIndex !== -1 && argv[fargsIndex + 1]) return argv[fargsIndex + 1];
|
|
15
|
+
{% if atom.doc.features.cli.fargs.default %}
|
|
16
|
+
else return "{{atom.doc.features.cli.fargs.default}}";
|
|
17
|
+
{% endif %}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const get_ftags = (argv) => {
|
|
21
|
+
const ftags = [];
|
|
22
|
+
for (let i = 0; i < argv.length; i++) {
|
|
23
|
+
if (argv[i] === '--ftag' && argv[i + 1]) {
|
|
24
|
+
ftags.push(argv[i + 1]);
|
|
25
|
+
i++;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
{% if atom.doc.features.cli.fargs.tags %}
|
|
30
|
+
return ftags.length > 0 ? ftags : {{atom.doc.features.cli.fargs.tags | dump | safe}};
|
|
31
|
+
{% else %}
|
|
32
|
+
return ftags.length > 0 ? ftags : undefined;
|
|
33
|
+
{% endif %}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
{% endif %}
|
|
37
|
+
|
|
38
|
+
{% if atom.doc.features.project.format === 'esm' %}
|
|
39
|
+
|
|
40
|
+
export default async () => {
|
|
41
|
+
|
|
42
|
+
let schema = inputSchema;
|
|
43
|
+
let initial;
|
|
44
|
+
|
|
45
|
+
{% if atom.doc.features.cli.fargs and atom.doc.features.cli.fargs?.enabled !== false %}
|
|
46
|
+
const fargs = get_fargs(process.argv.slice(2));
|
|
47
|
+
const ftags = get_ftags(process.argv.slice(2));
|
|
48
|
+
|
|
49
|
+
if (fargs) {
|
|
50
|
+
const { default: fnetConfig } = await import("@fnet/config");
|
|
51
|
+
const config = await fnetConfig({ name: fargs, tags: ftags });
|
|
52
|
+
if (config?.data) {
|
|
53
|
+
initial=config.data;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
{% endif %}
|
|
57
|
+
|
|
58
|
+
const packageCallback = async () => {
|
|
59
|
+
const { default: url } = await import("node:url");
|
|
60
|
+
const { default: path } = await import("node:path");
|
|
61
|
+
const { default: fs } = await import("node:fs");
|
|
62
|
+
let currentDir = path.dirname(url.fileURLToPath(import.meta.url));
|
|
63
|
+
let firstPackageJson = path.join(currentDir, "package.json");
|
|
64
|
+
while (currentDir !== path.parse(currentDir).root && !fs.existsSync(firstPackageJson)) {
|
|
65
|
+
currentDir = path.dirname(currentDir);
|
|
66
|
+
firstPackageJson = path.join(currentDir, "package.json");
|
|
67
|
+
}
|
|
68
|
+
if (!fs.existsSync(firstPackageJson)) return {
|
|
69
|
+
name: "Unknown",
|
|
70
|
+
version: "Unknown"
|
|
71
|
+
}
|
|
72
|
+
else return await JSON.parse(fs.readFileSync(firstPackageJson, "utf8"));
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
return await fnetArgs({schema,initial,validate,packageCallback});
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
{% elif atom.doc.features.project.format === 'cjs' %}
|
|
79
|
+
|
|
80
|
+
module.exports = async () => {
|
|
81
|
+
|
|
82
|
+
let schema = inputSchema;
|
|
83
|
+
let initial;
|
|
84
|
+
|
|
85
|
+
{% if atom.doc.features.cli.fargs and atom.doc.features.cli.fargs?.enabled !== false %}
|
|
86
|
+
const fargs = get_fargs(process.argv.slice(2));
|
|
87
|
+
const ftags = get_ftags(process.argv.slice(2));
|
|
88
|
+
|
|
89
|
+
if (fargs) {
|
|
90
|
+
const { default: fnetConfig } = await import("@fnet/config");
|
|
91
|
+
const config = await fnetConfig({ name: fargs, tags: ftags });
|
|
92
|
+
if (config?.data) {
|
|
93
|
+
initial=config.data;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
{% endif %}
|
|
97
|
+
|
|
98
|
+
const packageCallback = async () => {
|
|
99
|
+
const path = require("node:path");
|
|
100
|
+
const fs = require("node:fs");
|
|
101
|
+
|
|
102
|
+
let currentDir = __dirname;
|
|
103
|
+
let firstPackageJson = path.join(currentDir, "package.json");
|
|
104
|
+
|
|
105
|
+
while (currentDir !== path.parse(currentDir).root && !fs.existsSync(firstPackageJson)) {
|
|
106
|
+
currentDir = path.dirname(currentDir);
|
|
107
|
+
firstPackageJson = path.join(currentDir, "package.json");
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (!fs.existsSync(firstPackageJson)) {
|
|
111
|
+
return {
|
|
112
|
+
name: "Unknown",
|
|
113
|
+
version: "Unknown"
|
|
114
|
+
};
|
|
115
|
+
} else {
|
|
116
|
+
return JSON.parse(fs.readFileSync(firstPackageJson, "utf8"));
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
return await fnetArgs({schema,initial,validate,packageCallback});
|
|
121
|
+
};
|
|
122
|
+
{% endif %}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"include": [
|
|
3
|
+
"src/**/*.js"
|
|
4
|
+
],
|
|
5
|
+
"compilerOptions": {
|
|
6
|
+
"outDir": "./types",
|
|
7
|
+
"declaration": true,
|
|
8
|
+
"allowJs": true,
|
|
9
|
+
"emitDeclarationOnly": true,
|
|
10
|
+
"target": "es5",
|
|
11
|
+
"strict": true,
|
|
12
|
+
"forceConsistentCasingInFileNames": true,
|
|
13
|
+
"skipLibCheck": true,
|
|
14
|
+
"jsx": "react-jsx"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
{% if runtime==='node' %}
|
|
2
|
+
{
|
|
3
|
+
// Use IntelliSense to learn about possible attributes.
|
|
4
|
+
// Hover to view descriptions of existing attributes.
|
|
5
|
+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
6
|
+
"version": "0.2.0",
|
|
7
|
+
"configurations": [
|
|
8
|
+
{
|
|
9
|
+
"name": "debug-fnode-cli",
|
|
10
|
+
"type": "node",
|
|
11
|
+
"request": "launch",
|
|
12
|
+
"skipFiles": [
|
|
13
|
+
"<node_internals>/**"
|
|
14
|
+
],
|
|
15
|
+
"program": "${workspaceFolder}/.workspace/dist/cli/esm/index.js",
|
|
16
|
+
"cwd": "${workspaceFolder}/.workspace",
|
|
17
|
+
"preLaunchTask": "fnode-watch",
|
|
18
|
+
"console": "integratedTerminal"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"name": "debug-fnode-app",
|
|
22
|
+
"type": "chrome",
|
|
23
|
+
"request": "launch",
|
|
24
|
+
"url": "http://localhost:3000/dist/app/esm/",
|
|
25
|
+
"webRoot": "${workspaceFolder}/.workspace",
|
|
26
|
+
"preLaunchTask": "fnode-watch",
|
|
27
|
+
// "userDataDir": false,
|
|
28
|
+
// "runtimeArgs": [
|
|
29
|
+
// "--profile-directory=<profile-name>",
|
|
30
|
+
// ]
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
// "compounds": [
|
|
34
|
+
// {
|
|
35
|
+
// "name": "debug-fnode-all",
|
|
36
|
+
// "configurations": [
|
|
37
|
+
// "debug-fnode-cli",
|
|
38
|
+
// "debug-fnode-app"
|
|
39
|
+
// ]
|
|
40
|
+
// }
|
|
41
|
+
// ]
|
|
42
|
+
}
|
|
43
|
+
{% elif runtime==='python' %}
|
|
44
|
+
{
|
|
45
|
+
// Use IntelliSense to learn about possible attributes.
|
|
46
|
+
// Hover to view descriptions of existing attributes.
|
|
47
|
+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
48
|
+
"version": "0.2.0",
|
|
49
|
+
"configurations": [
|
|
50
|
+
{
|
|
51
|
+
"name": "debug-fnode-cli",
|
|
52
|
+
"type": "debugpy",
|
|
53
|
+
"request": "launch",
|
|
54
|
+
"program": "${workspaceFolder}/.workspace/src/cli/index.py",
|
|
55
|
+
"console": "integratedTerminal",
|
|
56
|
+
"cwd": "${workspaceFolder}/.workspace",
|
|
57
|
+
"env": {
|
|
58
|
+
"PYTHONPATH": "${workspaceFolder}/.workspace/src"
|
|
59
|
+
},
|
|
60
|
+
{% if platform ==='win32' %}
|
|
61
|
+
"python": "${workspaceFolder}/.workspace/.conda/python.exe",
|
|
62
|
+
{% else %}
|
|
63
|
+
"python":"${workspaceFolder}/.workspace/.conda/bin/python",
|
|
64
|
+
{% endif %}
|
|
65
|
+
"args": []
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
}
|
|
69
|
+
{% else %}
|
|
70
|
+
{
|
|
71
|
+
// Use IntelliSense to learn about possible attributes.
|
|
72
|
+
// Hover to view descriptions of existing attributes.
|
|
73
|
+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
74
|
+
"version": "0.2.0",
|
|
75
|
+
"configurations": [
|
|
76
|
+
]
|
|
77
|
+
}
|
|
78
|
+
{% endif %}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "2.0.0",
|
|
3
|
+
"tasks": [
|
|
4
|
+
{
|
|
5
|
+
"label": "fnode-build",
|
|
6
|
+
"type": "shell",
|
|
7
|
+
"command": "fnode build",
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"label": "fnode-watch",
|
|
11
|
+
"type": "shell",
|
|
12
|
+
"command": "fnode watch",
|
|
13
|
+
"isBackground": true
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"label": "fnode-deploy",
|
|
17
|
+
"type": "shell",
|
|
18
|
+
"command": "fnode deploy",
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"label": "fnode-cli",
|
|
22
|
+
"type": "shell",
|
|
23
|
+
"command": "fnode cli",
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"label": "fnode-app",
|
|
27
|
+
"type": "shell",
|
|
28
|
+
"command": "fnode app",
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"label": "fnode-project-update",
|
|
32
|
+
"type": "shell",
|
|
33
|
+
"command": "fnode project -u",
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"label": "fnode-npm-update",
|
|
37
|
+
"type": "shell",
|
|
38
|
+
"command": "fnode npm update",
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"label": "fnode-npm-outdated",
|
|
42
|
+
"type": "shell",
|
|
43
|
+
"command": "fnode npm outdated",
|
|
44
|
+
}
|
|
45
|
+
]
|
|
46
|
+
}
|