lacis 0.2.7 → 0.2.8

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/cli/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env node
2
- import {resolve,join,relative}from'path';import {unlink,writeFile,readdir}from'fs/promises';import {spawn}from'child_process';import {watch,existsSync,readFileSync}from'fs';async function N(e){let t=[];async function n(r,s=[]){let c;try{c=await readdir(r,{withFileTypes:!0});}catch{return}let o=c.find(i=>!i.isDirectory()&&(i.name==="index.ts"||i.name==="index.js"));if(o){let i="./"+relative(e,join(r,o.name)).replace(/\\/g,"/").replace(/\.ts$/,".js"),u="/"+s.map(m=>m.replace(/^\[(\w+)\??\]$/,":$1")).join("/");t.push({importPath:i,routePath:u==="//"?"/":u});}for(let i of c)i.isDirectory()&&!i.name.startsWith("+")&&await n(join(r,i.name),[...s,i.name]);}return await n(e),t}async function f(e){let t=await N(e),n=t.map((c,o)=>`import * as _route_${o} from '${c.importPath}'`).join(`
3
- `),r=t.map((c,o)=>` { path: '${c.routePath}', handlers: _route_${o} }`).join(`,
4
- `),s=["// AUTO-GENERATED by lacis build \u2014 do not edit",n,"","export const routes = [",r,"]",""].join(`
5
- `);await writeFile(join(e,"_manifest.ts"),s,"utf-8"),console.log(`[lacis] Generated manifest with ${t.length} route(s)`);}function R(e){if(existsSync(join(e,"netlify.toml")))return "netlify";if(existsSync(join(e,"vercel.json")))return "vercel";try{let t=JSON.parse(readFileSync(join(e,"package.json"),"utf-8")),n={...t.dependencies,...t.devDependencies};if(n["@netlify/functions"]||n["netlify-cli"])return "netlify";if(n.vercel||n["@vercel/node"])return "vercel"}catch{}return process.versions.bun!==void 0||existsSync(join(e,"bun.lockb"))||existsSync(join(e,"bun.lock"))?"bun":"node"}function S(e){try{let t=JSON.parse(readFileSync(join(e,"package.json"),"utf-8")),n=t.module??t.main;if(typeof n=="string"&&existsSync(join(e,n)))return n}catch{}for(let t of ["server.ts","index.ts","app.ts","main.ts"])if(existsSync(join(e,t)))return t;return null}function F(e){try{return JSON.parse(readFileSync(join(e,"tsconfig.json"),"utf-8")).compilerOptions?.outDir??null}catch{return null}}async function v(e){let t=[],n;try{n=await readdir(e,{withFileTypes:!0});}catch{return t}for(let r of n)r.isDirectory()?t.push(...await v(join(e,r.name))):r.name.endsWith(".ts")&&r.name!=="_manifest.ts"&&t.push(join(e,r.name));return t}function D(e,t,n){return new Promise((r,s)=>{let c=spawn(e,t,{stdio:"inherit",cwd:n});c.on("close",o=>{o===0?r():s(new Error(`${e} exited with code ${o}`));}),c.on("error",o=>{o.code==="ENOENT"?s(new Error(`Command not found: ${e}. Make sure it is installed.`)):s(o);});})}async function b(e,t){let n=process.cwd(),r=R(n),s=join(e,"_manifest.ts");relative(n,s).replace(/\\/g,"/");if(await f(e),r==="vercel"||r==="netlify"){console.log(`[lacis] ${r} detected \u2014 manifest generated, platform handles compilation`);return}try{if(r==="bun"){let o=t??S(n);if(!o)throw new Error("Entry point not found. Specify one with --entry <file>.");let i=await v(e),u=[join(n,o),s,...i],m=await globalThis.Bun.build({entrypoints:u,outdir:join(n,"dist"),root:n,external:["*"],target:"bun"});if(!m.success){let $=m.logs.map(y=>y.message??String(y)).join(`
2
+ import {resolve,join,relative}from'path';import {unlink,writeFile,readdir}from'fs/promises';import {spawn}from'child_process';import {watch,existsSync,readFileSync}from'fs';async function N(e){let t=[];async function n(o,s=[]){let c;try{c=await readdir(o,{withFileTypes:!0});}catch{return}let r=c.find(i=>!i.isDirectory()&&(i.name==="index.ts"||i.name==="index.js"));if(r){let i="./"+relative(e,join(o,r.name)).replace(/\\/g,"/").replace(/\.ts$/,".js"),u="/"+s.map(m=>m.replace(/^\[(\w+)\??\]$/,":$1")).join("/");t.push({importPath:i,routePath:u==="//"?"/":u});}for(let i of c)i.isDirectory()&&!i.name.startsWith("+")&&await n(join(o,i.name),[...s,i.name]);}return await n(e),t}async function f(e){let t=await N(e),n=t.map((c,r)=>`import * as _route_${r} from '${c.importPath}'`).join(`
3
+ `),o=t.map((c,r)=>` { path: '${c.routePath}', handlers: _route_${r} }`).join(`,
4
+ `),s=["// AUTO-GENERATED by lacis build \u2014 do not edit",n,"","export const routes = [",o,"]",""].join(`
5
+ `);await writeFile(join(e,"_manifest.ts"),s,"utf-8"),console.log(`[lacis] Generated manifest with ${t.length} route(s)`);}function R(e){if(existsSync(join(e,"netlify.toml")))return "netlify";if(existsSync(join(e,"vercel.json")))return "vercel";try{let t=JSON.parse(readFileSync(join(e,"package.json"),"utf-8")),n={...t.dependencies,...t.devDependencies};if(n["@netlify/functions"]||n["netlify-cli"])return "netlify";if(n.vercel||n["@vercel/node"])return "vercel"}catch{}return process.versions.bun!==void 0||existsSync(join(e,"bun.lockb"))||existsSync(join(e,"bun.lock"))?"bun":"node"}function S(e){try{let t=JSON.parse(readFileSync(join(e,"package.json"),"utf-8")),n=t.module??t.main;if(typeof n=="string"&&existsSync(join(e,n)))return n}catch{}for(let t of ["server.ts","index.ts","app.ts","main.ts"])if(existsSync(join(e,t)))return t;return null}function F(e){try{return JSON.parse(readFileSync(join(e,"tsconfig.json"),"utf-8")).compilerOptions?.outDir??null}catch{return null}}async function v(e){let t=[],n;try{n=await readdir(e,{withFileTypes:!0});}catch{return t}for(let o of n)o.isDirectory()?t.push(...await v(join(e,o.name))):o.name.endsWith(".ts")&&o.name!=="_manifest.ts"&&t.push(join(e,o.name));return t}function D(e,t,n){return new Promise((o,s)=>{let c=spawn(e,t,{stdio:"inherit",cwd:n});c.on("close",r=>{r===0?o():s(new Error(`${e} exited with code ${r}`));}),c.on("error",r=>{r.code==="ENOENT"?s(new Error(`Command not found: ${e}. Make sure it is installed.`)):s(r);});})}async function b(e,t){let n=process.cwd(),o=R(n),s=join(e,"_manifest.ts");relative(n,s).replace(/\\/g,"/");if(await f(e),o==="vercel"||o==="netlify"){console.log(`[lacis] ${o} detected \u2014 manifest generated, platform handles compilation`);return}try{if(o==="bun"){let r=t??S(n);if(!r)throw new Error("Entry point not found. Specify one with --entry <file>.");let i=await v(e),u=[join(n,r),s,...i],m=await globalThis.Bun.build({entrypoints:u,outdir:join(n,"dist"),root:n,external:["*"],target:"bun"});if(!m.success){let T=m.logs.map(y=>y.message??String(y)).join(`
6
6
  `);throw new Error(`Bun build failed:
7
- ${$}`)}}else {let o=F(n)??"dist";await D("npx",["tsc","--outDir",o],n);}}finally{await unlink(s).catch(()=>{});}console.log("[lacis] Build complete \u2192 dist/");}async function d(e){await f(e);let t=null;watch(e,{recursive:true},(n,r)=>{!r||r==="_manifest.ts"||(t&&clearTimeout(t),t=setTimeout(async()=>{console.log(`[lacis] Route changed: ${r}, regenerating manifest...`);try{await f(e);}catch(s){console.error("[lacis] Failed to regenerate manifest:",s);}},100));});}function J(e){if(existsSync(join(e,"netlify.toml")))return "netlify";if(existsSync(join(e,"vercel.json")))return "vercel";try{let t=JSON.parse(readFileSync(join(e,"package.json"),"utf-8")),n={...t.dependencies,...t.devDependencies};if(n["@netlify/functions"]||n["netlify-cli"])return "netlify";if(n.vercel||n["@vercel/node"])return "vercel"}catch{}return "node"}async function x(e){let t=process.cwd();if(process.env.VERCEL==="1"){await f(e);return}if(process.env.NETLIFY==="true"){await d(e);return}let n=J(t);if(console.log(`[lacis] Detected platform: ${n}`),await d(e),n==="node"){console.log("[lacis] Node mode: watching routes for changes...");return}let[r,s]=n==="netlify"?["netlify",["dev"]]:["vercel",["dev"]],c=spawn(r,s,{stdio:"inherit",shell:true,cwd:t});c.on("error",i=>{i.code==="ENOENT"?console.error(`[lacis] ${r} CLI not found. Install it with: ${n==="netlify"?"npm i -g netlify-cli":"npm i -g vercel"}`):console.error(`[lacis] Failed to start ${r} dev:`,i.message);});let o=i=>{process.on(i,()=>c.kill(i));};o("SIGINT"),o("SIGTERM");}function A(e){let t=e.slice(2),n=t[0]??"",r=t.indexOf("--routes"),s=r!==-1?t[r+1]:void 0,c=s?resolve(process.cwd(),s):resolve(process.cwd(),"routes"),o=t.indexOf("--entry"),i=o!==-1?t[o+1]:void 0;return {command:n,routesDir:c,entry:i}}function B(){console.log(`
7
+ ${T}`)}}else {let r=join(n,"node_modules",".bin","tsc");if(!existsSync(r))throw new Error("TypeScript not found. Add it to your project: npm install --save-dev typescript");let i=F(n)??"dist";await D(r,["--outDir",i],n);}}finally{await unlink(s).catch(()=>{});}console.log("[lacis] Build complete \u2192 dist/");}async function d(e){await f(e);let t=null;watch(e,{recursive:true},(n,o)=>{!o||o==="_manifest.ts"||(t&&clearTimeout(t),t=setTimeout(async()=>{console.log(`[lacis] Route changed: ${o}, regenerating manifest...`);try{await f(e);}catch(s){console.error("[lacis] Failed to regenerate manifest:",s);}},100));});}function A(e){if(existsSync(join(e,"netlify.toml")))return "netlify";if(existsSync(join(e,"vercel.json")))return "vercel";try{let t=JSON.parse(readFileSync(join(e,"package.json"),"utf-8")),n={...t.dependencies,...t.devDependencies};if(n["@netlify/functions"]||n["netlify-cli"])return "netlify";if(n.vercel||n["@vercel/node"])return "vercel"}catch{}return "node"}async function P(e){let t=process.cwd();if(process.env.VERCEL==="1"){await f(e);return}if(process.env.NETLIFY==="true"){await d(e);return}let n=A(t);if(console.log(`[lacis] Detected platform: ${n}`),await d(e),n==="node"){console.log("[lacis] Node mode: watching routes for changes...");return}let[o,s]=n==="netlify"?["netlify",["dev"]]:["vercel",["dev"]],c=spawn(o,s,{stdio:"inherit",shell:true,cwd:t});c.on("error",i=>{i.code==="ENOENT"?console.error(`[lacis] ${o} CLI not found. Install it with: ${n==="netlify"?"npm i -g netlify-cli":"npm i -g vercel"}`):console.error(`[lacis] Failed to start ${o} dev:`,i.message);});let r=i=>{process.on(i,()=>c.kill(i));};r("SIGINT"),r("SIGTERM");}function B(e){let t=e.slice(2),n=t[0]??"",o=t.indexOf("--routes"),s=o!==-1?t[o+1]:void 0,c=s?resolve(process.cwd(),s):resolve(process.cwd(),"routes"),r=t.indexOf("--entry"),i=r!==-1?t[r+1]:void 0;return {command:n,routesDir:c,entry:i}}function J(){console.log(`
8
8
  Usage: lacis <command> [options]
9
9
 
10
10
  Commands:
@@ -17,4 +17,4 @@ To scaffold a new project: npm create lacis@latest
17
17
  Options:
18
18
  --routes <dir> Path to routes directory (default: ./routes)
19
19
  --entry <file> Entry point for bundlers (default: auto-detected from package.json)
20
- `);}async function C(){let{command:e,routesDir:t,entry:n}=A(process.argv);switch(e){case "build":await b(t,n);break;case "watch":await d(t);break;case "dev":await x(t);break;default:B(),e&&(console.error(`Unknown command: ${e}`),process.exit(1));}}C().catch(e=>{console.error("[lacis]",e),process.exit(1);});
20
+ `);}async function C(){let{command:e,routesDir:t,entry:n}=B(process.argv);switch(e){case "build":await b(t,n);break;case "watch":await d(t);break;case "dev":await P(t);break;default:J(),e&&(console.error(`Unknown command: ${e}`),process.exit(1));}}C().catch(e=>{console.error("[lacis]",e),process.exit(1);});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lacis",
3
- "version": "0.2.7",
3
+ "version": "0.2.8",
4
4
  "description": "Zero-dependency TypeScript web framework",
5
5
  "license": "MIT",
6
6
  "repository": {