@fnet/cli 0.111.1 → 0.112.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.DBSKvJyG.js → index.B3bzhxbL.js} +1 -1
- package/dist/fnet/index.js +1 -1
- package/dist/fnode/index.B_EoIJV1.js +1 -0
- package/dist/fnode/{index.CLlKzCGk.js → index.CLPC6OJN.js} +1 -1
- package/dist/fnode/index.D5QuQuJX.js +1 -0
- package/dist/fnode/index.axpuK8O5.js +1 -0
- package/dist/fnode/index.js +1 -1
- package/dist/fnode/index.teSOwugt.js +1 -0
- package/dist/fnode/index.uvOH1EJS.js +1 -0
- package/package.json +5 -4
- package/{README.md → readme.md} +115 -9
- package/template/fnet/node/package.json.njk +4 -3
- package/template/fnode/bun/build.js.njk +1 -1
- package/template/fnode/bun/package.json.njk +3 -1
- package/template/fnode/node/package.json.njk +4 -3
- package/template/fnode/project/fnode.yaml.njk +1 -1
- package/dist/fnode/index.53yND1Av.js +0 -1
- package/dist/fnode/index.B1zLg4Y2.js +0 -1
- package/dist/fnode/index.B2LXSSn7.js +0 -1
- package/dist/fnode/index.BBrItYB9.js +0 -1
- package/dist/fnode/index.BSQp_bJN.js +0 -1
- package/dist/fnode/index.Bqzc7Bx8.js +0 -1
- package/dist/fnode/index.BwhWziH6.js +0 -1
- package/dist/fnode/index.Chvv_TJm.js +0 -1
- package/dist/fnode/index.D4KQB1ot.js +0 -1
- package/dist/fnode/index.DItyYiZ_.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"node:fs";import t from"node:path";import a from"nunjucks";import s from"@flownet/lib-parse-imports-js";import o from"@flownet/lib-parse-node-url";import{B as i,c as r,a as n}from"./index.D5QuQuJX.js";import p from"lodash.merge";import{f as l,i as c,a as d,b as u,c as f,d as b,p as m,e as g,g as _,h,j as y,k as w,l as x,m as v,r as k}from"./index.CLPC6OJN.js";import j from"@fnet/npm-list-versions";import D from"@fnet/shelljs";import"node:crypto";import"yaml";import"chalk";import"@flownet/lib-atom-api-js";import"@fnet/config";import"@fnet/list-files";import"redis";import"@flownet/lib-is-redis-online";import"@fnet/yaml";import"@flownet/lib-render-templates-dir";import"@fnet/npm-pick-versions";import"object-hash";import"ajv/dist/2020.js";import"ajv/dist/standalone/index.js";import"ajv-formats";import"./index.js";import"node:url";import"node:child_process";import"node:os";import"yargs";import"@fnet/prompt";import"node:util";import"tree-kill";function C({dir:a,name:s="index"}){let o=t.resolve(a,`./${s}.tsx`);if(e.existsSync(o)||(o=t.resolve(a,`./${s}.ts`)),e.existsSync(o)||(o=t.resolve(a,`./${s}.jsx`)),e.existsSync(o)||(o=t.resolve(a,`./${s}.js`)),!e.existsSync(o))return{};const i=o,r=t.extname(o);return{file:i,ext:r,ts:".ts"===r||".tsx"===r,name:s}}async function S(e){const{atom:a,context:o,setProgress:i}=e;i("Initializing features..."),a.doc.features=a.doc.features||{};const r=a.doc.features;r.project=r.project||{},r.project.format=r.project.format||r.project_format||"esm",r.project_format=r.project.format,r.dts_enabled=!0===r.dts||void 0!==r.dts&&!1!==r.dts;const n=t.resolve(o.project.projectDir),m=C({dir:t.resolve(n,"./app")});if(m.file){i("Parsing app entry imports...");let e=await s({file:m.file,recursive:!0}),t=e.all.some((e=>!0===e.usesJSX&&"local"===e.type));r.app_uses_jsx=t,r.app_has_entry=!0,e=await s({file:m.file}),t=e.all.some((e=>!0===e.usesJSX&&"local"===e.type)),r.app_entry_uses_jsx=t,r.app_entry_is_ts=m.ts,r.app_entry_ext=m.ext}const g=C({dir:t.resolve(n,"./cli")});if(g.file){i("Parsing cli entry imports...");let e=await s({file:g.file,recursive:!0}),t=e.all.some((e=>!0===e.usesJSX&&"local"===e.type));r.cli_uses_jsx=t,r.cli_has_entry=!0,e=await s({file:g.file}),t=e.all.some((e=>!0===e.usesJSX&&"local"===e.type)),r.cli_entry_uses_jsx=t,r.cli_entry_is_ts=g.ts,r.cli_entry_ext=g.ext}if("workflow.lib"===a.type){const e=C({dir:t.resolve(n,"./src")});if(e.file){i("Parsing src entry imports...");let t=await s({file:e.file,recursive:!0}),a=t.all.some((e=>!0===e.usesJSX&&"local"===e.type));r.src_uses_jsx=a,r.src_has_entry=!0,t=await s({file:e.file}),a=t.all.some((e=>!0===e.usesJSX&&"local"===e.type)),r.src_entry_uses_jsx=a,r.src_entry_is_ts=e.ts,r.src_entry_ext=e.ext}}const _=Reflect.has(r,"app_entry_uses_jsx")?!0===r.app_entry_uses_jsx:!0===r.src_entry_uses_jsx,h=Reflect.has(r,"cli_entry_uses_jsx")?!0===r.cli_entry_uses_jsx:!0===r.src_entry_uses_jsx;r.form_enabled=_||h||!0===r.form||!0===r.form?.enabled,r.multiple_enabled=r.multiple_enabled||!0===r.multiple||!0===r.multiple?.enabled,!1===r.app?r.app={enabled:!1}:!0===r.app?r.app={enabled:!0,extend:!0===r.app_has_entry,export:!0,react:_}:r.app={enabled:!0,extend:!0===r.app_has_entry,export:!0,react:_,...r.app||{}},r.app.enabled=!0===r.app.enabled&&(!0===a.doc.features.form_enabled||!0===r.app.extend||!0===r.app.enabled),r.app.format=r.app.format||"esm",r.app.folder=r.app.folder||r.app.format||"default",!1===r.cli?r.cli={enabled:!1}:!0===r.cli?r.cli={enabled:!0,extend:!0===r.cli_has_entry,export:!0,react:h}:r.cli={enabled:!0,extend:!0===r.cli_has_entry,export:!0,react:h,...r.cli||{}},r.cli.enabled=!0===r.cli.enabled&&(!1===a.doc.features.form_enabled||!0===r.cli.extend||!0===r.cli.enabled),r.cli.format=r.cli.format||"esm",r.cli.folder=r.cli.folder||r.cli.folder||"esm",r.cli.node_options=r.cli.node?.options||r.cli.node_options||"",r.cli.bin=r.cli.bin||a.doc.name,r.cli.installable=!0===r.cli.installable,r.cli.enabled&&(a.doc["npm::bin"]=r.cli.bin,console.log(`Setting npm::bin to ${r.cli.bin} from features.cli.bin`)),r.json=r.cli.enabled||r.json;const y={cjs:{format:"cjs",context:r.form_enabled?"window":"global",babel:!0===r.src_uses_jsx||!1,browser:!1,replace:!0,terser:!0,enabled:!1!==r.cjs,copy:!1},esm:{format:"esm",context:r.form_enabled?"window":"global",babel:!0===r.src_uses_jsx||!1,browser:!1,replace:!0,terser:!1,enabled:!1!==r.esm,copy:!0},iife:{format:"iife",context:r.form_enabled?"window":"global",babel:!0,browser:!0,replace:!0,enabled:!0===r.iife,terser:!0,copy:!1}};!0===r.webos&&(y.webos={format:"iife",browser:!0,babel:!0,context:"window",replace:!0,terser:!0,input:"./src/app/index.js",output_dir:"./dist/app/webos",copy:!1,babel_options:{targets:{chrome:"79"}}}),!0===r.electron&&(y.electron={format:"iife",browser:!0,babel:!0,context:"window",replace:!0,terser:!0,copy:!1,input:"./src/app/index.js",output_dir:"./dist/app/electron"}),!0===r.nextjs&&(y.nextjs={format:"esm",browser:!0,babel:!0,context:"window",replace:!0,terser:!0,copy:!1,input:"./src/app/index.js",output_dir:"./dist/app/nextjs"}),!0===r.ios&&(y.ios={format:"iife",browser:!0,babel:!0,context:"window",replace:!0,terser:!0,copy:!1,input:"./src/app/index.js",output_dir:"./dist/app/ios"}),!0===r.macos&&(y.macos={format:"iife",browser:!0,babel:!0,context:"window",replace:!0,terser:!0,copy:!1,input:"./src/app/index.js",output_dir:"./dist/app/macos"}),!0===r.app.enabled&&(r.app.dir=`./dist/app/${r.app.folder}`,y.app={format:r.app.format,browser:!0,babel:!0,context:"window",replace:!0,input:"./src/app/index.js",output_dir:r.app.dir,terser:!0,output_exports:!1===r.app.export?"none":"auto",browsersync:!0}),!0===r.cli.enabled&&(r.cli.dir=`./dist/cli/${r.cli.folder}`,y.cli={format:r.cli.format,context:"global",babel:!0===r.src_uses_jsx||!0===r.cli_uses_jsx||!1,browser:!1,replace:!0,enabled:!0,input:"./src/cli/index.js",output_dir:r.cli.dir,banner:"#!/usr/bin/env node",terser:!0,output_exports:!1===r.cli.export?"none":"auto"});const w={server:".",startPath:`${t.normalize(r.app.dir||".")}`,files:[t.normalize("./dist/**/*")],cors:!0,open:!1};r.babel_options=p({targets:{browsers:"last 9 versions, not dead",node:"18"}},r.babel_options||r.babel?.options),r.browsersync_options=p(w,r.browsersync_options||r.browsersync?.options||{}),r.replace_options=p({},r.replace_options||r.replace?.options||{}),Reflect.has(r.browsersync_options,"proxy")&&delete r.browsersync_options.server,r.rollup=r.rollup||{},r.rollup_output=p(y,r.rollup_output||r.rollup?.output||{}),r.preact_enabled=!0===r.preact||r.preact&&!1!==r.preact?.enabled;let x=Object.keys(y);for(const e of x){const t=y[e];t&&(!1!==r.rollup[e]?(t.babel_options=t.babel_options||r.babel_options,t.browsersync_options=p(r.browsersync_options,t.browsersync_options),t.replace_options=p(r.replace_options,t.replace_options),r.preact_enabled&&(t.alias_enabled=!0,t.alias=t.alias||{},t.alias.entries=t.alias.entries||{},t.alias.entries.react="preact/compat",t.alias.entries["react-dom"]="preact/compat"),(r.form_enabled||r.babel)&&(t.babel=!0)):delete r.rollup_output[e])}x=Object.keys(r.rollup_output),r.babel_enabled=x.some((e=>!0===r.rollup_output[e].babel)),r.browser_enabled=x.some((e=>!0===r.rollup_output[e].babel)),r.browsersync_enabled=!1!==r.browsersync&&x.some((e=>!0===r.rollup_output[e].browsersync)),r.browsersync_enabled=r.browsersync_enabled&&r.app.enabled,r.dependency_auto_enabled=!1!==r.dependency_auto&&!1!==r.dependency_auto?.enabled,r.npm_install_flags=r.npm_install_flags||"",r.react_version=r.react_version||r.react?.version||18,c(e),d(e),function(e){const{atom:t,packageDevDependencies:a}=e,s=t.doc.features;l({feature:{name:"wasm",packages:[["@rollup/plugin-wasm","^6"]]},features:s,packageDevDependencies:a})}(e),function(e){const{atom:t,packageDevDependencies:a}=e,s=t.doc.features;l({feature:{name:"terser",packages:[["@rollup/plugin-terser","^0.4"]]},features:s,packageDevDependencies:a})}(e),u(e),f(e),b(e),function(e){const{atom:t,packageDevDependencies:a}=e,s=t.doc.features;l({feature:{name:"analyzer",packages:[["rollup-plugin-analyzer","^3"]],options:{summaryOnly:!0,limit:12},explicit:!0},features:s,packageDevDependencies:a})}(e),function(e){const{atom:t,packageDevDependencies:a}=e,s=t.doc.features;l({feature:{name:"visualizer",packages:[["rollup-plugin-visualizer","^5"]]},features:s,packageDevDependencies:a})}(e),function(e){const{atom:t,packageDevDependencies:a}=e,s=t.doc.features;l({feature:{name:"polyfill",packages:[["rollup-plugin-node-polyfills","^0.2"]]},features:s,packageDevDependencies:a})}(e),function(e){const{atom:t,packageDevDependencies:a}=e,s=t.doc.features;l({feature:{name:"nunjucks",packages:[["@fnet/rollup-plugin-nunjucks","0.1.8"]]},features:s,packageDevDependencies:a})}(e),function(e){const{atom:t,packageDevDependencies:a}=e,s=t.doc.features;l({feature:{name:"workbox",packages:[["rollup-plugin-workbox","^8"]],options:{generate:{swDest:"dist/app/esm/sw.js",globDirectory:"dist/app/esm",globPatterns:["**/*.{html,js,css,png,jpg}"],skipWaiting:!0,clientsClaim:!0}},explicit:!0},features:s,packageDevDependencies:a})}(e),function(e){const{atom:t,packageDevDependencies:a}=e,s=t.doc.features;l({feature:{name:"gzip",packages:[["rollup-plugin-gzip","^4"]],explicit:!0},features:s,packageDevDependencies:a})}(e)}class A extends i{async initRuntime(){await S(this.apiContext),await async function({atom:e,packageDependencies:t,packageDevDependencies:a,setProgress:s}){s("Initializing dependencies");const o=e.doc.dependencies||[];if(o.filter((e=>!e.dev)).forEach((e=>t.push(e))),o.filter((e=>e.dev)).forEach((e=>a.push(e))),"workflow"===e.type&&(t.push({package:"get-value",version:"^3"}),t.push({package:"set-value",version:"^4"})),e.doc.features.form_enabled&&e.doc.features.dependency_auto_enabled){let a="^18.2";s("Fetching React versions"),a=`^${(await j({name:"react",groupBy:{major:!0}})).find((t=>t[0]===e.doc.features.react_version.toString()))[0]}`,t.push({package:"react",version:a}),t.push({package:"react-dom",version:a}),"workflow"===e.type&&(t.push({package:"@fnet/react-app",version:"^0.1"}),t.push({package:"@fnet/react-app-state",version:"^0.1"}))}e.doc.features.preact_enabled&&t.push({package:"preact",version:"^10"}),!0===e.doc.features.cli.enabled&&(t.push({package:"@fnet/args",version:"^0.1"}),a.push({package:"ajv",version:"^8"}),e.doc.features.cli.fargs&&!1!==e.doc.features.cli.fargs?.enabled&&t.push({package:"@fnet/config",version:"0.2.21"})),e.doc.features.render&&!1!==e.doc.features.render.enabled&&a.push({package:"@flownet/lib-render-templates-dir",version:"0.1.19"}),a.push({package:"@babel/core",version:"^7"}),a.push({package:"@rollup/plugin-commonjs",version:"^28"}),a.push({package:"@rollup/plugin-node-resolve",version:"^16"}),a.push({package:"@rollup/plugin-replace",version:"^6"}),a.push({package:"rollup",version:"^4"}),e.doc.features.dts_enabled&&a.push({package:"rollup-plugin-dts",version:"^6"}),a.push({package:"rollup-plugin-peer-deps-external",version:"^2"}),a.push({package:"@rollup/plugin-alias",version:"^5"}),a.push({package:"fs-extra",version:"^11"}),e.doc.features.babel_enabled&&(a.push({package:"@rollup/plugin-babel",version:"^6"}),a.push({package:"@babel/preset-env",version:"^7"}),a.push({package:"@babel/preset-react",version:"^7"}),e.doc.features.babel?.options?.plugins?.forEach((e=>{switch(e[0]){case"@babel/plugin-proposal-decorators":a.push({package:"@babel/plugin-proposal-decorators",version:"^7"});break;case"@babel/plugin-proposal-class-properties":a.push({package:"@babel/plugin-proposal-class-properties",version:"^7"});break;case"@babel/plugin-proposal-private-methods":a.push({package:"@babel/plugin-proposal-private-methods",version:"^7"});break;case"@babel/plugin-proposal-private-property-in-object":a.push({package:"@babel/plugin-proposal-private-property-in-object",version:"^7"});break;case"@babel/plugin-proposal-optional-chaining":a.push({package:"@babel/plugin-proposal-optional-chaining",version:"^7"})}}))),a.push({package:"@fnet/rollup-plugin-delete",version:"0.1.10"}),e.doc.features.browsersync_enabled&&a.push({package:"@fnet/rollup-plugin-browsersync",version:"0.1.11"})}(this.apiContext),await this.initLibraryDir(),await this.initNunjucks(),await this.initLibs()}async initLibs(){this.setProgress({message:"Initializing external libs."});const e=[{name:this.atom.doc.name,type:"atom",parent_id:this.atom.parent_id}];this.libs=e,await this.initAtomLibsAndDeps({libs:e,packageDependencies:this.apiContext.packageDependencies})}async initAtomLibsAndDeps({libs:e,packageDependencies:t}){const a=e.filter((e=>"atom"===e.type));for(let e=0;e<a.length;e++){const s=a[e],o=await this.findAtomLibrary({url:s.name});s.atom=o;const i=o.doc.dependencies?.filter((e=>void 0===e.repo||"npm"===e.repo));i?.forEach((e=>{const a=t.find((t=>t.package===e.package));a?"string"==typeof e.path?(a.path||[]).some((t=>t===e.path))||(a.path=a.path||[],a.path.push(e.path)):Array.isArray(e.path)&&e.path.forEach((e=>{(a.path||[]).some((t=>t===e))||(a.path=a.path||[],a.path.push(e))})):t.push(e)}))}t.sort(((e,t)=>e.package?.localeCompare(t.package)))}async findAtomLibrary({url:e}){const a=o({url:e});if(!a)throw new Error(`Invalid package name: ${e}`);if(a.protocol||(a.protocol=this.context.protocol),"ac:"===a.protocol){const t=a.pathname.split("/");if(1===t.length)return await this.apiContext.Atom.first({where:{name:e,parent_id:this.atomConfig.env.ATOM_LIBRARIES_ID,type:"workflow.lib"}});if(2===t.length){const e=await this.apiContext.Atom.first({where:{name:t[0],parent_id:this.atomConfig.env.ATOM_LIBRARIES_ID,type:"folder"}});return await this.apiContext.Atom.first({where:{name:t[1],parent_id:e.id,type:"workflow.lib"}})}}else if("local:"===a.protocol){const e=this.atom;e.protocol="local:",e.doc.dependencies=e.doc.dependencies||[],e.name=e.doc.name;const a=t.resolve(this.context.projectSrcDir,"index.js"),o=await s({file:a,recursive:!0}),i=e.doc.dependencies,r=o.all;for await(const e of r){if("npm"!==e.type)continue;if(i.find((t=>t.package===e.package)))continue;const t=await m({name:e.package,projectDir:this.context.projectDir,setProgress:this.apiContext.setProgress});i.push({package:e.package,subpath:e.subpath,version:t.minorRange,type:"npm"})}return e}}async createAtomLibFiles({libs:a}){await this.setProgress({message:"Creating external lib files."}),this.atom.typesDir="./types";const s=a.filter((e=>"atom"===e.type));for(let a=0;a<s.length;a++){const o=s[a].atom,i=this.context.projectDir;if("local:"===o.protocol){const a=t.resolve(this.context.projectSrcDir,`${o.fileName||o.name}.js`),s=t.relative(t.join(this.context.projectDir,"src","default"),a);if(!e.existsSync(a)){e.mkdirSync(t.dirname(a),{recursive:!0});let s="export default async (args)=>{\n";s+="}",e.writeFileSync(a,s,"utf8")}o.relativePath=s.split(t.sep).join("/"),this.atom.typesDir=`./types/${t.basename(i)}/src`}else{const a=t.join(i,"src","libs",`${o.id}.js`),s=o.doc.contents?.find((e=>"esm"===e.format))||o.doc;e.writeFileSync(a,s.content,"utf8")}}}async createEngine(){await this.setProgress({message:"Creating engine file."});const s={libs:this.libs.filter((e=>"atom"===e.type)),libraryAtom:this.atom,atom:this.atom},o=this.context.templateDir,i=a.compile(e.readFileSync(t.resolve(o,t.join("src","default","engine.js.njk")),"utf8"),this.apiContext.njEnv).render(s),r=this.context.projectDir,n=t.resolve(r,t.join("src","default","index.js"));e.writeFileSync(n,i,"utf8")}async build(){try{this.fileMode&&(await this.createAtomLibFiles({libs:this.libs}),await this.createEngine(),await this.createProjectYaml(),await r(this.apiContext),await g(this.apiContext),await n(this.apiContext),await _(this.apiContext),await h(this.apiContext),await y(this.apiContext),await async function({atom:o,setProgress:i,context:r,packageDependencies:n}){await i({message:"Creating rollup file."});const p={atom:o,packageDependencies:n},l=t.resolve(r.projectDir,"src","default/index.js");if(!e.existsSync(l))throw new Error(`Entry file not found: ${l}`);const c=(await s({file:l,recursive:!0})).all.filter((e=>"node"===e.type)).map((e=>e.path)),d=o.doc.features.rollup_output,u=Object.keys(d);for(let e=0;e<u.length;e++){const t=d[u[e]];if(!0===t.browser&&c.length>0){t.globals_enabled=!0,t.globals=t.globals||[],t.globals=t.globals.concat(c.map((e=>({key:e,value:e})))),t.alias_enabled=!0,t.alias=t.alias||{},t.alias.entries=t.alias.entries||{};for(let e=0;e<c.length;e++){const a=c[e];t.alias.entries[a]=`node:${a}`,t.alias.entries[`node:${a}`]=a}t.external_enabled=!0,t.external=t.external||[],t.external=t.external.concat(c)}}const f=r.templateDir;let b=a.compile(e.readFileSync(t.resolve(f,"rollup.config.mjs.njk"),"utf8"),a.configure(f)).render(p);const m=r.projectDir;let g=t.resolve(m,"rollup.config.mjs");e.writeFileSync(g,b,"utf8")}(this.apiContext),await w(this.apiContext),await x(this.apiContext),await async function({atom:e,setProgress:t,context:a}){if(!e.doc.features.dts_enabled)return;const s=a.projectDir;if(await t({message:"Creating .d.ts"}),0!==(await D("tsc",{cwd:s})).code)throw new Error("Couldnt create .d.ts files.")}(this.apiContext),this.buildMode&&(await v(this.apiContext),await k(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{A as default};
|
package/dist/fnode/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import e,{delimiter as t,join as o}from"node:path";import{fileURLToPath as n}from"node:url";import{spawn as r}from"node:child_process";import i from"node:os";import a,{existsSync as s}from"node:fs";import c from"yaml";import l from"yargs";import p from"@fnet/prompt";import d from"@fnet/shelljs";import m from"@fnet/yaml";import u from"@fnet/config";import"@fnet/shell-flow";import f from"@flownet/lib-render-templates-dir";import{promisify as y}from"node:util";import w from"tree-kill";const g=e.dirname(n(import.meta.url));var h=e=>{const n=process.env.PATH||"",r="win32"===process.platform?(process.env.PATHEXT||".EXE;.CMD;.BAT;.COM").split(";"):[""],i=n.split(t);for(const t of i)for(const n of r){const r=o(t,"win32"===process.platform?e+n:e);if(s(r))return r}return null};const b=y(w);let j=!1;async function v(e,t){if(j)return;if(j=!0,!e.killed&&e.pid)try{await b(e.pid,"SIGTERM").catch((()=>{})),await new Promise((e=>setTimeout(e,500))),e.killed||await b(e.pid,"SIGKILL").catch((()=>{}))}catch(e){}await new Promise((e=>setTimeout(e,100)));const o="SIGINT"===t?130:"SIGTERM"===t?143:1;process.exit(o)}function x(e){["SIGINT","SIGTERM","SIGQUIT"].forEach((t=>{process.once(t,(async()=>{await v(e,t)}))})),process.on("uncaughtException",(async t=>{await v(e)})),process.on("unhandledRejection",(async t=>{await v(e)})),e.on("close",(e=>{j||process.exit(e)}))}const S=e.dirname(n(import.meta.url)),$=process.cwd();function E(t){const o=e.resolve($,t);if(a.existsSync(o))return o;const n=e.resolve(S,"../..",t);if(a.existsSync(n))return n;throw new Error(`Template path not found: ${t}`)}class I{static async createBuilder(e){if(!e.project){return new(0,(await import("./index.BSQp_bJN.js")).default)(e)}const t=e.project?.runtime?.type||"node";try{return new(await this.loadBuilderClass(t))(e)}catch(o){console.warn(`Warning: Could not load builder for runtime '${t}'. Falling back to legacy builder.`),console.warn(`Error: ${o.message}`);return new(0,(await import("./index.BSQp_bJN.js")).default)(e)}}static async loadBuilderClass(e){switch(e.toLowerCase()){case"node":return(await import("./index.DItyYiZ_.js")).default;case"python":return(await import("./index.B2LXSSn7.js")).default;case"bun":return(await import("./index.Chvv_TJm.js")).default;default:throw new Error(`Unsupported runtime type: ${e}`)}}}const T=e.dirname(n(import.meta.url)),D=process.cwd();process.on("uncaughtException",(e=>{j||(j=!0,setTimeout((()=>process.exit(1)),500))})),process.on("unhandledRejection",(e=>{j||(j=!0,setTimeout((()=>process.exit(1)),500))})),u({name:["redis"],dir:D,optional:!0});const F=function({baseDir:t}){let o=t=t||g;for(;o!==e.parse(o).root;){const t=e.join(o,"node_modules");if(a.existsSync(t))return t;o=e.dirname(o)}return null}({baseDir:T}),P="win32"===process.platform?";":":";F&&(process.env.PATH=`${e.join(F,"/.bin")}${P}${process.env.PATH}`);let A=l(process.argv.slice(2)).command("create","Create flow node project",(e=>e.option("name",{type:"Project name",demandOption:!0}).option("vscode",{type:"boolean",default:!0,alias:"vs"}).option("runtime",{type:"string",default:"node",choices:["node","python","bun"]})),(async t=>{try{const o=E("./template/fnode/project"),n=e.resolve(D,t.name);a.existsSync(n)||a.mkdirSync(n),await f({dir:o,outDir:n,context:{name:t.name,runtime:t.runtime,platform:i.platform()},copyUnmatchedAlso:!0});let r=await d("fnode build",{cwd:n});if(0!==r.code)throw new Error("Failed to build project.");if(h("git")&&(r=await d("git init --initial-branch=main",{cwd:n}),0!==r.code))throw new Error("Failed to initialize git.");if(h("code")&&t.vscode&&(r=await d(`cd ${n} && code .`),0!==r.code))throw new Error("Failed to open vscode.");console.log("Creating project succeeded!"),process.exit(0)}catch(e){console.error("Initialization failed!",e.message),process.exit(1)}})).command("project","Flow node project",(e=>e.option("update",{type:"boolean",default:!1,alias:"-u"})),(async e=>{try{const t=E("./template/fnode/project"),o=process.cwd(),n=await k(e);if(e.update){if(await f({dir:t,outDir:o,context:{name:n.project.projectFileParsed.name,runtime:n.project.runtime.type,platform:i.platform()},copyUnmatchedAlso:!0}),0!==(await d("fnode build",{cwd:o})).code)throw new Error("Failed to build project.");console.log("Updating project succeeded!")}process.exit(0)}catch(e){console.error("Project failed.",e.message),process.exit(1)}})).command("build","Build flow node project",(e=>e.option("id",{type:"string"}).option("buildId",{type:"string",alias:"bid"}).option("mode",{type:"string",default:"build",choices:["all","file","build","deploy","bpmn"]}).option("ftag",{type:"array"})),(async e=>{try{const t=await k(e),o=await I.createBuilder(t);await o.init(),await o.build(),console.log("Building library succeeded!"),process.exit(0)}catch(e){console.error("Building library failed!",e.message),process.exit(1)}})).command("deploy","Build and deploy flow node project",(e=>e.option("id",{type:"string"}).option("buildId",{type:"string",alias:"bid"}).option("ftag",{type:"array"})),(async e=>{try{const t=await k({...e,mode:"all"}),o=await I.createBuilder(t);await o.init(),await o.build(),console.log("Building library succeeded!"),process.exit(0)}catch(e){console.error("Building library failed!",e.message),process.exit(1)}})).command("file","Just create files",(e=>e.option("id",{type:"string"}).option("buildId",{type:"string",alias:"bid"}).option("ftag",{type:"array"})),(async e=>{try{const t=await k({...e,mode:"file"}),o=await I.createBuilder(t);await o.init(),await o.build(),console.log("Building library succeeded!"),process.exit(0)}catch(e){console.error("Building library failed!",e.message),process.exit(1)}}));function B(e,{name:t,bin:o,preArgs:n=[]}){return"function"==typeof o&&(o=o()),e.command(`${t||o} [commands..]`,`${o} ${n.join(" ")}`,(e=>e.help(!1).version(!1)),(async e=>{try{const t=await k(e),{projectDir:i}=t,a=e=>e.includes(" ")?"win32"===process.platform?`"${e.replace(/(["^])/g,"^$1")}"`:`"${e.replace(/(["\\$`])/g,"\\$1")}"`:e,s=process.argv.slice(3).map(a);x(r(o,[...n,...s],{cwd:i,stdio:"inherit",shell:!0,detached:!0}))}catch(e){console.error(e.message),process.exit(1)}}))}function C(t,{name:o,bin:n,preArgs:i=[]}){return t.command(`${o||n} [commands..]`,`${n} ${i.join(" ")}`,(e=>e.help(!1).version(!1)),(async t=>{try{const a=await k(t),{projectDir:s}=a,c=e=>e.includes(" ")?"win32"===process.platform?`"${e.replace(/(["^])/g,"^$1")}"`:`"${e.replace(/(["\\$`])/g,"\\$1")}"`:e,l=process.argv.slice(3).map(c);n=e.join(s,".conda","bin",n||o);x(r(n,[...i,...l],{cwd:s,stdio:"inherit",shell:!0,detached:!0,env:{PYTHONPATH:s}}))}catch(e){console.error(e.message),process.exit(1)}}))}async function k(t){if(t.id)return{id:t.id,buildId:t.buildId,mode:t.mode,protocol:t.protocol||"ac:",templateDir:E("./template/fnode/node"),projectDir:e.resolve(D,`./.output/${t.id}`),tags:t.ftag};{const o=await async function({tags:t}){let o=function(t){const o=e.resolve(t,"node.yaml"),n=e.resolve(t,"fnode.yaml");if(a.existsSync(n))return n;if(a.existsSync(o))try{const e=a.readFileSync(o,"utf8");return a.writeFileSync(n,e,"utf8"),a.unlinkSync(o),console.log(`Migrated node.yaml to fnode.yaml in ${t}`),n}catch(e){return console.error(`Error migrating node.yaml to fnode.yaml: ${e.message}`),o}return n}(D);if(!a.existsSync(o))throw new Error("fnode.yaml file not found in current directory.");const{raw:n,parsed:r}=await m({file:o,tags:t}),i=e.dirname(o);r.features=r.features||{};const s=r.features;s.runtime=s.runtime||{},s.runtime.type=s.runtime.type||"node","python"===s.runtime.type?s.runtime.template=s.runtime.template||"python":"bun"===s.runtime.type?s.runtime.template=s.runtime.template||"bun":s.runtime.template=s.runtime.template||"node";const l={libraryAtom:{doc:{...r},fileName:"index"},projectDir:i,projectFilePath:o,projectFileContent:n,projectFileParsed:r,runtime:s.runtime};let p=e.resolve(i,"fnet/targets.yaml");if(!a.existsSync(p)&&(p=e.resolve(i,"node.devops.yaml"),a.existsSync(p))){const t=e.resolve(i,"fnet");a.existsSync(t)||a.mkdirSync(t),a.copyFileSync(p,e.resolve(i,"fnet/targets.yaml")),a.unlinkSync(p)}if(a.existsSync(p)){const{raw:e,parsed:o}=await m({file:p,tags:t}),n=c.parseDocument(e);l.devops={filePath:p,fileContent:e,yamlDocument:n,doc:{...o},type:"library.deploy",save:async()=>{a.writeFileSync(l.devops.filePath,n.toString())}}}const d=e.resolve(i,"readme.md");if(a.existsSync(d)){const e=a.readFileSync(d,"utf8");l.readme={filePath:d,fileContent:e,doc:{content:e,"content-type":"markdown"},type:"wiki"}}return l}({tags:t.ftag});return{buildId:t.buildId,mode:t.mode,protocol:t.protocol||"local:",templateDir:E(`./template/fnode/${o.runtime.template}`),projectDir:e.resolve(o.projectDir,"./.workspace"),projectSrcDir:e.resolve(o.projectDir,"./src"),project:o,tags:t.ftag}}}A=A.command("input [name]","Create or modify an input config file",(e=>e.positional("name",{type:"string",demandOption:!1}).help(!1).version(!1)),(async t=>{try{const o=await k(t),{project:n}=o,{projectDir:r,projectFileParsed:i}=n,s=i.input;if(!s)throw new Error("Config schema not found in project file.");if(!Reflect.has(t,"name")){const{inputName:e}=await p({type:"input",name:"inputName",message:"Input name:",initial:"dev"});t.name=e}const c=e.resolve(r,".fnet");a.existsSync(c)||a.mkdirSync(c);const l=e.resolve(c,`${t.name}.fnet`),d=a.existsSync(l),m=(await import("@fnet/object-from-schema")).default,u=await m({schema:s,format:"yaml",ref:d?l:void 0});a.writeFileSync(l,u)}catch(e){console.error(e.message),process.exit(1)}})),A=B(A,{bin:"npm"}),A=B(A,{bin:"node"}),A=B(A,{bin:"bun"}),A=B(A,{name:"serve",bin:"bun",preArgs:["run","serve","--"]}),A=B(A,{name:"watch",bin:"bun",preArgs:["run","watch","--"]}),A=B(A,{name:"app",bin:"bun",preArgs:["run","app","--"]}),A=B(A,{name:"cli",bin:"bun",preArgs:["run","cli","--"]}),A=B(A,{bin:"npx"}),A=B(A,{bin:"cdk"}),A=B(A,{bin:"aws"}),A=function(e,{name:t,preArgs:o=[]}){return e.command(`${t} <config> <command> [options..]`,"Run a command with a config context",(e=>e.positional("config",{type:"string"}).positional("command",{type:"string"}).help(!1).version(!1)),(async e=>{try{const t=await k(e),{projectDir:n}=t,i=e.config,s=await u({name:i,dir:n,transferEnv:!1,optional:!0,tags:t.tags}),c=s?.data?.env||void 0,l=e.command,p=process.argv.slice(5);x(r(l,[...o,...p],{cwd:a.existsSync(n)?n:D,stdio:"inherit",shell:!0,detached:!0,env:{...process.env,...c}}))}catch(e){console.error(e.message),process.exit(1)}}))}(A,{name:"with"}),A=function(e,{name:t}){return e.command(`${t} group [options..]`,"Run a command group.",(e=>e.positional("group",{type:"string"}).option("ftag",{type:"array"}).help(!1).version(!1)),(async e=>{try{const{runCommandGroup:t}=await import("./index.DrwlOzAe.js");await t({projectType:"fnode",group:e.group,tags:e.ftag,args:e,argv:process.argv})}catch(e){console.error(e.message),process.exit(1)}}))}(A,{name:"run"}),A=C(A,{name:"python"}),A=C(A,{name:"python3"}),A=C(A,{name:"pip"}),A=C(A,{name:"pip3"}),A.demandCommand(1,"You need at least one command before moving on").help().argv;export{E as r,h as w};
|
|
2
|
+
import e,{delimiter as t,join as o}from"node:path";import{fileURLToPath as n}from"node:url";import{spawn as r}from"node:child_process";import i from"node:os";import a,{existsSync as s}from"node:fs";import c from"yaml";import l from"yargs";import p from"chalk";import d from"@fnet/prompt";import m from"@fnet/shelljs";import u from"@fnet/yaml";import f from"@fnet/config";import y from"@flownet/lib-render-templates-dir";import{promisify as w}from"node:util";import g from"tree-kill";const h=e.dirname(n(import.meta.url));var b=e=>{const n=process.env.PATH||"",r="win32"===process.platform?(process.env.PATHEXT||".EXE;.CMD;.BAT;.COM").split(";"):[""],i=n.split(t);for(const t of i)for(const n of r){const r=o(t,"win32"===process.platform?e+n:e);if(s(r))return r}return null};const j=w(g);let v=!1;async function x(e,t){if(v)return;if(v=!0,!e.killed&&e.pid)try{await j(e.pid,"SIGTERM").catch((()=>{})),await new Promise((e=>setTimeout(e,500))),e.killed||await j(e.pid,"SIGKILL").catch((()=>{}))}catch(e){}await new Promise((e=>setTimeout(e,100)));const o="SIGINT"===t?130:"SIGTERM"===t?143:1;process.exit(o)}function S(e){["SIGINT","SIGTERM","SIGQUIT"].forEach((t=>{process.once(t,(async()=>{await x(e,t)}))})),process.on("uncaughtException",(async t=>{await x(e)})),process.on("unhandledRejection",(async t=>{await x(e)})),e.on("close",(e=>{v||process.exit(e)}))}const $=e.dirname(n(import.meta.url)),I=process.cwd();function E(t){const o=e.resolve(I,t);if(a.existsSync(o))return o;const n=e.resolve($,"../..",t);if(a.existsSync(n))return n;throw new Error(`Template path not found: ${t}`)}class D{static async createBuilder(e){if(!e.project){console.warn("No project provided, defaulting to node runtime");return new(0,(await import("./index.axpuK8O5.js")).default)(e)}const t=e.project?.runtime?.type||"node";try{return new(await this.loadBuilderClass(t))(e)}catch(o){console.warn(`Warning: Could not load builder for runtime '${t}'. Falling back to node builder.`),console.warn(`Error: ${o.message}`);return new(0,(await import("./index.axpuK8O5.js")).default)(e)}}static async loadBuilderClass(e){switch(e.toLowerCase()){case"node":return(await import("./index.axpuK8O5.js")).default;case"python":return(await import("./index.B_EoIJV1.js")).default;case"bun":return(await import("./index.teSOwugt.js")).default;default:throw new Error(`Unsupported runtime type: ${e}`)}}}const F=e.dirname(n(import.meta.url)),P=process.cwd();process.on("uncaughtException",(e=>{v||(v=!0,setTimeout((()=>process.exit(1)),500))})),process.on("unhandledRejection",(e=>{v||(v=!0,setTimeout((()=>process.exit(1)),500))})),f({name:["redis"],dir:P,optional:!0});const T=function({baseDir:t}){let o=t=t||h;for(;o!==e.parse(o).root;){const t=e.join(o,"node_modules");if(a.existsSync(t))return t;o=e.dirname(o)}return null}({baseDir:F}),A="win32"===process.platform?";":":";T&&(process.env.PATH=`${e.join(T,"/.bin")}${A}${process.env.PATH}`);let C=l(process.argv.slice(2)).command("create","Create flow node project",(e=>e.option("name",{type:"Project name",demandOption:!0}).option("vscode",{type:"boolean",default:!0,alias:"vs"}).option("runtime",{type:"string",default:"node",choices:["node","python","bun"]})),(async t=>{try{const o=E("./template/fnode/project"),n=e.resolve(P,t.name);a.existsSync(n)||a.mkdirSync(n),await y({dir:o,outDir:n,context:{name:t.name,runtime:t.runtime,platform:i.platform()},copyUnmatchedAlso:!0});let r=await m("fnode build",{cwd:n});if(0!==r.code)throw new Error("Failed to build project.");if(b("git")&&(r=await m("git init --initial-branch=main",{cwd:n}),0!==r.code))throw new Error("Failed to initialize git.");if(b("code")&&t.vscode&&(r=await m(`cd ${n} && code .`),0!==r.code))throw new Error("Failed to open vscode.");console.log("Creating project succeeded!"),process.exit(0)}catch(e){console.error("Initialization failed!",e.message),process.exit(1)}})).command("project","Flow node project",(e=>e.option("update",{type:"boolean",default:!1,alias:"-u"})),(async e=>{try{const t=E("./template/fnode/project"),o=process.cwd(),n=await G(e);if(e.update){if(await y({dir:t,outDir:o,context:{name:n.project.projectFileParsed.name,runtime:n.project.runtime.type,platform:i.platform()},copyUnmatchedAlso:!0}),0!==(await m("fnode build",{cwd:o})).code)throw new Error("Failed to build project.");console.log("Updating project succeeded!")}process.exit(0)}catch(e){console.error("Project failed.",e.message),process.exit(1)}})).command("build","Build flow node project",(e=>e.option("id",{type:"string"}).option("buildId",{type:"string",alias:"bid"}).option("mode",{type:"string",default:"build",choices:["all","file","build","deploy","bpmn"]}).option("ftag",{type:"array"})),(async e=>{try{const t=await G(e),o=await D.createBuilder(t);await o.init(),await o.build(),console.log("Building library succeeded!"),process.exit(0)}catch(e){console.error("Building library failed!",e.message),process.exit(1)}})).command("deploy","Build and deploy flow node project",(e=>e.option("id",{type:"string"}).option("buildId",{type:"string",alias:"bid"}).option("ftag",{type:"array"})),(async e=>{try{const t=await G({...e,mode:"all"}),o=await D.createBuilder(t);await o.init(),await o.build(),console.log("Building library succeeded!"),process.exit(0)}catch(e){console.error("Building library failed!",e.message),process.exit(1)}})).command("file","Just create files",(e=>e.option("id",{type:"string"}).option("buildId",{type:"string",alias:"bid"}).option("ftag",{type:"array"})),(async e=>{try{const t=await G({...e,mode:"file"}),o=await D.createBuilder(t);await o.init(),await o.build(),console.log("Building library succeeded!"),process.exit(0)}catch(e){console.error("Building library failed!",e.message),process.exit(1)}}));function B(e,{name:t,bin:o,preArgs:n=[]}){return"function"==typeof o&&(o=o()),e.command(`${t||o} [commands..]`,`${o} ${n.join(" ")}`,(e=>e.help(!1).version(!1)),(async e=>{try{const t=await G(e),{projectDir:i}=t,a=e=>e.includes(" ")?"win32"===process.platform?`"${e.replace(/(["^])/g,"^$1")}"`:`"${e.replace(/(["\\$`])/g,"\\$1")}"`:e,s=process.argv.slice(3).map(a);S(r(o,[...n,...s],{cwd:i,stdio:"inherit",shell:!0,detached:!0}))}catch(e){console.error(e.message),process.exit(1)}}))}function k(t,{name:o,bin:n,preArgs:i=[]}){return t.command(`${o||n} [commands..]`,`${n} ${i.join(" ")}`,(e=>e.help(!1).version(!1)),(async t=>{try{const a=await G(t),{projectDir:s}=a,c=e=>e.includes(" ")?"win32"===process.platform?`"${e.replace(/(["^])/g,"^$1")}"`:`"${e.replace(/(["\\$`])/g,"\\$1")}"`:e,l=process.argv.slice(3).map(c);n=e.join(s,".conda","bin",n||o);S(r(n,[...i,...l],{cwd:s,stdio:"inherit",shell:!0,detached:!0,env:{PYTHONPATH:s}}))}catch(e){console.error(e.message),process.exit(1)}}))}async function G(t){if(t.id)return{id:t.id,buildId:t.buildId,mode:t.mode,protocol:t.protocol||"ac:",templateDir:E("./template/fnode/node"),projectDir:e.resolve(P,`./.output/${t.id}`),tags:t.ftag};{const o=await async function({tags:t}){let o=function(t){const o=e.resolve(t,"node.yaml"),n=e.resolve(t,"fnode.yaml");if(a.existsSync(n))return n;if(a.existsSync(o))try{const e=a.readFileSync(o,"utf8");return a.writeFileSync(n,e,"utf8"),a.unlinkSync(o),console.log(`Migrated node.yaml to fnode.yaml in ${t}`),n}catch(e){return console.error(`Error migrating node.yaml to fnode.yaml: ${e.message}`),o}return n}(P);if(!a.existsSync(o))throw new Error("fnode.yaml file not found in current directory.");const{raw:n,parsed:r}=await u({file:o,tags:t}),i=e.dirname(o);r.features=r.features||{};const s=r.features;s.runtime=s.runtime||{},s.runtime.type=s.runtime.type||"node","python"===s.runtime.type?s.runtime.template=s.runtime.template||"python":"bun"===s.runtime.type?s.runtime.template=s.runtime.template||"bun":s.runtime.template=s.runtime.template||"node";const l={libraryAtom:{doc:{...r},fileName:"index"},projectDir:i,projectFilePath:o,projectFileContent:n,projectFileParsed:r,runtime:s.runtime};let p=e.resolve(i,"fnet/targets.yaml");if(!a.existsSync(p)&&(p=e.resolve(i,"node.devops.yaml"),a.existsSync(p))){const t=e.resolve(i,"fnet");a.existsSync(t)||a.mkdirSync(t),a.copyFileSync(p,e.resolve(i,"fnet/targets.yaml")),a.unlinkSync(p)}if(a.existsSync(p)){const{raw:e,parsed:o}=await u({file:p,tags:t}),n=c.parseDocument(e);l.devops={filePath:p,fileContent:e,yamlDocument:n,doc:{...o},type:"library.deploy",save:async()=>{a.writeFileSync(l.devops.filePath,n.toString())}}}const d=e.resolve(i,"readme.md");if(a.existsSync(d)){const e=a.readFileSync(d,"utf8");l.readme={filePath:d,fileContent:e,doc:{content:e,"content-type":"markdown"},type:"wiki"}}return l}({tags:t.ftag});return{buildId:t.buildId,mode:t.mode,protocol:t.protocol||"local:",templateDir:E(`./template/fnode/${o.runtime.template}`),projectDir:e.resolve(o.projectDir,"./.workspace"),projectSrcDir:e.resolve(o.projectDir,"./src"),project:o,tags:t.ftag}}}C=C.command("input [name]","Create or modify an input config file",(e=>e.positional("name",{type:"string",demandOption:!1}).help(!1).version(!1)),(async t=>{try{const o=await G(t),{project:n}=o,{projectDir:r,projectFileParsed:i}=n,s=i.input;if(!s)throw new Error("Config schema not found in project file.");if(!Reflect.has(t,"name")){const{inputName:e}=await d({type:"input",name:"inputName",message:"Input name:",initial:"dev"});t.name=e}const c=e.resolve(r,".fnet");a.existsSync(c)||a.mkdirSync(c);const l=e.resolve(c,`${t.name}.fnet`),p=a.existsSync(l),m=(await import("@fnet/object-from-schema")).default,u=await m({schema:s,format:"yaml",ref:p?l:void 0});a.writeFileSync(l,u)}catch(e){console.error(e.message),process.exit(1)}})),C=B(C,{bin:"npm"}),C=B(C,{bin:"node"}),C=B(C,{bin:"bun"}),C=B(C,{name:"serve",bin:"bun",preArgs:["run","serve","--"]}),C=B(C,{name:"watch",bin:"bun",preArgs:["run","watch","--"]}),C=B(C,{name:"app",bin:"bun",preArgs:["run","app","--"]}),C=B(C,{name:"cli",bin:"bun",preArgs:["run","cli","--"]}),C=B(C,{name:"compile",bin:"bun",preArgs:["run","compile","--"]}),C=function(t,{name:o}){return t.command(`${o} [options]`,"Install the project as a binary",(e=>e.option("name",{alias:"n",describe:"Name to use for the installed binary",type:"string"}).option("force",{alias:"f",describe:"Force overwrite if binary already exists",type:"boolean",default:!1}).option("version",{alias:"v",describe:"Version of the binary",type:"string"}).option("yes",{alias:"y",describe:"Automatically answer yes to all prompts",type:"boolean",default:!1}).help(!1).version(!1)),(async t=>{try{const o=await G(t),{projectDir:n}=o;console.log(p.blue("Compiling project..."));const r=e.join(n,".bin");a.existsSync(r)||a.mkdirSync(r,{recursive:!0});const i=e.basename(e.dirname(n)),s=o.project?.projectFileParsed?.features?.cli?.bin,c=t.name||s||i;console.log(p.blue(`Using binary name: ${c}`));const l=e.join(r,c),{spawn:d}=await import("child_process"),m=d("bun",["build","./dist/cli/esm/index.js","--compile",`--outfile=${l}`],{cwd:n,stdio:"inherit",shell:!0});await new Promise(((e,t)=>{m.on("close",(o=>{0===o?e():t(new Error(`Compilation failed with code ${o}`))})),m.on("error",(e=>{t(e)}))})),"win32"!==process.platform&&a.chmodSync(l,493),console.log(p.green(`Binary compiled successfully: ${l}`)),console.log(p.blue("Installing binary..."));const u=["install",l];t.name&&u.push("--name",t.name),t.version&&u.push("--version",t.version),t.force&&u.push("--force"),t.yes&&u.push("--yes");const f=d("fbin",u,{stdio:"inherit",shell:!0});await new Promise(((e,t)=>{f.on("close",(o=>{0===o?e():t(new Error(`Installation failed with code ${o}`))})),f.on("error",(e=>{t(e)}))}))}catch(e){console.error(p.red(`Failed to install binary: ${e.message}`)),process.exit(1)}}))}(C,{name:"install"}),C=B(C,{bin:"npx"}),C=B(C,{bin:"cdk"}),C=B(C,{bin:"aws"}),C=function(e,{name:t,preArgs:o=[]}){return e.command(`${t} <config> <command> [options..]`,"Run a command with a config context",(e=>e.positional("config",{type:"string"}).positional("command",{type:"string"}).help(!1).version(!1)),(async e=>{try{const t=await G(e),{projectDir:n}=t,i=e.config,s=await f({name:i,dir:n,transferEnv:!1,optional:!0,tags:t.tags}),c=s?.data?.env||void 0,l=e.command,p=process.argv.slice(5);S(r(l,[...o,...p],{cwd:a.existsSync(n)?n:P,stdio:"inherit",shell:!0,detached:!0,env:{...process.env,...c}}))}catch(e){console.error(e.message),process.exit(1)}}))}(C,{name:"with"}),C=function(e,{name:t}){return e.command(`${t} group [options..]`,"Run a command group.",(e=>e.positional("group",{type:"string"}).option("ftag",{type:"array"}).help(!1).version(!1)),(async e=>{try{const{runCommandGroup:t}=await import("./index.DrwlOzAe.js");await t({projectType:"fnode",group:e.group,tags:e.ftag,args:e,argv:process.argv})}catch(e){console.error(e.message),process.exit(1)}}))}(C,{name:"run"}),C=k(C,{name:"python"}),C=k(C,{name:"python3"}),C=k(C,{name:"pip"}),C=k(C,{name:"pip3"}),C.demandCommand(1,"You need at least one command before moving on").help().argv;export{E as r,b as w};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"node:fs";import t from"node:path";import a from"nunjucks";import i from"@flownet/lib-parse-imports-js";import s from"@flownet/lib-parse-node-url";import{B as r,c as o,a as n}from"./index.D5QuQuJX.js";import p from"lodash.merge";import{i as l,a as c,b as d,c as m,d as f,p as u,e as h,g as _,h as y,j as b,k as x,l as g,m as j,r as w}from"./index.CLPC6OJN.js";import v from"@fnet/npm-list-versions";import"node:crypto";import"yaml";import"chalk";import"@flownet/lib-atom-api-js";import"@fnet/config";import"@fnet/list-files";import"redis";import"@flownet/lib-is-redis-online";import"@fnet/yaml";import"@flownet/lib-render-templates-dir";import"@fnet/npm-pick-versions";import"object-hash";import"ajv/dist/2020.js";import"ajv/dist/standalone/index.js";import"ajv-formats";import"@fnet/shelljs";import"./index.js";import"node:url";import"node:child_process";import"node:os";import"yargs";import"@fnet/prompt";import"node:util";import"tree-kill";function k({dir:a,name:i="index"}){let s=t.resolve(a,`./${i}.tsx`);if(e.existsSync(s)||(s=t.resolve(a,`./${i}.ts`)),e.existsSync(s)||(s=t.resolve(a,`./${i}.jsx`)),e.existsSync(s)||(s=t.resolve(a,`./${i}.js`)),!e.existsSync(s))return{};const r=s,o=t.extname(s);return{file:r,ext:o,ts:".ts"===o||".tsx"===o,name:i}}class D extends r{async initRuntime(){await async function({atom:e,context:a,setProgress:s}){await s({message:"Initializing features..."}),e.doc.features=e.doc.features||{};const r=e.doc.features;r.project=r.project||{},r.project.format=r.project.format||r.project_format||"esm",r.project_format=r.project.format,r.dts_enabled=!0===r.dts||void 0!==r.dts&&!1!==r.dts;const o=t.resolve(a.project.projectDir),n=k({dir:t.resolve(o,"./app")});if(n.file){s("Parsing app entry imports...");let e=await i({file:n.file,recursive:!0}),t=e.all.some((e=>!0===e.usesJSX&&"local"===e.type));r.app_uses_jsx=t,r.app_has_entry=!0,e=await i({file:n.file}),t=e.all.some((e=>!0===e.usesJSX&&"local"===e.type)),r.app_entry_uses_jsx=t,r.app_entry_is_ts=n.ts,r.app_entry_ext=n.ext}const u=k({dir:t.resolve(o,"./cli")});if(u.file){s("Parsing cli entry imports...");let e=await i({file:u.file,recursive:!0}),t=e.all.some((e=>!0===e.usesJSX&&"local"===e.type));r.cli_uses_jsx=t,r.cli_has_entry=!0,e=await i({file:u.file}),t=e.all.some((e=>!0===e.usesJSX&&"local"===e.type)),r.cli_entry_uses_jsx=t,r.cli_entry_is_ts=u.ts,r.cli_entry_ext=u.ext}if("workflow.lib"===e.type){const e=k({dir:t.resolve(o,"./src")});if(e.file){s("Parsing src entry imports...");let t=await i({file:e.file,recursive:!0}),a=t.all.some((e=>!0===e.usesJSX&&"local"===e.type));r.src_uses_jsx=a,r.src_has_entry=!0,t=await i({file:e.file}),a=t.all.some((e=>!0===e.usesJSX&&"local"===e.type)),r.src_entry_uses_jsx=a,r.src_entry_is_ts=e.ts,r.src_entry_ext=e.ext}}const h=Reflect.has(r,"app_entry_uses_jsx")?!0===r.app_entry_uses_jsx:!0===r.src_entry_uses_jsx,_=Reflect.has(r,"cli_entry_uses_jsx")?!0===r.cli_entry_uses_jsx:!0===r.src_entry_uses_jsx;r.form_enabled=h||_||!0===r.form||!0===r.form?.enabled,r.multiple_enabled=r.multiple_enabled||!0===r.multiple||!0===r.multiple?.enabled,!1===r.app?r.app={enabled:!1}:!0===r.app?r.app={enabled:!0,extend:!0===r.app_has_entry,export:!0,react:h}:r.app={enabled:!0,extend:!0===r.app_has_entry,export:!0,react:h,...r.app||{}},r.app.enabled=!0===r.app.enabled&&(!0===e.doc.features.form_enabled||!0===r.app.extend||!0===r.app.enabled),r.app.format=r.app.format||"esm",r.app.folder=r.app.folder||r.app.format||"esm",r.app.dir=`./dist/app/${r.app.folder}`,r.app.html=!1!==r.app.html,!1===r.cli?r.cli={enabled:!1}:!0===r.cli?r.cli={enabled:!0,extend:!0===r.cli_has_entry,export:!0,react:_}:r.cli={enabled:!0,extend:!0===r.cli_has_entry,export:!0,react:_,...r.cli||{}},r.cli.enabled=!0===r.cli.enabled&&(!1===e.doc.features.form_enabled||!0===r.cli.extend||!0===r.cli.enabled),r.cli.format=r.cli.format||"esm",r.cli.folder=r.cli.folder||r.cli.folder||"esm",r.cli.dir=`./dist/cli/${r.cli.folder}`,r.cli.node_options=r.cli.node?.options||r.cli.node_options||"",r.json=r.cli.enabled||r.json,r.bun=r.bun||{},r.bun.build=r.bun.build||{};const y={default:{format:"esm",target:"browser",minify:!1,sourcemap:"external",entrypoints:["./src/default/index.js"],outdir:"./dist/default/esm"},defaultCjs:{format:"cjs",target:"node",minify:!1,sourcemap:"external",entrypoints:["./src/default/index.js"],outdir:"./dist/default/cjs"}};r.cli.enabled&&(y.cli={format:"esm",target:"node",minify:!1,sourcemap:"external",entrypoints:["./src/cli/index.js"],outdir:r.cli.dir}),r.app.enabled&&(y.app={format:"esm",target:"browser",minify:!1,sourcemap:"external",entrypoints:["./src/app/index.js"],outdir:r.app.dir}),r.bun.build=p(y,r.bun.build||{}),r.preact_enabled=!0===r.preact||r.preact&&!1!==r.preact?.enabled,r.dependency_auto_enabled=!1!==r.dependency_auto&&!1!==r.dependency_auto?.enabled,r.npm_install_flags=r.npm_install_flags||"",r.react_version=r.react_version||r.react?.version||18,r.runtime=r.runtime||{},r.runtime.type="bun",r.runtime.template="bun",l({atom:e}),c({atom:e}),d({atom:e}),m({atom:e}),f({atom:e})}(this.apiContext),await async function({atom:e,packageDependencies:t,packageDevDependencies:a,setProgress:i}){i("Initializing dependencies for Bun");const s=e.doc.dependencies||[];if(s.filter((e=>!e.dev)).forEach((e=>t.push(e))),s.filter((e=>e.dev)).forEach((e=>a.push(e))),"workflow"===e.type&&(t.push({package:"get-value",version:"^3"}),t.push({package:"set-value",version:"^4"})),e.doc.features.form_enabled&&e.doc.features.dependency_auto_enabled){let a="^18.2";i("Fetching React versions"),a=`^${(await v({name:"react",groupBy:{major:!0}})).find((t=>t[0]===e.doc.features.react_version.toString()))[0]}`,t.push({package:"react",version:a}),t.push({package:"react-dom",version:a}),"workflow"===e.type&&(t.push({package:"@fnet/react-app",version:"^0.1"}),t.push({package:"@fnet/react-app-state",version:"^0.1"}))}e.doc.features.preact_enabled&&t.push({package:"preact",version:"^10"}),!0===e.doc.features.cli.enabled&&(t.push({package:"@fnet/args",version:"^0.1"}),a.push({package:"ajv",version:"^8"}),e.doc.features.cli.fargs&&!1!==e.doc.features.cli.fargs?.enabled&&t.push({package:"@fnet/config",version:"0.2.21"})),e.doc.features.render&&!1!==e.doc.features.render.enabled&&a.push({package:"@flownet/lib-render-templates-dir",version:"0.1.19"})}(this.apiContext),await this.initLibraryDir(),await this.initNunjucks(),await this.initLibs()}async initLibs(){this.setProgress({message:"Initializing external libs."});const e=[{name:this.atom.doc.name,type:"atom",parent_id:this.atom.parent_id}];this.libs=e,await this.initAtomLibsAndDeps({libs:e,packageDependencies:this.apiContext.packageDependencies})}async initAtomLibsAndDeps({libs:e,packageDependencies:t}){const a=e.filter((e=>"atom"===e.type));for(let e=0;e<a.length;e++){const i=a[e],s=await this.findAtomLibrary({url:i.name});i.atom=s;const r=s.doc.dependencies?.filter((e=>void 0===e.repo||"npm"===e.repo));r?.forEach((e=>{const a=t.find((t=>t.package===e.package));a?"string"==typeof e.path?(a.path||[]).some((t=>t===e.path))||(a.path=a.path||[],a.path.push(e.path)):Array.isArray(e.path)&&e.path.forEach((e=>{(a.path||[]).some((t=>t===e))||(a.path=a.path||[],a.path.push(e))})):t.push(e)}))}t.sort(((e,t)=>e.package?.localeCompare(t.package)))}async findAtomLibrary({url:e}){const a=s({url:e});if(!a)throw new Error(`Invalid package name: ${e}`);if(a.protocol||(a.protocol=this.context.protocol),"ac:"===a.protocol){const t=a.pathname.split("/");if(1===t.length)return await this.apiContext.Atom.first({where:{name:e,parent_id:this.atomConfig.env.ATOM_LIBRARIES_ID,type:"workflow.lib"}});if(2===t.length){const e=await this.apiContext.Atom.first({where:{name:t[0],parent_id:this.atomConfig.env.ATOM_LIBRARIES_ID,type:"folder"}});return await this.apiContext.Atom.first({where:{name:t[1],parent_id:e.id,type:"workflow.lib"}})}}else if("local:"===a.protocol){const e=this.atom;e.protocol="local:",e.doc.dependencies=e.doc.dependencies||[],e.name=e.doc.name;const a=t.resolve(this.context.projectSrcDir,"index.js"),s=await i({file:a,recursive:!0}),r=e.doc.dependencies,o=s.all;for await(const e of o){if("npm"!==e.type)continue;if(r.find((t=>t.package===e.package)))continue;const t=await u({name:e.package,projectDir:this.context.projectDir,setProgress:this.apiContext.setProgress});r.push({package:e.package,subpath:e.subpath,version:t.minorRange,type:"npm"})}return e}}async createAtomLibFiles({libs:a}){await this.setProgress({message:"Creating external lib files."}),this.atom.typesDir="./types";const i=a.filter((e=>"atom"===e.type));for(let a=0;a<i.length;a++){const s=i[a].atom,r=this.context.projectDir;if("local:"===s.protocol){const a=t.resolve(this.context.projectSrcDir,`${s.fileName||s.name}.js`),i=t.relative(t.join(this.context.projectDir,"src","default"),a);if(!e.existsSync(a)){e.mkdirSync(t.dirname(a),{recursive:!0});let i="export default async (args)=>{\n";i+="}",e.writeFileSync(a,i,"utf8")}s.relativePath=i.split(t.sep).join("/"),this.atom.typesDir=`./types/${t.basename(r)}/src`}else{const a=t.join(r,"src","libs",`${s.id}.js`),i=s.doc.contents?.find((e=>"esm"===e.format))||s.doc;e.writeFileSync(a,i.content,"utf8")}}}async createEngine(){await this.setProgress({message:"Creating engine file."});const i={libs:this.libs.filter((e=>"atom"===e.type)),libraryAtom:this.atom,atom:this.atom},s=this.context.templateDir,r=a.compile(e.readFileSync(t.resolve(s,t.join("src","default","engine.js.njk")),"utf8"),this.apiContext.njEnv).render(i),o=this.context.projectDir,n=t.resolve(o,t.join("src","default","index.js"));e.writeFileSync(n,r,"utf8")}async build(){try{this.fileMode&&(await this.createAtomLibFiles({libs:this.libs}),await this.createEngine(),await this.createProjectYaml(),await o(this.apiContext),await h(this.apiContext),await n(this.apiContext),await _(this.apiContext),await y(this.apiContext),await b(this.apiContext),await async function({atom:i,setProgress:s,context:r,packageDependencies:o}){await s({message:"Creating build.js file."});const n={atom:i,packageDependencies:o},p=r.templateDir,l=a.compile(e.readFileSync(t.resolve(p,"build.js.njk"),"utf8"),a.configure(p)).render(n),c=r.projectDir,d=t.resolve(c,"build.js");e.writeFileSync(d,l,"utf8"),e.chmodSync(d,"755")}(this.apiContext),await x(this.apiContext),await g(this.apiContext),this.buildMode&&(await j(this.apiContext),await w(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{D as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"node:fs";import r from"node:path";import t from"semver";import i from"@fnet/shelljs";import o from"@fnet/config";import n from"@fnet/object-from-schema";import s from"yaml";import{r as a,w as m}from"./index.js";import{fileURLToPath as p}from"node:url";import"node:child_process";import"node:os";import"yargs";import"chalk";import"@fnet/prompt";import"@fnet/yaml";import"@flownet/lib-render-templates-dir";import"node:util";import"tree-kill";async function c({atom:p,setProgress:c,context:l,deploymentProject:d,deploymentProjectTarget:f,yamlTarget:y}){await c({message:"Deploying it as npm package."});const g=l.projectDir,u=r.resolve(g,"package.json"),w=e.readFileSync(u),b=JSON.parse(w);b.name=f.params.name,b.version=t.inc(f.version,"patch");const h=f.params.bin?.name||f.params.bin;!1!==f.params.bin?.enabled&&h&&"string"==typeof h&&(b.bin={[h]:"dist/cli/esm/index.js"}),delete b.scripts,delete b.devDependencies,b.scripts={serve:"npx serve ."},e.writeFileSync(u,JSON.stringify(b,null,"\t"));const v=f.config||"npm";let j=(await o({name:v,dir:l.projectDir,tags:l.tags,optional:!0}))?.data;if(!j){const t=a("./template/schemas/to-npm.yaml"),i=await n({schema:t,tags:l.tags}),o=l.project.projectDir,m=r.resolve(o,".fnet");e.existsSync(m)||e.mkdirSync(m),e.writeFileSync(r.resolve(m,`${v}.fnet`),s.stringify(i)),j=i}if(e.writeFileSync(r.resolve(g,".npmrc"),`//registry.npmjs.org/:_authToken=${j.env.NPM_TOKEN}`),!0!==f.dryRun){if(m("bun")){if(0!==(await i("bun publish --access public",{cwd:g})).code)throw new Error("Couldnt publish to npm")}else{if(0!==(await i("npm publish --access public",{cwd:g})).code)throw new Error("Couldnt publish to npm")}e.writeFileSync(u,w),d.isDirty=!0,f.version=b.version,y.set("version",b.version)}}r.dirname(p(import.meta.url)),process.cwd();export{c as default};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fnet/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.112.0",
|
|
4
4
|
"files": [
|
|
5
5
|
"dist",
|
|
6
6
|
"template"
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"build": "rollup --config",
|
|
12
12
|
"deploy": "bun publish --access public",
|
|
13
13
|
"watch": "rollup --config --watch --sourcemap --environment DEVELOPMENT",
|
|
14
|
-
"postbuild": "chmod +x dist/fnode/index.js dist/fnet/index.js dist/frun/index.js"
|
|
14
|
+
"postbuild": "chmod +x dist/fnode/index.js dist/fnet/index.js dist/frun/index.js dist/fbin/index.js"
|
|
15
15
|
},
|
|
16
16
|
"repository": {
|
|
17
17
|
"type": "git",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"@fnet/object-from-schema": "^0.1.25",
|
|
42
42
|
"@fnet/prompt": "^0.2.16",
|
|
43
43
|
"@fnet/rollup-plugin-delete": "^0.1.10",
|
|
44
|
-
"@fnet/shell-flow": "^0.1.
|
|
44
|
+
"@fnet/shell-flow": "^0.1.46",
|
|
45
45
|
"@fnet/shelljs": "^0.2.4",
|
|
46
46
|
"@fnet/to-pyip": "^0.1.7",
|
|
47
47
|
"@fnet/to-rust": "^0.1.14",
|
|
@@ -74,7 +74,8 @@
|
|
|
74
74
|
"bin": {
|
|
75
75
|
"fnet": "dist/fnet/index.js",
|
|
76
76
|
"fnode": "dist/fnode/index.js",
|
|
77
|
-
"frun": "dist/frun/index.js"
|
|
77
|
+
"frun": "dist/frun/index.js",
|
|
78
|
+
"fbin": "dist/fbin/index.js"
|
|
78
79
|
},
|
|
79
80
|
"devDependencies": {
|
|
80
81
|
"@rollup/plugin-commonjs": "^28.0.3",
|
package/{README.md → readme.md}
RENAMED
|
@@ -20,11 +20,14 @@ Flownet is a revolutionary development framework that isolates non-functional co
|
|
|
20
20
|
|
|
21
21
|
### Key Features
|
|
22
22
|
|
|
23
|
-
- **Language Agnostic**: Support for multiple programming languages (JavaScript, Python
|
|
23
|
+
- **Language Agnostic**: Support for multiple programming languages (JavaScript, Python) in the same project
|
|
24
24
|
- **Runtime Flexibility**: Choose the best runtime for each task (Node.js, Python, Bun)
|
|
25
25
|
- **Unified Interface**: Consistent commands across different project types
|
|
26
26
|
- **Tag-Based Configuration**: Powerful conditional configuration with `--ftag` parameter
|
|
27
27
|
- **Isolated Workspace**: All build artifacts and dependencies are kept in `.workspace` directory
|
|
28
|
+
- **Binary System**: Compile, install, and manage CLI tools with the integrated binary system
|
|
29
|
+
- **Project File Configuration**: Configure CLI features directly in your project files
|
|
30
|
+
- **Fast Startup**: Pre-compiled binaries start much faster than interpreted scripts
|
|
28
31
|
|
|
29
32
|
## Installation
|
|
30
33
|
|
|
@@ -70,6 +73,30 @@ fnode cli
|
|
|
70
73
|
frun <command-group> [--ftag <tags>]
|
|
71
74
|
```
|
|
72
75
|
|
|
76
|
+
### Compile and Install
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
# Compile a JavaScript file to a binary
|
|
80
|
+
fbin compile script.js -o my-tool
|
|
81
|
+
|
|
82
|
+
# Install a compiled binary
|
|
83
|
+
fbin install ./my-tool --name awesome-tool
|
|
84
|
+
|
|
85
|
+
# Install a CLI-enabled project
|
|
86
|
+
cd my-project
|
|
87
|
+
fnode install --yes
|
|
88
|
+
|
|
89
|
+
# Or use npm scripts in your project
|
|
90
|
+
npm run compile
|
|
91
|
+
npm run install-bin
|
|
92
|
+
|
|
93
|
+
# List installed binaries
|
|
94
|
+
fbin list
|
|
95
|
+
|
|
96
|
+
# Uninstall a binary
|
|
97
|
+
fbin uninstall awesome-tool --yes
|
|
98
|
+
```
|
|
99
|
+
|
|
73
100
|
## Project Types
|
|
74
101
|
|
|
75
102
|
Flownet supports two main project types:
|
|
@@ -93,24 +120,22 @@ An **fnet project** (Flow Project) is a workflow-oriented project that focuses o
|
|
|
93
120
|
|
|
94
121
|
## CLI Tools
|
|
95
122
|
|
|
96
|
-
Flownet provides
|
|
123
|
+
Flownet provides four main CLI tools:
|
|
97
124
|
|
|
98
125
|
- **`fnode`**: For Node/classic projects (uses `fnode.yaml`)
|
|
99
126
|
- **`fnet`**: For Workflow projects (uses `fnet.yaml`)
|
|
100
127
|
- **`frun`**: Unified interface that works with both project types (auto-detects project file)
|
|
128
|
+
- **`fbin`**: Binary management system for installing, compiling, and managing CLI tools
|
|
101
129
|
|
|
102
130
|
## Multi-Language Support
|
|
103
131
|
|
|
104
|
-
Flownet
|
|
132
|
+
Flownet supports multiple programming languages simultaneously within the same project:
|
|
105
133
|
|
|
106
134
|
```text
|
|
107
135
|
my-project/
|
|
108
136
|
├── src/
|
|
109
|
-
│ ├── index.js # JavaScript implementation
|
|
110
|
-
│
|
|
111
|
-
│ ├── index.go # Go implementation
|
|
112
|
-
│ ├── index.rs # Rust implementation
|
|
113
|
-
│ └── index.c # C implementation
|
|
137
|
+
│ ├── index.js # JavaScript implementation (used by both Node.js and Bun)
|
|
138
|
+
│ └── index.py # Python implementation
|
|
114
139
|
├── fnode.yaml # Project configuration file
|
|
115
140
|
└── .workspace/ # Build infrastructure (managed by CLI)
|
|
116
141
|
```
|
|
@@ -119,7 +144,7 @@ This allows you to:
|
|
|
119
144
|
|
|
120
145
|
- Write your core logic once and migrate it to other languages as needed
|
|
121
146
|
- Choose the best language for each specific use case
|
|
122
|
-
-
|
|
147
|
+
- Use JavaScript with Node.js for quick development, Python for data processing, and JavaScript with Bun for improved performance
|
|
123
148
|
|
|
124
149
|
## Tag-Based Configuration
|
|
125
150
|
|
|
@@ -143,3 +168,84 @@ t::dev::database:
|
|
|
143
168
|
t::prod::database:
|
|
144
169
|
url: "mongodb://production-server:27017"
|
|
145
170
|
```
|
|
171
|
+
|
|
172
|
+
## Binary System
|
|
173
|
+
|
|
174
|
+
Flownet includes a powerful binary system that makes it easy to create, distribute, and manage CLI tools:
|
|
175
|
+
|
|
176
|
+
### Binary System Features
|
|
177
|
+
|
|
178
|
+
- **Fast Startup**: Pre-compiled binaries start much faster than interpreted scripts
|
|
179
|
+
- **Cross-Platform Support**: Works on macOS, Linux, and Windows
|
|
180
|
+
- **Multiple Shell Support**: Compatible with Bash, Zsh, Fish, PowerShell, and more
|
|
181
|
+
- **Version Management**: Keeps track of binary versions and metadata
|
|
182
|
+
- **Project Integration**: Easily compile and install CLI-enabled projects
|
|
183
|
+
- **Automation Support**: All commands support the `--yes` flag for scripting
|
|
184
|
+
|
|
185
|
+
### Setup and Usage
|
|
186
|
+
|
|
187
|
+
```bash
|
|
188
|
+
# Initialize the bin system
|
|
189
|
+
fbin setup
|
|
190
|
+
|
|
191
|
+
# Add bin directory to PATH
|
|
192
|
+
fbin path
|
|
193
|
+
|
|
194
|
+
# Compile a JavaScript file to a binary
|
|
195
|
+
fbin compile script.js -o my-tool
|
|
196
|
+
|
|
197
|
+
# Install a binary to the bin directory
|
|
198
|
+
fbin install ./my-tool --name awesome-tool
|
|
199
|
+
|
|
200
|
+
# List installed binaries
|
|
201
|
+
fbin list
|
|
202
|
+
|
|
203
|
+
# Uninstall a binary
|
|
204
|
+
fbin uninstall awesome-tool
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
### Project Integration
|
|
208
|
+
|
|
209
|
+
The binary system integrates seamlessly with Flownet projects:
|
|
210
|
+
|
|
211
|
+
```bash
|
|
212
|
+
# Compile and install a CLI-enabled fnode project
|
|
213
|
+
fnode compile
|
|
214
|
+
fnode install
|
|
215
|
+
|
|
216
|
+
# Compile and install a CLI-enabled fnet project
|
|
217
|
+
fnet compile
|
|
218
|
+
fnet install
|
|
219
|
+
|
|
220
|
+
# Using npm scripts in your project
|
|
221
|
+
npm run compile
|
|
222
|
+
npm run install-bin
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
This makes it easy to distribute your Flownet projects as standalone CLI tools.
|
|
226
|
+
|
|
227
|
+
### CLI Configuration in Project Files
|
|
228
|
+
|
|
229
|
+
You can configure CLI features directly in your project files:
|
|
230
|
+
|
|
231
|
+
```yaml
|
|
232
|
+
# In fnode.yaml or fnet.yaml
|
|
233
|
+
name: my-project
|
|
234
|
+
|
|
235
|
+
features:
|
|
236
|
+
# For fnode projects
|
|
237
|
+
s::runtime.type: node # or python, bun
|
|
238
|
+
|
|
239
|
+
# CLI configuration
|
|
240
|
+
cli:
|
|
241
|
+
enabled: true
|
|
242
|
+
bin: custom-bin-name # Name of the binary (defaults to project name)
|
|
243
|
+
installable: true # Enable 'fnode install' or 'fnet install' command
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
This configuration will:
|
|
247
|
+
|
|
248
|
+
1. Enable CLI functionality for your project
|
|
249
|
+
2. Set the binary name to `custom-bin-name`
|
|
250
|
+
3. Add `compile` and `install-bin` scripts to your package.json
|
|
251
|
+
4. Allow you to install the binary with `fnode install` or `npm run install-bin`
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"main": "dist/default/esm/index.js",
|
|
21
21
|
"type":"module",
|
|
22
22
|
{% else %}
|
|
23
|
-
"main": "dist/default/cjs/index.cjs",
|
|
23
|
+
"main": "dist/default/cjs/index.cjs",
|
|
24
24
|
{% endif %}
|
|
25
25
|
{% if atom.doc.features.dts_enabled ===true %}
|
|
26
26
|
"types": "dist/default/types/index.d.ts",
|
|
@@ -62,7 +62,8 @@
|
|
|
62
62
|
{% else %}
|
|
63
63
|
,"cli": "bun {{atom.doc.features.cli.node_options}} {{atom.doc.features.cli.dir}}/"
|
|
64
64
|
{% endif %}
|
|
65
|
-
|
|
65
|
+
,"compile": "fbin compile {{atom.doc.features.cli.dir}}/index.js -o {{atom.doc['npm::bin'] or atom.doc['name'] or atom['id']}}"
|
|
66
|
+
,"install-bin": "fbin install ./{{atom.doc['npm::bin'] or atom.doc['name'] or atom['id']}} --yes"
|
|
66
67
|
{% endif %}
|
|
67
68
|
{% if atom.doc.features.app.enabled %}
|
|
68
69
|
,"app": "bunx serve {{atom.doc.features.app.dir}}/"
|
|
@@ -71,7 +72,7 @@
|
|
|
71
72
|
"devDependencies": {
|
|
72
73
|
{% for dep in packageDevDependencies %}
|
|
73
74
|
"{{dep.package}}":"{{dep.version}}" {% if not loop.last%},{%endif%}
|
|
74
|
-
{% endfor%}
|
|
75
|
+
{% endfor%}
|
|
75
76
|
},
|
|
76
77
|
"dependencies": {
|
|
77
78
|
{% for dep in packageDependencies %}
|
|
@@ -55,7 +55,7 @@ async function buildOutput(name, config) {
|
|
|
55
55
|
external: (() => {
|
|
56
56
|
try {
|
|
57
57
|
const pkg = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
|
|
58
|
-
return [...Object.keys(pkg.dependencies || {})
|
|
58
|
+
return [...Object.keys(pkg.dependencies || {})];
|
|
59
59
|
} catch (err) {
|
|
60
60
|
console.warn('Could not read package.json:', err.message);
|
|
61
61
|
return [];
|
|
@@ -62,9 +62,11 @@
|
|
|
62
62
|
{% else %}
|
|
63
63
|
,"cli": "bun {{atom.doc.features.cli.node_options}} {{atom.doc.features.cli.dir}}/"
|
|
64
64
|
{% endif %}
|
|
65
|
+
,"compile": "fbin compile {{atom.doc.features.cli.dir}}/index.js -o {{atom.doc['npm::bin'] or atom.doc['name'] or atom['id']}}"
|
|
66
|
+
,"install-bin": "fbin install ./{{atom.doc['npm::bin'] or atom.doc['name'] or atom['id']}} --yes"
|
|
65
67
|
{% endif %}
|
|
66
68
|
{% if atom.doc.features.app.enabled %}
|
|
67
|
-
,"app": "
|
|
69
|
+
,"app": "bun {{atom.doc.features.app.dir}}/index.html"
|
|
68
70
|
{% endif %}
|
|
69
71
|
},
|
|
70
72
|
"devDependencies": {
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"main": "dist/default/esm/index.js",
|
|
21
21
|
"type":"module",
|
|
22
22
|
{% else %}
|
|
23
|
-
"main": "dist/default/cjs/index.cjs",
|
|
23
|
+
"main": "dist/default/cjs/index.cjs",
|
|
24
24
|
{% endif %}
|
|
25
25
|
{% if atom.doc.features.dts_enabled ===true %}
|
|
26
26
|
"types": "dist/default/types/index.d.ts",
|
|
@@ -62,7 +62,8 @@
|
|
|
62
62
|
{% else %}
|
|
63
63
|
,"cli": "bun {{atom.doc.features.cli.node_options}} {{atom.doc.features.cli.dir}}/"
|
|
64
64
|
{% endif %}
|
|
65
|
-
|
|
65
|
+
,"compile": "fbin compile {{atom.doc.features.cli.dir}}/index.js -o {{atom.doc['npm::bin'] or atom.doc['name'] or atom['id']}}"
|
|
66
|
+
,"install-bin": "fbin install ./{{atom.doc['npm::bin'] or atom.doc['name'] or atom['id']}} --yes"
|
|
66
67
|
{% endif %}
|
|
67
68
|
{% if atom.doc.features.app.enabled %}
|
|
68
69
|
,"app": "bunx serve {{atom.doc.features.app.dir}}/"
|
|
@@ -71,7 +72,7 @@
|
|
|
71
72
|
"devDependencies": {
|
|
72
73
|
{% for dep in packageDevDependencies %}
|
|
73
74
|
"{{dep.package}}":"{{dep.version}}" {% if not loop.last%},{%endif%}
|
|
74
|
-
{% endfor%}
|
|
75
|
+
{% endfor%}
|
|
75
76
|
},
|
|
76
77
|
"dependencies": {
|
|
77
78
|
{% for dep in packageDependencies %}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import e from"node:fs";import r from"node:path";import t from"semver";import o from"@fnet/shelljs";import i from"@fnet/config";import n from"@fnet/object-from-schema";import s from"yaml";import{r as m,w as a}from"./index.js";import{fileURLToPath as p}from"node:url";import"node:child_process";import"node:os";import"yargs";import"@fnet/prompt";import"@fnet/yaml";import"@fnet/shell-flow";import"@flownet/lib-render-templates-dir";import"node:util";import"tree-kill";async function c({atom:p,setProgress:c,context:l,deploymentProject:d,deploymentProjectTarget:f,yamlTarget:y}){await c({message:"Deploying it as npm package."});const g=l.projectDir,w=r.resolve(g,"package.json"),u=e.readFileSync(w),b=JSON.parse(u);b.name=f.params.name,b.version=t.inc(f.version,"patch");const h=f.params.bin?.name||f.params.bin;!1!==f.params.bin?.enabled&&h&&"string"==typeof h&&(b.bin={[h]:"dist/cli/esm/index.js"}),delete b.scripts,delete b.devDependencies,b.scripts={serve:"npx serve ."},e.writeFileSync(w,JSON.stringify(b,null,"\t"));const v=f.config||"npm";let j=(await i({name:v,dir:l.projectDir,tags:l.tags,optional:!0}))?.data;if(!j){const t=m("./template/schemas/to-npm.yaml"),o=await n({schema:t,tags:l.tags}),i=l.project.projectDir,a=r.resolve(i,".fnet");e.existsSync(a)||e.mkdirSync(a),e.writeFileSync(r.resolve(a,`${v}.fnet`),s.stringify(o)),j=o}if(e.writeFileSync(r.resolve(g,".npmrc"),`//registry.npmjs.org/:_authToken=${j.env.NPM_TOKEN}`),!0!==f.dryRun){if(a("bun")){if(0!==(await o("bun publish --access public",{cwd:g})).code)throw new Error("Couldnt publish to npm")}else{if(0!==(await o("npm publish --access public",{cwd:g})).code)throw new Error("Couldnt publish to npm")}e.writeFileSync(w,u),d.isDirty=!0,f.version=b.version,y.set("version",b.version)}}r.dirname(p(import.meta.url)),process.cwd();export{c as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import e from"lodash.merge";import t from"node:fs";import a from"node:path";import s from"@flownet/lib-parse-imports-js";import{h as r,j as n,k as i,l as o,m as l}from"./index.CLlKzCGk.js";import p from"@fnet/npm-list-versions";import c from"nunjucks";function d({dir:e,name:s="index"}){let r=a.resolve(e,`./${s}.tsx`);if(t.existsSync(r)||(r=a.resolve(e,`./${s}.ts`)),t.existsSync(r)||(r=a.resolve(e,`./${s}.jsx`)),t.existsSync(r)||(r=a.resolve(e,`./${s}.js`)),!t.existsSync(r))return{};const n=r,i=a.extname(r);return{file:n,ext:i,ts:".ts"===i||".tsx"===i,name:s}}async function f({atom:t,context:p,setProgress:c}){await c({message:"Initializing features..."}),t.doc.features=t.doc.features||{};const f=t.doc.features;f.project=f.project||{},f.project.format=f.project.format||f.project_format||"esm",f.project_format=f.project.format,f.dts_enabled=!0===f.dts||void 0!==f.dts&&!1!==f.dts;const u=a.resolve(p.project.projectDir),m=d({dir:a.resolve(u,"./app")});if(m.file){c("Parsing app entry imports...");let e=await s({file:m.file,recursive:!0}),t=e.all.some((e=>!0===e.usesJSX&&"local"===e.type));f.app_uses_jsx=t,f.app_has_entry=!0,e=await s({file:m.file}),t=e.all.some((e=>!0===e.usesJSX&&"local"===e.type)),f.app_entry_uses_jsx=t,f.app_entry_is_ts=m.ts,f.app_entry_ext=m.ext}const _=d({dir:a.resolve(u,"./cli")});if(_.file){c("Parsing cli entry imports...");let e=await s({file:_.file,recursive:!0}),t=e.all.some((e=>!0===e.usesJSX&&"local"===e.type));f.cli_uses_jsx=t,f.cli_has_entry=!0,e=await s({file:_.file}),t=e.all.some((e=>!0===e.usesJSX&&"local"===e.type)),f.cli_entry_uses_jsx=t,f.cli_entry_is_ts=_.ts,f.cli_entry_ext=_.ext}if("workflow.lib"===t.type){const e=d({dir:a.resolve(u,"./src")});if(e.file){c("Parsing src entry imports...");let t=await s({file:e.file,recursive:!0}),a=t.all.some((e=>!0===e.usesJSX&&"local"===e.type));f.src_uses_jsx=a,f.src_has_entry=!0,t=await s({file:e.file}),a=t.all.some((e=>!0===e.usesJSX&&"local"===e.type)),f.src_entry_uses_jsx=a,f.src_entry_is_ts=e.ts,f.src_entry_ext=e.ext}}const y=Reflect.has(f,"app_entry_uses_jsx")?!0===f.app_entry_uses_jsx:!0===f.src_entry_uses_jsx,b=Reflect.has(f,"cli_entry_uses_jsx")?!0===f.cli_entry_uses_jsx:!0===f.src_entry_uses_jsx;f.form_enabled=y||b||!0===f.form||!0===f.form?.enabled,f.multiple_enabled=f.multiple_enabled||!0===f.multiple||!0===f.multiple?.enabled,!1===f.app?f.app={enabled:!1}:!0===f.app?f.app={enabled:!0,extend:!0===f.app_has_entry,export:!0,react:y}:f.app={enabled:!0,extend:!0===f.app_has_entry,export:!0,react:y,...f.app||{}},f.app.enabled=!0===f.app.enabled&&(!0===t.doc.features.form_enabled||!0===f.app.extend||!0===f.app.enabled),f.app.format=f.app.format||"esm",f.app.folder=f.app.folder||f.app.format||"esm",f.app.dir=`./dist/app/${f.app.folder}`,f.app.html=!1!==f.app.html,!1===f.cli?f.cli={enabled:!1}:!0===f.cli?f.cli={enabled:!0,extend:!0===f.cli_has_entry,export:!0,react:b}:f.cli={enabled:!0,extend:!0===f.cli_has_entry,export:!0,react:b,...f.cli||{}},f.cli.enabled=!0===f.cli.enabled&&(!1===t.doc.features.form_enabled||!0===f.cli.extend||!0===f.cli.enabled),f.cli.format=f.cli.format||"esm",f.cli.folder=f.cli.folder||f.cli.folder||"esm",f.cli.dir=`./dist/cli/${f.cli.folder}`,f.cli.node_options=f.cli.node?.options||f.cli.node_options||"",f.json=f.cli.enabled||f.json,f.bun=f.bun||{},f.bun.build=f.bun.build||{};const x={default:{format:"esm",target:"browser",minify:!1,sourcemap:"external",entrypoints:["./src/default/index.js"],outdir:"./dist/default/esm"},defaultCjs:{format:"cjs",target:"node",minify:!1,sourcemap:"external",entrypoints:["./src/default/index.js"],outdir:"./dist/default/cjs"}};f.cli.enabled&&(x.cli={format:"esm",target:"node",minify:!1,sourcemap:"external",entrypoints:["./src/cli/index.js"],outdir:f.cli.dir}),f.app.enabled&&(x.app={format:"esm",target:"browser",minify:!1,sourcemap:"external",entrypoints:["./src/app/index.js"],outdir:f.app.dir}),f.bun.build=e(x,f.bun.build||{}),f.preact_enabled=!0===f.preact||f.preact&&!1!==f.preact?.enabled,f.dependency_auto_enabled=!1!==f.dependency_auto&&!1!==f.dependency_auto?.enabled,f.npm_install_flags=f.npm_install_flags||"",f.react_version=f.react_version||f.react?.version||18,f.runtime=f.runtime||{},f.runtime.type="bun",f.runtime.template="bun",r({atom:t}),n({atom:t}),i({atom:t}),o({atom:t}),l({atom:t})}async function u({atom:e,packageDependencies:t,packageDevDependencies:a,setProgress:s}){s("Initializing dependencies for Bun");const r=e.doc.dependencies||[];if(r.filter((e=>!e.dev)).forEach((e=>t.push(e))),r.filter((e=>e.dev)).forEach((e=>a.push(e))),"workflow"===e.type&&(t.push({package:"get-value",version:"^3"}),t.push({package:"set-value",version:"^4"})),e.doc.features.form_enabled&&e.doc.features.dependency_auto_enabled){let a="^18.2";s("Fetching React versions");a=`^${(await p({name:"react",groupBy:{major:!0}})).find((t=>t[0]===e.doc.features.react_version.toString()))[0]}`,t.push({package:"react",version:a}),t.push({package:"react-dom",version:a}),"workflow"===e.type&&(t.push({package:"@fnet/react-app",version:"^0.1"}),t.push({package:"@fnet/react-app-state",version:"^0.1"}))}e.doc.features.preact_enabled&&t.push({package:"preact",version:"^10"}),!0===e.doc.features.cli.enabled&&(t.push({package:"@fnet/args",version:"^0.1"}),a.push({package:"ajv",version:"^8"}),e.doc.features.cli.fargs&&!1!==e.doc.features.cli.fargs?.enabled&&t.push({package:"@fnet/config",version:"0.2.21"})),e.doc.features.render&&!1!==e.doc.features.render.enabled&&a.push({package:"@flownet/lib-render-templates-dir",version:"0.1.19"})}async function m({atom:e,setProgress:s,context:r,packageDependencies:n}){await s({message:"Creating build.js file."});const i={atom:e,packageDependencies:n},o=r.templateDir,l=c.compile(t.readFileSync(a.resolve(o,"build.js.njk"),"utf8"),c.configure(o)).render(i),p=r.projectDir,d=a.resolve(p,"build.js");t.writeFileSync(d,l,"utf8"),t.chmodSync(d,"755")}export{u as a,m as c,f as i};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import t from"node:fs";import i from"node:path";import e from"node:os";import s from"@fnet/list-files";import{B as o}from"./index.Bqzc7Bx8.js";import{i as r,a,c as n,b as c}from"./index.BBrItYB9.js";import{c as l,a as m}from"./index.BwhWziH6.js";import"node:crypto";import"yaml";import"nunjucks";import"chalk";import"@flownet/lib-atom-api-js";import"@fnet/config";import"@flownet/lib-render-templates-dir";import"@fnet/auto-conda-env";import"redis";import"@flownet/lib-is-redis-online";import"@fnet/yaml";class d extends o{async initRuntime(){await r(this.apiContext),await a(this.apiContext),await this.initLibraryDirPython(),await this.initNunjucks(),await this.initLibsPython()}async initLibraryDirPython(){this.setProgress({message:"Initializing library directory."});const o=this.context.projectDir;this.setProgress({message:"Cleaning project directory."});const r=s({dir:o,ignore:[".cache","node_modules",".conda"],absolute:!0});for(const i of r)t.rmSync(i,{recursive:!0,force:!0});this.setProgress({message:"Creating project directory."});let a=o;t.existsSync(a)||t.mkdirSync(a,{recursive:!0}),a=i.join(o,"src"),t.existsSync(a)||t.mkdirSync(a,{recursive:!0}),a=i.join(o,"src","default");const n=this.context.projectSrcDir;if(!t.existsSync(a))try{"win32"===e.platform()?t.symlinkSync(n,a,"junction"):t.symlinkSync(n,a,"dir")}catch(t){throw new Error(`Couldn't create symlink. Error: ${t.message}`)}}async initLibsPython(){this.setProgress({message:"Initializing external libs."});const t=this.atom;t.protocol="local:",t.doc.dependencies=t.doc.dependencies||[],t.name=t.doc.name;const i=[{name:this.atom.doc.name,type:"atom",parent_id:this.atom.parent_id,atom:t}];this.libs=i}async createAtomLibFilesPython({libs:e}){await this.setProgress({message:"Creating external lib files."});const s=e.filter((t=>"atom"===t.type));for(let e=0;e<s.length;e++){const o=s[e].atom;if("local:"===o.protocol){const e=i.resolve(this.context.projectSrcDir,`${o.fileName||o.name}.py`);if(!t.existsSync(e)){t.mkdirSync(i.dirname(e),{recursive:!0});let s="def default():\n";s+=' print("Hello world!")\n',t.writeFileSync(e,s,"utf8")}}}}async build(){try{this.fileMode&&(await this.createAtomLibFilesPython({libs:this.libs}),await this.createProjectYaml(),await l(this.apiContext),await m(this.apiContext),await n(this.apiContext),this.buildMode&&(await c(this.apiContext),this.deployMode&&await this.deploy())),await this._cache_set(this.buildKey,{status:"COMPLETED"})}catch(t){throw await this._cache_set(this.buildKey,{status:"FAILED",message:t.message||t}),console.log(t),t}}}export{d as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import e from"node:fs";import a from"node:path";import n from"@flownet/lib-render-templates-dir";import t from"@fnet/auto-conda-env";async function r(e){const{atom:a,context:n,setProgress:t}=e;t("Initializing features..."),a.doc.features=a.doc.features||{};const r=a.doc.features;!1===r.cli?r.cli={enabled:!1}:(r.cli,r.cli={enabled:!0}),r.cli.enabled=!0===r.cli.enabled&&(!1===a.doc.features.form_enabled||!0===r.cli.extend||!0===r.cli.enabled)}async function i({atom:e,packageDependencies:a,packageDevDependencies:n,setProgress:t}){t("Initializing dependencies")}async function o({atom:t,setProgress:r,context:i,packageDependencies:o}){if(!0!==t.doc.features.cli.enabled)return;await r({message:"Creating cli."});const s={atom:t,packageDependencies:o},c=i.templateDir,p=a.join(i.projectDir,"src","cli");e.existsSync(p)||e.mkdirSync(p,{recursive:!0}),await n({pattern:["index.py.njk","__init__.py.njk"],dir:a.join(c,"src","cli"),outDir:p,context:s})}async function s(e){const{setProgress:r,atom:i,context:o}=e;r({message:"Installing Python packages"});const s=o.projectDir,c=await t({pythonVersion:"3.12",packages:[{package:"fnet-import-parser",version:"0.1.9"}]}),{errors:p,result:d}=await c.runBin("fnet_import_parser",["--entry_file",a.join(s,"src","default","index.py")],{captureName:"result"});if(p)throw new Error(p.format());const m=JSON.parse(d.items[0].stdout),l=m.required["third-party"]?.map((e=>({package:e.metadata?.package||e.path,version:e.metadata?.version||void 0,channel:e.metadata?.channel||void 0})))||[],f=i.doc.dependencies||[];for(const e of l)f.some((a=>a.package===e.package))||f.push(e);const u=a.join(s,".conda"),g=await t({envDir:u,pythonVersion:i.doc.features.runtime.version||"3.12",packages:f});o.pythonEnv=g,e.packageDependencies=f;const k=i.doc.features.render?.dirs||[];for(const e of k)e.dir=a.resolve(s,e.dir),e.outDir=a.resolve(s,e.outDir),await n(e);let y={params:{}};y.params.package_name=i.doc.name,y.params.version="0.1.0",y.params.bin_name=i.doc.name,y.params.python_requires=i.doc.features.runtime.version||">=3.12",y.params.dependencies=f,y.params.scripts=JSON.stringify({cli:`PYTHONPATH='${a.join("src")}' '${a.relative(o.projectDir,g.pythonBin)}' '${a.join("src","cli","index.py")}'`}),await n({pattern:["setup.py.njk","package.json.njk","pyproject.toml.njk"],dir:o.templateDir,outDir:o.projectDir,context:y})}export{i as a,s as b,o as c,r as i};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import t from"node:fs";import i from"node:path";import e from"node:os";import s from"yaml";import a from"nunjucks";import{randomUUID as o}from"node:crypto";import{Atom as n}from"@flownet/lib-atom-api-js";import r from"@flownet/lib-parse-node-url";import c from"@fnet/config";import p from"@flownet/lib-parse-imports-js";import h from"@fnet/list-files";import l from"chalk";import{A as d,d as m,c as y,a as f,b as g}from"./index.BwhWziH6.js";import{i as u,a as w,c as x,b}from"./index.D4KQB1ot.js";import{i as j,a as C,c as k,b as D}from"./index.BBrItYB9.js";import{i as v,a as P,c as _}from"./index.B1zLg4Y2.js";import{p as S,c as A,a as E,b as L,d as I,e as M,f as T,i as F,r as N}from"./index.CLlKzCGk.js";import"redis";import"@flownet/lib-is-redis-online";import"@fnet/yaml";import"lodash.merge";import"@fnet/npm-list-versions";import"@fnet/shelljs";import"@flownet/lib-render-templates-dir";import"@fnet/auto-conda-env";import"@fnet/npm-pick-versions";import"object-hash";import"ajv/dist/2020.js";import"ajv/dist/standalone/index.js";import"ajv-formats";import"./index.js";import"node:url";import"node:child_process";import"yargs";import"@fnet/prompt";import"@fnet/shell-flow";import"node:util";import"tree-kill";class B{#t;#i;#e;#s;#a;#o;#n;#r;#c;#p;#h;#l;#d;#m;#y;#f;#g;constructor(t){this.#t=new d,this.#i=t,this.#o=[],this.#n=[],this._expire_ttl=3600,this._expire_ttl_short=300,this.#g={packageDependencies:this.#o,packageDevDependencies:this.#n,setProgress:this.setProgress.bind(this),context:this.#i,Atom:n,registerToPackageManager:this.registerToPackageManager.bind(this)}}async _cache_set(t,i,e){this._redis_client&&await this._redis_client.SETEX(t,e||this._expire_ttl,JSON.stringify(i)).catch(console.error)}async initAuth(){this.#i.id&&(this.#r=await this.#t.init({config:this.#l}),this.#g.atomAccessToken=this.#r)}async initLibrary(){const t=this.#i.id;this.#e=this.#i.project?.libraryAtom||await n.get({id:t});let i=this.#e.doc.bundleName;i=i||(this.#e.doc.name||"").toUpperCase().replace(/[^A-Z0-9]/g,"_"),this.#e.doc.bundleName=i,this.#e.type=this.#e.type||"workflow.lib",this.#g.atom=this.#e}async initLibraryDir(){this.setProgress({message:"Initializing library directory."});const e=this.#i.projectDir;this.setProgress({message:"Cleaning project directory."});const s=h({dir:e,ignore:[".cache","node_modules",".conda"],absolute:!0});for(const i of s)t.rmSync(i,{recursive:!0,force:!0});this.setProgress({message:"Creating project directory."});let a=e;t.existsSync(a)||t.mkdirSync(a,{recursive:!0}),a=i.join(e,"src"),t.existsSync(a)||t.mkdirSync(a,{recursive:!0}),a=i.join(e,"src","default"),t.existsSync()||t.mkdirSync(a,{recursive:!0})}async initLibraryDirPython(){this.setProgress({message:"Initializing library directory."});const s=this.#i.projectDir;this.setProgress({message:"Cleaning project directory."});const a=h({dir:s,ignore:[".cache","node_modules",".conda"],absolute:!0});for(const i of a)t.rmSync(i,{recursive:!0,force:!0});this.setProgress({message:"Creating project directory."});let o=s;t.existsSync(o)||t.mkdirSync(o,{recursive:!0}),o=i.join(s,"src"),t.existsSync(o)||t.mkdirSync(o,{recursive:!0}),o=i.join(s,"src","default");const n=this.#i.projectSrcDir;if(!t.existsSync(o))try{"win32"===e.platform()?t.symlinkSync(n,o,"junction"):t.symlinkSync(n,o,"dir")}catch(t){throw new Error(`Couldn't create symlink. Error: ${t.message}`)}}async initNunjucks(){this.setProgress({message:"Initializing nunjucks."});const t=this.#i.templateDir;this.#s=a.configure(t,{watch:!1,dev:!0}),this.#g.njEnv=this.#s}async initLibs(){this.setProgress({message:"Initializing external libs."});const t=[{name:this.#e.doc.name,type:"atom",parent_id:this.#e.parent_id}];this.#a=t,await this.initAtomLibsAndDeps({libs:t,packageDependencies:this.#o})}async initLibsPython(){this.setProgress({message:"Initializing external libs."});const t=this.#e;t.protocol="local:",t.doc.dependencies=t.doc.dependencies||[],t.name=t.doc.name;const i=[{name:this.#e.doc.name,type:"atom",parent_id:this.#e.parent_id,atom:t}];this.#a=i}async initAtomLibsAndDeps({libs:t,packageDependencies:i}){const e=t.filter((t=>"atom"===t.type));for(let t=0;t<e.length;t++){const s=e[t],a=await this.findAtomLibrary({url:s.name});s.atom=a;const o=a.doc.dependencies?.filter((t=>void 0===t.repo||"npm"===t.repo));o?.forEach((t=>{const e=i.find((i=>i.package===t.package));e?"string"==typeof t.path?(e.path||[]).some((i=>i===t.path))||(e.path=e.path||[],e.path.push(t.path)):Array.isArray(t.path)&&t.path.forEach((t=>{(e.path||[]).some((i=>i===t))||(e.path=e.path||[],e.path.push(t))})):i.push(t)}))}i.sort(((t,i)=>t.package?.localeCompare(i.package)))}async findAtomLibrary({url:t}){const e=r({url:t});if(!e)throw new Error(`Invalid package name: ${t}`);if(e.protocol||(e.protocol=this.#h),"ac:"===e.protocol){const i=e.pathname.split("/");if(1===i.length)return await n.first({where:{name:t,parent_id:this.#l.env.ATOM_LIBRARIES_ID,type:"workflow.lib"}});if(2===i.length){const t=await n.first({where:{name:i[0],parent_id:this.#l.env.ATOM_LIBRARIES_ID,type:"folder"}});return await n.first({where:{name:i[1],parent_id:t.id,type:"workflow.lib"}})}}else if("local:"===e.protocol){const t=this.#e;t.protocol="local:",t.doc.dependencies=t.doc.dependencies||[],t.name=t.doc.name;const e=i.resolve(this.#i.projectSrcDir,"index.js"),s=await p({file:e,recursive:!0}),a=t.doc.dependencies,o=s.all;for await(const t of o){if("npm"!==t.type)continue;if(a.find((i=>i.package===t.package)))continue;const i=await S({name:t.package,projectDir:this.#i.projectDir,setProgress:this.#g.setProgress});a.push({package:t.package,subpath:t.subpath,version:i.minorRange,type:"npm"})}return t}}async createAtomLibFiles({libs:e}){await this.setProgress({message:"Creating external lib files."}),this.#e.typesDir="./types";const s=e.filter((t=>"atom"===t.type));for(let e=0;e<s.length;e++){const a=s[e].atom,o=this.#i.projectDir;if("local:"===a.protocol){const e=i.resolve(this.#i.projectSrcDir,`${a.fileName||a.name}.js`),s=i.relative(i.join(this.#i.projectDir,"src","default"),e);if(!t.existsSync(e)){t.mkdirSync(i.dirname(e),{recursive:!0});let s="export default async (args)=>{\n";s+="}",t.writeFileSync(e,s,"utf8")}a.relativePath=s.split(i.sep).join("/"),this.#e.typesDir=`./types/${i.basename(o)}/src`}else{const e=i.join(o,"src","libs",`${a.id}.js`),s=a.doc.contents?.find((t=>"esm"===t.format))||a.doc;t.writeFileSync(e,s.content,"utf8")}}}async createAtomLibFilesPython({libs:e}){await this.setProgress({message:"Creating external lib files."});const s=e.filter((t=>"atom"===t.type));for(let e=0;e<s.length;e++){const a=s[e].atom;if("local:"===a.protocol){const e=i.resolve(this.#i.projectSrcDir,`${a.fileName||a.name}.py`);if(!t.existsSync(e)){t.mkdirSync(i.dirname(e),{recursive:!0});let s="def default():\n";s+=' print("Hello world!")\n',t.writeFileSync(e,s,"utf8")}}}}async createEngine(){await this.setProgress({message:"Creating engine file."});const e={libs:this.#a.filter((t=>"atom"===t.type)),libraryAtom:this.#e,atom:this.#e},s=this.#i.templateDir,o=a.compile(t.readFileSync(i.resolve(s,i.join("src","default","engine.js.njk")),"utf8"),this.#s).render(e),n=this.#i.projectDir,r=i.resolve(n,i.join("src","default","index.js"));t.writeFileSync(r,o,"utf8")}async createProjectYaml(){const e="fnode.yaml",o=`Creating ${e}`;await this.setProgress({message:o});const{content:n,...r}=this.#e.doc,c={content:s.stringify(r)},p=this.#i.templateDir,h=i.resolve(p,`${e}.njk`);if(!t.existsSync(h))throw new Error(`fnode.yaml.njk template not found in ${p}`);const l=a.compile(t.readFileSync(h,"utf8"),this.#s).render(c),d=this.#i.projectDir,m=i.resolve(d,`${e}`);t.writeFileSync(m,l,"utf8")}async deploy(){if(await this.setProgress({message:"Deploying."}),this.#i.project?.devops){const t=[this.#i.project?.devops];for(let i=0;i<t.length;i++){let e=t[i];await this.deployProject({deploymentProject:e}),!0===e.isDirty&&await e.save()}}else if(this.#e.id){const t=await n.list({type:"library.deploy",parent_id:this.#e.id});for(let i=0;i<t.length;i++){let e=t[i];await this.deployProject({deploymentProject:e}),!0===e.isDirty&&(e=await n.update(e,{id:e.id}))}}}async deployProject(t){const{deploymentProject:i}=t,{yamlDocument:e}=i;if(i.doc.targets&&Array.isArray(i.doc.targets))throw new Error("Deployment project targets are deprecated. Please update targets in the yaml file.");const s=Object.keys(i.doc||{}),a=e||{};for(let t=0;t<s.length;t++){const e=i.doc[s[t]];e.name=s[t];const o=a.get(s[t]);await m({...this.#g,deploymentProject:i,deploymentProjectTarget:e,yamlTarget:o})}}async registerToPackageManager(t){const{target:i,packageJSON:e}=t;if(!this.#i.id)return;let s=await n.first({name:i.params.name,parent_id:this.#l.env.ATOM_PACKAGES_ID});s?(s.doc.versions.splice(0,0,{v:e.version}),await n.update(s,{id:s.id})):s=await n.create({parent_id:this.#l.env.ATOM_PACKAGES_ID,doc:{name:i.params.name,type:"pm",versions:[{v:e.version}]}})}async setProgress(t){const i="string"==typeof t?t:t?.message;console.log(l.blue(i)),await this._cache_set(this.#p,{status:"IN_PROGRESS",message:i})}async initNode(){await u(this.#g),await w(this.#g),await this.initLibraryDir(),await this.initNunjucks(),await this.initLibs()}async initBun(){await v(this.#g),await P(this.#g),await this.initLibraryDir(),await this.initNunjucks(),await this.initLibs()}async initPython(){await j(this.#g),await C(this.#g),await this.initLibraryDirPython(),await this.initNunjucks(),await this.initLibsPython()}async nodeBuild(){this.#m&&(await this.createAtomLibFiles({libs:this.#a}),await this.createEngine(),await this.createProjectYaml(),await y(this.#g),await A(this.#g),await f(this.#g),await E(this.#g),await L(this.#g),await I(this.#g),await x(this.#g),await M(this.#g),await T(this.#g),await b(this.#g),this.#y&&(await F(this.#g),await N(this.#g),this.#f&&await this.deploy()))}async bunBuild(){this.#m&&(await this.createAtomLibFiles({libs:this.#a}),await this.createEngine(),await this.createProjectYaml(),await y(this.#g),await A(this.#g),await f(this.#g),await E(this.#g),await L(this.#g),await I(this.#g),await _(this.#g),await M(this.#g),await T(this.#g),this.#y&&(await F(this.#g),await N(this.#g),this.#f&&await this.deploy()))}async pythonBuild(){this.#m&&(await this.createAtomLibFilesPython({libs:this.#a}),await this.createProjectYaml(),await y(this.#g),await f(this.#g),await k(this.#g),this.#y&&(await D(this.#g),this.#f&&await this.deploy()))}async init(){this._redis_client=await g(),this.#c=this.#i.buildId||o(),this.#g.buildId=this.#c,this.#d=this.#i.mode,this.#m=["all","deploy","build","file"].includes(this.#d),this.#y=["all","deploy","build"].includes(this.#d),this.#f=["all","deploy"].includes(this.#d),this.#h=this.#i.protocol,this.#p="BUILD:"+this.#c,this.#l=(await c({optional:!0,name:this.#i.atomConfig||"atom",dir:this.#i.projectDir,tags:this.#i.tags}))?.data;try{await this.setProgress({message:"Initialization started."}),await this.initAuth(),await this.initLibrary(),"node"===this.#e.doc.features.runtime.type?await this.initNode():"bun"===this.#e.doc.features.runtime.type?await this.initBun():"python"===this.#e.doc.features.runtime.type&&await this.initPython()}catch(t){throw await this._cache_set(this.#p,{status:"FAILED",message:t?.message||t}),t}}async build(){try{"node"===this.#e.doc.features.runtime.type?await this.nodeBuild():"bun"===this.#e.doc.features.runtime.type?await this.bunBuild():"python"===this.#e.doc.features.runtime.type&&await this.pythonBuild(),await this._cache_set(this.#p,{status:"COMPLETED"})}catch(t){throw await this._cache_set(this.#p,{status:"FAILED",message:t.message||t}),console.log(t),t}}}export{B as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import t from"node:fs";import e from"node:path";import{randomUUID as i}from"node:crypto";import s from"yaml";import o from"nunjucks";import n from"chalk";import{Atom as a}from"@flownet/lib-atom-api-js";import r from"@fnet/config";import c from"@fnet/list-files";import{A as d,d as l,b as h}from"./index.BwhWziH6.js";class m{#t;#e;#i;#s;#o;#n;#a;#r;#c;#d;#l;#h;#m;#p;#g;#y;#u;constructor(t){this.#t=new d,this.#e=t,this.#n=[],this.#a=[],this._expire_ttl=3600,this._expire_ttl_short=300,this.#u={packageDependencies:this.#n,packageDevDependencies:this.#a,setProgress:this.setProgress.bind(this),context:this.#e,Atom:a,registerToPackageManager:this.registerToPackageManager.bind(this)}}get apiContext(){return this.#u}get context(){return this.#e}get atom(){return this.#i}get libs(){return this.#o}set libs(t){this.#o=t}get fileMode(){return this.#p}get buildMode(){return this.#g}get deployMode(){return this.#y}async _cache_set(t,e,i){this._redis_client&&await this._redis_client.SETEX(t,i||this._expire_ttl,JSON.stringify(e)).catch(console.error)}async initAuth(){this.#e.id&&(this.#r=await this.#t.init({config:this.#h}),this.#u.atomAccessToken=this.#r)}async initLibrary(){const t=this.#e.id;this.#i=this.#e.project?.libraryAtom||await a.get({id:t});let e=this.#i.doc.bundleName;e=e||(this.#i.doc.name||"").toUpperCase().replace(/[^A-Z0-9]/g,"_"),this.#i.doc.bundleName=e,this.#i.type=this.#i.type||"workflow.lib",this.#u.atom=this.#i}async initLibraryDir(){this.setProgress({message:"Initializing library directory."});const i=this.#e.projectDir;this.setProgress({message:"Cleaning project directory."});const s=c({dir:i,ignore:[".cache","node_modules",".conda"],absolute:!0});for(const e of s)t.rmSync(e,{recursive:!0,force:!0});this.setProgress({message:"Creating project directory."});let o=i;t.existsSync(o)||t.mkdirSync(o,{recursive:!0}),o=e.join(i,"src"),t.existsSync(o)||t.mkdirSync(o,{recursive:!0}),o=e.join(i,"src","default"),t.existsSync(o)||t.mkdirSync(o,{recursive:!0})}async initNunjucks(){this.setProgress({message:"Initializing nunjucks."});const t=this.#e.templateDir;this.#s=o.configure(t,{watch:!1,dev:!0}),this.#u.njEnv=this.#s}async createProjectYaml(){const i="fnode.yaml",n=`Creating ${i}`;await this.setProgress({message:n});const{content:a,...r}=this.#i.doc,c={content:s.stringify(r)},d=this.#e.templateDir,l=e.resolve(d,`${i}.njk`);if(!t.existsSync(l))throw new Error(`fnode.yaml.njk template not found in ${d}`);const h=o.compile(t.readFileSync(l,"utf8"),this.#s).render(c),m=this.#e.projectDir,p=e.resolve(m,`${i}`);t.writeFileSync(p,h,"utf8")}async deploy(){if(await this.setProgress({message:"Deploying."}),this.#e.project?.devops){const t=[this.#e.project?.devops];for(let e=0;e<t.length;e++){let i=t[e];await this.deployProject({deploymentProject:i}),!0===i.isDirty&&await i.save()}}else if(this.#i.id){const t=await a.list({type:"library.deploy",parent_id:this.#i.id});for(let e=0;e<t.length;e++){let i=t[e];await this.deployProject({deploymentProject:i}),!0===i.isDirty&&(i=await a.update(i,{id:i.id}))}}}async deployProject(t){const{deploymentProject:e}=t,{yamlDocument:i}=e;if(e.doc.targets&&Array.isArray(e.doc.targets))throw new Error("Deployment project targets are deprecated. Please update targets in the yaml file.");const s=Object.keys(e.doc||{}),o=i||{};for(let t=0;t<s.length;t++){const i=e.doc[s[t]];i.name=s[t];const n=o.get(s[t]);await l({...this.#u,deploymentProject:e,deploymentProjectTarget:i,yamlTarget:n})}}async registerToPackageManager(t){const{target:e,packageJSON:i}=t;if(!this.#e.id)return;let s=await a.first({name:e.params.name,parent_id:this.#h.env.ATOM_PACKAGES_ID});s?(s.doc.versions.splice(0,0,{v:i.version}),await a.update(s,{id:s.id})):s=await a.create({parent_id:this.#h.env.ATOM_PACKAGES_ID,doc:{name:e.params.name,type:"pm",versions:[{v:i.version}]}})}async setProgress(t){const e="string"==typeof t?t:t?.message;console.log(n.blue(e)),await this._cache_set(this.#d,{status:"IN_PROGRESS",message:e})}async init(){this._redis_client=await h(),this.#c=this.#e.buildId||i(),this.#u.buildId=this.#c,this.#m=this.#e.mode,this.#p=["all","deploy","build","file"].includes(this.#m),this.#g=["all","deploy","build"].includes(this.#m),this.#y=["all","deploy"].includes(this.#m),this.#l=this.#e.protocol,this.#d="BUILD:"+this.#c,this.#h=(await r({optional:!0,name:this.#e.atomConfig||"atom",dir:this.#e.projectDir,tags:this.#e.tags}))?.data;try{await this.setProgress({message:"Initialization started."}),await this.initAuth(),await this.initLibrary(),await this.initRuntime()}catch(t){throw await this._cache_set(this.#d,{status:"FAILED",message:t?.message||t}),t}}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")}}export{m as B};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import e from"redis";import t from"@flownet/lib-is-redis-online";import{Api as r}from"@flownet/lib-atom-api-js";import i from"node:fs";import o from"node:path";import a from"nunjucks";import n from"@fnet/yaml";async function s(){if(!await t({host:process.env.REDIS_HOST,port:process.env.REDIS_PORT}))return;const r=e.createClient({socket:{host:process.env.REDIS_HOST,port:process.env.REDIS_PORT}});return await r.connect(),r}class c{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)}))}))}}async function p({atom:e,setProgress:t,context:r,packageDependencies:n}){await t({message:"Creating .gitignore"});const s={atom:e,packageDependencies:n},c=r.templateDir,p=a.compile(i.readFileSync(o.resolve(c,".gitignore.njk"),"utf8"),a.configure(c)).render(s),d=r.projectDir,l=o.resolve(d,".gitignore");i.writeFileSync(l,p,"utf8")}async function d({atom:e,context:t,setProgress:r,Atom:s}){const c="readme.md",p=`Creating ${c}`;if(await r({message:p}),t.project?.readme){const e=t.projectDir,r={content:t.project.readme.doc.content},s=o.resolve(t.project.projectDir,"fnet/how-to.md");if(i.existsSync(s)){const e=i.readFileSync(s,"utf8");r.howto=e}const p=o.resolve(t.project.projectDir,"fnet/input.yaml");if(i.existsSync(p)){const e=await n({file:p,tags:t.tags});r.input=e.content}const d=o.resolve(t.project.projectDir,"fnet/output.yaml");if(i.existsSync(d)){const e=await n({file:d,tags:t.tags});r.output=e.content}const l=t.templateDir,f=a.compile(i.readFileSync(o.resolve(l,`${c}.njk`),"utf8"),a.configure(l)).render(r),m=o.resolve(e,`${c}`);i.writeFileSync(m,f,"utf8")}else if(e.id){const r=await s.first({type:"wiki",parent_id:e.id});if(!r||"markdown"!==r.doc?.["content-type"])return;const{content:n,...p}=r.doc,d={content:n},l=t.templateDir,f=a.compile(i.readFileSync(o.resolve(l,`${c}.njk`),"utf8"),a.configure(l)).render(d),m=t.projectDir,w=o.resolve(m,`${c}`);i.writeFileSync(w,f,"utf8")}}var l=async e=>{const{atom:t,packageDependencies:r,context:i,deploymentProjectTarget:o,setProgress:a,deploymentProject:n,yamlTarget:s}=e;if(!0!==o.enabled)return;const c=o.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.53yND1Av.js")).default({...e});else if("gcs"===c)await(await import("./index.UOds5XLl.js")).default({...e});else if("gitlab"===c)await(await import("./index.DI3yyTtl.js")).default({...e});else if("fnet-package"===c)await(await import("./index.Bfg4lyu-.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:o,onProgress:a,projectDir:i.projectDir,dependencies:r,context:i,yamlTarget:s}),n.isDirty=!0;else if("webos"===c)await(await import("./index.CMC8mlye.js")).default({atom:t,target:o,onProgress:a,projectDir:i.projectDir,dependencies:r,context:i,yamlTarget:s}),n.isDirty=!0;else if("electron"===c)await(await import("./index.xd8c7XMr.js")).default({atom:t,target:o,onProgress:a,projectDir:i.projectDir,dependencies:r,context:i,yamlTarget:s}),n.isDirty=!0;else if("docker"===c)await(await import("./index.D2N9YZmA.js")).default({atom:t,target:o,onProgress:a,projectDir:i.projectDir,dependencies:r,context:i,yamlTarget:s}),n.isDirty=!0;else if("ios"===c)await(await import("./index.B5XE4ChJ.js")).default({atom:t,target:o,onProgress:a,projectDir:i.projectDir,dependencies:r,context:i,yamlTarget:s}),n.isDirty=!0;else if("macos"===c)await(await import("./index.W6RYgypK.js")).default({atom:t,target:o,onProgress:a,projectDir:i.projectDir,dependencies:r,context:i,yamlTarget:s}),n.isDirty=!0;else if("rust"===c)await(await import("./index.CzAV0S36.js")).default({atom:t,target:o,onProgress:a,projectDir:i.projectDir,dependencies:r,context:i,yamlTarget:s}),n.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:o,onProgress:a,projectDir:i.projectDir,dependencies:r,context:i,yamlTarget:s}),n.isDirty=!0}}catch(e){throw console.error(`Error during deployment for type "${c}":`,e),e}};export{c as A,p as a,s as b,d as c,l as d};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import t from"node:fs";import i from"node:path";import e from"nunjucks";import a from"@flownet/lib-parse-imports-js";import s from"@flownet/lib-parse-node-url";import{B as o}from"./index.Bqzc7Bx8.js";import{i as n,a as r,c as p}from"./index.B1zLg4Y2.js";import{p as c,c as l,a as m,b as h,d,e as f,f as w,i as g,r as y}from"./index.CLlKzCGk.js";import{c as x,a as u}from"./index.BwhWziH6.js";import"node:crypto";import"yaml";import"chalk";import"@flownet/lib-atom-api-js";import"@fnet/config";import"@fnet/list-files";import"lodash.merge";import"@fnet/npm-list-versions";import"@flownet/lib-render-templates-dir";import"@fnet/npm-pick-versions";import"object-hash";import"ajv/dist/2020.js";import"ajv/dist/standalone/index.js";import"ajv-formats";import"@fnet/shelljs";import"./index.js";import"node:url";import"node:child_process";import"node:os";import"yargs";import"@fnet/prompt";import"@fnet/yaml";import"@fnet/shell-flow";import"node:util";import"tree-kill";import"redis";import"@flownet/lib-is-redis-online";class b extends o{async initRuntime(){await n(this.apiContext),await r(this.apiContext),await this.initLibraryDir(),await this.initNunjucks(),await this.initLibs()}async initLibs(){this.setProgress({message:"Initializing external libs."});const t=[{name:this.atom.doc.name,type:"atom",parent_id:this.atom.parent_id}];this.libs=t,await this.initAtomLibsAndDeps({libs:t,packageDependencies:this.apiContext.packageDependencies})}async initAtomLibsAndDeps({libs:t,packageDependencies:i}){const e=t.filter((t=>"atom"===t.type));for(let t=0;t<e.length;t++){const a=e[t],s=await this.findAtomLibrary({url:a.name});a.atom=s;const o=s.doc.dependencies?.filter((t=>void 0===t.repo||"npm"===t.repo));o?.forEach((t=>{const e=i.find((i=>i.package===t.package));e?"string"==typeof t.path?(e.path||[]).some((i=>i===t.path))||(e.path=e.path||[],e.path.push(t.path)):Array.isArray(t.path)&&t.path.forEach((t=>{(e.path||[]).some((i=>i===t))||(e.path=e.path||[],e.path.push(t))})):i.push(t)}))}i.sort(((t,i)=>t.package?.localeCompare(i.package)))}async findAtomLibrary({url:t}){const e=s({url:t});if(!e)throw new Error(`Invalid package name: ${t}`);if(e.protocol||(e.protocol=this.context.protocol),"ac:"===e.protocol){const i=e.pathname.split("/");if(1===i.length)return await this.apiContext.Atom.first({where:{name:t,parent_id:this.atomConfig.env.ATOM_LIBRARIES_ID,type:"workflow.lib"}});if(2===i.length){const t=await this.apiContext.Atom.first({where:{name:i[0],parent_id:this.atomConfig.env.ATOM_LIBRARIES_ID,type:"folder"}});return await this.apiContext.Atom.first({where:{name:i[1],parent_id:t.id,type:"workflow.lib"}})}}else if("local:"===e.protocol){const t=this.atom;t.protocol="local:",t.doc.dependencies=t.doc.dependencies||[],t.name=t.doc.name;const e=i.resolve(this.context.projectSrcDir,"index.js"),s=await a({file:e,recursive:!0}),o=t.doc.dependencies,n=s.all;for await(const t of n){if("npm"!==t.type)continue;if(o.find((i=>i.package===t.package)))continue;const i=await c({name:t.package,projectDir:this.context.projectDir,setProgress:this.apiContext.setProgress});o.push({package:t.package,subpath:t.subpath,version:i.minorRange,type:"npm"})}return t}}async createAtomLibFiles({libs:e}){await this.setProgress({message:"Creating external lib files."}),this.atom.typesDir="./types";const a=e.filter((t=>"atom"===t.type));for(let e=0;e<a.length;e++){const s=a[e].atom,o=this.context.projectDir;if("local:"===s.protocol){const e=i.resolve(this.context.projectSrcDir,`${s.fileName||s.name}.js`),a=i.relative(i.join(this.context.projectDir,"src","default"),e);if(!t.existsSync(e)){t.mkdirSync(i.dirname(e),{recursive:!0});let a="export default async (args)=>{\n";a+="}",t.writeFileSync(e,a,"utf8")}s.relativePath=a.split(i.sep).join("/"),this.atom.typesDir=`./types/${i.basename(o)}/src`}else{const e=i.join(o,"src","libs",`${s.id}.js`),a=s.doc.contents?.find((t=>"esm"===t.format))||s.doc;t.writeFileSync(e,a.content,"utf8")}}}async createEngine(){await this.setProgress({message:"Creating engine file."});const a={libs:this.libs.filter((t=>"atom"===t.type)),libraryAtom:this.atom,atom:this.atom},s=this.context.templateDir,o=e.compile(t.readFileSync(i.resolve(s,i.join("src","default","engine.js.njk")),"utf8"),this.apiContext.njEnv).render(a),n=this.context.projectDir,r=i.resolve(n,i.join("src","default","index.js"));t.writeFileSync(r,o,"utf8")}async build(){try{this.fileMode&&(await this.createAtomLibFiles({libs:this.libs}),await this.createEngine(),await this.createProjectYaml(),await x(this.apiContext),await l(this.apiContext),await u(this.apiContext),await m(this.apiContext),await h(this.apiContext),await d(this.apiContext),await p(this.apiContext),await f(this.apiContext),await w(this.apiContext),this.buildMode&&(await g(this.apiContext),await y(this.apiContext),this.deployMode&&await this.deploy())),await this._cache_set(this.buildKey,{status:"COMPLETED"})}catch(t){throw await this._cache_set(this.buildKey,{status:"FAILED",message:t.message||t}),console.log(t),t}}}export{b as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import e from"lodash.merge";import a from"node:fs";import s from"node:path";import r from"@flownet/lib-parse-imports-js";import{g as t,h as o,j as n,k as p,l,m as i}from"./index.CLlKzCGk.js";import c from"@fnet/npm-list-versions";import u from"nunjucks";import d from"@fnet/shelljs";function b({dir:e,name:r="index"}){let t=s.resolve(e,`./${r}.tsx`);if(a.existsSync(t)||(t=s.resolve(e,`./${r}.ts`)),a.existsSync(t)||(t=s.resolve(e,`./${r}.jsx`)),a.existsSync(t)||(t=s.resolve(e,`./${r}.js`)),!a.existsSync(t))return{};const o=t,n=s.extname(t);return{file:o,ext:n,ts:".ts"===n||".tsx"===n,name:r}}async function f(a){const{atom:c,context:u,setProgress:d}=a;d("Initializing features..."),c.doc.features=c.doc.features||{};const f=c.doc.features;f.project=f.project||{},f.project.format=f.project.format||f.project_format||"esm",f.project_format=f.project.format,f.dts_enabled=!0===f.dts||void 0!==f.dts&&!1!==f.dts;const _=s.resolve(u.project.projectDir),g=b({dir:s.resolve(_,"./app")});if(g.file){d("Parsing app entry imports...");let e=await r({file:g.file,recursive:!0}),a=e.all.some((e=>!0===e.usesJSX&&"local"===e.type));f.app_uses_jsx=a,f.app_has_entry=!0,e=await r({file:g.file}),a=e.all.some((e=>!0===e.usesJSX&&"local"===e.type)),f.app_entry_uses_jsx=a,f.app_entry_is_ts=g.ts,f.app_entry_ext=g.ext}const m=b({dir:s.resolve(_,"./cli")});if(m.file){d("Parsing cli entry imports...");let e=await r({file:m.file,recursive:!0}),a=e.all.some((e=>!0===e.usesJSX&&"local"===e.type));f.cli_uses_jsx=a,f.cli_has_entry=!0,e=await r({file:m.file}),a=e.all.some((e=>!0===e.usesJSX&&"local"===e.type)),f.cli_entry_uses_jsx=a,f.cli_entry_is_ts=m.ts,f.cli_entry_ext=m.ext}if("workflow.lib"===c.type){const e=b({dir:s.resolve(_,"./src")});if(e.file){d("Parsing src entry imports...");let a=await r({file:e.file,recursive:!0}),s=a.all.some((e=>!0===e.usesJSX&&"local"===e.type));f.src_uses_jsx=s,f.src_has_entry=!0,a=await r({file:e.file}),s=a.all.some((e=>!0===e.usesJSX&&"local"===e.type)),f.src_entry_uses_jsx=s,f.src_entry_is_ts=e.ts,f.src_entry_ext=e.ext}}const y=Reflect.has(f,"app_entry_uses_jsx")?!0===f.app_entry_uses_jsx:!0===f.src_entry_uses_jsx,v=Reflect.has(f,"cli_entry_uses_jsx")?!0===f.cli_entry_uses_jsx:!0===f.src_entry_uses_jsx;f.form_enabled=y||v||!0===f.form||!0===f.form?.enabled,f.multiple_enabled=f.multiple_enabled||!0===f.multiple||!0===f.multiple?.enabled,!1===f.app?f.app={enabled:!1}:!0===f.app?f.app={enabled:!0,extend:!0===f.app_has_entry,export:!0,react:y}:f.app={enabled:!0,extend:!0===f.app_has_entry,export:!0,react:y,...f.app||{}},f.app.enabled=!0===f.app.enabled&&(!0===c.doc.features.form_enabled||!0===f.app.extend||!0===f.app.enabled),f.app.format=f.app.format||"esm",f.app.folder=f.app.folder||f.app.format||"default",!1===f.cli?f.cli={enabled:!1}:!0===f.cli?f.cli={enabled:!0,extend:!0===f.cli_has_entry,export:!0,react:v}:f.cli={enabled:!0,extend:!0===f.cli_has_entry,export:!0,react:v,...f.cli||{}},f.cli.enabled=!0===f.cli.enabled&&(!1===c.doc.features.form_enabled||!0===f.cli.extend||!0===f.cli.enabled),f.cli.format=f.cli.format||"esm",f.cli.folder=f.cli.folder||f.cli.folder||"esm",f.cli.node_options=f.cli.node?.options||f.cli.node_options||"",f.json=f.cli.enabled||f.json;const x={cjs:{format:"cjs",context:f.form_enabled?"window":"global",babel:!0===f.src_uses_jsx||!1,browser:!1,replace:!0,terser:!0,enabled:!1!==f.cjs,copy:!1},esm:{format:"esm",context:f.form_enabled?"window":"global",babel:!0===f.src_uses_jsx||!1,browser:!1,replace:!0,terser:!1,enabled:!1!==f.esm,copy:!0},iife:{format:"iife",context:f.form_enabled?"window":"global",babel:!0,browser:!0,replace:!0,enabled:!0===f.iife,terser:!0,copy:!1}};!0===f.webos&&(x.webos={format:"iife",browser:!0,babel:!0,context:"window",replace:!0,terser:!0,input:"./src/app/index.js",output_dir:"./dist/app/webos",copy:!1,babel_options:{targets:{chrome:"79"}}}),!0===f.electron&&(x.electron={format:"iife",browser:!0,babel:!0,context:"window",replace:!0,terser:!0,copy:!1,input:"./src/app/index.js",output_dir:"./dist/app/electron"}),!0===f.nextjs&&(x.nextjs={format:"esm",browser:!0,babel:!0,context:"window",replace:!0,terser:!0,copy:!1,input:"./src/app/index.js",output_dir:"./dist/app/nextjs"}),!0===f.ios&&(x.ios={format:"iife",browser:!0,babel:!0,context:"window",replace:!0,terser:!0,copy:!1,input:"./src/app/index.js",output_dir:"./dist/app/ios"}),!0===f.macos&&(x.macos={format:"iife",browser:!0,babel:!0,context:"window",replace:!0,terser:!0,copy:!1,input:"./src/app/index.js",output_dir:"./dist/app/macos"}),!0===f.app.enabled&&(f.app.dir=`./dist/app/${f.app.folder}`,x.app={format:f.app.format,browser:!0,babel:!0,context:"window",replace:!0,input:"./src/app/index.js",output_dir:f.app.dir,terser:!0,output_exports:!1===f.app.export?"none":"auto",browsersync:!0}),!0===f.cli.enabled&&(f.cli.dir=`./dist/cli/${f.cli.folder}`,x.cli={format:f.cli.format,context:"global",babel:!0===f.src_uses_jsx||!0===f.cli_uses_jsx||!1,browser:!1,replace:!0,enabled:!0,input:"./src/cli/index.js",output_dir:f.cli.dir,banner:"#!/usr/bin/env node",terser:!0,output_exports:!1===f.cli.export?"none":"auto"});const w={server:".",startPath:`${s.normalize(f.app.dir||".")}`,files:[s.normalize("./dist/**/*")],cors:!0,open:!1};f.babel_options=e({targets:{browsers:"last 9 versions, not dead",node:"18"}},f.babel_options||f.babel?.options),f.browsersync_options=e(w,f.browsersync_options||f.browsersync?.options||{}),f.replace_options=e({},f.replace_options||f.replace?.options||{}),Reflect.has(f.browsersync_options,"proxy")&&delete f.browsersync_options.server,f.rollup=f.rollup||{},f.rollup_output=e(x,f.rollup_output||f.rollup?.output||{}),f.preact_enabled=!0===f.preact||f.preact&&!1!==f.preact?.enabled;let k=Object.keys(x);for(const a of k){const s=x[a];s&&(!1!==f.rollup[a]?(s.babel_options=s.babel_options||f.babel_options,s.browsersync_options=e(f.browsersync_options,s.browsersync_options),s.replace_options=e(f.replace_options,s.replace_options),f.preact_enabled&&(s.alias_enabled=!0,s.alias=s.alias||{},s.alias.entries=s.alias.entries||{},s.alias.entries.react="preact/compat",s.alias.entries["react-dom"]="preact/compat"),(f.form_enabled||f.babel)&&(s.babel=!0)):delete f.rollup_output[a])}k=Object.keys(f.rollup_output),f.babel_enabled=k.some((e=>!0===f.rollup_output[e].babel)),f.browser_enabled=k.some((e=>!0===f.rollup_output[e].babel)),f.browsersync_enabled=!1!==f.browsersync&&k.some((e=>!0===f.rollup_output[e].browsersync)),f.browsersync_enabled=f.browsersync_enabled&&f.app.enabled,f.dependency_auto_enabled=!1!==f.dependency_auto&&!1!==f.dependency_auto?.enabled,f.npm_install_flags=f.npm_install_flags||"",f.react_version=f.react_version||f.react?.version||18,o(a),n(a),function(e){const{atom:a,packageDevDependencies:s}=e,r=a.doc.features;t({feature:{name:"wasm",packages:[["@rollup/plugin-wasm","^6"]]},features:r,packageDevDependencies:s})}(a),function(e){const{atom:a,packageDevDependencies:s}=e,r=a.doc.features;t({feature:{name:"terser",packages:[["@rollup/plugin-terser","^0.4"]]},features:r,packageDevDependencies:s})}(a),p(a),l(a),i(a),function(e){const{atom:a,packageDevDependencies:s}=e,r=a.doc.features;t({feature:{name:"analyzer",packages:[["rollup-plugin-analyzer","^3"]],options:{summaryOnly:!0,limit:12},explicit:!0},features:r,packageDevDependencies:s})}(a),function(e){const{atom:a,packageDevDependencies:s}=e,r=a.doc.features;t({feature:{name:"visualizer",packages:[["rollup-plugin-visualizer","^5"]]},features:r,packageDevDependencies:s})}(a),function(e){const{atom:a,packageDevDependencies:s}=e,r=a.doc.features;t({feature:{name:"polyfill",packages:[["rollup-plugin-node-polyfills","^0.2"]]},features:r,packageDevDependencies:s})}(a),function(e){const{atom:a,packageDevDependencies:s}=e,r=a.doc.features;t({feature:{name:"nunjucks",packages:[["@fnet/rollup-plugin-nunjucks","0.1.8"]]},features:r,packageDevDependencies:s})}(a),function(e){const{atom:a,packageDevDependencies:s}=e,r=a.doc.features;t({feature:{name:"workbox",packages:[["rollup-plugin-workbox","^8"]],options:{generate:{swDest:"dist/app/esm/sw.js",globDirectory:"dist/app/esm",globPatterns:["**/*.{html,js,css,png,jpg}"],skipWaiting:!0,clientsClaim:!0}},explicit:!0},features:r,packageDevDependencies:s})}(a),function(e){const{atom:a,packageDevDependencies:s}=e,r=a.doc.features;t({feature:{name:"gzip",packages:[["rollup-plugin-gzip","^4"]],explicit:!0},features:r,packageDevDependencies:s})}(a)}async function _({atom:e,packageDependencies:a,packageDevDependencies:s,setProgress:r}){r("Initializing dependencies");const t=e.doc.dependencies||[];if(t.filter((e=>!e.dev)).forEach((e=>a.push(e))),t.filter((e=>e.dev)).forEach((e=>s.push(e))),"workflow"===e.type&&(a.push({package:"get-value",version:"^3"}),a.push({package:"set-value",version:"^4"})),e.doc.features.form_enabled&&e.doc.features.dependency_auto_enabled){let s="^18.2";r("Fetching React versions");s=`^${(await c({name:"react",groupBy:{major:!0}})).find((a=>a[0]===e.doc.features.react_version.toString()))[0]}`,a.push({package:"react",version:s}),a.push({package:"react-dom",version:s}),"workflow"===e.type&&(a.push({package:"@fnet/react-app",version:"^0.1"}),a.push({package:"@fnet/react-app-state",version:"^0.1"}))}e.doc.features.preact_enabled&&a.push({package:"preact",version:"^10"}),!0===e.doc.features.cli.enabled&&(a.push({package:"@fnet/args",version:"^0.1"}),s.push({package:"ajv",version:"^8"}),e.doc.features.cli.fargs&&!1!==e.doc.features.cli.fargs?.enabled&&a.push({package:"@fnet/config",version:"0.2.21"})),e.doc.features.render&&!1!==e.doc.features.render.enabled&&s.push({package:"@flownet/lib-render-templates-dir",version:"0.1.19"}),s.push({package:"@babel/core",version:"^7"}),s.push({package:"@rollup/plugin-commonjs",version:"^28"}),s.push({package:"@rollup/plugin-node-resolve",version:"^16"}),s.push({package:"@rollup/plugin-replace",version:"^6"}),s.push({package:"rollup",version:"^4"}),e.doc.features.dts_enabled&&s.push({package:"rollup-plugin-dts",version:"^6"}),s.push({package:"rollup-plugin-peer-deps-external",version:"^2"}),s.push({package:"@rollup/plugin-alias",version:"^5"}),s.push({package:"fs-extra",version:"^11"}),e.doc.features.babel_enabled&&(s.push({package:"@rollup/plugin-babel",version:"^6"}),s.push({package:"@babel/preset-env",version:"^7"}),s.push({package:"@babel/preset-react",version:"^7"}),e.doc.features.babel?.options?.plugins?.forEach((e=>{switch(e[0]){case"@babel/plugin-proposal-decorators":s.push({package:"@babel/plugin-proposal-decorators",version:"^7"});break;case"@babel/plugin-proposal-class-properties":s.push({package:"@babel/plugin-proposal-class-properties",version:"^7"});break;case"@babel/plugin-proposal-private-methods":s.push({package:"@babel/plugin-proposal-private-methods",version:"^7"});break;case"@babel/plugin-proposal-private-property-in-object":s.push({package:"@babel/plugin-proposal-private-property-in-object",version:"^7"});break;case"@babel/plugin-proposal-optional-chaining":s.push({package:"@babel/plugin-proposal-optional-chaining",version:"^7"})}}))),s.push({package:"@fnet/rollup-plugin-delete",version:"0.1.10"}),e.doc.features.browsersync_enabled&&s.push({package:"@fnet/rollup-plugin-browsersync",version:"0.1.11"})}async function g({atom:e,setProgress:t,context:o,packageDependencies:n}){await t({message:"Creating rollup file."});const p={atom:e,packageDependencies:n},l=s.resolve(o.projectDir,"src","default/index.js");if(!a.existsSync(l))throw new Error(`Entry file not found: ${l}`);const i=(await r({file:l,recursive:!0})).all.filter((e=>"node"===e.type)).map((e=>e.path)),c=e.doc.features.rollup_output,d=Object.keys(c);for(let e=0;e<d.length;e++){const a=c[d[e]];if(!0===a.browser&&i.length>0){a.globals_enabled=!0,a.globals=a.globals||[],a.globals=a.globals.concat(i.map((e=>({key:e,value:e})))),a.alias_enabled=!0,a.alias=a.alias||{},a.alias.entries=a.alias.entries||{};for(let e=0;e<i.length;e++){const s=i[e];a.alias.entries[s]=`node:${s}`,a.alias.entries[`node:${s}`]=s}a.external_enabled=!0,a.external=a.external||[],a.external=a.external.concat(i)}}const b=o.templateDir;let f=u.compile(a.readFileSync(s.resolve(b,"rollup.config.mjs.njk"),"utf8"),u.configure(b)).render(p);const _=o.projectDir;let g=s.resolve(_,"rollup.config.mjs");a.writeFileSync(g,f,"utf8")}async function m({atom:e,setProgress:a,context:s}){if(!e.doc.features.dts_enabled)return;const r=s.projectDir;await a({message:"Creating .d.ts"});if(0!==(await d("tsc",{cwd:r})).code)throw new Error("Couldnt create .d.ts files.")}export{_ as a,m as b,g as c,f as i};
|