UNPKG

@mango-js/scripts

Version:

Scripts required for building and testing Mango applications

5 lines (4 loc) 909 B
import r from"fs";import n from"path";import i from"serve-handler";import c from"http";import o from"chalk";import{execSync as d,spawnSync as p}from"child_process";const a=process.cwd(),e=n.join(a,"dist");r.existsSync(e)||(console.error(o.red.bold("\u2716 \u{1F6A8} No dist directory found")),process.exit(1));const t=n.join(e,"server.js");r.existsSync(t)?(console.log(o.yellow.bold(`\u{1F4E6} Installing dependencies... `)),d("npm install",{cwd:e}),console.log(o.yellow.bold(`\u231B Starting Mango production server... `)),console.log(o.green.bold("\u2705 Server running at http://localhost:3000")),p("node",[t],{cwd:e,shell:!0,stdio:"inherit"})):c.createServer((s,l)=>i(s,l,{public:e,rewrites:[{source:"**",destination:"/index.html"}]})).listen(3e3,()=>{console.log(o.yellow.bold(`\u231B Starting Mango production server... `)),console.log(o.green.bold("\u2705 Server running at http://localhost:3000"))});