@fnet/cli 0.114.0 → 0.115.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/fnet/index.js +1 -1
- package/dist/fnode/{index.mC936qdY.js → index.Brxbka97.js} +1 -1
- package/dist/fnode/{index.Cl6LPgIY.js → index.CoRsFBwp.js} +1 -1
- package/dist/fnode/index.DIZA_GzC.js +1 -0
- package/dist/fnode/{index.CLPC6OJN.js → index.Dg0hAD29.js} +1 -1
- package/dist/fnode/index.js +1 -1
- package/dist/fnode/{index.qJ6fWMSj.js → index.uPDSav7E.js} +1 -1
- package/package.json +1 -1
- package/template/fnet/bun/src/cli/index.js.njk +1 -1
- package/template/fnet/node/rollup.config.mjs.njk +144 -11
- package/template/fnet/node/src/cli/index.js.njk +195 -16
- package/template/fnode/bun/src/cli/index.js.njk +2 -2
- package/template/fnode/node/rollup.config.mjs.njk +144 -11
- package/template/fnode/node/src/cli/index.js.njk +388 -23
- package/dist/fnode/index.BlhtGEKB.js +0 -1
- package/template/fnet/bun/fnet/flows.yaml.njk +0 -1
- package/template/fnet/bun/fnet.yaml.njk +0 -1
- package/template/fnet/node/fnet/flows.yaml.njk +0 -1
- package/template/fnet/node/fnet.yaml.njk +0 -1
- package/template/fnet/node/rollup_config_external.njk +0 -8
- package/template/fnet/node/rollup_config_onwarn.njk +0 -9
- package/template/fnet/node/rollup_config_output_banner.njk +0 -3
- package/template/fnet/node/rollup_config_output_footer.njk +0 -5
- package/template/fnet/node/rollup_config_output_globals.njk +0 -9
- package/template/fnet/node/rollup_config_output_name.njk +0 -3
- package/template/fnet/node/rollup_config_plugins.njk +0 -90
- package/template/fnode/bun/fnode.yaml.njk +0 -1
- package/template/fnode/node/fnode.yaml.njk +0 -1
- package/template/fnode/node/rollup_config_external.njk +0 -8
- package/template/fnode/node/rollup_config_onwarn.njk +0 -9
- package/template/fnode/node/rollup_config_output_banner.njk +0 -3
- package/template/fnode/node/rollup_config_output_footer.njk +0 -5
- package/template/fnode/node/rollup_config_output_globals.njk +0 -9
- package/template/fnode/node/rollup_config_output_name.njk +0 -3
- package/template/fnode/node/rollup_config_plugins.njk +0 -90
- package/template/fnode/python/fnode.yaml.njk +0 -1
- /package/template/fnet/bun/src/default/{to.args.js.njk → input.args.js.njk} +0 -0
- /package/template/fnet/node/src/default/{to.args.js.njk → input.args.js.njk} +0 -0
- /package/template/fnet/project/.vscode/{launch.json → launch.json.njk} +0 -0
- /package/template/fnet/project/.vscode/{tasks.json → tasks.json.njk} +0 -0
- /package/template/fnode/bun/src/default/{to.args.js.njk → input.args.js.njk} +0 -0
- /package/template/fnode/node/src/default/{to.args.js.njk → input.args.js.njk} +0 -0
|
@@ -1 +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.BlhtGEKB.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,h as _,j as w,k as y,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"yargs";import"node:util";import"tree-kill";import"node:child_process";import"node:os";import"@fnet/prompt";import"fs";import"path";import"@fnet/shell-flow";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 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===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:_}:r.cli={enabled:!0,extend:!0===r.cli_has_entry,export:!0,react:_,...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 w={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&&(w.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&&(w.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&&(w.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&&(w.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&&(w.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}`,w.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}`,w.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 y={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(y,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(w,r.rollup_output||r.rollup?.output||{}),r.preact_enabled=!0===r.preact||r.preact&&!1!==r.preact?.enabled;let x=Object.keys(w);for(const e of x){const t=w[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 h(this.apiContext),await _(this.apiContext),await w(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 y(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};
|
|
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.DIZA_GzC.js";import p from"lodash.merge";import{f as l,i as c,a as d,b as u,c as f,d as m,p as b,e as g,g as h,h as _,j as w,k as y,l as x,m as v,r as k}from"./index.Dg0hAD29.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"yargs";import"node:util";import"tree-kill";import"node:child_process";import"node:os";import"@fnet/prompt";import"fs";import"path";import"@fnet/shell-flow";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),b=C({dir:t.resolve(n,"./app")});if(b.file){i("Parsing app entry imports...");let e=await s({file:b.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:b.file}),t=e.all.some((e=>!0===e.usesJSX&&"local"===e.type)),r.app_entry_uses_jsx=t,r.app_entry_is_ts=b.ts,r.app_entry_ext=b.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 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===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:_}:r.cli={enabled:!0,extend:!0===r.cli_has_entry,export:!0,react:_,...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 w={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&&(w.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&&(w.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&&(w.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&&(w.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&&(w.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}`,w.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}`,w.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 y={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(y,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(w,r.rollup_output||r.rollup?.output||{}),r.preact_enabled=!0===r.preact||r.preact&&!1!==r.preact?.enabled;let x=Object.keys(w);for(const e of x){const t=w[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),m(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.cli.mcp&&!0===e.doc.features.cli.mcp.enabled&&t.push({package:"@modelcontextprotocol/sdk",version:"^1.10"})),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 b({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 h(this.apiContext),await _(this.apiContext),await w(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 m=a.compile(e.readFileSync(t.resolve(f,"rollup.config.mjs.njk"),"utf8"),a.configure(f)).render(p);const b=r.projectDir;let g=t.resolve(b,"rollup.config.mjs");e.writeFileSync(g,m,"utf8")}(this.apiContext),await y(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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"node:fs";import t from"node:path";import{randomUUID as i}from"node:crypto";import o from"yaml";import s from"nunjucks";import a from"chalk";import{Api as r,Atom as n}from"@flownet/lib-atom-api-js";import c from"@fnet/config";import d from"@fnet/list-files";import l from"redis";import p from"@flownet/lib-is-redis-online";import m from"@fnet/yaml";class g{init({config:e,accessToken:t}){return new Promise(((i,o)=>{if(r.set_api_url(e.data.url),t)return r.set_req_token(t),void i(t);fetch(`${e.data.issuer}/protocol/openid-connect/token`,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams(e.data.grant.params)}).then((async e=>{if(!e.ok)throw new Error(await e.text());return e.json()})).then((e=>{r.set_req_token(e.access_token),i(e.access_token)})).catch((e=>{r.set_req_token(),o(e)}))}))}}var h=async e=>{const{atom:t,packageDependencies:i,context:o,deploymentProjectTarget:s,setProgress:a,deploymentProject:r,yamlTarget:n}=e;if(!0!==s.enabled)return;const c=s.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.xPP3GBoc.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:s,onProgress:a,projectDir:o.projectDir,dependencies:i,context:o,yamlTarget:n}),r.isDirty=!0;else if("webos"===c)await(await import("./index.CMC8mlye.js")).default({atom:t,target:s,onProgress:a,projectDir:o.projectDir,dependencies:i,context:o,yamlTarget:n}),r.isDirty=!0;else if("electron"===c)await(await import("./index.xd8c7XMr.js")).default({atom:t,target:s,onProgress:a,projectDir:o.projectDir,dependencies:i,context:o,yamlTarget:n}),r.isDirty=!0;else if("docker"===c)await(await import("./index.D2N9YZmA.js")).default({atom:t,target:s,onProgress:a,projectDir:o.projectDir,dependencies:i,context:o,yamlTarget:n}),r.isDirty=!0;else if("ios"===c)await(await import("./index.B5XE4ChJ.js")).default({atom:t,target:s,onProgress:a,projectDir:o.projectDir,dependencies:i,context:o,yamlTarget:n}),r.isDirty=!0;else if("macos"===c)await(await import("./index.W6RYgypK.js")).default({atom:t,target:s,onProgress:a,projectDir:o.projectDir,dependencies:i,context:o,yamlTarget:n}),r.isDirty=!0;else if("rust"===c)await(await import("./index.CzAV0S36.js")).default({atom:t,target:s,onProgress:a,projectDir:o.projectDir,dependencies:i,context:o,yamlTarget:n}),r.isDirty=!0;else{if("pypi"!==c)return void console.warn(`No deployer found for type: ${c}`);await(await import("./index.C7saWH6d.js")).default({atom:t,target:s,onProgress:a,projectDir:o.projectDir,dependencies:i,context:o,yamlTarget:n}),r.isDirty=!0}}catch(e){throw console.error(`Error during deployment for type "${c}":`,e),e}};class f{#e;#t;#i;#o;#s;#a;#r;#n;#c;#d;#l;#p;#m;#g;#h;#f;#y;constructor(e){this.#e=new g,this.#t=e,this.#a=[],this.#r=[],this._expire_ttl=3600,this._expire_ttl_short=300,this.#y={packageDependencies:this.#a,packageDevDependencies:this.#r,setProgress:this.setProgress.bind(this),context:this.#t,Atom:n,registerToPackageManager:this.registerToPackageManager.bind(this)}}get apiContext(){return this.#y}get context(){return this.#t}get atom(){return this.#i}get libs(){return this.#s}set libs(e){this.#s=e}get fileMode(){return this.#g}get buildMode(){return this.#h}get deployMode(){return this.#f}async _cache_set(e,t,i){this._redis_client&&await this._redis_client.SETEX(e,i||this._expire_ttl,JSON.stringify(t)).catch(console.error)}async initAuth(){this.#t.id&&(this.#n=await this.#e.init({config:this.#p}),this.#y.atomAccessToken=this.#n)}async initLibrary(){const e=this.#t.id;this.#i=this.#t.project?.libraryAtom||await n.get({id:e});let t=this.#i.doc.bundleName;t=t||(this.#i.doc.name||"").toUpperCase().replace(/[^A-Z0-9]/g,"_"),this.#i.doc.bundleName=t,this.#i.type=this.#i.type||"workflow.lib",this.#y.atom=this.#i}async initLibraryDir(){this.setProgress({message:"Initializing library directory."});const i=this.#t.projectDir;this.setProgress({message:"Cleaning project directory."});const o=d({dir:i,ignore:[".cache","node_modules",".conda",".bin"],absolute:!0});for(const t of o)e.rmSync(t,{recursive:!0,force:!0});this.setProgress({message:"Creating project directory."});let s=i;e.existsSync(s)||e.mkdirSync(s,{recursive:!0}),s=t.join(i,"src"),e.existsSync(s)||e.mkdirSync(s,{recursive:!0}),s=t.join(i,"src","default"),e.existsSync(s)||e.mkdirSync(s,{recursive:!0})}async initNunjucks(){this.setProgress({message:"Initializing nunjucks."});const e=this.#t.templateDir;this.#o=s.configure(e,{watch:!1,dev:!0}),this.#y.njEnv=this.#o}async createProjectYaml(){const i="fnode.yaml",s=`Creating ${i}`;await this.setProgress({message:s});const{content:a,...r}=this.#i.doc,n=this.#t.projectDir,c=t.resolve(n,`${i}`);e.writeFileSync(c,o.stringify(r),"utf8")}async deploy(){if(await this.setProgress({message:"Deploying."}),this.#t.project?.devops){const e=[this.#t.project?.devops];for(let t=0;t<e.length;t++){let i=e[t];await this.deployProject({deploymentProject:i}),!0===i.isDirty&&await i.save()}}else if(this.#i.id){const e=await n.list({type:"library.deploy",parent_id:this.#i.id});for(let t=0;t<e.length;t++){let i=e[t];await this.deployProject({deploymentProject:i}),!0===i.isDirty&&(i=await n.update(i,{id:i.id}))}}}async deployProject(e){const{deploymentProject:t}=e,{yamlDocument:i}=t;if(t.doc.targets&&Array.isArray(t.doc.targets))throw new Error("Deployment project targets are deprecated. Please update targets in the yaml file.");const o=Object.keys(t.doc||{}),s=i||{};for(let e=0;e<o.length;e++){const i=t.doc[o[e]];i.name=o[e];const a=s.get(o[e]);await h({...this.#y,deploymentProject:t,deploymentProjectTarget:i,yamlTarget:a})}}async registerToPackageManager(e){const{target:t,packageJSON:i}=e;if(!this.#t.id)return;let o=await n.first({name:t.params.name,parent_id:this.#p.env.ATOM_PACKAGES_ID});o?(o.doc.versions.splice(0,0,{v:i.version}),await n.update(o,{id:o.id})):o=await n.create({parent_id:this.#p.env.ATOM_PACKAGES_ID,doc:{name:t.params.name,type:"pm",versions:[{v:i.version}]}})}async setProgress(e){const t="string"==typeof e?e:e?.message;console.log(a.blue(t)),await this._cache_set(this.#d,{status:"IN_PROGRESS",message:t})}async init(){this._redis_client=await async function(){if(!await p({host:process.env.REDIS_HOST,port:process.env.REDIS_PORT}))return;const e=l.createClient({socket:{host:process.env.REDIS_HOST,port:process.env.REDIS_PORT}});return await e.connect(),e}(),this.#c=this.#t.buildId||i(),this.#y.buildId=this.#c,this.#m=this.#t.mode,this.#g=["all","deploy","build","file"].includes(this.#m),this.#h=["all","deploy","build"].includes(this.#m),this.#f=["all","deploy"].includes(this.#m),this.#l=this.#t.protocol,this.#d="BUILD:"+this.#c,this.#p=(await c({optional:!0,name:this.#t.atomConfig||"atom",dir:this.#t.projectDir,tags:this.#t.tags}))?.data;try{await this.setProgress({message:"Initialization started."}),await this.initAuth(),await this.initLibrary(),await this.initRuntime()}catch(e){throw await this._cache_set(this.#d,{status:"FAILED",message:e?.message||e}),e}}async initRuntime(){throw new Error("initRuntime method must be implemented by runtime-specific builder")}async build(){throw new Error("build method must be implemented by runtime-specific builder")}}async function y({atom:i,setProgress:o,context:a,packageDependencies:r}){await o({message:"Creating .gitignore"});const n={atom:i,packageDependencies:r},c=a.templateDir,d=s.compile(e.readFileSync(t.resolve(c,".gitignore.njk"),"utf8"),s.configure(c)).render(n),l=a.projectDir,p=t.resolve(l,".gitignore");e.writeFileSync(p,d,"utf8")}async function u({atom:i,context:o,setProgress:a,Atom:r}){const n="readme.md",c=`Creating ${n}`;if(await a({message:c}),o.project?.readme){const i=o.projectDir,a={content:o.project.readme.doc.content},r=t.resolve(o.project.projectDir,"fnet/how-to.md");if(e.existsSync(r)){const t=e.readFileSync(r,"utf8");a.howto=t}const c=t.resolve(o.project.projectDir,"fnet/input.yaml");if(e.existsSync(c)){const e=await m({file:c,tags:o.tags});a.input=e.content}const d=t.resolve(o.project.projectDir,"fnet/output.yaml");if(e.existsSync(d)){const e=await m({file:d,tags:o.tags});a.output=e.content}const l=o.templateDir,p=s.compile(e.readFileSync(t.resolve(l,`${n}.njk`),"utf8"),s.configure(l)).render(a),g=t.resolve(i,`${n}`);e.writeFileSync(g,p,"utf8")}else if(i.id){const a=await r.first({type:"wiki",parent_id:i.id});if(!a||"markdown"!==a.doc?.["content-type"])return;const{content:c,...d}=a.doc,l={content:c},p=o.templateDir,m=s.compile(e.readFileSync(t.resolve(p,`${n}.njk`),"utf8"),s.configure(p)).render(l),g=o.projectDir,h=t.resolve(g,`${n}`);e.writeFileSync(h,m,"utf8")}}export{f as B,y as a,u as c};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"lodash.merge";import s from"node:fs";import t from"node:path";import a from"@flownet/lib-render-templates-dir";import n from"nunjucks";import o from"@flownet/lib-parse-imports-js";import r from"@fnet/npm-pick-versions";import c from"object-hash";import i from"ajv/dist/2020.js";import p from"ajv/dist/standalone/index.js";import l from"ajv-formats";import f from"@fnet/shelljs";import{w as d}from"./index.js";function u({feature:s,features:t,packageDevDependencies:a}){const{name:n,packages:o,options:r,extraCheck:c,explicit:i}=s,p=`${n}_enabled`,l=t.rollup_output||{},f=Object.keys(l);let d=r||{};const u=t[n]?.options;u&&(d=e(d,u));const m=!t[n]||!1===t[n]?.enabled;f.forEach((e=>{const s=t.rollup_output[e];if(s){if(Reflect.has(s,n)){if(m||!s[n]||!1===s[n]?.enabled)return void delete s[n];!0===s[n]&&(s[n]={enabled:!0,options:d})}else{if(m||i||!1===t[p])return;s[n]={enabled:!0}}s[n]=s[n]||{},s[n].options={...d,...s[n].options}}}));let g=f.some((e=>!0===t.rollup_output[e][n]?.enabled));c&&(g=c()&&g),t[p]=g,g&&o.forEach((e=>a.push({package:e[0],version:e[1]})))}function m(e){const{atom:s,packageDevDependencies:t}=e;u({feature:{name:"string",packages:[["rollup-plugin-string","^3"]]},features:s.doc.features,packageDevDependencies:t})}function g(e){const{atom:s,packageDevDependencies:t}=e;u({feature:{name:"image",packages:[["@rollup/plugin-image","^3"]]},features:s.doc.features,packageDevDependencies:t})}function k(e){const{atom:s,packageDevDependencies:t}=e;u({feature:{name:"json",packages:[["@rollup/plugin-json","^6"]]},features:s.doc.features,packageDevDependencies:t})}function j(e){const{atom:s,packageDevDependencies:t}=e,a=s.doc.features,n={};!0===a.app?.enabled&&(n.targets=n.targets||[],n.targets.push({src:"./src/app/index.html",dest:a.app.dir}),Reflect.has(a.app,"copy")||Reflect.has(a,"copy")||(a.copy=!0)),u({feature:{name:"copy",packages:[["rollup-plugin-copy","^3"],["chokidar","^3"]],options:n},features:a,packageDevDependencies:t})}function v(e){const{atom:s,packageDevDependencies:t}=e,a=s.doc.features,n=a.css&&!1!==a.css.enabled;let o=[];if(n){o.push(["rollup-plugin-postcss","^4"]),o.push(["sass","^1.66"]);(a.css?.options?.plugins||[]).forEach((e=>{switch(e.name){case"postcss-import":o.push(["postcss-import","^15"]);break;case"postcss-url":o.push(["postcss-url","^10"]);break;case"postcss-preset-env":o.push(["postcss-preset-env","^9"]);break;case"autoprefixer":o.push(["autoprefixer","^10"]);break;case"cssnano":o.push(["cssnano","^6"])}}))}u({feature:{name:"css",packages:o},features:a,packageDevDependencies:t})}async function D({atom:e,setProgress:n,context:o,packageDependencies:r}){if(!0!==e.doc.features.app.enabled)return;await n({message:"Creating app folder"});const c={atom:e,packageDependencies:r,ts:Date.now()},i=o.templateDir,p=t.resolve(o.projectDir,"src/app");s.existsSync(p)||s.mkdirSync(p,{recursive:!0});let l=["index.js.njk"];!1!==e.doc.features.app.html&&l.push("index.html.njk"),await a({pattern:l,dir:t.resolve(i,"src/app"),outDir:p,context:c})}async function h({projectDir:e,name:a,setProgress:n,count:o=1}){let i;const p=c(["npm-pick-versions",a,o]),l=t.join(e,".cache"),f=t.join(l,p+".json");return s.existsSync(f)?(n&&n(`Picking npm version of ${a} from cache ...`),i=JSON.parse(s.readFileSync(f,"utf8"))):(n&&n(`Picking npm version of ${a} ...`),i=await r({name:a,count:o}),s.mkdirSync(l,{recursive:!0}),s.writeFileSync(f,JSON.stringify(i),"utf8")),i}async function
|
|
1
|
+
import e from"lodash.merge";import s from"node:fs";import t from"node:path";import a from"@flownet/lib-render-templates-dir";import n from"nunjucks";import o from"@flownet/lib-parse-imports-js";import r from"@fnet/npm-pick-versions";import c from"object-hash";import i from"ajv/dist/2020.js";import p from"ajv/dist/standalone/index.js";import l from"ajv-formats";import f from"@fnet/shelljs";import{w as d}from"./index.js";function u({feature:s,features:t,packageDevDependencies:a}){const{name:n,packages:o,options:r,extraCheck:c,explicit:i}=s,p=`${n}_enabled`,l=t.rollup_output||{},f=Object.keys(l);let d=r||{};const u=t[n]?.options;u&&(d=e(d,u));const m=!t[n]||!1===t[n]?.enabled;f.forEach((e=>{const s=t.rollup_output[e];if(s){if(Reflect.has(s,n)){if(m||!s[n]||!1===s[n]?.enabled)return void delete s[n];!0===s[n]&&(s[n]={enabled:!0,options:d})}else{if(m||i||!1===t[p])return;s[n]={enabled:!0}}s[n]=s[n]||{},s[n].options={...d,...s[n].options}}}));let g=f.some((e=>!0===t.rollup_output[e][n]?.enabled));c&&(g=c()&&g),t[p]=g,g&&o.forEach((e=>a.push({package:e[0],version:e[1]})))}function m(e){const{atom:s,packageDevDependencies:t}=e;u({feature:{name:"string",packages:[["rollup-plugin-string","^3"]]},features:s.doc.features,packageDevDependencies:t})}function g(e){const{atom:s,packageDevDependencies:t}=e;u({feature:{name:"image",packages:[["@rollup/plugin-image","^3"]]},features:s.doc.features,packageDevDependencies:t})}function k(e){const{atom:s,packageDevDependencies:t}=e;u({feature:{name:"json",packages:[["@rollup/plugin-json","^6"]]},features:s.doc.features,packageDevDependencies:t})}function j(e){const{atom:s,packageDevDependencies:t}=e,a=s.doc.features,n={};!0===a.app?.enabled&&(n.targets=n.targets||[],n.targets.push({src:"./src/app/index.html",dest:a.app.dir}),Reflect.has(a.app,"copy")||Reflect.has(a,"copy")||(a.copy=!0)),u({feature:{name:"copy",packages:[["rollup-plugin-copy","^3"],["chokidar","^3"]],options:n},features:a,packageDevDependencies:t})}function v(e){const{atom:s,packageDevDependencies:t}=e,a=s.doc.features,n=a.css&&!1!==a.css.enabled;let o=[];if(n){o.push(["rollup-plugin-postcss","^4"]),o.push(["sass","^1.66"]);(a.css?.options?.plugins||[]).forEach((e=>{switch(e.name){case"postcss-import":o.push(["postcss-import","^15"]);break;case"postcss-url":o.push(["postcss-url","^10"]);break;case"postcss-preset-env":o.push(["postcss-preset-env","^9"]);break;case"autoprefixer":o.push(["autoprefixer","^10"]);break;case"cssnano":o.push(["cssnano","^6"])}}))}u({feature:{name:"css",packages:o},features:a,packageDevDependencies:t})}async function D({atom:e,setProgress:n,context:o,packageDependencies:r}){if(!0!==e.doc.features.app.enabled)return;await n({message:"Creating app folder"});const c={atom:e,packageDependencies:r,ts:Date.now()},i=o.templateDir,p=t.resolve(o.projectDir,"src/app");s.existsSync(p)||s.mkdirSync(p,{recursive:!0});let l=["index.js.njk"];!1!==e.doc.features.app.html&&l.push("index.html.njk"),await a({pattern:l,dir:t.resolve(i,"src/app"),outDir:p,context:c})}async function h({projectDir:e,name:a,setProgress:n,count:o=1}){let i;const p=c(["npm-pick-versions",a,o]),l=t.join(e,".cache"),f=t.join(l,p+".json");return s.existsSync(f)?(n&&n(`Picking npm version of ${a} from cache ...`),i=JSON.parse(s.readFileSync(f,"utf8"))):(n&&n(`Picking npm version of ${a} ...`),i=await r({name:a,count:o}),s.mkdirSync(l,{recursive:!0}),s.writeFileSync(f,JSON.stringify(i),"utf8")),i}async function w({atom:e,context:a,packageDependencies:r,packageDevDependencies:c,setProgress:i}){await i({message:"Creating package.json."});r.filter((e=>!0===e.dev)).forEach((e=>{c.find((s=>s.package===e.package))||c.push(e);const s=r.findIndex((s=>s.package===e.package));r.splice(s,1)}));const p=r.find((e=>"react"===e.package)),l=r.find((e=>"react-dom"===e.package));p&&!l?r.push({package:"react-dom",version:p.version}):p&&l&&(l.version=p.version),p&&e.doc.features.react_version>=17&&(r.find((e=>"@emotion/react"===e.package))||r.push({package:"@emotion/react",version:"^11"}),r.find((e=>"@emotion/styled"===e.package))||r.push({package:"@emotion/styled",version:"^11"}));const f=[];!0===e.doc.features.app.enabled&&f.push({file:t.resolve(a.projectDir,"src/app/index.js"),dev:!1!==e.doc.features.app.dev}),!0===e.doc.features.cli.enabled&&f.push({file:t.resolve(a.projectDir,"src/cli/index.js"),dev:!1!==e.doc.features.cli.dev});for await(const e of f){const t=e.file;if(!s.existsSync(t))throw new Error(`App file not found: ${t}`);const n=(await o({file:t,recursive:!0})).all;for await(const s of n){if("npm"!==s.type)continue;if(r.find((e=>e.package===s.package)))continue;if(c.find((e=>e.package===s.package)))continue;const t=await h({name:s.package,projectDir:a.projectDir,setProgress:i});(!0===e.dev?c:r).push({package:s.package,subpath:s.subpath,version:t.minorRange,type:"npm"})}}const d={atom:e,packageDependencies:r,packageDevDependencies:c},u=a.templateDir,m=n.compile(s.readFileSync(t.resolve(u,"package.json.njk"),"utf8"),n.configure(u)).render(d),g=a.projectDir,k=t.resolve(g,"package.json");s.writeFileSync(k,m,"utf8");const j=t.resolve(a.project.projectDir,"fnet");if(s.existsSync(j)){const e=t.resolve(a.projectDir,"fnet");s.existsSync(e)||s.mkdirSync(e);const n=s.readdirSync(j);for(const a of n){const n=t.resolve(j,a);if(!s.lstatSync(n).isFile())continue;const o=t.resolve(e,a);s.copyFileSync(n,o)}}}async function y({atom:e,setProgress:n,context:o,packageDependencies:r}){if(!0!==e.doc.features.cli.enabled)return;await n({message:"Creating cli."});const c={atom:e,packageDependencies:r},i=o.templateDir,p=t.resolve(o.projectDir,"src/cli");s.existsSync(p)||s.mkdirSync(p,{recursive:!0}),await a({pattern:["index.js.njk"],dir:t.resolve(i,"src/cli"),outDir:p,context:c})}async function b({atom:e,setProgress:a,context:o,njEnv:r}){if(!0!==e.doc.features.cli.enabled)return;await a({message:"Creating input args."});let c={};if(c=e.doc.input?e.doc.input:{type:"object",properties:{},required:[]},e.doc.features.cli.fargs&&!1!==e.doc.features.cli.fargs?.enabled){const s=e.doc.features.cli.fargs,t={type:"string",description:"Config name to load args",hidden:!1},a={type:"array",description:"Tags to filter the config",hidden:!1};Reflect.has(s,"default")&&(t.default=s.default),c.properties&&(c.properties.fargs=t,c.properties.ftag=a)}const f={options:c,imports:[],atom:e},d=o.templateDir,u=n.compile(s.readFileSync(t.resolve(d,"src/default/input.args.js.njk"),"utf8"),r).render(f),m=o.projectDir,g=t.resolve(m,"src/default/input.args.js");s.writeFileSync(g,u,"utf8");const k=new i({allErrors:!0,useDefaults:!0,formats:{},strict:!1,code:{esm:!0,lines:!0,optimize:!1,source:!0}});l(k);const j=k.compile(c),v=p(k,j);s.writeFileSync(t.resolve(m,"src/default/validate_input.js"),v,"utf8")}async function x({atom:e,setProgress:a,context:o,packageDependencies:r}){await a({message:"Creating tsconfig.json."});const c={atom:e,packageDependencies:r},i=o.templateDir,p=n.compile(s.readFileSync(t.resolve(i,"tsconfig.json.njk"),"utf8"),n.configure(i)).render(c),l=o.projectDir,f=t.resolve(l,"tsconfig.json");s.writeFileSync(f,p,"utf8")}async function S({setProgress:e,context:s}){const a=s.projectDir;await e({message:"Prettifiying source files."});let n=t.join("src","**","*");if(d("bun")){const e=await f(`prettier --write ${n} *.{js,cjs,mjs,json,yaml,html} --no-error-on-unmatched-pattern`,{cwd:a});if(0!==e.code)throw new Error(e.stderr)}else{const e=await f(`prettier --write ${n} *.{js,cjs,mjs,json,yaml,html} --no-error-on-unmatched-pattern`,{cwd:a});if(0!==e.code)throw new Error(e.stderr)}}async function P({setProgress:e,atom:s,context:t}){const a=t.projectDir;if(await e({message:"Installing npm packages."}),d("bun")){if(0!==(await f(`bun install ${s.doc.features.npm_install_flags}`,{cwd:a})).code)throw new Error("Couldnt install npm packages.")}else{if(0!==(await f(`npm install ${s.doc.features.npm_install_flags}`,{cwd:a})).code)throw new Error("Couldnt install npm packages.")}}async function E({setProgress:e,context:s}){const t=s.projectDir;await e({message:"Building main project."});if(0!==(await f("npm run build",{cwd:t})).code)throw new Error("Couldnt build project.")}export{j as a,k as b,m as c,g as d,x as e,u as f,b as g,y as h,v as i,D as j,w as k,S as l,P as m,h as p,E as r};
|
package/dist/fnode/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import e,{delimiter as o,join as t}from"node:path";import{fileURLToPath as n}from"node:url";import r from"yargs";import i from"chalk";import s from"@fnet/config";import a,{existsSync as c}from"node:fs";import{promisify as l}from"node:util";import d from"tree-kill";import{spawn as p}from"node:child_process";import m from"node:os";import u from"@flownet/lib-render-templates-dir";import f from"@fnet/shelljs";import y from"@fnet/yaml";import g from"yaml";import w from"@fnet/prompt";import"fs";import"path";import"@fnet/shell-flow";const h=e.dirname(n(import.meta.url));const j=l(d);let b=!1;async function x(e,o){if(b)return;if(b=!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 t="SIGINT"===o?130:"SIGTERM"===o?143:1;process.exit(t)}function v(e){["SIGINT","SIGTERM","SIGQUIT"].forEach((o=>{process.once(o,(async()=>{await x(e,o)}))})),process.on("uncaughtException",(async o=>{await x(e)})),process.on("unhandledRejection",(async o=>{await x(e)})),e.on("close",(e=>{b||process.exit(e)}))}function $(e,{name:o,bin:t,preArgs:n=[]}){return"function"==typeof t&&(t=t()),e.command(`${o||t} [commands..]`,`${t} ${n.join(" ")}`,(e=>e.help(!1).version(!1)),(async e=>{try{const o=await P(e),{projectDir:r}=o,i=e=>e.includes(" ")?"win32"===process.platform?`"${e.replace(/(["^])/g,"^$1")}"`:`"${e.replace(/(["\\$`])/g,"\\$1")}"`:e,s=process.argv.slice(3).map(i);v(p(t,[...n,...s],{cwd:r,stdio:"inherit",shell:!0,detached:!0}))}catch(e){console.error(e.message),process.exit(1)}}))}function S(o,{name:t,bin:n,preArgs:r=[]}){return o.command(`${t||n} [commands..]`,`${n} ${r.join(" ")}`,(e=>e.help(!1).version(!1)),(async o=>{try{const i=await P(o),{projectDir:s}=i,a=e=>e.includes(" ")?"win32"===process.platform?`"${e.replace(/(["^])/g,"^$1")}"`:`"${e.replace(/(["\\$`])/g,"\\$1")}"`:e,c=process.argv.slice(3).map(a);n=e.join(s,".conda","bin",n||t);v(p(n,[...r,...c],{cwd:s,stdio:"inherit",shell:!0,detached:!0,env:{PYTHONPATH:s}}))}catch(e){console.error(e.message),process.exit(1)}}))}async function P(e){try{const o=process.argv[1].split("/").pop().split(".")[0];if("fnode"===o){const{createContext:o}=await Promise.resolve().then((function(){return F}));return o(e)}if("fnet"===o){const{createContext:o}=await import("./index.6_yfJqit.js");return o(e)}if("frun"===o){const{createContext:o}=await import("./index.CuMyez3E.js");return o(e)}if("fbin"===o){const{createContext:o}=await import("./index.DWpw12No.js");return o(e)}}catch(e){console.warn(`Warning: Could not import context from CLI tool: ${e.message}`)}return{projectDir:process.cwd(),tags:e.ftag}}var D=e=>{const n=process.env.PATH||"",r="win32"===process.platform?(process.env.PATHEXT||".EXE;.CMD;.BAT;.COM").split(";"):[""],i=n.split(o);for(const o of i)for(const n of r){const r=t(o,"win32"===process.platform?e+n:e);if(c(r))return r}return null};const I=e.dirname(n(import.meta.url)),E=process.cwd();function C(o){const t=e.resolve(E,o);if(a.existsSync(t))return t;const n=e.resolve(I,"../..",o);if(a.existsSync(n))return n;throw new Error(`Template path not found: ${o}`)}const N={command:"create",describe:"Create a new fnode project",builder:e=>e.option("name",{type:"string",describe:"Project name",demandOption:!0}).option("vscode",{type:"boolean",default:!0,alias:"vs",describe:"Open in VS Code after creation"}).option("runtime",{type:"string",default:"node",choices:["node","python","bun"],describe:"Runtime environment"}),handler:async o=>{try{const t=process.cwd(),n=C("./template/fnode/project"),r=e.resolve(t,o.name);a.existsSync(r)||a.mkdirSync(r),await u({dir:n,outDir:r,context:{name:o.name,runtime:o.runtime,platform:m.platform()},copyUnmatchedAlso:!0});let i=await f("fnode build",{cwd:r});if(0!==i.code)throw new Error("Failed to build project.");if(D("git")&&(i=await f("git init --initial-branch=main",{cwd:r}),0!==i.code))throw new Error("Failed to initialize git.");if(D("code")&&o.vscode&&(i=await f(`cd ${r} && code .`),0!==i.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)}}};async function T(o){if(o.id)return{id:o.id,buildId:o.buildId,mode:o.mode,protocol:o.protocol||"ac:",templateDir:C("./template/fnode/node"),projectDir:e.resolve(process.cwd(),`./.output/${o.id}`),tags:o.ftag};try{const t=await async function({tags:o}){let t=function(o){const t=e.resolve(o,"node.yaml"),n=e.resolve(o,"fnode.yaml");if(a.existsSync(n))return n;if(a.existsSync(t))try{const e=a.readFileSync(t,"utf8");return a.writeFileSync(n,e,"utf8"),a.unlinkSync(t),console.log(`Migrated node.yaml to fnode.yaml in ${o}`),n}catch(e){return console.error(`Error migrating node.yaml to fnode.yaml: ${e.message}`),t}return n}(process.cwd());if(!a.existsSync(t))throw new Error("fnode.yaml file not found in current directory.");const{raw:n,parsed:r}=await y({file:t,tags:o}),i=e.dirname(t);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 c={libraryAtom:{doc:{...r},fileName:"index"},projectDir:i,projectFilePath:t,projectFileContent:n,projectFileParsed:r,runtime:s.runtime};let l=e.resolve(i,"fnet/targets.yaml");if(!a.existsSync(l)&&(l=e.resolve(i,"node.devops.yaml"),a.existsSync(l))){const o=e.resolve(i,"fnet");a.existsSync(o)||a.mkdirSync(o),a.copyFileSync(l,e.resolve(i,"fnet/targets.yaml")),a.unlinkSync(l)}if(a.existsSync(l)){const{raw:e,parsed:t}=await y({file:l,tags:o}),n=g.parseDocument(e);c.devops={filePath:l,fileContent:e,yamlDocument:n,doc:{...t},type:"library.deploy",save:async()=>{a.writeFileSync(c.devops.filePath,n.toString())}}}const d=e.resolve(i,"readme.md");if(a.existsSync(d)){const e=a.readFileSync(d,"utf8");c.readme={filePath:d,fileContent:e,doc:{content:e,"content-type":"markdown"},type:"wiki"}}return c}({tags:o.ftag});return{buildId:o.buildId,mode:o.mode,protocol:o.protocol||"local:",templateDir:C(`./template/fnode/${t.runtime.template}`),projectDir:e.resolve(t.projectDir,"./.workspace"),projectSrcDir:e.resolve(t.projectDir,"./src"),project:t,tags:o.ftag}}catch(e){return console.warn(`Warning: Could not load project: ${e.message}`),{projectDir:process.cwd(),tags:o.ftag}}}var F=Object.freeze({__proto__:null,createContext:T});const k={command:"project",describe:"Manage fnode project",builder:e=>e.option("update",{type:"boolean",default:!1,alias:"-u",describe:"Update project files"}),handler:async e=>{try{const o=C("./template/fnode/project"),t=process.cwd(),n=await T(e);if(e.update){if(await u({dir:o,outDir:t,context:{name:n.project.projectFileParsed.name,runtime:n.project.runtime.type,platform:m.platform()},copyUnmatchedAlso:!0}),0!==(await f("fnode build",{cwd:t})).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)}}};class B{static async createBuilder(e){if(!e.project){console.warn("No project provided, defaulting to node runtime");return new(0,(await import("./index.Cl6LPgIY.js")).default)(e)}const o=e.project?.runtime?.type||"node";try{return new(await this.loadBuilderClass(o))(e)}catch(t){console.warn(`Warning: Could not load builder for runtime '${o}'. Falling back to node builder.`),console.warn(`Error: ${t.message}`);return new(0,(await import("./index.Cl6LPgIY.js")).default)(e)}}static async loadBuilderClass(e){switch(e.toLowerCase()){case"node":return(await import("./index.Cl6LPgIY.js")).default;case"python":return(await import("./index.qJ6fWMSj.js")).default;case"bun":return(await import("./index.mC936qdY.js")).default;default:throw new Error(`Unsupported runtime type: ${e}`)}}}const A={command:"build",describe:"Build fnode project",builder:e=>e.option("id",{type:"string",describe:"Project ID"}).option("buildId",{type:"string",alias:"bid",describe:"Build ID"}).option("mode",{type:"string",default:"build",choices:["all","file","build","deploy","bpmn"],describe:"Build mode"}).option("ftag",{type:"array",describe:"Tags for conditional configuration"}),handler:async e=>{try{const o=await T(e),t=await B.createBuilder(o);await t.init(),await t.build(),console.log("Building library succeeded!"),process.exit(0)}catch(e){console.error("Building library failed!",e.message),process.exit(1)}}},M={command:"deploy",describe:"Build and deploy fnode project",builder:e=>e.option("id",{type:"string",describe:"Project ID"}).option("buildId",{type:"string",alias:"bid",describe:"Build ID"}).option("ftag",{type:"array",describe:"Tags for conditional configuration"}),handler:async e=>{try{const o=await T({...e,mode:"all"}),t=await B.createBuilder(o);await t.init(),await t.build(),console.log("Building library succeeded!"),process.exit(0)}catch(e){console.error("Building library failed!",e.message),process.exit(1)}}},O={command:"file",describe:"Just create files",builder:e=>e.option("id",{type:"string",describe:"Project ID"}).option("buildId",{type:"string",alias:"bid",describe:"Build ID"}).option("ftag",{type:"array",describe:"Tags for conditional configuration"}),handler:async e=>{try{const o=await T({...e,mode:"file"}),t=await B.createBuilder(o);await t.init(),await t.build(),console.log("Building library succeeded!"),process.exit(0)}catch(e){console.error("Building library failed!",e.message),process.exit(1)}}},W={command:"input [name]",describe:"Create or modify an input config file",builder:e=>e.positional("name",{type:"string",demandOption:!1,describe:"Input name"}),handler:async o=>{try{const t=await T(o),{project:n}=t,{projectDir:r,projectFileParsed:i}=n,s=i.input;if(!s)throw new Error("Config schema not found in project file.");if(!Reflect.has(o,"name")){const{inputName:e}=await w({type:"input",name:"inputName",message:"Input name:",initial:"dev"});o.name=e}const c=e.resolve(r,".fnet");a.existsSync(c)||a.mkdirSync(c);const l=e.resolve(c,`${o.name}.fnet`),d=a.existsSync(l),p=(await import("@fnet/object-from-schema")).default,m=await p({schema:s,format:"yaml",ref:d?l:void 0});a.writeFileSync(l,m)}catch(e){console.error(e.message),process.exit(1)}}},R=e.join(m.homedir(),".fnet","express");async function U(o){o.command(["$0 [project-name]","create [project-name]"],"Create a new express project",(e=>e.positional("project-name",{describe:"Name of the project",type:"string"}).option("yes",{alias:"y",describe:"Skip all prompts and use defaults",type:"boolean",default:!1}).option("runtime",{describe:"Runtime to use (node, python, bun)",type:"string",choices:["node","python","bun"],default:"node"})),(async o=>{await async function(o){try{a.existsSync(R)||a.mkdirSync(R,{recursive:!0});const t=(new Date).toISOString().slice(0,10).replace(/-/g,""),n=e.join(R,t);a.existsSync(n)||a.mkdirSync(n,{recursive:!0});let r,s=o.projectName,c=o.runtime;if(o.yes){if(!s){const e=a.readdirSync(n).filter((e=>e.startsWith("fnode-"))).map((e=>parseInt(e.replace("fnode-",""),10))).filter((e=>!isNaN(e))),o=e.length>0?Math.max(...e)+1:1;s=`fnode-${o}`}c||(c="node")}else{if(!s){const e=a.readdirSync(n).filter((e=>e.startsWith("fnode-"))).map((e=>parseInt(e.replace("fnode-",""),10))).filter((e=>!isNaN(e))),o=`fnode-${e.length>0?Math.max(...e)+1:1}`,t=await w([{type:"input",name:"projectName",message:"Enter project name:",default:o}]);s=t.projectName}const e=c||"node";c=(await w({type:"select",name:"runtime",message:"Select runtime:",choices:["node","python","bun"],initial:e})).runtime}if(r=e.join(n,s),a.existsSync(r)){let o=1;for(;a.existsSync(e.join(n,`${s}-${o}`));)o++;s=`${s}-${o}`,r=e.join(n,s)}if(!o.yes){if(!(await w([{type:"confirm",name:"proceed",message:`Create express project "${s}" in ${r}?`,default:!0}])).proceed)return void console.log(i.yellow("Project creation cancelled."))}console.log(i.blue(`Creating express project "${s}" in ${r}...`));const l=e.dirname(r),d=["create","--name",e.basename(r)];d.push("--runtime",c),o.yes&&d.push("--yes"),a.existsSync(l)||a.mkdirSync(l,{recursive:!0});const m=p("fnode",d,{stdio:"inherit",shell:!0,cwd:l});return new Promise(((e,t)=>{m.on("close",(n=>{0===n?(console.log(i.green(`\nExpress project "${s}" created successfully!`)),console.log(i.blue(`\nProject location: ${r}`)),o.yes?e():async function(e){try{(await w({type:"confirm",name:"openIDE",message:"Would you like to open the project in an IDE?",initial:!0})).openIDE&&await L(e)}catch(e){console.error(i.red(`Error opening IDE: ${e.message}`))}}(r)):(console.error(i.red(`\nFailed to create express project "${s}".`)),t(new Error(`Process exited with code ${n}`)))}))}))}catch(e){console.error(i.red(`Error creating express project: ${e.message}`)),process.exit(1)}}(o)})).command("list","List express projects",(e=>e.option("today",{describe:"Show only projects created today",type:"boolean",default:!1}).option("type",{describe:"Filter by project type (fnode or fnet)",type:"string",choices:["fnode","fnet"]}).option("name",{describe:"Filter by project name",type:"string"})),(async o=>{await async function(o){try{if(!a.existsSync(R))return void console.log(i.yellow("No express projects found."));const t=a.readdirSync(R).filter((e=>/^\d{8}$/.test(e))).sort(((e,o)=>o.localeCompare(e)));if(o.today){const e=(new Date).toISOString().slice(0,10).replace(/-/g,""),o=t.indexOf(e);if(-1===o)return void console.log(i.yellow("No express projects found for today."));t.splice(0,o),t.splice(1)}const n=[];for(const r of t){const t=e.join(R,r),i=a.readdirSync(t);for(const s of i){const i=e.join(t,s),c=a.statSync(i);let l="unknown";if(s.startsWith("fnode-")||a.existsSync(e.join(i,"fnode.yaml"))?l="fnode":(s.startsWith("fnet-")||a.existsSync(e.join(i,"fnet.yaml")))&&(l="fnet"),o.type&&l!==o.type)continue;if(o.name&&!s.includes(o.name))continue;const d=`${r.slice(0,4)}-${r.slice(4,6)}-${r.slice(6,8)}`;n.push({name:s,type:l,date:d,path:i,created:c.birthtime})}}if(n.sort(((e,o)=>o.created-e.created)),0===n.length)return void console.log(i.yellow("No express projects found matching the criteria."));console.log(i.blue("\nExpress Projects:")),console.log(i.blue("=================\n"));const r=n.map((e=>{let o=e.path;return o.startsWith(m.homedir())&&(o="~"+o.substring(m.homedir().length)),{Name:e.name,Type:e.type,Date:e.date,Path:o}}));console.table(r),console.log(i.green("Projects: ")+i.yellow(n.filter((e=>"fnode"===e.type)).length+" fnode, ")+i.cyan(n.filter((e=>"fnet"===e.type)).length+" fnet")),console.log(i.blue(`\nTotal: ${n.length} projects`))}catch(e){console.error(i.red(`Error listing express projects: ${e.message}`)),process.exit(1)}}(o)})).command("open [project-name]","Open an express project",(e=>e.positional("project-name",{describe:"Name of the project to open",type:"string"}).option("latest",{describe:"Open the most recent project",type:"boolean",default:!1})),(async o=>{await async function(o){try{if(!a.existsSync(R))return void console.log(i.yellow("No express projects found."));let t;if(o.latest){if(t=await G(),!t)return void console.log(i.yellow("No express projects found."))}else if(o.projectName){if(t=await _(o.projectName),!t)return void console.log(i.yellow(`Project "${o.projectName}" not found.`))}else{const o=await H();if(!o)return void console.log(i.yellow("No project selected."));t=e.join(R,o)}await L(t)}catch(e){console.error(i.red(`Error opening express project: ${e.message}`)),process.exit(1)}}(o)})).command("move [project-name] [destination]","Move an express project to a real project location",(e=>e.positional("project-name",{describe:"Name of the project to move",type:"string"}).positional("destination",{describe:"Destination directory",type:"string"}).option("latest",{describe:"Move the most recent project",type:"boolean",default:!1})),(async o=>{await async function(o){try{const t=process.cwd();let n;if(t.includes(R))n=t,console.log(i.blue(`Using current express project: ${e.basename(n)}`));else if(o.latest){if(n=await G(),!n)return void console.log(i.yellow("No express projects found."))}else if(o.projectName){if(n=await _(o.projectName),!n)return void console.log(i.yellow(`Project "${o.projectName}" not found.`))}else{const o=await H();if(!o)return void console.log(i.yellow("No project selected."));n=e.join(R,o)}let r=o.destination;if(!r){r=(await w({type:"input",name:"destination",message:"Enter destination directory:",initial:e.join(process.cwd(),e.basename(n))})).destination}if(r.startsWith("~")&&(r=e.join(m.homedir(),r.slice(1))),r=e.resolve(r),r.startsWith(n+e.sep)||r===n)return void console.log(i.red("Destination cannot be inside the source directory."));if(a.existsSync(r)){if(!a.statSync(r).isDirectory())return void console.log(i.red(`Destination "${r}" is not a directory.`));if(a.readdirSync(r).length>0){if(!(await w({type:"confirm",name:"overwrite",message:`Destination "${r}" is not empty. Continue anyway?`,initial:!1})).overwrite)return void console.log(i.yellow("Project move cancelled."))}}else a.mkdirSync(r,{recursive:!0});console.log(i.blue(`Moving project from ${n} to ${r}...`)),V(n,r),console.log(i.green(`\nProject moved successfully to ${r}`));(await w({type:"confirm",name:"deleteOriginal",message:"Delete the original express project?",initial:!1})).deleteOriginal&&(a.rmSync(n,{recursive:!0,force:!0}),console.log(i.green("Original project deleted."))),await L(r)}catch(e){console.error(i.red(`Error moving express project: ${e.message}`)),process.exit(1)}}(o)})).demandCommand(1,"You need to specify a command").help()}async function G(){const o=a.readdirSync(R).filter((e=>/^\d{8}$/.test(e))).sort(((e,o)=>o.localeCompare(e)));if(0===o.length)return null;const t=o[0],n=e.join(R,t),r=a.readdirSync(n);if(0===r.length)return null;let i=null,s=0;for(const o of r){const t=e.join(n,o),r=a.statSync(t);r.birthtimeMs>s&&(s=r.birthtimeMs,i=t)}return i}async function _(o){const t=a.readdirSync(R).filter((e=>/^\d{8}$/.test(e))).sort(((e,o)=>o.localeCompare(e)));for(const n of t){const t=e.join(R,n),r=a.readdirSync(t);if(r.includes(o))return e.join(t,o);const i=r.filter((e=>e.includes(o)));if(i.length>0){if(1===i.length)return e.join(t,i[0]);return(await w({type:"select",name:"selectedProject",message:`Multiple projects match "${o}". Please select one:`,choices:i.map((o=>({name:`${o} (${n})`,value:e.join(t,o)})))})).selectedProject}}return null}async function H(){const o=[],t=a.readdirSync(R).filter((e=>/^\d{8}$/.test(e))).sort(((e,o)=>o.localeCompare(e)));for(const n of t){const t=e.join(R,n),r=a.readdirSync(t);for(const i of r){const r=e.join(t,i),s=a.statSync(r),c=`${n}/${i}`;o.push({name:c,value:c,created:s.birthtime})}}if(o.sort(((e,o)=>o.created-e.created)),0===o.length)return null;return(await w({type:"select",name:"selectedProject",message:"Select a project:",choices:o})).selectedProject}async function L(e){const o=await z("code --version"),t=await z("code-insiders --version");let n=null;if(o&&t){const e=await w({type:"select",name:"ide",message:"Which IDE would you like to use?",choices:[{name:"Visual Studio Code",value:"code"},{name:"Visual Studio Code Insiders",value:"code-insiders"}]});n=e.ide}else if(o)n="code";else{if(!t)return console.log(i.yellow("No supported IDE found. Please open the project manually.")),void console.log(i.blue(`Project path: ${e}`));n="code-insiders"}console.log(i.blue(`Opening project in ${n}...`)),console.log(i.blue(`Project path: ${e}`));const r=p(n,[e],{stdio:"inherit",shell:!0});return new Promise(((e,o)=>{r.on("close",(t=>{0===t?(console.log(i.green(`Project opened in ${n}.`)),e()):(console.error(i.red(`Failed to open project in ${n}.`)),o(new Error(`Process exited with code ${t}`)))}))}))}async function z(e){return new Promise((o=>{p(e,{shell:!0,stdio:"ignore"}).on("close",(e=>{o(0===e)}))}))}function V(o,t){a.existsSync(t)||a.mkdirSync(t,{recursive:!0});const n=a.readdirSync(o,{withFileTypes:!0});for(const r of n){const n=e.join(o,r.name),i=e.join(t,r.name);if(r.isDirectory()){if(".git"===r.name||".workspace"===r.name)continue;V(n,i)}else a.copyFileSync(n,i)}}const Y=e.dirname(n(import.meta.url)),X=process.cwd();process.on("uncaughtException",(e=>{b||(b=!0,setTimeout((()=>process.exit(1)),500))})),process.on("unhandledRejection",(e=>{b||(b=!0,setTimeout((()=>process.exit(1)),500))})),function(){s({name:["redis"],dir:X,optional:!0});const o=function({baseDir:o}){let t=o=o||h;for(;t!==e.parse(t).root;){const o=e.join(t,"node_modules");if(a.existsSync(o))return o;t=e.dirname(t)}return null}({baseDir:Y}),t="win32"===process.platform?";":":";o&&(process.env.PATH=`${e.join(o,"/.bin")}${t}${process.env.PATH}`)}(),async function(){try{let o=r(process.argv.slice(2)).usage("Usage: $0 <command> [options]").command(N).command(k).command(A).command(M).command(O).command(W).command("express","Create and manage express projects",U);o=$(o,{bin:"npm"}),o=$(o,{bin:"node"}),o=$(o,{bin:"bun"}),o=$(o,{name:"serve",bin:"bun",preArgs:["run","serve","--"]}),o=$(o,{name:"watch",bin:"bun",preArgs:["run","watch","--"]}),o=$(o,{name:"app",bin:"bun",preArgs:["run","app","--"]}),o=$(o,{name:"cli",bin:"bun",preArgs:["run","cli","--"]}),o=$(o,{name:"compile",bin:"bun",preArgs:["run","compile","--"]}),o=function(o,{name:t}){return o.command(`${t} [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("yes",{alias:"y",describe:"Automatically answer yes to all prompts",type:"boolean",default:!1})),(async o=>{try{const t=await P(o),{projectDir:n}=t;console.log(i.blue("Compiling project..."));const r=e.join(n,".bin");a.existsSync(r)||a.mkdirSync(r,{recursive:!0});const s=e.basename(e.dirname(n)),c=t.project?.projectFileParsed?.features?.cli?.bin,l=o.name||c||s;console.log(i.blue(`Using binary name: ${l}`));const d=e.join(r,l),{spawn:p}=await import("child_process"),m=p("bun",["build","./dist/cli/esm/index.js","--compile",`--outfile=${d}`],{cwd:n,stdio:"inherit",shell:!0});await new Promise(((e,o)=>{m.on("close",(t=>{0===t?e():o(new Error(`Compilation failed with code ${t}`))})),m.on("error",(e=>{o(e)}))})),"win32"!==process.platform&&a.chmodSync(d,493),console.log(i.green(`Binary compiled successfully: ${d}`)),console.log(i.blue("Installing binary..."));const u=["install",d];o.name&&u.push("--name",o.name),o.force&&u.push("--force"),o.yes&&u.push("--yes");const f=p("fbin",u,{stdio:"inherit",shell:!0});await new Promise(((e,o)=>{f.on("close",(t=>{0===t?e():o(new Error(`Installation failed with code ${t}`))})),f.on("error",(e=>{o(e)}))}))}catch(e){console.error(i.red(`Failed to install binary: ${e.message}`)),process.exit(1)}}))}(o,{name:"install"}),o=$(o,{bin:"npx"}),o=$(o,{bin:"cdk"}),o=$(o,{bin:"aws"}),o=function(e,{name:o,preArgs:t=[]}){return e.command(`${o} <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 o=await P(e),{projectDir:n}=o,r=e.config,i=await s({name:r,dir:n,transferEnv:!1,optional:!0,tags:o.tags}),c=i?.data?.env||void 0,l=e.command,d=process.argv.slice(5);v(p(l,[...t,...d],{cwd:a.existsSync(n)?n:process.cwd(),stdio:"inherit",shell:!0,detached:!0,env:{...process.env,...c}}))}catch(e){console.error(e.message),process.exit(1)}}))}(o,{name:"with"}),o=function(e,{name:o,projectType:t="auto"}){return e.command(`${o} 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:o}=await import("./index.DrwlOzAe.js");await o({projectType:t,group:e.group,tags:e.ftag,args:e,argv:process.argv})}catch(e){console.error(e.message),process.exit(1)}}))}(o,{name:"run",projectType:"fnode"}),o=S(o,{name:"python"}),o=S(o,{name:"python3"}),o=S(o,{name:"pip"}),o=S(o,{name:"pip3"}),o.demandCommand(1,"You need at least one command before moving on").help().version().argv}catch(e){console.error(i.red(`Fatal error: ${e.message}`)),process.exit(1)}}().catch((e=>{console.error(i.red(`Fatal error: ${e.message}`)),process.exit(1)}));export{C as r,D as w};
|
|
2
|
+
import e,{delimiter as o,join as t}from"node:path";import{fileURLToPath as n}from"node:url";import r from"yargs";import i from"chalk";import s from"@fnet/config";import a,{existsSync as c}from"node:fs";import{promisify as l}from"node:util";import d from"tree-kill";import{spawn as p}from"node:child_process";import m from"node:os";import u from"@flownet/lib-render-templates-dir";import f from"@fnet/shelljs";import y from"@fnet/yaml";import g from"yaml";import w from"@fnet/prompt";import"fs";import"path";import"@fnet/shell-flow";const h=e.dirname(n(import.meta.url));const j=l(d);let b=!1;async function x(e,o){if(b)return;if(b=!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 t="SIGINT"===o?130:"SIGTERM"===o?143:1;process.exit(t)}function v(e){["SIGINT","SIGTERM","SIGQUIT"].forEach((o=>{process.once(o,(async()=>{await x(e,o)}))})),process.on("uncaughtException",(async o=>{await x(e)})),process.on("unhandledRejection",(async o=>{await x(e)})),e.on("close",(e=>{b||process.exit(e)}))}function $(e,{name:o,bin:t,preArgs:n=[]}){return"function"==typeof t&&(t=t()),e.command(`${o||t} [commands..]`,`${t} ${n.join(" ")}`,(e=>e.help(!1).version(!1)),(async e=>{try{const o=await P(e),{projectDir:r}=o,i=e=>e.includes(" ")?"win32"===process.platform?`"${e.replace(/(["^])/g,"^$1")}"`:`"${e.replace(/(["\\$`])/g,"\\$1")}"`:e,s=process.argv.slice(3).map(i);v(p(t,[...n,...s],{cwd:r,stdio:"inherit",shell:!0,detached:!0}))}catch(e){console.error(e.message),process.exit(1)}}))}function S(o,{name:t,bin:n,preArgs:r=[]}){return o.command(`${t||n} [commands..]`,`${n} ${r.join(" ")}`,(e=>e.help(!1).version(!1)),(async o=>{try{const i=await P(o),{projectDir:s}=i,a=e=>e.includes(" ")?"win32"===process.platform?`"${e.replace(/(["^])/g,"^$1")}"`:`"${e.replace(/(["\\$`])/g,"\\$1")}"`:e,c=process.argv.slice(3).map(a);n=e.join(s,".conda","bin",n||t);v(p(n,[...r,...c],{cwd:s,stdio:"inherit",shell:!0,detached:!0,env:{PYTHONPATH:s}}))}catch(e){console.error(e.message),process.exit(1)}}))}async function P(e){try{const o=process.argv[1].split("/").pop().split(".")[0];if("fnode"===o){const{createContext:o}=await Promise.resolve().then((function(){return F}));return o(e)}if("fnet"===o){const{createContext:o}=await import("./index.6_yfJqit.js");return o(e)}if("frun"===o){const{createContext:o}=await import("./index.CuMyez3E.js");return o(e)}if("fbin"===o){const{createContext:o}=await import("./index.DWpw12No.js");return o(e)}}catch(e){console.warn(`Warning: Could not import context from CLI tool: ${e.message}`)}return{projectDir:process.cwd(),tags:e.ftag}}var D=e=>{const n=process.env.PATH||"",r="win32"===process.platform?(process.env.PATHEXT||".EXE;.CMD;.BAT;.COM").split(";"):[""],i=n.split(o);for(const o of i)for(const n of r){const r=t(o,"win32"===process.platform?e+n:e);if(c(r))return r}return null};const I=e.dirname(n(import.meta.url)),E=process.cwd();function C(o){const t=e.resolve(E,o);if(a.existsSync(t))return t;const n=e.resolve(I,"../..",o);if(a.existsSync(n))return n;throw new Error(`Template path not found: ${o}`)}const N={command:"create",describe:"Create a new fnode project",builder:e=>e.option("name",{type:"string",describe:"Project name",demandOption:!0}).option("vscode",{type:"boolean",default:!0,alias:"vs",describe:"Open in VS Code after creation"}).option("runtime",{type:"string",default:"node",choices:["node","python","bun"],describe:"Runtime environment"}),handler:async o=>{try{const t=process.cwd(),n=C("./template/fnode/project"),r=e.resolve(t,o.name);a.existsSync(r)||a.mkdirSync(r),await u({dir:n,outDir:r,context:{name:o.name,runtime:o.runtime,platform:m.platform()},copyUnmatchedAlso:!0});let i=await f("fnode build",{cwd:r});if(0!==i.code)throw new Error("Failed to build project.");if(D("git")&&(i=await f("git init --initial-branch=main",{cwd:r}),0!==i.code))throw new Error("Failed to initialize git.");if(D("code")&&o.vscode&&(i=await f(`cd ${r} && code .`),0!==i.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)}}};async function T(o){if(o.id)return{id:o.id,buildId:o.buildId,mode:o.mode,protocol:o.protocol||"ac:",templateDir:C("./template/fnode/node"),projectDir:e.resolve(process.cwd(),`./.output/${o.id}`),tags:o.ftag};try{const t=await async function({tags:o}){let t=function(o){const t=e.resolve(o,"node.yaml"),n=e.resolve(o,"fnode.yaml");if(a.existsSync(n))return n;if(a.existsSync(t))try{const e=a.readFileSync(t,"utf8");return a.writeFileSync(n,e,"utf8"),a.unlinkSync(t),console.log(`Migrated node.yaml to fnode.yaml in ${o}`),n}catch(e){return console.error(`Error migrating node.yaml to fnode.yaml: ${e.message}`),t}return n}(process.cwd());if(!a.existsSync(t))throw new Error("fnode.yaml file not found in current directory.");const{raw:n,parsed:r}=await y({file:t,tags:o}),i=e.dirname(t);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 c={libraryAtom:{doc:{...r},fileName:"index"},projectDir:i,projectFilePath:t,projectFileContent:n,projectFileParsed:r,runtime:s.runtime};let l=e.resolve(i,"fnet/targets.yaml");if(!a.existsSync(l)&&(l=e.resolve(i,"node.devops.yaml"),a.existsSync(l))){const o=e.resolve(i,"fnet");a.existsSync(o)||a.mkdirSync(o),a.copyFileSync(l,e.resolve(i,"fnet/targets.yaml")),a.unlinkSync(l)}if(a.existsSync(l)){const{raw:e,parsed:t}=await y({file:l,tags:o}),n=g.parseDocument(e);c.devops={filePath:l,fileContent:e,yamlDocument:n,doc:{...t},type:"library.deploy",save:async()=>{a.writeFileSync(c.devops.filePath,n.toString())}}}const d=e.resolve(i,"readme.md");if(a.existsSync(d)){const e=a.readFileSync(d,"utf8");c.readme={filePath:d,fileContent:e,doc:{content:e,"content-type":"markdown"},type:"wiki"}}return c}({tags:o.ftag});return{buildId:o.buildId,mode:o.mode,protocol:o.protocol||"local:",templateDir:C(`./template/fnode/${t.runtime.template}`),projectDir:e.resolve(t.projectDir,"./.workspace"),projectSrcDir:e.resolve(t.projectDir,"./src"),project:t,tags:o.ftag}}catch(e){return console.warn(`Warning: Could not load project: ${e.message}`),{projectDir:process.cwd(),tags:o.ftag}}}var F=Object.freeze({__proto__:null,createContext:T});const k={command:"project",describe:"Manage fnode project",builder:e=>e.option("update",{type:"boolean",default:!1,alias:"-u",describe:"Update project files"}),handler:async e=>{try{const o=C("./template/fnode/project"),t=process.cwd(),n=await T(e);if(e.update){if(await u({dir:o,outDir:t,context:{name:n.project.projectFileParsed.name,runtime:n.project.runtime.type,platform:m.platform()},copyUnmatchedAlso:!0}),0!==(await f("fnode build",{cwd:t})).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)}}};class B{static async createBuilder(e){if(!e.project){console.warn("No project provided, defaulting to node runtime");return new(0,(await import("./index.CoRsFBwp.js")).default)(e)}const o=e.project?.runtime?.type||"node";try{return new(await this.loadBuilderClass(o))(e)}catch(t){console.warn(`Warning: Could not load builder for runtime '${o}'. Falling back to node builder.`),console.warn(`Error: ${t.message}`);return new(0,(await import("./index.CoRsFBwp.js")).default)(e)}}static async loadBuilderClass(e){switch(e.toLowerCase()){case"node":return(await import("./index.CoRsFBwp.js")).default;case"python":return(await import("./index.uPDSav7E.js")).default;case"bun":return(await import("./index.Brxbka97.js")).default;default:throw new Error(`Unsupported runtime type: ${e}`)}}}const A={command:"build",describe:"Build fnode project",builder:e=>e.option("id",{type:"string",describe:"Project ID"}).option("buildId",{type:"string",alias:"bid",describe:"Build ID"}).option("mode",{type:"string",default:"build",choices:["all","file","build","deploy","bpmn"],describe:"Build mode"}).option("ftag",{type:"array",describe:"Tags for conditional configuration"}),handler:async e=>{try{const o=await T(e),t=await B.createBuilder(o);await t.init(),await t.build(),console.log("Building library succeeded!"),process.exit(0)}catch(e){console.error("Building library failed!",e.message),process.exit(1)}}},M={command:"deploy",describe:"Build and deploy fnode project",builder:e=>e.option("id",{type:"string",describe:"Project ID"}).option("buildId",{type:"string",alias:"bid",describe:"Build ID"}).option("ftag",{type:"array",describe:"Tags for conditional configuration"}),handler:async e=>{try{const o=await T({...e,mode:"all"}),t=await B.createBuilder(o);await t.init(),await t.build(),console.log("Building library succeeded!"),process.exit(0)}catch(e){console.error("Building library failed!",e.message),process.exit(1)}}},O={command:"file",describe:"Just create files",builder:e=>e.option("id",{type:"string",describe:"Project ID"}).option("buildId",{type:"string",alias:"bid",describe:"Build ID"}).option("ftag",{type:"array",describe:"Tags for conditional configuration"}),handler:async e=>{try{const o=await T({...e,mode:"file"}),t=await B.createBuilder(o);await t.init(),await t.build(),console.log("Building library succeeded!"),process.exit(0)}catch(e){console.error("Building library failed!",e.message),process.exit(1)}}},W={command:"input [name]",describe:"Create or modify an input config file",builder:e=>e.positional("name",{type:"string",demandOption:!1,describe:"Input name"}),handler:async o=>{try{const t=await T(o),{project:n}=t,{projectDir:r,projectFileParsed:i}=n,s=i.input;if(!s)throw new Error("Config schema not found in project file.");if(!Reflect.has(o,"name")){const{inputName:e}=await w({type:"input",name:"inputName",message:"Input name:",initial:"dev"});o.name=e}const c=e.resolve(r,".fnet");a.existsSync(c)||a.mkdirSync(c);const l=e.resolve(c,`${o.name}.fnet`),d=a.existsSync(l),p=(await import("@fnet/object-from-schema")).default,m=await p({schema:s,format:"yaml",ref:d?l:void 0});a.writeFileSync(l,m)}catch(e){console.error(e.message),process.exit(1)}}},R=e.join(m.homedir(),".fnet","express");async function U(o){o.command(["$0 [project-name]","create [project-name]"],"Create a new express project",(e=>e.positional("project-name",{describe:"Name of the project",type:"string"}).option("yes",{alias:"y",describe:"Skip all prompts and use defaults",type:"boolean",default:!1}).option("runtime",{describe:"Runtime to use (node, python, bun)",type:"string",choices:["node","python","bun"],default:"node"})),(async o=>{await async function(o){try{a.existsSync(R)||a.mkdirSync(R,{recursive:!0});const t=(new Date).toISOString().slice(0,10).replace(/-/g,""),n=e.join(R,t);a.existsSync(n)||a.mkdirSync(n,{recursive:!0});let r,s=o.projectName,c=o.runtime;if(o.yes){if(!s){const e=a.readdirSync(n).filter((e=>e.startsWith("fnode-"))).map((e=>parseInt(e.replace("fnode-",""),10))).filter((e=>!isNaN(e))),o=e.length>0?Math.max(...e)+1:1;s=`fnode-${o}`}c||(c="node")}else{if(!s){const e=a.readdirSync(n).filter((e=>e.startsWith("fnode-"))).map((e=>parseInt(e.replace("fnode-",""),10))).filter((e=>!isNaN(e))),o=`fnode-${e.length>0?Math.max(...e)+1:1}`,t=await w([{type:"input",name:"projectName",message:"Enter project name:",default:o}]);s=t.projectName}const e=c||"node";c=(await w({type:"select",name:"runtime",message:"Select runtime:",choices:["node","python","bun"],initial:e})).runtime}if(r=e.join(n,s),a.existsSync(r)){let o=1;for(;a.existsSync(e.join(n,`${s}-${o}`));)o++;s=`${s}-${o}`,r=e.join(n,s)}if(!o.yes){if(!(await w([{type:"confirm",name:"proceed",message:`Create express project "${s}" in ${r}?`,default:!0}])).proceed)return void console.log(i.yellow("Project creation cancelled."))}console.log(i.blue(`Creating express project "${s}" in ${r}...`));const l=e.dirname(r),d=["create","--name",e.basename(r)];d.push("--runtime",c),o.yes&&d.push("--yes"),a.existsSync(l)||a.mkdirSync(l,{recursive:!0});const m=p("fnode",d,{stdio:"inherit",shell:!0,cwd:l});return new Promise(((e,t)=>{m.on("close",(n=>{0===n?(console.log(i.green(`\nExpress project "${s}" created successfully!`)),console.log(i.blue(`\nProject location: ${r}`)),o.yes?e():async function(e){try{(await w({type:"confirm",name:"openIDE",message:"Would you like to open the project in an IDE?",initial:!0})).openIDE&&await L(e)}catch(e){console.error(i.red(`Error opening IDE: ${e.message}`))}}(r)):(console.error(i.red(`\nFailed to create express project "${s}".`)),t(new Error(`Process exited with code ${n}`)))}))}))}catch(e){console.error(i.red(`Error creating express project: ${e.message}`)),process.exit(1)}}(o)})).command("list","List express projects",(e=>e.option("today",{describe:"Show only projects created today",type:"boolean",default:!1}).option("type",{describe:"Filter by project type (fnode or fnet)",type:"string",choices:["fnode","fnet"]}).option("name",{describe:"Filter by project name",type:"string"})),(async o=>{await async function(o){try{if(!a.existsSync(R))return void console.log(i.yellow("No express projects found."));const t=a.readdirSync(R).filter((e=>/^\d{8}$/.test(e))).sort(((e,o)=>o.localeCompare(e)));if(o.today){const e=(new Date).toISOString().slice(0,10).replace(/-/g,""),o=t.indexOf(e);if(-1===o)return void console.log(i.yellow("No express projects found for today."));t.splice(0,o),t.splice(1)}const n=[];for(const r of t){const t=e.join(R,r),i=a.readdirSync(t);for(const s of i){const i=e.join(t,s),c=a.statSync(i);let l="unknown";if(s.startsWith("fnode-")||a.existsSync(e.join(i,"fnode.yaml"))?l="fnode":(s.startsWith("fnet-")||a.existsSync(e.join(i,"fnet.yaml")))&&(l="fnet"),o.type&&l!==o.type)continue;if(o.name&&!s.includes(o.name))continue;const d=`${r.slice(0,4)}-${r.slice(4,6)}-${r.slice(6,8)}`;n.push({name:s,type:l,date:d,path:i,created:c.birthtime})}}if(n.sort(((e,o)=>o.created-e.created)),0===n.length)return void console.log(i.yellow("No express projects found matching the criteria."));console.log(i.blue("\nExpress Projects:")),console.log(i.blue("=================\n"));const r=n.map((e=>{let o=e.path;return o.startsWith(m.homedir())&&(o="~"+o.substring(m.homedir().length)),{Name:e.name,Type:e.type,Date:e.date,Path:o}}));console.table(r),console.log(i.green("Projects: ")+i.yellow(n.filter((e=>"fnode"===e.type)).length+" fnode, ")+i.cyan(n.filter((e=>"fnet"===e.type)).length+" fnet")),console.log(i.blue(`\nTotal: ${n.length} projects`))}catch(e){console.error(i.red(`Error listing express projects: ${e.message}`)),process.exit(1)}}(o)})).command("open [project-name]","Open an express project",(e=>e.positional("project-name",{describe:"Name of the project to open",type:"string"}).option("latest",{describe:"Open the most recent project",type:"boolean",default:!1})),(async o=>{await async function(o){try{if(!a.existsSync(R))return void console.log(i.yellow("No express projects found."));let t;if(o.latest){if(t=await G(),!t)return void console.log(i.yellow("No express projects found."))}else if(o.projectName){if(t=await _(o.projectName),!t)return void console.log(i.yellow(`Project "${o.projectName}" not found.`))}else{const o=await H();if(!o)return void console.log(i.yellow("No project selected."));t=e.join(R,o)}await L(t)}catch(e){console.error(i.red(`Error opening express project: ${e.message}`)),process.exit(1)}}(o)})).command("move [project-name] [destination]","Move an express project to a real project location",(e=>e.positional("project-name",{describe:"Name of the project to move",type:"string"}).positional("destination",{describe:"Destination directory",type:"string"}).option("latest",{describe:"Move the most recent project",type:"boolean",default:!1})),(async o=>{await async function(o){try{const t=process.cwd();let n;if(t.includes(R))n=t,console.log(i.blue(`Using current express project: ${e.basename(n)}`));else if(o.latest){if(n=await G(),!n)return void console.log(i.yellow("No express projects found."))}else if(o.projectName){if(n=await _(o.projectName),!n)return void console.log(i.yellow(`Project "${o.projectName}" not found.`))}else{const o=await H();if(!o)return void console.log(i.yellow("No project selected."));n=e.join(R,o)}let r=o.destination;if(!r){r=(await w({type:"input",name:"destination",message:"Enter destination directory:",initial:e.join(process.cwd(),e.basename(n))})).destination}if(r.startsWith("~")&&(r=e.join(m.homedir(),r.slice(1))),r=e.resolve(r),r.startsWith(n+e.sep)||r===n)return void console.log(i.red("Destination cannot be inside the source directory."));if(a.existsSync(r)){if(!a.statSync(r).isDirectory())return void console.log(i.red(`Destination "${r}" is not a directory.`));if(a.readdirSync(r).length>0){if(!(await w({type:"confirm",name:"overwrite",message:`Destination "${r}" is not empty. Continue anyway?`,initial:!1})).overwrite)return void console.log(i.yellow("Project move cancelled."))}}else a.mkdirSync(r,{recursive:!0});console.log(i.blue(`Moving project from ${n} to ${r}...`)),V(n,r),console.log(i.green(`\nProject moved successfully to ${r}`));(await w({type:"confirm",name:"deleteOriginal",message:"Delete the original express project?",initial:!1})).deleteOriginal&&(a.rmSync(n,{recursive:!0,force:!0}),console.log(i.green("Original project deleted."))),await L(r)}catch(e){console.error(i.red(`Error moving express project: ${e.message}`)),process.exit(1)}}(o)})).demandCommand(1,"You need to specify a command").help()}async function G(){const o=a.readdirSync(R).filter((e=>/^\d{8}$/.test(e))).sort(((e,o)=>o.localeCompare(e)));if(0===o.length)return null;const t=o[0],n=e.join(R,t),r=a.readdirSync(n);if(0===r.length)return null;let i=null,s=0;for(const o of r){const t=e.join(n,o),r=a.statSync(t);r.birthtimeMs>s&&(s=r.birthtimeMs,i=t)}return i}async function _(o){const t=a.readdirSync(R).filter((e=>/^\d{8}$/.test(e))).sort(((e,o)=>o.localeCompare(e)));for(const n of t){const t=e.join(R,n),r=a.readdirSync(t);if(r.includes(o))return e.join(t,o);const i=r.filter((e=>e.includes(o)));if(i.length>0){if(1===i.length)return e.join(t,i[0]);return(await w({type:"select",name:"selectedProject",message:`Multiple projects match "${o}". Please select one:`,choices:i.map((o=>({name:`${o} (${n})`,value:e.join(t,o)})))})).selectedProject}}return null}async function H(){const o=[],t=a.readdirSync(R).filter((e=>/^\d{8}$/.test(e))).sort(((e,o)=>o.localeCompare(e)));for(const n of t){const t=e.join(R,n),r=a.readdirSync(t);for(const i of r){const r=e.join(t,i),s=a.statSync(r),c=`${n}/${i}`;o.push({name:c,value:c,created:s.birthtime})}}if(o.sort(((e,o)=>o.created-e.created)),0===o.length)return null;return(await w({type:"select",name:"selectedProject",message:"Select a project:",choices:o})).selectedProject}async function L(e){const o=await z("code --version"),t=await z("code-insiders --version");let n=null;if(o&&t){const e=await w({type:"select",name:"ide",message:"Which IDE would you like to use?",choices:[{name:"Visual Studio Code",value:"code"},{name:"Visual Studio Code Insiders",value:"code-insiders"}]});n=e.ide}else if(o)n="code";else{if(!t)return console.log(i.yellow("No supported IDE found. Please open the project manually.")),void console.log(i.blue(`Project path: ${e}`));n="code-insiders"}console.log(i.blue(`Opening project in ${n}...`)),console.log(i.blue(`Project path: ${e}`));const r=p(n,[e],{stdio:"inherit",shell:!0});return new Promise(((e,o)=>{r.on("close",(t=>{0===t?(console.log(i.green(`Project opened in ${n}.`)),e()):(console.error(i.red(`Failed to open project in ${n}.`)),o(new Error(`Process exited with code ${t}`)))}))}))}async function z(e){return new Promise((o=>{p(e,{shell:!0,stdio:"ignore"}).on("close",(e=>{o(0===e)}))}))}function V(o,t){a.existsSync(t)||a.mkdirSync(t,{recursive:!0});const n=a.readdirSync(o,{withFileTypes:!0});for(const r of n){const n=e.join(o,r.name),i=e.join(t,r.name);if(r.isDirectory()){if(".git"===r.name||".workspace"===r.name)continue;V(n,i)}else a.copyFileSync(n,i)}}const Y=e.dirname(n(import.meta.url)),X=process.cwd();process.on("uncaughtException",(e=>{b||(b=!0,setTimeout((()=>process.exit(1)),500))})),process.on("unhandledRejection",(e=>{b||(b=!0,setTimeout((()=>process.exit(1)),500))})),function(){s({name:["redis"],dir:X,optional:!0});const o=function({baseDir:o}){let t=o=o||h;for(;t!==e.parse(t).root;){const o=e.join(t,"node_modules");if(a.existsSync(o))return o;t=e.dirname(t)}return null}({baseDir:Y}),t="win32"===process.platform?";":":";o&&(process.env.PATH=`${e.join(o,"/.bin")}${t}${process.env.PATH}`)}(),async function(){try{let o=r(process.argv.slice(2)).usage("Usage: $0 <command> [options]").command(N).command(k).command(A).command(M).command(O).command(W).command("express","Create and manage express projects",U);o=$(o,{bin:"npm"}),o=$(o,{bin:"node"}),o=$(o,{bin:"bun"}),o=$(o,{name:"serve",bin:"bun",preArgs:["run","serve","--"]}),o=$(o,{name:"watch",bin:"bun",preArgs:["run","watch","--"]}),o=$(o,{name:"app",bin:"bun",preArgs:["run","app","--"]}),o=$(o,{name:"cli",bin:"bun",preArgs:["run","cli","--"]}),o=$(o,{name:"compile",bin:"bun",preArgs:["run","compile","--"]}),o=function(o,{name:t}){return o.command(`${t} [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("yes",{alias:"y",describe:"Automatically answer yes to all prompts",type:"boolean",default:!1})),(async o=>{try{const t=await P(o),{projectDir:n}=t;console.log(i.blue("Compiling project..."));const r=e.join(n,".bin");a.existsSync(r)||a.mkdirSync(r,{recursive:!0});const s=e.basename(e.dirname(n)),c=t.project?.projectFileParsed?.features?.cli?.bin,l=o.name||c||s;console.log(i.blue(`Using binary name: ${l}`));const d=e.join(r,l),{spawn:p}=await import("child_process"),m=p("bun",["build","./dist/cli/esm/index.js","--compile",`--outfile=${d}`],{cwd:n,stdio:"inherit",shell:!0});await new Promise(((e,o)=>{m.on("close",(t=>{0===t?e():o(new Error(`Compilation failed with code ${t}`))})),m.on("error",(e=>{o(e)}))})),"win32"!==process.platform&&a.chmodSync(d,493),console.log(i.green(`Binary compiled successfully: ${d}`)),console.log(i.blue("Installing binary..."));const u=["install",d];o.name&&u.push("--name",o.name),o.force&&u.push("--force"),o.yes&&u.push("--yes");const f=p("fbin",u,{stdio:"inherit",shell:!0});await new Promise(((e,o)=>{f.on("close",(t=>{0===t?e():o(new Error(`Installation failed with code ${t}`))})),f.on("error",(e=>{o(e)}))}))}catch(e){console.error(i.red(`Failed to install binary: ${e.message}`)),process.exit(1)}}))}(o,{name:"install"}),o=$(o,{bin:"npx"}),o=$(o,{bin:"cdk"}),o=$(o,{bin:"aws"}),o=function(e,{name:o,preArgs:t=[]}){return e.command(`${o} <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 o=await P(e),{projectDir:n}=o,r=e.config,i=await s({name:r,dir:n,transferEnv:!1,optional:!0,tags:o.tags}),c=i?.data?.env||void 0,l=e.command,d=process.argv.slice(5);v(p(l,[...t,...d],{cwd:a.existsSync(n)?n:process.cwd(),stdio:"inherit",shell:!0,detached:!0,env:{...process.env,...c}}))}catch(e){console.error(e.message),process.exit(1)}}))}(o,{name:"with"}),o=function(e,{name:o,projectType:t="auto"}){return e.command(`${o} 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:o}=await import("./index.DrwlOzAe.js");await o({projectType:t,group:e.group,tags:e.ftag,args:e,argv:process.argv})}catch(e){console.error(e.message),process.exit(1)}}))}(o,{name:"run",projectType:"fnode"}),o=S(o,{name:"python"}),o=S(o,{name:"python3"}),o=S(o,{name:"pip"}),o=S(o,{name:"pip3"}),o.demandCommand(1,"You need at least one command before moving on").help().version().argv}catch(e){console.error(i.red(`Fatal error: ${e.message}`)),process.exit(1)}}().catch((e=>{console.error(i.red(`Fatal error: ${e.message}`)),process.exit(1)}));export{C as r,D as w};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"node:fs";import t from"node:path";import i from"node:os";import a from"@fnet/list-files";import{B as s,c as n,a as r}from"./index.
|
|
1
|
+
import e from"node:fs";import t from"node:path";import i from"node:os";import a from"@fnet/list-files";import{B as s,c as n,a as r}from"./index.DIZA_GzC.js";import o from"@flownet/lib-render-templates-dir";import c from"@fnet/auto-conda-env";import"node:crypto";import"yaml";import"nunjucks";import"chalk";import"@flownet/lib-atom-api-js";import"@fnet/config";import"redis";import"@flownet/lib-is-redis-online";import"@fnet/yaml";class p extends s{async initRuntime(){await async function(e){const{atom:t,context:i,setProgress:a}=e;a("Initializing features..."),t.doc.features=t.doc.features||{};const s=t.doc.features;!1===s.cli?s.cli={enabled:!1}:(s.cli,s.cli={enabled:!0}),s.cli.enabled=!0===s.cli.enabled&&(!1===t.doc.features.form_enabled||!0===s.cli.extend||!0===s.cli.enabled)}(this.apiContext),await async function({atom:e,packageDependencies:t,packageDevDependencies:i,setProgress:a}){a("Initializing dependencies")}(this.apiContext),await this.initLibraryDirPython(),await this.initNunjucks(),await this.initLibsPython()}async initLibraryDirPython(){this.setProgress({message:"Initializing library directory."});const s=this.context.projectDir;this.setProgress({message:"Cleaning project directory."});const n=a({dir:s,ignore:[".cache","node_modules",".conda",".bin"],absolute:!0});for(const t of n)e.rmSync(t,{recursive:!0,force:!0});this.setProgress({message:"Creating project directory."});let r=s;e.existsSync(r)||e.mkdirSync(r,{recursive:!0}),r=t.join(s,"src"),e.existsSync(r)||e.mkdirSync(r,{recursive:!0}),r=t.join(s,"src","default");const o=this.context.projectSrcDir;if(!e.existsSync(r))try{"win32"===i.platform()?e.symlinkSync(o,r,"junction"):e.symlinkSync(o,r,"dir")}catch(e){throw new Error(`Couldn't create symlink. Error: ${e.message}`)}}async initLibsPython(){this.setProgress({message:"Initializing external libs."});const e=this.atom;e.protocol="local:",e.doc.dependencies=e.doc.dependencies||[],e.name=e.doc.name;const t=[{name:this.atom.doc.name,type:"atom",parent_id:this.atom.parent_id,atom:e}];this.libs=t}async createAtomLibFilesPython({libs:i}){await this.setProgress({message:"Creating external lib files."});const a=i.filter((e=>"atom"===e.type));for(let i=0;i<a.length;i++){const s=a[i].atom;if("local:"===s.protocol){const i=t.resolve(this.context.projectSrcDir,`${s.fileName||s.name}.py`);if(!e.existsSync(i)){e.mkdirSync(t.dirname(i),{recursive:!0});let a="def default():\n";a+=' print("Hello world!")\n',e.writeFileSync(i,a,"utf8")}}}}async build(){try{this.fileMode&&(await this.createAtomLibFilesPython({libs:this.libs}),await this.createProjectYaml(),await n(this.apiContext),await r(this.apiContext),await async function({atom:i,setProgress:a,context:s,packageDependencies:n}){if(!0!==i.doc.features.cli.enabled)return;await a({message:"Creating cli."});const r={atom:i,packageDependencies:n},c=s.templateDir,p=t.join(s.projectDir,"src","cli");e.existsSync(p)||e.mkdirSync(p,{recursive:!0}),await o({pattern:["index.py.njk","__init__.py.njk"],dir:t.join(c,"src","cli"),outDir:p,context:r})}(this.apiContext),this.buildMode&&(await async function(e){const{setProgress:i,atom:a,context:s}=e;i({message:"Installing Python packages"});const n=s.projectDir,r=await c({pythonVersion:"3.12",packages:[{package:"fnet-import-parser",version:"0.1.9"}]}),{errors:p,result:l}=await r.runBin("fnet_import_parser",["--entry_file",t.join(n,"src","default","index.py")],{captureName:"result"});if(p)throw new Error(p.format());const d=JSON.parse(l.items[0].stdout),m=d.required["third-party"]?.map((e=>({package:e.metadata?.package||e.path,version:e.metadata?.version||void 0,channel:e.metadata?.channel||void 0})))||[],y=a.doc.dependencies||[];for(const e of m)y.some((t=>t.package===e.package))||y.push(e);const f=t.join(n,".conda"),h=await c({envDir:f,pythonVersion:a.doc.features.runtime.version||"3.12",packages:y});s.pythonEnv=h,e.packageDependencies=y;const u=a.doc.features.render?.dirs||[];for(const e of u)e.dir=t.resolve(n,e.dir),e.outDir=t.resolve(n,e.outDir),await o(e);let g={params:{}};g.params.package_name=a.doc.name,g.params.version="0.1.0",g.params.bin_name=a.doc.name,g.params.python_requires=a.doc.features.runtime.version||">=3.12",g.params.dependencies=y,g.params.scripts=JSON.stringify({cli:`PYTHONPATH='${t.join("src")}' '${t.relative(s.projectDir,h.pythonBin)}' '${t.join("src","cli","index.py")}'`}),await o({pattern:["setup.py.njk","package.json.njk","pyproject.toml.njk"],dir:s.templateDir,outDir:s.projectDir,context:g})}(this.apiContext),this.deployMode&&await this.deploy())),await this._cache_set(this.buildKey,{status:"COMPLETED"})}catch(e){throw await this._cache_set(this.buildKey,{status:"FAILED",message:e.message||e}),console.log(e),e}}}export{p as default};
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{% if atom.doc.features.cli.enabled===true %}
|
|
2
|
-
import argv from '../default/
|
|
2
|
+
import argv from '../default/input.args.js';
|
|
3
3
|
import { default as Engine } from '../default/{{atom.doc.features.cli_default_entry_file or atom.doc.features.main_default_entry_file}}';
|
|
4
4
|
|
|
5
5
|
{% if atom.doc.features.cli.extend===true %}
|
|
@@ -182,9 +182,9 @@ const initPlugins = async (options) => {
|
|
|
182
182
|
{% if atom.doc.features.project.format ==='esm' %}
|
|
183
183
|
include: /node_modules/,
|
|
184
184
|
ignore: ["fsevents"],
|
|
185
|
-
{% endif %}
|
|
185
|
+
{% endif %}
|
|
186
186
|
}));
|
|
187
|
-
|
|
187
|
+
|
|
188
188
|
|
|
189
189
|
{# POLYFILL #}
|
|
190
190
|
{% if atom.doc.features.polyfill_enabled===true %}
|
|
@@ -193,7 +193,7 @@ const initPlugins = async (options) => {
|
|
|
193
193
|
plugins.push(polyfills(options.polyfill.options));
|
|
194
194
|
}
|
|
195
195
|
{% endif %}
|
|
196
|
-
|
|
196
|
+
|
|
197
197
|
{# WORKBOX #}
|
|
198
198
|
{% if atom.doc.features.workbox_enabled===true %}
|
|
199
199
|
if (options?.workbox) {
|
|
@@ -291,7 +291,7 @@ const createConfigs = async () => {
|
|
|
291
291
|
if (!fs.existsSync(groupDir)) {
|
|
292
292
|
fs.mkdirSync(groupDir, { recursive: true });
|
|
293
293
|
}
|
|
294
|
-
|
|
294
|
+
|
|
295
295
|
{% for key, value in atom.doc.features.rollup_output %}
|
|
296
296
|
{% if value and value.enabled !== false %}
|
|
297
297
|
{
|
|
@@ -310,17 +310,150 @@ const createConfigs = async () => {
|
|
|
310
310
|
entryFileNames: "[name].cjs",
|
|
311
311
|
chunkFileNames: "[name]-[hash].cjs",
|
|
312
312
|
{% endif %}
|
|
313
|
-
{
|
|
314
|
-
{%
|
|
315
|
-
{
|
|
316
|
-
{%
|
|
313
|
+
{# BEGIN: rollup_config_output_name #}
|
|
314
|
+
{% if value.format==='iife' or value.format==='umd'%}
|
|
315
|
+
name: "{{atom.doc.bundleName}}",
|
|
316
|
+
{% endif %}
|
|
317
|
+
{# END: rollup_config_output_name #}
|
|
318
|
+
{# BEGIN: rollup_config_output_globals #}
|
|
319
|
+
{% if value.browser===true %}
|
|
320
|
+
{% if value.globals.length %}
|
|
321
|
+
globals: {
|
|
322
|
+
{% for global in value.globals %}
|
|
323
|
+
"{{global.key}}":"{{global.value}}" {% if not loop.last %},{% endif %}
|
|
324
|
+
{% endfor %}
|
|
325
|
+
},
|
|
326
|
+
{% endif %}
|
|
327
|
+
{% endif %}
|
|
328
|
+
{# END: rollup_config_output_globals #}
|
|
329
|
+
{# BEGIN: rollup_config_output_banner #}
|
|
330
|
+
{% if value.banner %}
|
|
331
|
+
banner:'{{value.banner}}',
|
|
332
|
+
{% endif %}
|
|
333
|
+
{# END: rollup_config_output_banner #}
|
|
334
|
+
{# BEGIN: rollup_config_output_footer #}
|
|
335
|
+
{% if value.format==='iife' %}
|
|
336
|
+
{% if atom.type==='workflow'%}
|
|
337
|
+
{# footer: "new {{atom.doc.bundleName}}().run().catch(e=>{});" #}
|
|
338
|
+
{% endif %}
|
|
339
|
+
{% endif %}
|
|
340
|
+
{# END: rollup_config_output_footer #}
|
|
317
341
|
},
|
|
318
342
|
{% if value.context %}
|
|
319
343
|
context: "{{value.context}}",
|
|
320
344
|
{% endif %}
|
|
321
|
-
{
|
|
322
|
-
{%
|
|
323
|
-
|
|
345
|
+
{# BEGIN: rollup_config_external #}
|
|
346
|
+
{% if value.external_enabled %}
|
|
347
|
+
external: [
|
|
348
|
+
{% for external in value.external %}
|
|
349
|
+
"{{external}}" {% if not loop.last %},{% endif %}
|
|
350
|
+
{% endfor %}
|
|
351
|
+
],
|
|
352
|
+
{% endif %}
|
|
353
|
+
{# END: rollup_config_external #}
|
|
354
|
+
{# BEGIN: rollup_config_onwarn #}
|
|
355
|
+
onwarn(warning, warn) {
|
|
356
|
+
switch (warning.code) {
|
|
357
|
+
case 'MODULE_LEVEL_DIRECTIVE':
|
|
358
|
+
case 'CIRCULAR_DEPENDENCY':
|
|
359
|
+
return;
|
|
360
|
+
default:
|
|
361
|
+
warn(warning);
|
|
362
|
+
}
|
|
363
|
+
},
|
|
364
|
+
{# END: rollup_config_onwarn #}
|
|
365
|
+
{# BEGIN: rollup_config_plugins #}
|
|
366
|
+
plugins: await initPlugins({
|
|
367
|
+
delete:{ targets: [path.normalize(groupDir + '{{key}}')], runOnce: DEVELOPMENT },
|
|
368
|
+
|
|
369
|
+
format:"{{ value.format }}",
|
|
370
|
+
|
|
371
|
+
{% if value.babel===true %}
|
|
372
|
+
babel:{{value.babel_options | dump | safe}},
|
|
373
|
+
{% endif %}
|
|
374
|
+
|
|
375
|
+
{% if value.replace ===true %}
|
|
376
|
+
replace:{{value.replace_options | dump | safe}},
|
|
377
|
+
{% endif %}
|
|
378
|
+
|
|
379
|
+
{% if value.browser===true %}
|
|
380
|
+
browser:true,
|
|
381
|
+
{% endif %}
|
|
382
|
+
|
|
383
|
+
{% if value.browsersync===true and atom.doc.features.browsersync_enabled===true%}
|
|
384
|
+
browsersync: {{value.browsersync_options | dump | safe}},
|
|
385
|
+
{% endif %}
|
|
386
|
+
|
|
387
|
+
{% if value.alias_enabled===true %}
|
|
388
|
+
alias:{{value.alias | dump | safe}},
|
|
389
|
+
{% endif %}
|
|
390
|
+
|
|
391
|
+
{# OK #}
|
|
392
|
+
{% if value.css %}
|
|
393
|
+
postcss:{{value.css | dump | safe}},
|
|
394
|
+
{% endif %}
|
|
395
|
+
|
|
396
|
+
{# OK #}
|
|
397
|
+
{% if value.copy %}
|
|
398
|
+
copy:{{value.copy | dump | safe}},
|
|
399
|
+
{% endif %}
|
|
400
|
+
|
|
401
|
+
{# OK #}
|
|
402
|
+
{% if value.terser%}
|
|
403
|
+
terser:{{value.terser | dump | safe}},
|
|
404
|
+
{% endif %}
|
|
405
|
+
|
|
406
|
+
{# OK #}
|
|
407
|
+
{% if value.json %}
|
|
408
|
+
json:{{value.json | dump | safe}},
|
|
409
|
+
{% endif %}
|
|
410
|
+
|
|
411
|
+
{# OK #}
|
|
412
|
+
{% if value.wasm %}
|
|
413
|
+
wasm: {{value.wasm | dump | safe}},
|
|
414
|
+
{% endif %}
|
|
415
|
+
|
|
416
|
+
{# OK #}
|
|
417
|
+
{% if value.string %}
|
|
418
|
+
string:{{value.string | dump | safe}},
|
|
419
|
+
{% endif %}
|
|
420
|
+
|
|
421
|
+
{# OK #}
|
|
422
|
+
{% if value.image %}
|
|
423
|
+
image:{{value.image | dump | safe}},
|
|
424
|
+
{% endif %}
|
|
425
|
+
|
|
426
|
+
{# OK #}
|
|
427
|
+
{% if value.analyzer %}
|
|
428
|
+
analyzer:{{value.analyzer | dump | safe}},
|
|
429
|
+
{% endif %}
|
|
430
|
+
|
|
431
|
+
{# OK #}
|
|
432
|
+
{% if value.visualizer %}
|
|
433
|
+
visualizer:{{value.visualizer | dump | safe}},
|
|
434
|
+
{% endif %}
|
|
435
|
+
|
|
436
|
+
{# OK #}
|
|
437
|
+
{% if value.polyfill %}
|
|
438
|
+
polyfill:{{value.polyfill | dump | safe}},
|
|
439
|
+
{% endif %}
|
|
440
|
+
|
|
441
|
+
{# OK #}
|
|
442
|
+
{% if value.nunjucks %}
|
|
443
|
+
nunjucks:{{value.nunjucks | dump | safe}},
|
|
444
|
+
{% endif %}
|
|
445
|
+
|
|
446
|
+
{# OK #}
|
|
447
|
+
{% if value.workbox %}
|
|
448
|
+
workbox:{{value.workbox | dump | safe}},
|
|
449
|
+
{% endif %}
|
|
450
|
+
|
|
451
|
+
{# OK #}
|
|
452
|
+
{% if value.gzip %}
|
|
453
|
+
gzip:{{value.gzip | dump | safe}},
|
|
454
|
+
{% endif %}
|
|
455
|
+
}),
|
|
456
|
+
{# END: rollup_config_plugins #}
|
|
324
457
|
}
|
|
325
458
|
configs.push(config);
|
|
326
459
|
}
|