@fnet/cli 0.115.0 → 0.116.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/fnet/index.BZuqvTVt.js +1 -0
- package/dist/fnet/index.js +1 -1
- package/dist/fnode/index.B_0ZxySP.js +1 -0
- package/dist/fnode/{index.CoRsFBwp.js → index.D3C-8oZW.js} +1 -1
- package/dist/fnode/index.D4sPJLOP.js +1 -0
- package/dist/fnode/{index.Brxbka97.js → index.DMkgR1Dh.js} +1 -1
- package/dist/fnode/index.js +1 -1
- package/package.json +2 -1
- package/template/fnet/node/package.json.njk +1 -0
- package/template/fnet/node/src/cli/index.js.njk +308 -199
- package/template/fnode/node/package.json.njk +10 -1
- package/template/fnode/node/src/cli/index.js.njk +191 -320
- package/dist/fnet/index.PNP2oTpU.js +0 -1
- package/dist/fnode/index.6_yfJqit.js +0 -1
- package/dist/fnode/index.Dg0hAD29.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"lodash.merge";import t from"node:fs";import s from"node:path";import a from"@flownet/lib-render-templates-dir";import n from"nunjucks";import r from"@flownet/lib-parse-imports-js";import o 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:t,features:s,packageDevDependencies:a}){const{name:n,packages:r,options:o,extraCheck:c,explicit:i}=t,p=`${n}_enabled`,l=s.rollup_output||{},f=Object.keys(l);let d=o||{};const u=s[n]?.options;u&&(d=e(d,u));const m=!s[n]||!1===s[n]?.enabled;f.forEach((e=>{const t=s.rollup_output[e];if(t){if(Reflect.has(t,n)){if(m||!t[n]||!1===t[n]?.enabled)return void delete t[n];!0===t[n]&&(t[n]={enabled:!0,options:d})}else{if(m||i||!1===s[p])return;t[n]={enabled:!0}}t[n]=t[n]||{},t[n].options={...d,...t[n].options}}}));let g=f.some((e=>!0===s.rollup_output[e][n]?.enabled));c&&(g=c()&&g),s[p]=g,g&&r.forEach((e=>a.push({package:e[0],version:e[1]})))}function m(e){const{atom:t,packageDevDependencies:s}=e;u({feature:{name:"string",packages:[["rollup-plugin-string","^3"]]},features:t.doc.features,packageDevDependencies:s})}function g(e){const{atom:t,packageDevDependencies:s}=e;u({feature:{name:"image",packages:[["@rollup/plugin-image","^3"]]},features:t.doc.features,packageDevDependencies:s})}function k(e){const{atom:t,packageDevDependencies:s}=e;u({feature:{name:"json",packages:[["@rollup/plugin-json","^6"]]},features:t.doc.features,packageDevDependencies:s})}function j(e){const{atom:t,packageDevDependencies:s}=e,a=t.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:s})}function v(e){const{atom:t,packageDevDependencies:s}=e,a=t.doc.features,n=a.css&&!1!==a.css.enabled;let r=[];if(n){r.push(["rollup-plugin-postcss","^4"]),r.push(["sass","^1.66"]);(a.css?.options?.plugins||[]).forEach((e=>{switch(e.name){case"postcss-import":r.push(["postcss-import","^15"]);break;case"postcss-url":r.push(["postcss-url","^10"]);break;case"postcss-preset-env":r.push(["postcss-preset-env","^9"]);break;case"autoprefixer":r.push(["autoprefixer","^10"]);break;case"cssnano":r.push(["cssnano","^6"])}}))}u({feature:{name:"css",packages:r},features:a,packageDevDependencies:s})}async function D({atom:e,setProgress:n,context:r,packageDependencies:o}){if(!0!==e.doc.features.app.enabled)return;await n({message:"Creating app folder"});const c={atom:e,packageDependencies:o,ts:Date.now()},i=r.templateDir,p=s.resolve(r.projectDir,"src/app");t.existsSync(p)||t.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:s.resolve(i,"src/app"),outDir:p,context:c})}async function h({projectDir:e,name:a,setProgress:n,count:r=1}){let i;const p=c(["npm-pick-versions",a,r]),l=s.join(e,".cache"),f=s.join(l,p+".json");return t.existsSync(f)?(n&&n(`Picking npm version of ${a} from cache ...`),i=JSON.parse(t.readFileSync(f,"utf8"))):(n&&n(`Picking npm version of ${a} ...`),i=await o({name:a,count:r}),t.mkdirSync(l,{recursive:!0}),t.writeFileSync(f,JSON.stringify(i),"utf8")),i}async function w({atom:e,context:a,packageDependencies:o,packageDevDependencies:c,setProgress:i}){await i({message:"Creating package.json."});o.filter((e=>!0===e.dev)).forEach((e=>{c.find((t=>t.package===e.package))||c.push(e);const t=o.findIndex((t=>t.package===e.package));o.splice(t,1)}));const p=o.find((e=>"react"===e.package)),l=o.find((e=>"react-dom"===e.package));p&&!l?o.push({package:"react-dom",version:p.version}):p&&l&&(l.version=p.version),p&&e.doc.features.react_version>=17&&(o.find((e=>"@emotion/react"===e.package))||o.push({package:"@emotion/react",version:"^11"}),o.find((e=>"@emotion/styled"===e.package))||o.push({package:"@emotion/styled",version:"^11"}));const f=[];!0===e.doc.features.app.enabled&&f.push({file:s.resolve(a.projectDir,"src/app/index.js"),dev:!1!==e.doc.features.app.dev}),!0===e.doc.features.cli.enabled&&f.push({file:s.resolve(a.projectDir,"src/cli/index.js"),dev:!1!==e.doc.features.cli.dev});for await(const e of f){const s=e.file;if(!t.existsSync(s))throw new Error(`App file not found: ${s}`);const n=(await r({file:s,recursive:!0})).all;for await(const t of n){if("npm"!==t.type)continue;if(o.find((e=>e.package===t.package)))continue;if(c.find((e=>e.package===t.package)))continue;const s=await h({name:t.package,projectDir:a.projectDir,setProgress:i});(!0===e.dev?c:o).push({package:t.package,subpath:t.subpath,version:s.minorRange,type:"npm"})}}const d={atom:e,packageDependencies:o,packageDevDependencies:c},u=a.templateDir,m=n.compile(t.readFileSync(s.resolve(u,"package.json.njk"),"utf8"),n.configure(u)).render(d),g=a.projectDir,k=s.resolve(g,"package.json");t.writeFileSync(k,m,"utf8");const j=s.resolve(a.project.projectDir,"fnet");if(t.existsSync(j)){const e=s.resolve(a.projectDir,"fnet");t.existsSync(e)||t.mkdirSync(e);const n=t.readdirSync(j);for(const a of n){const n=s.resolve(j,a);if(!t.lstatSync(n).isFile())continue;const r=s.resolve(e,a);t.copyFileSync(n,r)}}}async function y({atom:e,setProgress:n,context:r,packageDependencies:o}){if(!0!==e.doc.features.cli.enabled)return;await n({message:"Creating cli."});const c={atom:e,packageDependencies:o},i=r.templateDir,p=s.resolve(r.projectDir,"src/cli");t.existsSync(p)||t.mkdirSync(p,{recursive:!0}),await a({pattern:["index.js.njk"],dir:s.resolve(i,"src/cli"),outDir:p,context:c})}async function b({atom:e,setProgress:a,context:r,njEnv:o}){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 t=e.doc.features.cli.fargs,s={type:"string",description:"Config name to load args",hidden:!1},a={type:"array",description:"Tags to filter the config",hidden:!1};Reflect.has(t,"default")&&(s.default=t.default),c.properties&&(c.properties.fargs=s,c.properties.ftag=a)}const f={options:c,imports:[],atom:e},d=r.templateDir,u=n.compile(t.readFileSync(s.resolve(d,"src/default/input.args.js.njk"),"utf8"),o).render(f),m=r.projectDir,g=s.resolve(m,"src/default/input.args.js");t.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);t.writeFileSync(s.resolve(m,"src/default/validate_input.js"),v,"utf8")}async function x({atom:e,setProgress:a,context:r,packageDependencies:o}){await a({message:"Creating tsconfig.json."});const c={atom:e,packageDependencies:o},i=r.templateDir,p=n.compile(t.readFileSync(s.resolve(i,"tsconfig.json.njk"),"utf8"),n.configure(i)).render(c),l=r.projectDir,f=s.resolve(l,"tsconfig.json");t.writeFileSync(f,p,"utf8")}async function S({setProgress:e,context:t}){const a=t.projectDir;await e({message:"Prettifiying source files."});let n=s.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 E({setProgress:e,atom:t,context:s}){const a=s.projectDir;if(await e({message:"Installing npm packages."}),d("bun")){if(0!==(await f(`bun install ${t.doc.features.npm_install_flags}`,{cwd:a})).code)throw new Error("Couldnt install npm packages.")}else{if(0!==(await f(`npm install ${t.doc.features.npm_install_flags}`,{cwd:a})).code)throw new Error("Couldnt install npm packages.")}}async function P({setProgress:e,context:t}){const s=t.projectDir;if(await e({message:"Building main project."}),d("bun")){if(0!==(await f(t.dev?"bun run build:dev":"bun run build",{cwd:s})).code)throw new Error("Couldnt build project.")}else{if(0!==(await f(t.dev?"npm run build:dev":"npm run build",{cwd:s})).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,E as m,h as p,P as r};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"node:fs";import t from"node:path";import a from"nunjucks";import i from"@flownet/lib-parse-imports-js";import s from"@flownet/lib-parse-node-url";import{B as r,c as o,a as n}from"./index.DIZA_GzC.js";import p from"lodash.merge";import{i as l,a as c,b as d,c as m,d as f,p as u,e as h,g as _,h as y,j as b,k as x,l as g,m as j,r as w}from"./index.Dg0hAD29.js";import v from"@fnet/npm-list-versions";import"node:crypto";import"yaml";import"chalk";import"@flownet/lib-atom-api-js";import"@fnet/config";import"@fnet/list-files";import"redis";import"@flownet/lib-is-redis-online";import"@fnet/yaml";import"@flownet/lib-render-templates-dir";import"@fnet/npm-pick-versions";import"object-hash";import"ajv/dist/2020.js";import"ajv/dist/standalone/index.js";import"ajv-formats";import"@fnet/shelljs";import"./index.js";import"node:url";import"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 k({dir:a,name:i="index"}){let s=t.resolve(a,`./${i}.tsx`);if(e.existsSync(s)||(s=t.resolve(a,`./${i}.ts`)),e.existsSync(s)||(s=t.resolve(a,`./${i}.jsx`)),e.existsSync(s)||(s=t.resolve(a,`./${i}.js`)),!e.existsSync(s))return{};const r=s,o=t.extname(s);return{file:r,ext:o,ts:".ts"===o||".tsx"===o,name:i}}class D extends r{async initRuntime(){await async function({atom:e,context:a,setProgress:s}){await s({message:"Initializing features..."}),e.doc.features=e.doc.features||{};const r=e.doc.features;r.project=r.project||{},r.project.format=r.project.format||r.project_format||"esm",r.project_format=r.project.format,r.dts_enabled=!0===r.dts||void 0!==r.dts&&!1!==r.dts;const o=t.resolve(a.project.projectDir),n=k({dir:t.resolve(o,"./app")});if(n.file){s("Parsing app entry imports...");let e=await i({file:n.file,recursive:!0}),t=e.all.some((e=>!0===e.usesJSX&&"local"===e.type));r.app_uses_jsx=t,r.app_has_entry=!0,e=await i({file:n.file}),t=e.all.some((e=>!0===e.usesJSX&&"local"===e.type)),r.app_entry_uses_jsx=t,r.app_entry_is_ts=n.ts,r.app_entry_ext=n.ext}const u=k({dir:t.resolve(o,"./cli")});if(u.file){s("Parsing cli entry imports...");let e=await i({file:u.file,recursive:!0}),t=e.all.some((e=>!0===e.usesJSX&&"local"===e.type));r.cli_uses_jsx=t,r.cli_has_entry=!0,e=await i({file:u.file}),t=e.all.some((e=>!0===e.usesJSX&&"local"===e.type)),r.cli_entry_uses_jsx=t,r.cli_entry_is_ts=u.ts,r.cli_entry_ext=u.ext}if("workflow.lib"===e.type){const e=k({dir:t.resolve(o,"./src")});if(e.file){s("Parsing src entry imports...");let t=await i({file:e.file,recursive:!0}),a=t.all.some((e=>!0===e.usesJSX&&"local"===e.type));r.src_uses_jsx=a,r.src_has_entry=!0,t=await i({file:e.file}),a=t.all.some((e=>!0===e.usesJSX&&"local"===e.type)),r.src_entry_uses_jsx=a,r.src_entry_is_ts=e.ts,r.src_entry_ext=e.ext}}const h=Reflect.has(r,"app_entry_uses_jsx")?!0===r.app_entry_uses_jsx:!0===r.src_entry_uses_jsx,_=Reflect.has(r,"cli_entry_uses_jsx")?!0===r.cli_entry_uses_jsx:!0===r.src_entry_uses_jsx;r.form_enabled=h||_||!0===r.form||!0===r.form?.enabled,r.multiple_enabled=r.multiple_enabled||!0===r.multiple||!0===r.multiple?.enabled,!1===r.app?r.app={enabled:!1}:!0===r.app?r.app={enabled:!0,extend:!0===r.app_has_entry,export:!0,react:h}:r.app={enabled:!0,extend:!0===r.app_has_entry,export:!0,react:h,...r.app||{}},r.app.enabled=!0===r.app.enabled&&(!0===e.doc.features.form_enabled||!0===r.app.extend||!0===r.app.enabled),r.app.format=r.app.format||"esm",r.app.folder=r.app.folder||r.app.format||"esm",r.app.dir=`./dist/app/${r.app.folder}`,r.app.html=!1!==r.app.html,!1===r.cli?r.cli={enabled:!1}:!0===r.cli?r.cli={enabled:!0,extend:!0===r.cli_has_entry,export:!0,react:_}:r.cli={enabled:!0,extend:!0===r.cli_has_entry,export:!0,react:_,...r.cli||{}},r.cli.enabled=!0===r.cli.enabled&&(!1===e.doc.features.form_enabled||!0===r.cli.extend||!0===r.cli.enabled),r.cli.format=r.cli.format||"esm",r.cli.folder=r.cli.folder||r.cli.folder||"esm",r.cli.dir=`./dist/cli/${r.cli.folder}`,r.cli.node_options=r.cli.node?.options||r.cli.node_options||"",r.json=r.cli.enabled||r.json,r.bun=r.bun||{},r.bun.build=r.bun.build||{};const y={default:{format:"esm",target:"browser",minify:!1,sourcemap:"external",entrypoints:["./src/default/index.js"],outdir:"./dist/default/esm"},defaultCjs:{format:"cjs",target:"node",minify:!1,sourcemap:"external",entrypoints:["./src/default/index.js"],outdir:"./dist/default/cjs"}};r.cli.enabled&&(y.cli={format:"esm",target:"node",minify:!1,sourcemap:"external",entrypoints:["./src/cli/index.js"],outdir:r.cli.dir}),r.app.enabled&&(y.app={format:"esm",target:"browser",minify:!1,sourcemap:"external",entrypoints:["./src/app/index.js"],outdir:r.app.dir}),r.bun.build=p(y,r.bun.build||{}),r.preact_enabled=!0===r.preact||r.preact&&!1!==r.preact?.enabled,r.dependency_auto_enabled=!1!==r.dependency_auto&&!1!==r.dependency_auto?.enabled,r.npm_install_flags=r.npm_install_flags||"",r.react_version=r.react_version||r.react?.version||18,r.runtime=r.runtime||{},r.runtime.type="bun",r.runtime.template="bun",l({atom:e}),c({atom:e}),d({atom:e}),m({atom:e}),f({atom:e})}(this.apiContext),await async function({atom:e,packageDependencies:t,packageDevDependencies:a,setProgress:i}){i("Initializing dependencies for Bun");const s=e.doc.dependencies||[];if(s.filter((e=>!e.dev)).forEach((e=>t.push(e))),s.filter((e=>e.dev)).forEach((e=>a.push(e))),"workflow"===e.type&&(t.push({package:"get-value",version:"^3"}),t.push({package:"set-value",version:"^4"})),e.doc.features.form_enabled&&e.doc.features.dependency_auto_enabled){let a="^18.2";i("Fetching React versions"),a=`^${(await v({name:"react",groupBy:{major:!0}})).find((t=>t[0]===e.doc.features.react_version.toString()))[0]}`,t.push({package:"react",version:a}),t.push({package:"react-dom",version:a}),"workflow"===e.type&&(t.push({package:"@fnet/react-app",version:"^0.1"}),t.push({package:"@fnet/react-app-state",version:"^0.1"}))}e.doc.features.preact_enabled&&t.push({package:"preact",version:"^10"}),!0===e.doc.features.cli.enabled&&(t.push({package:"@fnet/args",version:"^0.1"}),a.push({package:"ajv",version:"^8"}),e.doc.features.cli.fargs&&!1!==e.doc.features.cli.fargs?.enabled&&t.push({package:"@fnet/config",version:"0.2.21"}),e.doc.features.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"})}(this.apiContext),await this.initLibraryDir(),await this.initNunjucks(),await this.initLibs()}async initLibs(){this.setProgress({message:"Initializing external libs."});const e=[{name:this.atom.doc.name,type:"atom",parent_id:this.atom.parent_id}];this.libs=e,await this.initAtomLibsAndDeps({libs:e,packageDependencies:this.apiContext.packageDependencies})}async initAtomLibsAndDeps({libs:e,packageDependencies:t}){const a=e.filter((e=>"atom"===e.type));for(let e=0;e<a.length;e++){const i=a[e],s=await this.findAtomLibrary({url:i.name});i.atom=s;const r=s.doc.dependencies?.filter((e=>void 0===e.repo||"npm"===e.repo));r?.forEach((e=>{const a=t.find((t=>t.package===e.package));a?"string"==typeof e.path?(a.path||[]).some((t=>t===e.path))||(a.path=a.path||[],a.path.push(e.path)):Array.isArray(e.path)&&e.path.forEach((e=>{(a.path||[]).some((t=>t===e))||(a.path=a.path||[],a.path.push(e))})):t.push(e)}))}t.sort(((e,t)=>e.package?.localeCompare(t.package)))}async findAtomLibrary({url:e}){const a=s({url:e});if(!a)throw new Error(`Invalid package name: ${e}`);if(a.protocol||(a.protocol=this.context.protocol),"ac:"===a.protocol){const t=a.pathname.split("/");if(1===t.length)return await this.apiContext.Atom.first({where:{name:e,parent_id:this.atomConfig.env.ATOM_LIBRARIES_ID,type:"workflow.lib"}});if(2===t.length){const e=await this.apiContext.Atom.first({where:{name:t[0],parent_id:this.atomConfig.env.ATOM_LIBRARIES_ID,type:"folder"}});return await this.apiContext.Atom.first({where:{name:t[1],parent_id:e.id,type:"workflow.lib"}})}}else if("local:"===a.protocol){const e=this.atom;e.protocol="local:",e.doc.dependencies=e.doc.dependencies||[],e.name=e.doc.name;const a=t.resolve(this.context.projectSrcDir,"index.js"),s=await i({file:a,recursive:!0}),r=e.doc.dependencies,o=s.all;for await(const e of o){if("npm"!==e.type)continue;if(r.find((t=>t.package===e.package)))continue;const t=await u({name:e.package,projectDir:this.context.projectDir,setProgress:this.apiContext.setProgress});r.push({package:e.package,subpath:e.subpath,version:t.minorRange,type:"npm"})}return e}}async createAtomLibFiles({libs:a}){await this.setProgress({message:"Creating external lib files."}),this.atom.typesDir="./types";const i=a.filter((e=>"atom"===e.type));for(let a=0;a<i.length;a++){const s=i[a].atom,r=this.context.projectDir;if("local:"===s.protocol){const a=t.resolve(this.context.projectSrcDir,`${s.fileName||s.name}.js`),i=t.relative(t.join(this.context.projectDir,"src","default"),a);if(!e.existsSync(a)){e.mkdirSync(t.dirname(a),{recursive:!0});let i="export default async (args)=>{\n";i+="}",e.writeFileSync(a,i,"utf8")}s.relativePath=i.split(t.sep).join("/"),this.atom.typesDir=`./types/${t.basename(r)}/src`}else{const a=t.join(r,"src","libs",`${s.id}.js`),i=s.doc.contents?.find((e=>"esm"===e.format))||s.doc;e.writeFileSync(a,i.content,"utf8")}}}async createEngine(){await this.setProgress({message:"Creating engine file."});const i={libs:this.libs.filter((e=>"atom"===e.type)),libraryAtom:this.atom,atom:this.atom},s=this.context.templateDir,r=a.compile(e.readFileSync(t.resolve(s,t.join("src","default","engine.js.njk")),"utf8"),this.apiContext.njEnv).render(i),o=this.context.projectDir,n=t.resolve(o,t.join("src","default","index.js"));e.writeFileSync(n,r,"utf8")}async build(){try{this.fileMode&&(await this.createAtomLibFiles({libs:this.libs}),await this.createEngine(),await this.createProjectYaml(),await o(this.apiContext),await h(this.apiContext),await n(this.apiContext),await _(this.apiContext),await y(this.apiContext),await b(this.apiContext),await async function({atom:i,setProgress:s,context:r,packageDependencies:o}){await s({message:"Creating build.js file."});const n={atom:i,packageDependencies:o},p=r.templateDir,l=a.compile(e.readFileSync(t.resolve(p,"build.js.njk"),"utf8"),a.configure(p)).render(n),c=r.projectDir,d=t.resolve(c,"build.js");e.writeFileSync(d,l,"utf8"),e.chmodSync(d,"755")}(this.apiContext),await x(this.apiContext),await g(this.apiContext),this.buildMode&&(await j(this.apiContext),await w(this.apiContext),this.deployMode&&await this.deploy())),await this._cache_set(this.buildKey,{status:"COMPLETED"})}catch(e){throw await this._cache_set(this.buildKey,{status:"FAILED",message:e.message||e}),console.log(e),e}}}export{D as default};
|
|
1
|
+
import e from"node:fs";import t from"node:path";import a from"nunjucks";import i from"@flownet/lib-parse-imports-js";import s from"@flownet/lib-parse-node-url";import{B as r,c as o,a as n}from"./index.DIZA_GzC.js";import p from"lodash.merge";import{i as l,a as c,b as d,c as m,d as f,p as u,e as h,g as _,h as y,j as b,k as x,l as g,m as j,r as w}from"./index.D4sPJLOP.js";import v from"@fnet/npm-list-versions";import"node:crypto";import"yaml";import"chalk";import"@flownet/lib-atom-api-js";import"@fnet/config";import"@fnet/list-files";import"redis";import"@flownet/lib-is-redis-online";import"@fnet/yaml";import"@flownet/lib-render-templates-dir";import"@fnet/npm-pick-versions";import"object-hash";import"ajv/dist/2020.js";import"ajv/dist/standalone/index.js";import"ajv-formats";import"@fnet/shelljs";import"./index.js";import"node:url";import"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 k({dir:a,name:i="index"}){let s=t.resolve(a,`./${i}.tsx`);if(e.existsSync(s)||(s=t.resolve(a,`./${i}.ts`)),e.existsSync(s)||(s=t.resolve(a,`./${i}.jsx`)),e.existsSync(s)||(s=t.resolve(a,`./${i}.js`)),!e.existsSync(s))return{};const r=s,o=t.extname(s);return{file:r,ext:o,ts:".ts"===o||".tsx"===o,name:i}}class D extends r{async initRuntime(){await async function({atom:e,context:a,setProgress:s}){await s({message:"Initializing features..."}),e.doc.features=e.doc.features||{};const r=e.doc.features;r.project=r.project||{},r.project.format=r.project.format||r.project_format||"esm",r.project_format=r.project.format,r.dts_enabled=!0===r.dts||void 0!==r.dts&&!1!==r.dts;const o=t.resolve(a.project.projectDir),n=k({dir:t.resolve(o,"./app")});if(n.file){s("Parsing app entry imports...");let e=await i({file:n.file,recursive:!0}),t=e.all.some((e=>!0===e.usesJSX&&"local"===e.type));r.app_uses_jsx=t,r.app_has_entry=!0,e=await i({file:n.file}),t=e.all.some((e=>!0===e.usesJSX&&"local"===e.type)),r.app_entry_uses_jsx=t,r.app_entry_is_ts=n.ts,r.app_entry_ext=n.ext}const u=k({dir:t.resolve(o,"./cli")});if(u.file){s("Parsing cli entry imports...");let e=await i({file:u.file,recursive:!0}),t=e.all.some((e=>!0===e.usesJSX&&"local"===e.type));r.cli_uses_jsx=t,r.cli_has_entry=!0,e=await i({file:u.file}),t=e.all.some((e=>!0===e.usesJSX&&"local"===e.type)),r.cli_entry_uses_jsx=t,r.cli_entry_is_ts=u.ts,r.cli_entry_ext=u.ext}if("workflow.lib"===e.type){const e=k({dir:t.resolve(o,"./src")});if(e.file){s("Parsing src entry imports...");let t=await i({file:e.file,recursive:!0}),a=t.all.some((e=>!0===e.usesJSX&&"local"===e.type));r.src_uses_jsx=a,r.src_has_entry=!0,t=await i({file:e.file}),a=t.all.some((e=>!0===e.usesJSX&&"local"===e.type)),r.src_entry_uses_jsx=a,r.src_entry_is_ts=e.ts,r.src_entry_ext=e.ext}}const h=Reflect.has(r,"app_entry_uses_jsx")?!0===r.app_entry_uses_jsx:!0===r.src_entry_uses_jsx,_=Reflect.has(r,"cli_entry_uses_jsx")?!0===r.cli_entry_uses_jsx:!0===r.src_entry_uses_jsx;r.form_enabled=h||_||!0===r.form||!0===r.form?.enabled,r.multiple_enabled=r.multiple_enabled||!0===r.multiple||!0===r.multiple?.enabled,!1===r.app?r.app={enabled:!1}:!0===r.app?r.app={enabled:!0,extend:!0===r.app_has_entry,export:!0,react:h}:r.app={enabled:!0,extend:!0===r.app_has_entry,export:!0,react:h,...r.app||{}},r.app.enabled=!0===r.app.enabled&&(!0===e.doc.features.form_enabled||!0===r.app.extend||!0===r.app.enabled),r.app.format=r.app.format||"esm",r.app.folder=r.app.folder||r.app.format||"esm",r.app.dir=`./dist/app/${r.app.folder}`,r.app.html=!1!==r.app.html,!1===r.cli?r.cli={enabled:!1}:!0===r.cli?r.cli={enabled:!0,extend:!0===r.cli_has_entry,export:!0,react:_}:r.cli={enabled:!0,extend:!0===r.cli_has_entry,export:!0,react:_,...r.cli||{}},r.cli.enabled=!0===r.cli.enabled&&(!1===e.doc.features.form_enabled||!0===r.cli.extend||!0===r.cli.enabled),r.cli.format=r.cli.format||"esm",r.cli.folder=r.cli.folder||r.cli.folder||"esm",r.cli.dir=`./dist/cli/${r.cli.folder}`,r.cli.node_options=r.cli.node?.options||r.cli.node_options||"",r.json=r.cli.enabled||r.json,r.bun=r.bun||{},r.bun.build=r.bun.build||{};const y={default:{format:"esm",target:"browser",minify:!1,sourcemap:"external",entrypoints:["./src/default/index.js"],outdir:"./dist/default/esm"},defaultCjs:{format:"cjs",target:"node",minify:!1,sourcemap:"external",entrypoints:["./src/default/index.js"],outdir:"./dist/default/cjs"}};r.cli.enabled&&(y.cli={format:"esm",target:"node",minify:!1,sourcemap:"external",entrypoints:["./src/cli/index.js"],outdir:r.cli.dir}),r.app.enabled&&(y.app={format:"esm",target:"browser",minify:!1,sourcemap:"external",entrypoints:["./src/app/index.js"],outdir:r.app.dir}),r.bun.build=p(y,r.bun.build||{}),r.preact_enabled=!0===r.preact||r.preact&&!1!==r.preact?.enabled,r.dependency_auto_enabled=!1!==r.dependency_auto&&!1!==r.dependency_auto?.enabled,r.npm_install_flags=r.npm_install_flags||"",r.react_version=r.react_version||r.react?.version||18,r.runtime=r.runtime||{},r.runtime.type="bun",r.runtime.template="bun",l({atom:e}),c({atom:e}),d({atom:e}),m({atom:e}),f({atom:e})}(this.apiContext),await async function({atom:e,packageDependencies:t,packageDevDependencies:a,setProgress:i}){i("Initializing dependencies for Bun");const s=e.doc.dependencies||[];if(s.filter((e=>!e.dev)).forEach((e=>t.push(e))),s.filter((e=>e.dev)).forEach((e=>a.push(e))),"workflow"===e.type&&(t.push({package:"get-value",version:"^3"}),t.push({package:"set-value",version:"^4"})),e.doc.features.form_enabled&&e.doc.features.dependency_auto_enabled){let a="^18.2";i("Fetching React versions"),a=`^${(await v({name:"react",groupBy:{major:!0}})).find((t=>t[0]===e.doc.features.react_version.toString()))[0]}`,t.push({package:"react",version:a}),t.push({package:"react-dom",version:a}),"workflow"===e.type&&(t.push({package:"@fnet/react-app",version:"^0.1"}),t.push({package:"@fnet/react-app-state",version:"^0.1"}))}e.doc.features.preact_enabled&&t.push({package:"preact",version:"^10"}),!0===e.doc.features.cli.enabled&&(t.push({package:"@fnet/args",version:"^0.1"}),a.push({package:"ajv",version:"^8"}),e.doc.features.cli.fargs&&!1!==e.doc.features.cli.fargs?.enabled&&t.push({package:"@fnet/config",version:"0.2.21"}),e.doc.features.cli.mcp&&!0===e.doc.features.cli.mcp.enabled&&(t.push({package:"@modelcontextprotocol/sdk",version:"^1.10"}),t.push({package:"express",version:"^4.18"}))),e.doc.features.render&&!1!==e.doc.features.render.enabled&&a.push({package:"@flownet/lib-render-templates-dir",version:"0.1.19"})}(this.apiContext),await this.initLibraryDir(),await this.initNunjucks(),await this.initLibs()}async initLibs(){this.setProgress({message:"Initializing external libs."});const e=[{name:this.atom.doc.name,type:"atom",parent_id:this.atom.parent_id}];this.libs=e,await this.initAtomLibsAndDeps({libs:e,packageDependencies:this.apiContext.packageDependencies})}async initAtomLibsAndDeps({libs:e,packageDependencies:t}){const a=e.filter((e=>"atom"===e.type));for(let e=0;e<a.length;e++){const i=a[e],s=await this.findAtomLibrary({url:i.name});i.atom=s;const r=s.doc.dependencies?.filter((e=>void 0===e.repo||"npm"===e.repo));r?.forEach((e=>{const a=t.find((t=>t.package===e.package));a?"string"==typeof e.path?(a.path||[]).some((t=>t===e.path))||(a.path=a.path||[],a.path.push(e.path)):Array.isArray(e.path)&&e.path.forEach((e=>{(a.path||[]).some((t=>t===e))||(a.path=a.path||[],a.path.push(e))})):t.push(e)}))}t.sort(((e,t)=>e.package?.localeCompare(t.package)))}async findAtomLibrary({url:e}){const a=s({url:e});if(!a)throw new Error(`Invalid package name: ${e}`);if(a.protocol||(a.protocol=this.context.protocol),"ac:"===a.protocol){const t=a.pathname.split("/");if(1===t.length)return await this.apiContext.Atom.first({where:{name:e,parent_id:this.atomConfig.env.ATOM_LIBRARIES_ID,type:"workflow.lib"}});if(2===t.length){const e=await this.apiContext.Atom.first({where:{name:t[0],parent_id:this.atomConfig.env.ATOM_LIBRARIES_ID,type:"folder"}});return await this.apiContext.Atom.first({where:{name:t[1],parent_id:e.id,type:"workflow.lib"}})}}else if("local:"===a.protocol){const e=this.atom;e.protocol="local:",e.doc.dependencies=e.doc.dependencies||[],e.name=e.doc.name;const a=t.resolve(this.context.projectSrcDir,"index.js"),s=await i({file:a,recursive:!0}),r=e.doc.dependencies,o=s.all;for await(const e of o){if("npm"!==e.type)continue;if(r.find((t=>t.package===e.package)))continue;const t=await u({name:e.package,projectDir:this.context.projectDir,setProgress:this.apiContext.setProgress});r.push({package:e.package,subpath:e.subpath,version:t.minorRange,type:"npm"})}return e}}async createAtomLibFiles({libs:a}){await this.setProgress({message:"Creating external lib files."}),this.atom.typesDir="./types";const i=a.filter((e=>"atom"===e.type));for(let a=0;a<i.length;a++){const s=i[a].atom,r=this.context.projectDir;if("local:"===s.protocol){const a=t.resolve(this.context.projectSrcDir,`${s.fileName||s.name}.js`),i=t.relative(t.join(this.context.projectDir,"src","default"),a);if(!e.existsSync(a)){e.mkdirSync(t.dirname(a),{recursive:!0});let i="export default async (args)=>{\n";i+="}",e.writeFileSync(a,i,"utf8")}s.relativePath=i.split(t.sep).join("/"),this.atom.typesDir=`./types/${t.basename(r)}/src`}else{const a=t.join(r,"src","libs",`${s.id}.js`),i=s.doc.contents?.find((e=>"esm"===e.format))||s.doc;e.writeFileSync(a,i.content,"utf8")}}}async createEngine(){await this.setProgress({message:"Creating engine file."});const i={libs:this.libs.filter((e=>"atom"===e.type)),libraryAtom:this.atom,atom:this.atom},s=this.context.templateDir,r=a.compile(e.readFileSync(t.resolve(s,t.join("src","default","engine.js.njk")),"utf8"),this.apiContext.njEnv).render(i),o=this.context.projectDir,n=t.resolve(o,t.join("src","default","index.js"));e.writeFileSync(n,r,"utf8")}async build(){try{this.fileMode&&(await this.createAtomLibFiles({libs:this.libs}),await this.createEngine(),await this.createProjectYaml(),await o(this.apiContext),await h(this.apiContext),await n(this.apiContext),await _(this.apiContext),await y(this.apiContext),await b(this.apiContext),await async function({atom:i,setProgress:s,context:r,packageDependencies:o}){await s({message:"Creating build.js file."});const n={atom:i,packageDependencies:o},p=r.templateDir,l=a.compile(e.readFileSync(t.resolve(p,"build.js.njk"),"utf8"),a.configure(p)).render(n),c=r.projectDir,d=t.resolve(c,"build.js");e.writeFileSync(d,l,"utf8"),e.chmodSync(d,"755")}(this.apiContext),await x(this.apiContext),await g(this.apiContext),this.buildMode&&(await j(this.apiContext),await w(this.apiContext),this.deployMode&&await this.deploy())),await this._cache_set(this.buildKey,{status:"COMPLETED"})}catch(e){throw await this._cache_set(this.buildKey,{status:"FAILED",message:e.message||e}),console.log(e),e}}}export{D as default};
|
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.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};
|
|
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.B_0ZxySP.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,dev:o.dev};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,dev:o.dev}}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.D3C-8oZW.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.D3C-8oZW.js")).default)(e)}}static async loadBuilderClass(e){switch(e.toLowerCase()){case"node":return(await import("./index.D3C-8oZW.js")).default;case"python":return(await import("./index.uPDSav7E.js")).default;case"bun":return(await import("./index.DMkgR1Dh.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"}).option("dev",{type:"boolean",default:!1,describe:"Development mode"}),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};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fnet/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.116.1",
|
|
4
4
|
"files": [
|
|
5
5
|
"dist",
|
|
6
6
|
"template"
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"description": "CLI for Flownet",
|
|
10
10
|
"scripts": {
|
|
11
11
|
"build": "rollup --config",
|
|
12
|
+
"build:dev": "rollup --config --sourcemap --environment DEVELOPMENT",
|
|
12
13
|
"deploy": "bun publish --access public",
|
|
13
14
|
"watch": "rollup --config --watch --sourcemap --environment DEVELOPMENT",
|
|
14
15
|
"postbuild": "chmod +x dist/fnode/index.js dist/fnet/index.js dist/frun/index.js dist/fbin/index.js"
|
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
"license": "{{atom.doc.license or 'MIT'}}",
|
|
55
55
|
"scripts": {
|
|
56
56
|
"build": "rollup --config",
|
|
57
|
+
"build:dev": "rollup --config --sourcemap --environment DEVELOPMENT",
|
|
57
58
|
"watch": "rollup --config --watch --sourcemap --environment DEVELOPMENT",
|
|
58
59
|
"serve": "bunx serve ./"
|
|
59
60
|
{% if atom.doc.features.cli.enabled %}
|