@fnet/cli 0.2.4 → 0.2.6
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.js +1 -1
- package/dist/fnode/index.CJof4wXN.js +1 -0
- package/dist/fnode/index.DCuAwmrd.js +1 -0
- package/dist/fnode/{index.Dw-7V8tX.js → index.Vs3L-_fp.js} +1 -1
- package/dist/fnode/index.js +1 -1
- package/package.json +3 -4
- package/template/fnode/node/package.json.njk +0 -1
- package/template/fnode/node/src/cli/index.js.njk +3 -397
- package/template/fnode/node/src/cli/index.js.v1.njk +468 -0
- package/template/fnode/node/src/cli/v2/core/args-parser.njk +10 -0
- package/template/fnode/node/src/cli/v2/core/imports.njk +31 -0
- package/template/fnode/node/src/cli/v2/core/run-wrapper.njk +25 -0
- package/template/fnode/node/src/cli/v2/index.js.njk +184 -0
- package/template/fnode/node/src/cli/v2/modes/default/extend.njk +11 -0
- package/template/fnode/node/src/cli/v2/modes/default/standard.njk +19 -0
- package/template/fnode/node/src/cli/v2/modes/http/builtin.njk +61 -0
- package/template/fnode/node/src/cli/v2/modes/http/imports.njk +9 -0
- package/template/fnode/node/src/cli/v2/modes/http/index.njk +12 -0
- package/template/fnode/node/src/cli/v2/modes/mcp/imports.njk +27 -0
- package/template/fnode/node/src/cli/v2/modes/mcp/index.njk +30 -0
- package/template/fnode/node/src/cli/v2/modes/mcp/server-setup.njk +15 -0
- package/template/fnode/node/src/cli/v2/modes/mcp/tool-handlers.njk +41 -0
- package/template/fnode/node/src/cli/v2/modes/mcp/transport-http.njk +118 -0
- package/template/fnode/node/src/cli/v2/modes/mcp/transport-stdio.njk +9 -0
- package/template/fnode/node/src/cli/v2/modes/pipeline/imports.njk +9 -0
- package/template/fnode/node/src/cli/v2/modes/pipeline/index.njk +103 -0
- package/template/fnode/node/src/cli/v2/modes/webhook/imports.njk +9 -0
- package/template/fnode/node/src/cli/v2/modes/webhook/index.njk +122 -0
- package/template/fnode/node/src/cli/v2/modes/websocket/imports.njk +15 -0
- package/template/fnode/node/src/cli/v2/modes/websocket/index.njk +99 -0
- package/dist/fnode/index.1IxoA5DY.js +0 -1
- package/dist/fnode/index.DiENZV8H.js +0 -1
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
{# ============================================================================
|
|
2
|
+
WEBHOOK MODE - IMPLEMENTATION
|
|
3
|
+
============================================================================
|
|
4
|
+
Event-driven HTTP webhook server with HMAC signature verification
|
|
5
|
+
============================================================================ #}
|
|
6
|
+
|
|
7
|
+
if (cliMode === 'webhook') {
|
|
8
|
+
const port = args['cli-port'] || args.cli_port || 3000;
|
|
9
|
+
const webhookPath = args['webhook-path'] || args.webhook_path || '/webhook';
|
|
10
|
+
const webhookSecret = args['webhook-secret'] || args.webhook_secret || process.env.WEBHOOK_SECRET;
|
|
11
|
+
const signatureHeader = args['webhook-signature-header'] || args.webhook_signature_header || 'x-hub-signature-256';
|
|
12
|
+
|
|
13
|
+
const server = http.createServer(async (req, res) => {
|
|
14
|
+
// CORS headers
|
|
15
|
+
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
16
|
+
res.setHeader('Access-Control-Allow-Methods', 'POST, OPTIONS');
|
|
17
|
+
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, ' + signatureHeader);
|
|
18
|
+
|
|
19
|
+
// Handle OPTIONS preflight
|
|
20
|
+
if (req.method === 'OPTIONS') {
|
|
21
|
+
res.writeHead(200);
|
|
22
|
+
res.end();
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Only accept POST requests
|
|
27
|
+
if (req.method !== 'POST') {
|
|
28
|
+
res.writeHead(405, { 'Content-Type': 'application/json' });
|
|
29
|
+
res.end(JSON.stringify({ error: 'Method not allowed. Use POST.' }));
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Only accept webhook path
|
|
34
|
+
if (req.url !== webhookPath) {
|
|
35
|
+
res.writeHead(404, { 'Content-Type': 'application/json' });
|
|
36
|
+
res.end(JSON.stringify({ error: 'Not found. Use ' + webhookPath }));
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Read request body
|
|
41
|
+
let body = '';
|
|
42
|
+
req.on('data', chunk => {
|
|
43
|
+
body += chunk.toString();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
req.on('end', async () => {
|
|
47
|
+
try {
|
|
48
|
+
// Verify signature if secret is provided
|
|
49
|
+
if (webhookSecret) {
|
|
50
|
+
const signature = req.headers[signatureHeader.toLowerCase()];
|
|
51
|
+
|
|
52
|
+
if (!signature) {
|
|
53
|
+
res.writeHead(401, { 'Content-Type': 'application/json' });
|
|
54
|
+
res.end(JSON.stringify({ error: 'Missing signature header: ' + signatureHeader }));
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Calculate expected signature (HMAC-SHA256)
|
|
59
|
+
const hmac = crypto.createHmac('sha256', webhookSecret);
|
|
60
|
+
hmac.update(body);
|
|
61
|
+
const expectedSignature = 'sha256=' + hmac.digest('hex');
|
|
62
|
+
|
|
63
|
+
// Compare signatures (timing-safe)
|
|
64
|
+
const signatureBuffer = Buffer.from(signature);
|
|
65
|
+
const expectedBuffer = Buffer.from(expectedSignature);
|
|
66
|
+
|
|
67
|
+
if (signatureBuffer.length !== expectedBuffer.length ||
|
|
68
|
+
!crypto.timingSafeEqual(signatureBuffer, expectedBuffer)) {
|
|
69
|
+
res.writeHead(401, { 'Content-Type': 'application/json' });
|
|
70
|
+
res.end(JSON.stringify({ error: 'Invalid signature' }));
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Parse JSON payload
|
|
76
|
+
let payload;
|
|
77
|
+
try {
|
|
78
|
+
payload = JSON.parse(body);
|
|
79
|
+
} catch (e) {
|
|
80
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
81
|
+
res.end(JSON.stringify({ error: 'Invalid JSON payload' }));
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Process webhook with Core
|
|
86
|
+
const result = await Node(payload);
|
|
87
|
+
|
|
88
|
+
// Send response
|
|
89
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
90
|
+
res.end(JSON.stringify(result));
|
|
91
|
+
|
|
92
|
+
} catch (error) {
|
|
93
|
+
res.writeHead(500, { 'Content-Type': 'application/json' });
|
|
94
|
+
res.end(JSON.stringify({
|
|
95
|
+
error: error.message,
|
|
96
|
+
type: 'processing_error'
|
|
97
|
+
}));
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
req.on('error', (error) => {
|
|
102
|
+
res.writeHead(500, { 'Content-Type': 'application/json' });
|
|
103
|
+
res.end(JSON.stringify({
|
|
104
|
+
error: error.message,
|
|
105
|
+
type: 'request_error'
|
|
106
|
+
}));
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
server.listen(port, () => {
|
|
111
|
+
console.log(`Webhook server started on port ${port}`);
|
|
112
|
+
console.log(`Webhook endpoint: ${webhookPath}`);
|
|
113
|
+
if (webhookSecret) {
|
|
114
|
+
console.log(`Signature verification: enabled (header: ${signatureHeader})`);
|
|
115
|
+
} else {
|
|
116
|
+
console.log(`Signature verification: disabled (no secret provided)`);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{# ============================================================================
|
|
2
|
+
WEBSOCKET MODE - IMPORTS
|
|
3
|
+
============================================================================
|
|
4
|
+
WebSocket server dependencies using 'ws' library
|
|
5
|
+
Supports both ESM and CJS formats
|
|
6
|
+
============================================================================ #}
|
|
7
|
+
|
|
8
|
+
{% if atom.doc.features.project.format==='esm' %}
|
|
9
|
+
// Using ws library for WebSocket mode
|
|
10
|
+
import { WebSocketServer } from 'ws';
|
|
11
|
+
{% elif atom.doc.features.project.format==='cjs' %}
|
|
12
|
+
// Using ws library for WebSocket mode
|
|
13
|
+
const { WebSocketServer } = require('ws');
|
|
14
|
+
{% endif %}
|
|
15
|
+
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
{# ============================================================================
|
|
2
|
+
WEBSOCKET MODE - MAIN
|
|
3
|
+
============================================================================
|
|
4
|
+
WebSocket server for real-time bidirectional communication
|
|
5
|
+
Supports connection handling, message processing, and heartbeat
|
|
6
|
+
============================================================================ #}
|
|
7
|
+
|
|
8
|
+
if (cliMode === 'websocket') {
|
|
9
|
+
// WebSocket mode code
|
|
10
|
+
const port = args['cli-port'] || args.cli_port || 3000;
|
|
11
|
+
const heartbeat = args['ws-heartbeat'] || args.ws_heartbeat || 30000; // 30 seconds default
|
|
12
|
+
|
|
13
|
+
const wss = new WebSocketServer({ port });
|
|
14
|
+
|
|
15
|
+
// Store active connections
|
|
16
|
+
const clients = new Set();
|
|
17
|
+
|
|
18
|
+
wss.on('connection', (ws) => {
|
|
19
|
+
console.log('WebSocket client connected');
|
|
20
|
+
clients.add(ws);
|
|
21
|
+
|
|
22
|
+
// Set up heartbeat
|
|
23
|
+
ws.isAlive = true;
|
|
24
|
+
ws.on('pong', () => {
|
|
25
|
+
ws.isAlive = true;
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
// Handle incoming messages
|
|
29
|
+
ws.on('message', async (data) => {
|
|
30
|
+
try {
|
|
31
|
+
// Parse message
|
|
32
|
+
const message = data.toString();
|
|
33
|
+
let input;
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
input = JSON.parse(message);
|
|
37
|
+
} catch (e) {
|
|
38
|
+
// If not JSON, wrap in object
|
|
39
|
+
input = { data: message };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Validate input
|
|
43
|
+
// TODO: Add schema validation if needed
|
|
44
|
+
|
|
45
|
+
// Process with Core
|
|
46
|
+
const result = await Node(input);
|
|
47
|
+
|
|
48
|
+
// Send response back to client
|
|
49
|
+
ws.send(JSON.stringify(result));
|
|
50
|
+
|
|
51
|
+
} catch (error) {
|
|
52
|
+
// Send error to client
|
|
53
|
+
ws.send(JSON.stringify({
|
|
54
|
+
error: error.message,
|
|
55
|
+
type: 'processing_error'
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// Handle client disconnect
|
|
61
|
+
ws.on('close', () => {
|
|
62
|
+
console.log('WebSocket client disconnected');
|
|
63
|
+
clients.delete(ws);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// Handle errors
|
|
67
|
+
ws.on('error', (error) => {
|
|
68
|
+
console.error('WebSocket error:', error.message);
|
|
69
|
+
clients.delete(ws);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// Heartbeat interval
|
|
74
|
+
if (heartbeat > 0) {
|
|
75
|
+
const interval = setInterval(() => {
|
|
76
|
+
wss.clients.forEach((ws) => {
|
|
77
|
+
if (ws.isAlive === false) {
|
|
78
|
+
console.log('Terminating inactive client');
|
|
79
|
+
return ws.terminate();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
ws.isAlive = false;
|
|
83
|
+
ws.ping();
|
|
84
|
+
});
|
|
85
|
+
}, heartbeat);
|
|
86
|
+
|
|
87
|
+
wss.on('close', () => {
|
|
88
|
+
clearInterval(interval);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
console.log(`WebSocket server started on port ${port}`);
|
|
93
|
+
if (heartbeat > 0) {
|
|
94
|
+
console.log(`Heartbeat interval: ${heartbeat}ms`);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import e from"node:fs";import t from"node:path";import{randomUUID as i}from"node:crypto";import o from"yaml";import a from"nunjucks";import s from"chalk";import{Api as r,Atom as n}from"@flownet/lib-atom-api-js";import c from"@fnet/config";import d from"@fnet/list-files";import l from"@fnet/yaml";class p{init({config:e,accessToken:t}){return new Promise(((i,o)=>{if(r.set_api_url(e.data.url),t)return r.set_req_token(t),void i(t);fetch(`${e.data.issuer}/protocol/openid-connect/token`,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams(e.data.grant.params)}).then((async e=>{if(!e.ok)throw new Error(await e.text());return e.json()})).then((e=>{r.set_req_token(e.access_token),i(e.access_token)})).catch((e=>{r.set_req_token(),o(e)}))}))}}var m=async e=>{const{atom:t,packageDependencies:i,context:o,deploymentProjectTarget:a,setProgress:s,deploymentProject:r,yamlTarget:n}=e;if(!0!==a.enabled)return;const c=a.type;try{if("lib"===c)await(await import("./index.DG8TqL-1.js")).default({...e});else if("red"===c)await(await import("./index.CmMM-Ek9.js")).default({...e});else if("npm"===c)await(await import("./index.N_a5FdgA.js")).default({...e});else if("gcs"===c)await(await import("./index.Bft2w7m3.js")).default({...e});else if("gitlab"===c)await(await import("./index.DI3yyTtl.js")).default({...e});else if("fnet-package"===c)await(await import("./index.D3p7pncT.js")).default({...e});else if("fnet-form"===c)await(await import("./index.Q-CYRcna.js")).default({...e});else if("fnet-node"===c)await(await import("./index.C2S9JYhS.js")).default({...e});else if("fnet-flow"===c)await(await import("./index.BuYxdKtK.js")).default({...e});else if("nextjs"===c)await(await import("./index.CDct_kkF.js")).default({atom:t,target:a,onProgress:s,projectDir:o.projectDir,dependencies:i,context:o,yamlTarget:n}),r.isDirty=!0;else if("webos"===c)await(await import("./index.CMC8mlye.js")).default({atom:t,target:a,onProgress:s,projectDir:o.projectDir,dependencies:i,context:o,yamlTarget:n}),r.isDirty=!0;else if("electron"===c)await(await import("./index.xd8c7XMr.js")).default({atom:t,target:a,onProgress:s,projectDir:o.projectDir,dependencies:i,context:o,yamlTarget:n}),r.isDirty=!0;else if("docker"===c)await(await import("./index.D2N9YZmA.js")).default({atom:t,target:a,onProgress:s,projectDir:o.projectDir,dependencies:i,context:o,yamlTarget:n}),r.isDirty=!0;else if("ios"===c)await(await import("./index.B5XE4ChJ.js")).default({atom:t,target:a,onProgress:s,projectDir:o.projectDir,dependencies:i,context:o,yamlTarget:n}),r.isDirty=!0;else if("macos"===c)await(await import("./index.W6RYgypK.js")).default({atom:t,target:a,onProgress:s,projectDir:o.projectDir,dependencies:i,context:o,yamlTarget:n}),r.isDirty=!0;else if("rust"===c)await(await import("./index.CzAV0S36.js")).default({atom:t,target:a,onProgress:s,projectDir:o.projectDir,dependencies:i,context:o,yamlTarget:n}),r.isDirty=!0;else{if("pypi"!==c)return void console.warn(`No deployer found for type: ${c}`);await(await import("./index.C7saWH6d.js")).default({atom:t,target:a,onProgress:s,projectDir:o.projectDir,dependencies:i,context:o,yamlTarget:n}),r.isDirty=!0}}catch(e){throw console.error(`Error during deployment for type "${c}":`,e),e}};class g{#e;#t;#i;#o;#a;#s;#r;#n;#c;#d;#l;#p;#m;#g;#h;#f;#y;constructor(e){this.#e=new p,this.#t=e,this.#s=[],this.#r=[],this._expire_ttl=3600,this._expire_ttl_short=300,this.#y={packageDependencies:this.#s,packageDevDependencies:this.#r,setProgress:this.setProgress.bind(this),context:this.#t,Atom:n,registerToPackageManager:this.registerToPackageManager.bind(this)}}get apiContext(){return this.#y}get context(){return this.#t}get atom(){return this.#i}get libs(){return this.#a}set libs(e){this.#a=e}get fileMode(){return this.#g}get buildMode(){return this.#h}get deployMode(){return this.#f}async _cache_set(e,t,i){}async initAuth(){this.#t.id&&(this.#n=await this.#e.init({config:this.#p}),this.#y.atomAccessToken=this.#n)}async initLibrary(){const e=this.#t.id;this.#i=this.#t.project?.libraryAtom||await n.get({id:e});let t=this.#i.doc.bundleName;t=t||(this.#i.doc.name||"").toUpperCase().replace(/[^A-Z0-9]/g,"_"),this.#i.doc.bundleName=t,this.#i.type=this.#i.type||"workflow.lib",this.#y.atom=this.#i}async initLibraryDir(){this.setProgress({message:"Initializing library directory."});const i=this.#t.projectDir;this.setProgress({message:"Cleaning project directory."});const o=d({dir:i,ignore:[".cache","node_modules",".conda",".bin"],absolute:!0});for(const t of o)e.rmSync(t,{recursive:!0,force:!0});this.setProgress({message:"Creating project directory."});let a=i;e.existsSync(a)||e.mkdirSync(a,{recursive:!0}),a=t.join(i,"src"),e.existsSync(a)||e.mkdirSync(a,{recursive:!0}),a=t.join(i,"src","default"),e.existsSync(a)||e.mkdirSync(a,{recursive:!0})}async initNunjucks(){this.setProgress({message:"Initializing nunjucks."});const e=this.#t.templateDir;this.#o=a.configure(e,{watch:!1,dev:!0}),this.#y.njEnv=this.#o}async createProjectYaml(){const i="fnode.yaml",a=`Creating ${i}`;await this.setProgress({message:a});const{content:s,...r}=this.#i.doc,n=this.#t.projectDir,c=t.resolve(n,`${i}`);e.writeFileSync(c,o.stringify(r),"utf8")}async deploy(){if(await this.setProgress({message:"Deploying."}),this.#t.project?.devops){const e=[this.#t.project?.devops];for(let t=0;t<e.length;t++){let i=e[t];await this.deployProject({deploymentProject:i}),!0===i.isDirty&&await i.save()}}else if(this.#i.id){const e=await n.list({type:"library.deploy",parent_id:this.#i.id});for(let t=0;t<e.length;t++){let i=e[t];await this.deployProject({deploymentProject:i}),!0===i.isDirty&&(i=await n.update(i,{id:i.id}))}}}async deployProject(e){const{deploymentProject:t}=e,{yamlDocument:i}=t;if(t.doc.targets&&Array.isArray(t.doc.targets))throw new Error("Deployment project targets are deprecated. Please update targets in the yaml file.");const o=Object.keys(t.doc||{}),a=i||{};for(let e=0;e<o.length;e++){const i=t.doc[o[e]];i.name=o[e];const s=a.get(o[e]);await m({...this.#y,deploymentProject:t,deploymentProjectTarget:i,yamlTarget:s})}}async registerToPackageManager(e){const{target:t,packageJSON:i}=e;if(!this.#t.id)return;let o=await n.first({name:t.params.name,parent_id:this.#p.env.ATOM_PACKAGES_ID});o?(o.doc.versions.splice(0,0,{v:i.version}),await n.update(o,{id:o.id})):o=await n.create({parent_id:this.#p.env.ATOM_PACKAGES_ID,doc:{name:t.params.name,type:"pm",versions:[{v:i.version}]}})}async setProgress(e){const t="string"==typeof e?e:e?.message;console.log(s.blue(t)),await this._cache_set(this.#d,{status:"IN_PROGRESS",message:t})}async init(){this.#c=this.#t.buildId||i(),this.#y.buildId=this.#c,this.#m=this.#t.mode,this.#g=["all","deploy","build","file"].includes(this.#m),this.#h=["all","deploy","build"].includes(this.#m),this.#f=["all","deploy"].includes(this.#m),this.#l=this.#t.protocol,this.#d="BUILD:"+this.#c,this.#p=(await c({optional:!0,name:this.#t.atomConfig||"atom",dir:this.#t.projectDir,tags:this.#t.tags}))?.data;try{await this.setProgress({message:"Initialization started."}),await this.initAuth(),await this.initLibrary(),await this.initRuntime()}catch(e){throw await this._cache_set(this.#d,{status:"FAILED",message:e?.message||e}),e}}async initRuntime(){throw new Error("initRuntime method must be implemented by runtime-specific builder")}async build(){throw new Error("build method must be implemented by runtime-specific builder")}}async function h({atom:i,setProgress:o,context:s,packageDependencies:r}){await o({message:"Creating .gitignore"});const n={atom:i,packageDependencies:r},c=s.templateDir,d=a.compile(e.readFileSync(t.resolve(c,".gitignore.njk"),"utf8"),a.configure(c)).render(n),l=s.projectDir,p=t.resolve(l,".gitignore");e.writeFileSync(p,d,"utf8")}async function f({atom:i,context:o,setProgress:s,Atom:r}){const n="readme.md",c=`Creating ${n}`;if(await s({message:c}),o.project?.readme){const i=o.projectDir,s={content:o.project.readme.doc.content},r=t.resolve(o.project.projectDir,"fnet/how-to.md");if(e.existsSync(r)){const t=e.readFileSync(r,"utf8");s.howto=t}const c=t.resolve(o.project.projectDir,"fnet/input.yaml");if(e.existsSync(c)){const e=await l({file:c,tags:o.tags});s.input=e.content}const d=t.resolve(o.project.projectDir,"fnet/output.yaml");if(e.existsSync(d)){const e=await l({file:d,tags:o.tags});s.output=e.content}const p=o.templateDir,m=a.compile(e.readFileSync(t.resolve(p,`${n}.njk`),"utf8"),a.configure(p)).render(s),g=t.resolve(i,`${n}`);e.writeFileSync(g,m,"utf8")}else if(i.id){const s=await r.first({type:"wiki",parent_id:i.id});if(!s||"markdown"!==s.doc?.["content-type"])return;const{content:c,...d}=s.doc,l={content:c},p=o.templateDir,m=a.compile(e.readFileSync(t.resolve(p,`${n}.njk`),"utf8"),a.configure(p)).render(l),g=o.projectDir,h=t.resolve(g,`${n}`);e.writeFileSync(h,m,"utf8")}}export{g as B,h as a,f as c};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import e from"node:fs";import t from"node:path";import i from"node:os";import a from"@fnet/list-files";import{B as s,c as n,a as r}from"./index.1IxoA5DY.js";import o from"@flownet/lib-render-templates-dir";import c from"@fnet/auto-conda-env";import"node:crypto";import"yaml";import"nunjucks";import"chalk";import"@flownet/lib-atom-api-js";import"@fnet/config";import"@fnet/yaml";class p extends s{async initRuntime(){await async function(e){const{atom:t,context:i,setProgress:a}=e;a("Initializing features..."),t.doc.features=t.doc.features||{};const s=t.doc.features;!1===s.cli?s.cli={enabled:!1}:(s.cli,s.cli={enabled:!0}),s.cli.enabled=!0===s.cli.enabled&&(!1===t.doc.features.form_enabled||!0===s.cli.extend||!0===s.cli.enabled)}(this.apiContext),await async function({atom:e,packageDependencies:t,packageDevDependencies:i,setProgress:a}){a("Initializing dependencies")}(this.apiContext),await this.initLibraryDirPython(),await this.initNunjucks(),await this.initLibsPython()}async initLibraryDirPython(){this.setProgress({message:"Initializing library directory."});const s=this.context.projectDir;this.setProgress({message:"Cleaning project directory."});const n=a({dir:s,ignore:[".cache","node_modules",".conda",".bin"],absolute:!0});for(const t of n)e.rmSync(t,{recursive:!0,force:!0});this.setProgress({message:"Creating project directory."});let r=s;e.existsSync(r)||e.mkdirSync(r,{recursive:!0}),r=t.join(s,"src"),e.existsSync(r)||e.mkdirSync(r,{recursive:!0}),r=t.join(s,"src","default");const o=this.context.projectSrcDir;if(!e.existsSync(r))try{"win32"===i.platform()?e.symlinkSync(o,r,"junction"):e.symlinkSync(o,r,"dir")}catch(e){throw new Error(`Couldn't create symlink. Error: ${e.message}`)}}async initLibsPython(){this.setProgress({message:"Initializing external libs."});const e=this.atom;e.protocol="src:",e.doc.dependencies=e.doc.dependencies||[],e.name=e.doc.name;const t=[{name:this.atom.doc.name,type:"atom",parent_id:this.atom.parent_id,atom:e}];this.libs=t}async createAtomLibFilesPython({libs:i}){await this.setProgress({message:"Creating external lib files."});const a=i.filter((e=>"atom"===e.type));for(let i=0;i<a.length;i++){const s=a[i].atom;if("src:"===s.protocol){const i=t.resolve(this.context.projectSrcDir,`${s.fileName||s.name}.py`);if(!e.existsSync(i)){e.mkdirSync(t.dirname(i),{recursive:!0});let a="def default():\n";a+=' print("Hello world!")\n',e.writeFileSync(i,a,"utf8")}}}}async build(){try{this.fileMode&&(await this.createAtomLibFilesPython({libs:this.libs}),await this.createProjectYaml(),await n(this.apiContext),await r(this.apiContext),await async function({atom:i,setProgress:a,context:s,packageDependencies:n}){if(!0!==i.doc.features.cli.enabled)return;await a({message:"Creating cli."});const r={atom:i,packageDependencies:n},c=s.templateDir,p=t.join(s.projectDir,"src","cli");e.existsSync(p)||e.mkdirSync(p,{recursive:!0}),await o({pattern:["index.py.njk","__init__.py.njk"],dir:t.join(c,"src","cli"),outDir:p,context:r})}(this.apiContext),this.buildMode&&(await async function(e){const{setProgress:i,atom:a,context:s}=e;i({message:"Installing Python packages"});const n=s.projectDir,r=await c({pythonVersion:"3.12",packages:[{package:"fnet-import-parser",version:"0.1.9"}]}),{errors:p,result:l}=await r.runBin("fnet_import_parser",["--entry_file",t.join(n,"src","default","index.py")],{captureName:"result"});if(p)throw new Error(p.format());const d=JSON.parse(l.items[0].stdout),m=d.required["third-party"]?.map((e=>({package:e.metadata?.package||e.path,version:e.metadata?.version||void 0,channel:e.metadata?.channel||void 0})))||[],y=a.doc.dependencies||[];for(const e of m)y.some((t=>t.package===e.package))||y.push(e);const h=t.join(n,".conda"),f=await c({envDir:h,pythonVersion:a.doc.features.runtime.version||"3.12",packages:y});s.pythonEnv=f,e.packageDependencies=y;const u=a.doc.features.render?.dirs||[];for(const e of u)e.dir=t.resolve(n,e.dir),e.outDir=t.resolve(n,e.outDir),await o(e);let g={params:{}};g.params.package_name=a.doc.name,g.params.version="0.1.0",g.params.bin_name=a.doc.name,g.params.python_requires=a.doc.features.runtime.version||">=3.12",g.params.dependencies=y,g.params.scripts=JSON.stringify({cli:`PYTHONPATH='${t.join("src")}' '${t.relative(s.projectDir,f.pythonBin)}' '${t.join("src","cli","index.py")}'`}),await o({pattern:["setup.py.njk","package.json.njk","pyproject.toml.njk"],dir:s.templateDir,outDir:s.projectDir,context:g})}(this.apiContext),this.deployMode&&await this.deploy())),await this._cache_set(this.buildKey,{status:"COMPLETED"})}catch(e){throw await this._cache_set(this.buildKey,{status:"FAILED",message:e.message||e}),console.log(e),e}}}export{p as default};
|