modelence 0.26.0-nd.dev.10 → 0.26.0-nd.dev.11
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/bin/modelence.js +1 -1
- package/dist/bin/modelence.js.map +1 -1
- package/dist/{chunk-IQOUXFAM.js → chunk-5ZSNEWEF.js} +5 -5
- package/dist/{chunk-IQOUXFAM.js.map → chunk-5ZSNEWEF.js.map} +1 -1
- package/dist/{chunk-52W7FC72.js → chunk-VHTPJRV3.js} +3 -3
- package/dist/{chunk-52W7FC72.js.map → chunk-VHTPJRV3.js.map} +1 -1
- package/dist/{package-KS634H3H.js → package-66NV53QF.js} +2 -2
- package/dist/{package-KS634H3H.js.map → package-66NV53QF.js.map} +1 -1
- package/dist/server-EJSEJXAM.js +2 -0
- package/dist/{server-I6C4KNMF.js.map → server-EJSEJXAM.js.map} +1 -1
- package/dist/server.js +1 -1
- package/package.json +1 -1
- package/dist/server-I6C4KNMF.js +0 -2
package/dist/bin/modelence.js
CHANGED
|
@@ -14,6 +14,6 @@ Next step \u2014 run the app on this machine:
|
|
|
14
14
|
`).length,r=t.offset-o.lastIndexOf(`
|
|
15
15
|
`);return `${printParseErrorCode(t.error)} at line ${n}, column ${r}`}async function $e(e,t=process.cwd()){await promises.writeFile(V(t),JSON.stringify(e,null,2)+`
|
|
16
16
|
`);}function De(e){let t=[];t.push(` runtime: ${e.runtime??"node"}`),t.push(` node: ${e.build?.node??"default (22)"}`),e.build?.root&&e.build.root!=="."&&t.push(` root: ${e.build.root}`),t.push(` install: ${e.build?.install??"default"}`),t.push(` build: ${Te(e.build?.command)}`);for(let[o,n]of Object.entries(e.build?.env??{}))t.push(` env: ${o}=${n}`);t.push(` start: ${Te(e.web?.start)}`);for(let o of e.web?.static??[])t.push(` static: ${o.path} -> ${o.dir}/`);return t}function Te(e){return e===void 0?"default":e===null||e===""?"(none)":e}async function Oe(e,t="."){if(typeof t!="string"||isAbsolute(t))throw new Error("build.root must be a relative directory inside the project.");let o=await promises.realpath(e),n=resolve(o,t);if(!_e(o,n))throw new Error("build.root must stay inside the project.");let r;try{r=await promises.realpath(n);}catch{throw new Error(`build.root "${t}" does not exist.`)}if(!_e(o,r)||!(await promises.stat(r)).isDirectory())throw new Error("build.root must be a directory inside the project.");return r}function _e(e,t){let o=relative(e,t);return o!==".."&&!o.startsWith(`..${sep}`)&&!isAbsolute(o)}var Me=["$schema","runtime","build","web"];async function Re(e){let t=await Ie(e);if(!t)throw new Error(Ht(e));Wt(t),t.build?.root!==void 0&&await Oe(e,t.build.root),console.log(`Build plan (${m}):`);for(let o of De(t))console.log(o);return t}function Ht(e){return [`${m} not found in ${e}.`,"Modelence Cloud builds and runs your app exactly as this file describes (install, build and start commands, Node.js version, static directories).","Ask your coding agent to create it with this prompt:","",` ${B}`,"",`Reference: ${k}`].join(`
|
|
17
|
-
`)}function Wt(e){let t=Object.keys(e).filter(o=>!Me.includes(o));if(t.length>0)throw new Error(`${m} has unknown key "${t[0]}" (allowed: ${Me.join(", ")}).`);for(let o of ["build","web"]){let n=e[o];if(n!==void 0&&(!n||typeof n!="object"||Array.isArray(n)))throw new Error(`${m}: "${o}" must be an object.`)}}function Fe(e,t){if(e.app&&e.env)return {appAlias:e.app,envAlias:e.env};if(e.env&&t.deploy?.appAlias)return {appAlias:t.deploy.appAlias,envAlias:e.env};if(e.env&&t.appId)return {appId:t.appId,envAlias:e.env};if(e.app||e.env)throw new Error("Pass both --app and --env, or neither to pick the target in the browser.");return t.deploy?.environmentId?{environmentId:t.deploy.environmentId}:null}var w=class extends Error{constructor(o,n){super(o);this.status=n;this.name="StudioApiError";}};async function f(e,t,{method:o="GET",token:n,body:r,query:i}={}){let c=new URL(t,e);for(let[s,p]of Object.entries(i??{}))c.searchParams.set(s,String(p));let l={};n&&(l.Authorization=`Bearer ${n}`),r!==void 0&&(l["Content-Type"]="application/json");let a=await fetch(c,{method:o,headers:l,body:r===void 0?void 0:JSON.stringify(r)});if(!a.ok){let s=await a.text(),p=s||a.statusText;try{let d=JSON.parse(s);p=d.error||d.message||p;}catch{}throw new w(p,a.status)}return await a.json()}var Qt="https://cloud.modelence.com";function z(e){return e instanceof w&&e.status===401}async function Le(e){return process.env.MODELENCE_TOKEN?process.env.MODELENCE_TOKEN:await ye(e)}async function ee(e,t,o){if(o)try{await ve(e,t,o);}catch(n){console.warn("Could not save the login for next time:",n);}}async function I(e){let t={environmentId:e.environmentId,appAlias:e.appAlias,envAlias:e.envAlias};try{await _({deploy:t,..."appId"in e?{appId:e.appId}:{}});}catch(o){console.warn("Could not record the deploy target in .modelence/project.json:",o);}}async function je(e,t){if(e)return e.replace(/\/$/,"");if(process.env.MODELENCE_SERVICE_ENDPOINT)return process.env.MODELENCE_SERVICE_ENDPOINT.replace(/\/$/,"");try{let o=parse(await promises.readFile(join(t,".modelence.env"),"utf8"));if(o.MODELENCE_SERVICE_ENDPOINT)return o.MODELENCE_SERVICE_ENDPOINT.replace(/\/$/,"")}catch{}return Qt}var Ue=3e3,eo=30*60*1e3,to=10*60*1e3;async function Be(e,t,o){let n=Date.now()+to,r=false;for(;Date.now()<n;){let i;try{({status:i}=await f(e,"/api/environment/status",{token:t,query:{environmentId:o}}));}catch(c){if(c instanceof w&&c.status===404)return false;throw c}if(i==="ready")return r;if(i==="failed")throw new Error("The environment failed to provision; check it in the dashboard.");r||(console.log("Waiting for the environment to finish provisioning..."),r=true),await new Promise(c=>setTimeout(c,Ue));}throw new Error("Timed out waiting for the environment to be ready.")}async function Ve(e,t,o,n){let r=Date.now()+eo,i="",c="",l=0,a=false;for(;Date.now()<r;){let s;try{s=await f(e.host,"/api/deploy/status",{token:e.token,query:{environmentId:o,buildId:n,logOffset:l}});}catch(p){if(!z(p)||a)throw p;a=true,await t();continue}for(let p of s.logs)process.stdout.write(` \u2502 ${p.replace(/\n$/,"")}
|
|
17
|
+
`)}function Wt(e){let t=Object.keys(e).filter(o=>!Me.includes(o));if(t.length>0)throw new Error(`${m} has unknown key "${t[0]}" (allowed: ${Me.join(", ")}).`);for(let o of ["build","web"]){let n=e[o];if(n!==void 0&&(!n||typeof n!="object"||Array.isArray(n)))throw new Error(`${m}: "${o}" must be an object.`)}for(let[o,n]of [["build.command",e.build?.command],["web.start",e.web?.start]])if(typeof n=="string"&&n.trim()==="")throw new Error(`${m}: "${o}" must not be empty; use null for none.`)}function Fe(e,t){if(e.app&&e.env)return {appAlias:e.app,envAlias:e.env};if(e.env&&t.deploy?.appAlias)return {appAlias:t.deploy.appAlias,envAlias:e.env};if(e.env&&t.appId)return {appId:t.appId,envAlias:e.env};if(e.app||e.env)throw new Error("Pass both --app and --env, or neither to pick the target in the browser.");return t.deploy?.environmentId?{environmentId:t.deploy.environmentId}:null}var w=class extends Error{constructor(o,n){super(o);this.status=n;this.name="StudioApiError";}};async function f(e,t,{method:o="GET",token:n,body:r,query:i}={}){let c=new URL(t,e);for(let[s,p]of Object.entries(i??{}))c.searchParams.set(s,String(p));let l={};n&&(l.Authorization=`Bearer ${n}`),r!==void 0&&(l["Content-Type"]="application/json");let a=await fetch(c,{method:o,headers:l,body:r===void 0?void 0:JSON.stringify(r)});if(!a.ok){let s=await a.text(),p=s||a.statusText;try{let d=JSON.parse(s);p=d.error||d.message||p;}catch{}throw new w(p,a.status)}return await a.json()}var Qt="https://cloud.modelence.com";function z(e){return e instanceof w&&e.status===401}async function Le(e){return process.env.MODELENCE_TOKEN?process.env.MODELENCE_TOKEN:await ye(e)}async function ee(e,t,o){if(o)try{await ve(e,t,o);}catch(n){console.warn("Could not save the login for next time:",n);}}async function I(e){let t={environmentId:e.environmentId,appAlias:e.appAlias,envAlias:e.envAlias};try{await _({deploy:t,..."appId"in e?{appId:e.appId}:{}});}catch(o){console.warn("Could not record the deploy target in .modelence/project.json:",o);}}async function je(e,t){if(e)return e.replace(/\/$/,"");if(process.env.MODELENCE_SERVICE_ENDPOINT)return process.env.MODELENCE_SERVICE_ENDPOINT.replace(/\/$/,"");try{let o=parse(await promises.readFile(join(t,".modelence.env"),"utf8"));if(o.MODELENCE_SERVICE_ENDPOINT)return o.MODELENCE_SERVICE_ENDPOINT.replace(/\/$/,"")}catch{}return Qt}var Ue=3e3,eo=30*60*1e3,to=10*60*1e3;async function Be(e,t,o){let n=Date.now()+to,r=false;for(;Date.now()<n;){let i;try{({status:i}=await f(e,"/api/environment/status",{token:t,query:{environmentId:o}}));}catch(c){if(c instanceof w&&c.status===404)return false;throw c}if(i==="ready")return r;if(i==="failed")throw new Error("The environment failed to provision; check it in the dashboard.");r||(console.log("Waiting for the environment to finish provisioning..."),r=true),await new Promise(c=>setTimeout(c,Ue));}throw new Error("Timed out waiting for the environment to be ready.")}async function Ve(e,t,o,n){let r=Date.now()+eo,i="",c="",l=0,a=false;for(;Date.now()<r;){let s;try{s=await f(e.host,"/api/deploy/status",{token:e.token,query:{environmentId:o,buildId:n,logOffset:l}});}catch(p){if(!z(p)||a)throw p;a=true,await t();continue}for(let p of s.logs)process.stdout.write(` \u2502 ${p.replace(/\n$/,"")}
|
|
18
18
|
`);if(l=Math.max(l,s.logCount),s.status!==i){i=s.status;let p=oo(s);p&&p!==c&&(c=p,console.log(p));}if(s.status==="deploy-completed"){s.siteUrl&&console.log(`Live at ${s.siteUrl}`);return}if(s.status==="build-failed"||s.status==="deploy-failed"){for(let p of s.errors)console.error(` ${p}`);if(s.containerLogs&&s.containerLogs.length>0){console.error("Container output:");for(let p of s.containerLogs)console.error(` \u2502 ${p.replace(/\n$/,"")}`);}process.exitCode=1;return}await new Promise(p=>setTimeout(p,Ue));}console.error("Timed out waiting for the deployment; check the dashboard for its status."),process.exitCode=1;}function oo(e){switch(e.status){case "build-pending":return "Building image...";case "deploy-pending":case "deploying":return "Image built. Deploying containers...";case "rolling-out":return "Rolling out new containers...";case "deploy-completed":return "Deployed successfully.";case "build-failed":return "Build failed.";case "deploy-failed":return "Deployment failed.";default:return null}}async function te({session:e,target:t,kind:o,archivePath:n,spec:r,project:i}){let{host:c,token:l}=e,a=()=>f(c,"/api/upload-bundle",{method:"POST",token:l,body:{...t,kind:o}}),s=await a();await Be(c,l,s.environmentId)&&(s=await a()),console.log(`Uploading to ${s.appAlias}/${s.envAlias}...`);let p=await openAsBlob(n,{type:"application/zip"}),d=await fetch(s.uploadUrl,{method:"PUT",body:p,headers:{"Content-Type":"application/zip"}});if(!d.ok)throw new Error(`Failed to upload: ${await ro(d)}`);let u=await f(c,"/api/deploy",{method:"POST",token:l,body:{environmentId:s.environmentId,bundleName:s.bundleName,kind:o,spec:r}});return (!i.deploy||i.deploy.environmentId!==u.environmentId)&&await I({environmentId:u.environmentId,appAlias:u.appAlias,envAlias:u.envAlias}),console.log(`Deployment started: ${u.deploymentUrl}`),{environmentId:u.environmentId,buildId:u.buildId}}async function ro(e){let t=await e.text().catch(()=>""),o=t.match(/<Code>([^<]+)<\/Code>/)?.[1],n=t.match(/<Message>([^<]+)<\/Message>/)?.[1],r=e.statusText||`HTTP ${e.status}`;return o?`${r} (${o}${n?`: ${n}`:""})`:r}async function Ge(e){let t=process.cwd(),o=await je(e.host,t),n=e.prebuilt?"bundle":"source",r=await P(t),i=Fe(e,r),c,l=join(t,".modelence","tmp",`${n}.zip`);if(n==="bundle")await b(),await F(),await ao(l);else {c=await Re(t);let{fileCount:a,sizeBytes:s,usedGit:p,excludedFiles:d}=await Ae(t,l);console.log(`Packed ${a} files (${Je(s)})`+(p?" from git":"; not a git repository, so only default exclusions applied")),d.length>0&&console.log(`Excluded ${d.length} local or generated files from the upload. Store secrets in the target environment.`);}try{let a=await Le(o);if(!a||!i){let u=await C(o,{pick:i?void 0:"deploy",purpose:"deploy",appId:r.appId});a=u.token,await ee(o,u.token,u.expiresAt),u.target&&(i={environmentId:u.target.environmentId},await I(u.target));}if(!i)throw new Error("No deploy target selected. Run again and pick an environment in the browser, or pass --app and --env.");let s={host:o,token:a},p=async()=>{await U(o),console.log("Your saved login has expired; please sign in again.");let u=await C(o,{pick:i?void 0:"deploy",purpose:"deploy",appId:r.appId});await ee(o,u.token,u.expiresAt),u.target&&(i={environmentId:u.target.environmentId},await I(u.target)),s.token=u.token;},d;try{d=await te({session:s,target:i,kind:n,archivePath:l,spec:c,project:r});}catch(u){if(!z(u))throw u;await p(),d=await te({session:s,target:i,kind:n,archivePath:l,spec:c,project:r});}d.buildId&&await Ve(s,p,d.environmentId,d.buildId);}finally{await promises.rm(l,{force:true});}}function Je(e){return `${(e/1024/1024).toFixed(2)} MB`}async function ao(e){await promises.rm(e,{force:true}),console.log("Creating deployment bundle..."),await promises.mkdir(join(e,".."),{recursive:true});let t=createWriteStream(e),o=Nt("zip",{zlib:{level:9}}),n=new Promise((l,a)=>{t.on("close",l),t.on("error",a),o.on("error",a);});o.pipe(t);let r=["package.json","package-lock.json","next.config.js","next.config.ts","modelence.config.ts"],i=["public","server","scripts",join(".modelence","build"),".next"];for(let l of r)await ze(v(l))&&o.file(v(l),{name:l});for(let l of i)await ze(v(l))&&o.directory(v(l),l);await o.finalize(),await n;let c=await promises.stat(e);console.log(`Deployment bundle created (${Je(c.size)})`);}async function ze(e){try{return await promises.access(e),!0}catch{return false}}function Ke(e={}){console.log("Starting Modelence dev server...");let t=E(),o=Y.resolve("./node_modules/.bin/tsx");execSync(`"${o}" watch --ignore "vite.config.ts.timestamp-*" "${t}"`,{stdio:"inherit",cwd:process.cwd(),env:{...process.env,NODE_ENV:"development",...e.takeover?{MODELENCE_TAKEOVER:"1"}:{}}});}function He(){console.log("Starting Modelence production server...");let e=E(),t=Y.basename(e,Y.extname(e)),o=R(`${t}.mjs`);execSync(`node "${o}"`,{stdio:"inherit",cwd:process.cwd(),env:{...process.env,NODE_ENV:"production"}});}async function We(e){let t=await Ee(e.host);await Promise.all(t.map(({host:o,token:n})=>uo(o,n))),await U(e.host),console.log(e.host?`Removed the saved login for ${e.host}.`:`Removed saved logins (${L()}).`);}async function uo(e,t){try{await f(e,"/api/cli/logout",{method:"POST",token:t});}catch{}}var fo="https://cloud.modelence.com";async function Ye(e){let t=process.cwd(),o=V(t);if(!e.force&&await go(o))throw new Error(`${m} already exists; pass --force to overwrite it.`);let r={$schema:`${(e.host??fo).replace(/\/$/,"")}/schema/modelence.json`,build:{node:"22",install:"npm ci",command:null},web:{start:null,static:[]}};await $e(r,t),console.log(`Wrote a ${m} template.`),console.log("Ask your coding agent to fill it in with this prompt:"),console.log(""),console.log(` ${B}`),console.log(""),console.log(`Reference: ${k}`),console.log(`Once ${m} describes your app, run \`modelence deploy\`.`);}async function go(e){try{return await promises.access(e),!0}catch{return false}}var bo=fileURLToPath(import.meta.url),Co=dirname(bo),So=JSON.parse(readFileSync(join(Co,"../../package.json"),"utf-8")),g=new Command().name("modelence").description("Modelence CLI tool").version(So.version);g.command("setup").description("Setup Modelence environment variables").option("-t, --token <token>","Modelence setup token (omit to authorize in the browser)").option("-h, --host <host>","Modelence host","https://cloud.modelence.com").action(async e=>{await ce(e);});g.command("build").description("Build the application").action(async()=>{await b(),await F();});g.command("deploy").description("Deploy the project described by modelence.json to Modelence Cloud (picks the target in the browser on first run)").option("-a, --app <app>","Application alias").option("-e, --env <env>","Environment alias").option("-h, --host <host>","Modelence host").option("--prebuilt","Build locally and upload the .modelence/build bundle (Modelence apps only)").action(async e=>{try{await Ge(e);}catch(t){console.error(`Deploy failed: ${t instanceof Error?t.message:String(t)}`),process.exit(1);}});g.command("init").description("Create a modelence.json template for this project").option("--force","Overwrite an existing modelence.json").option("-h, --host <host>","Modelence host used for the schema URL").action(async e=>{try{await Ye(e);}catch(t){console.error(`Init failed: ${t instanceof Error?t.message:String(t)}`),process.exit(1);}});g.command("logout").description("Forget the saved Modelence Cloud login").option("-h, --host <host>","Only forget the login for this host").action(async e=>{await We(e);});g.command("dev").description("Start development server").option("--takeover","Disconnect any instance currently holding the environment and connect this one").action(async e=>{await b(),Ke(e);});g.command("start").description("Start production server").action(async()=>{await b(),He();});g.parse(process.argv);//# sourceMappingURL=modelence.js.map
|
|
19
19
|
//# sourceMappingURL=modelence.js.map
|