dashnex 0.5.51 → 0.5.53

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.
@@ -1 +1 @@
1
- import e from"chalk";import t from"fs-extra";import o from"path";import r from"os";import{spawn as n}from"child_process";import i from"inquirer";import a from"adm-zip";import{debug as s,debugError as l}from"../../lib/debug.js";import{getBusinessApiBase as c}from"../../lib/api.js";import{ensureLoggedIn as d}from"../../services/auth.js";import{createSpinner as p}from"../../lib/spinner.js";import{isUserInterrupt as m,INTERRUPTED_MESSAGE as u}from"../../lib/errors.js";const f=(e,t,o)=>new Promise((r,i)=>{const a=n(t,{cwd:e,shell:!0,stdio:"inherit",env:o?{...process.env,...o}:void 0});a.on("error",e=>{l(e),i(e)}),a.on("close",e=>{r(null===e?0:e)})}),h=async(t,r)=>{const{install:a}=await i.prompt([{type:"confirm",name:"install",message:"Install dependencies?",default:!0}]);if(!a){if(o.resolve(t)!==o.resolve(r)){const n=o.relative(r,t);console.log(e.cyan(`Run "cd ${n}" to change to the application folder.`))}return}const c=await(async()=>{const e=e=>new Promise(t=>{const o=n(e,["--version"],{stdio:"ignore",shell:!0});o.on("error",()=>t(!1)),o.on("close",e=>t(0===e))});return await e("pnpm")?"pnpm":(await e("npm"),"npm")})();s(`Running ${c} install in ${t}`);try{const e=await f(t,`${c} install`,{NPM_CONFIG_LOGLEVEL:"error"});if(0!==e)return void s(`${c} install exited with code ${e}`)}catch(m){return l(m),void console.error(e.red(`Failed to run ${c} install.`))}const{migrate:d}=await i.prompt([{type:"confirm",name:"migrate",message:"Create or update database?",default:!0}]);if(!d)return;s(`Running dashnex db migrate in ${t}`);try{const e=await f(t,"dashnex db migrate");if(0!==e)return void s(`dashnex db migrate exited with code ${e}`)}catch(m){return l(m),void console.error(e.red("Failed to run dashnex db migrate."))}const{dev:p}=await i.prompt([{type:"confirm",name:"dev",message:"Run development server?",default:!0}]);if(p){s(`Running npm run dev in ${t}`);try{await f(t,"npm run dev")}catch(m){l(m),console.error(e.red("Failed to run dev server."))}}};class g{async execute(n={}){s("Pull flow started");const f=await d();if(!f)return;const g=process.cwd();let w;if(n.folder)w=n.folder.trim()||".",s(`Folder argument provided: ${w}`);else{s("No folder argument, prompting user");const{folder:e}=await i.prompt([{type:"input",name:"folder",message:"Which folder to pull the application to?",default:"."}]);w=e.trim()||"."}const v=o.resolve(g,w);s(`Target folder resolved: ${v}`);const y=await t.pathExists(v);let x=!1;if(y)try{x=(await t.readdir(v)).length>0,s(`Folder exists: ${y}, has files: ${x}`)}catch(R){s(`Error reading folder: ${R}`)}if(x&&!n.yes){const{confirm:t}=await i.prompt([{type:"confirm",name:"confirm",message:"Existing files will be overwritten. Continue?",default:!0}]);if(!t)return s("User declined confirmation, exiting"),void console.log(e.yellow("Pull cancelled."));s("User confirmed overwrite")}await t.ensureDir(v),s(`Target folder ensured: ${v}`);const $=`${c()}/business/v1/cli/pull`;s(`GET ${$}`);const b=o.join(r.tmpdir(),`dashnex-pull-${Date.now()}-${Math.random().toString(36).slice(2)}.zip`),E=p();E.start("Pulling application...");try{const r=await fetch($,{headers:{Authorization:`Bearer ${f.token}`}});if(s(`Response: ${r.status}`),!r.ok){E.stop();const t=r.headers.get("content-type")??"";let o="Failed to pull application.";if(401===r.status||403===r.status)o="Please run 'dashnex login' to authenticate.";else if(404===r.status)o="Business has no application. Run 'dashnex app create' to create one.";else if(t.includes("application/json")){const e=(e=>"string"==typeof e.error?e.error:"string"==typeof e.message?e.message:void 0)(await r.json().catch(()=>({})));e&&(o=e)}console.error(e.red(o)),process.exit(1)}E.text("Downloading...");const i=Buffer.from(await r.arrayBuffer());await t.writeFile(b,i),s("Zip written to temp file"),E.text("Extracting...");new a(b).extractAllTo(v,!0),E.stop(),s("Extracted to target folder"),o.resolve(v)!==o.resolve(g)?(console.log(e.green(((e,t)=>o.resolve(e)===o.resolve(t)?`Application is successfully pulled. Run "cd ${e}" to change to the application folder and then "dashnex app install" to install dependencies and then "dashnex app dev" to run it`:`Application is successfully pulled into ${o.relative(t,e)}.`)(v,g))),process.chdir(v),s(`Changed working directory to ${v}`)):console.log(e.green(`Application is successfully pulled. Run "cd ${v}" to change to the application folder and then "dashnex app install" to install dependencies and then "dashnex app dev" to run it`)),n.yes?s("CI mode (--yes), skipping post-pull child commands"):await h(v,g)}catch(R){if(E.stop(),l(R),R instanceof Error&&R.message.startsWith("EXIT:"))throw R;if(m(R))return void console.log(e.yellow(u));console.error(e.red("Could not reach DashNex API. Check your connection and try again.")),process.exit(1)}finally{await t.remove(b).catch(()=>{}),s("Temp zip removed")}}}export{g as PullCommand};
1
+ import e from"chalk";import t from"fs-extra";import o from"path";import r from"os";import{spawn as i}from"child_process";import n from"inquirer";import a from"adm-zip";import{debug as s,debugError as l}from"../../lib/debug.js";import{getBusinessApiBase as c}from"../../lib/api.js";import{ensureLoggedIn as d}from"../../services/auth.js";import{createSpinner as p}from"../../lib/spinner.js";import{isUserInterrupt as m,INTERRUPTED_MESSAGE as f}from"../../lib/errors.js";import{runInstallInDir as u}from"../install.js";import{runDevInDir as h}from"../dev.js";const g=async(t,r)=>{const{install:a}=await n.prompt([{type:"confirm",name:"install",message:"Install dependencies?",default:!0}]);if(!a){if(o.resolve(t)!==o.resolve(r)){const i=o.relative(r,t);console.log(e.cyan(`Run "cd ${i}" to change to the application folder.`))}return}try{const e=await u(t);if(0!==e)return void s(`install exited with code ${e}`)}catch(p){return l(p),void console.error(e.red(p instanceof Error?p.message:"Failed to run install."))}const{migrate:c}=await n.prompt([{type:"confirm",name:"migrate",message:"Create or update database?",default:!0}]);if(!c)return;s(`Running dashnex db migrate in ${t}`);try{const e=await((e,t)=>new Promise((o,r)=>{const n=i(t,{cwd:e,shell:!0,stdio:"inherit",env:void 0});n.on("error",e=>{l(e),r(e)}),n.on("close",e=>{o(null===e?0:e)})}))(t,"dashnex db migrate");if(0!==e)return void s(`dashnex db migrate exited with code ${e}`)}catch(p){return l(p),void console.error(e.red("Failed to run dashnex db migrate."))}const{dev:d}=await n.prompt([{type:"confirm",name:"dev",message:"Run development server?",default:!0}]);if(d)try{await h(t)}catch(p){l(p),console.error(e.red(p instanceof Error?p.message:"Failed to run dev server."))}};class w{async execute(i={}){s("Pull flow started");const u=await d();if(!u)return;const h=process.cwd();let w;if(i.folder)w=i.folder.trim()||".",s(`Folder argument provided: ${w}`);else{s("No folder argument, prompting user");const{folder:e}=await n.prompt([{type:"input",name:"folder",message:"Which folder to pull the application to?",default:"."}]);w=e.trim()||"."}const v=o.resolve(h,w);s(`Target folder resolved: ${v}`);const y=await t.pathExists(v);let x=!1;if(y)try{x=(await t.readdir(v)).length>0,s(`Folder exists: ${y}, has files: ${x}`)}catch(E){s(`Error reading folder: ${E}`)}if(x&&!i.yes){const{confirm:t}=await n.prompt([{type:"confirm",name:"confirm",message:"Existing files will be overwritten. Continue?",default:!0}]);if(!t)return s("User declined confirmation, exiting"),void console.log(e.yellow("Pull cancelled."));s("User confirmed overwrite")}await t.ensureDir(v),s(`Target folder ensured: ${v}`);const $=`${c()}/business/v1/cli/pull`;s(`GET ${$}`);const b=o.join(r.tmpdir(),`dashnex-pull-${Date.now()}-${Math.random().toString(36).slice(2)}.zip`),j=p();j.start("Pulling application...");try{const r=await fetch($,{headers:{Authorization:`Bearer ${u.token}`}});if(s(`Response: ${r.status}`),!r.ok){j.stop();const t=r.headers.get("content-type")??"";let o="Failed to pull application.";if(401===r.status||403===r.status)o="Please run 'dashnex login' to authenticate.";else if(404===r.status)o="Business has no application. Run 'dashnex app create' to create one.";else if(t.includes("application/json")){const e=(e=>"string"==typeof e.error?e.error:"string"==typeof e.message?e.message:void 0)(await r.json().catch(()=>({})));e&&(o=e)}console.error(e.red(o)),process.exit(1)}j.text("Downloading...");const n=Buffer.from(await r.arrayBuffer());await t.writeFile(b,n),s("Zip written to temp file"),j.text("Extracting...");new a(b).extractAllTo(v,!0),j.stop(),s("Extracted to target folder"),o.resolve(v)!==o.resolve(h)?(console.log(e.green(((e,t)=>o.resolve(e)===o.resolve(t)?`Application is successfully pulled. Run "cd ${e}" to change to the application folder and then "dashnex app install" to install dependencies and then "dashnex app dev" to run it`:`Application is successfully pulled into ${o.relative(t,e)}.`)(v,h))),process.chdir(v),s(`Changed working directory to ${v}`)):console.log(e.green(`Application is successfully pulled. Run "cd ${v}" to change to the application folder and then "dashnex app install" to install dependencies and then "dashnex app dev" to run it`)),i.yes?s("CI mode (--yes), skipping post-pull child commands"):await g(v,h)}catch(E){if(j.stop(),l(E),E instanceof Error&&E.message.startsWith("EXIT:"))throw E;if(m(E))return void console.log(e.yellow(f));console.error(e.red("Could not reach DashNex API. Check your connection and try again.")),process.exit(1)}finally{await t.remove(b).catch(()=>{}),s("Temp zip removed")}}}export{w as PullCommand};
@@ -1 +1 @@
1
- import{spawn as e}from"child_process";import o from"path";import s from"fs-extra";import r from"chalk";import{debug as n,debugError as t}from"../lib/debug.js";class a{async execute(a={}){n("Dev flow started");const i=process.cwd(),c=o.join(i,"dashnex.json"),p=o.join(i,"package.json");let l;n(`Checking for dashnex.json at: ${c}`),await s.pathExists(c)||(console.error(r.red("This is not a DashNex project.")),process.exit(1)),n("dashnex.json found, checking for package.json"),await s.pathExists(p)||(console.error(r.red("package.json is missing.")),process.exit(1)),n("package.json found, checking for dev script");try{l=await s.readJson(p)}catch(v){t(v),console.error(r.red("Failed to read package.json.")),process.exit(1)}l.scripts&&l.scripts.dev||(console.error(r.red('The "dev" script is missing from package.json. Please add a "dev" script to package.json.')),process.exit(1)),n("dev script found, checking for npm availability");const d=await(async o=>new Promise(s=>{const r=e(`${o} --version`,{stdio:"ignore",shell:!0});r.on("error",()=>{s(!1)}),r.on("close",e=>{s(0===e)})}))("npm");n(`npm available: ${d}`),d||(console.error(r.red("npm is not available. Please install npm to continue.")),process.exit(1));const m=a.https?["--","--experimental-https"]:[];let h;n("npm available, executing: npm run dev"+(a.https?" -- --experimental-https":""));try{h=await(async(o,s=[])=>{const r=s.length?`${o} ${s.join(" ")}`:o;return new Promise((o,s)=>{const n=e(r,{stdio:"inherit",cwd:process.cwd(),shell:!0,env:{...process.env,NODE_ENV:"development"}});n.on("error",e=>{t(e),s(e)}),n.on("close",e=>{o(null===e?0:e)})})})("npm run dev",m)}catch(v){return t(v),v instanceof Error?console.error(r.red(`Failed to run npm run dev: ${v.message}`)):console.error(r.red("Failed to run npm run dev")),void process.exit(1)}process.exit(h)}}export{a as DevCommand};
1
+ import{spawn as e}from"child_process";import t from"path";import r from"fs-extra";import s from"chalk";import{debug as n,debugError as o}from"../lib/debug.js";const i=["Using vars defined in \\.env","\\(node:\\d+\\) MaxListenersExceededWarning:","\\(Use `node --trace-warnings"],a=(e,t)=>t.length>0&&t.some(t=>t.test(e)),c=(e,t)=>{let r="";return{write:s=>{const n="string"==typeof s?s:s.toString();r+=n;const o=r.split(/\r?\n/);r=o.pop()??"";for(const r of o)a(r,t)||e.write(r+"\n")},flush:()=>{r&&!a(r,t)&&e.write(r),r=""}}},p=async(s,a={})=>{const p=t.join(s,"dashnex.json"),d=t.join(s,"package.json");if(n(`Checking for dashnex.json at: ${p}`),!(await r.pathExists(p)))throw new Error("This is not a DashNex project.");if(n("dashnex.json found, checking for package.json"),!(await r.pathExists(d)))throw new Error("package.json is missing.");let l;n("package.json found, checking for dev script");try{l=await r.readJson(d)}catch(m){throw o(m),new Error("Failed to read package.json.")}if(!l.scripts||!l.scripts.dev)throw new Error('The "dev" script is missing from package.json. Please add a "dev" script to package.json.');n("dev script found, checking for npm availability");const h=await(async t=>new Promise(r=>{const s=e(`${t} --version`,{stdio:"ignore",shell:!0});s.on("error",()=>{r(!1)}),s.on("close",e=>{r(0===e)})}))("npm");if(n(`npm available: ${h}`),!h)throw new Error("npm is not available. Please install npm to continue.");const f=a.https?["--","--experimental-https"]:[];n(`npm available, executing: npm run dev in ${s}${a.https?" -- --experimental-https":""}`);return(async(t,r=[],s=process.cwd(),n=[])=>{const i=r.length?`${t} ${r.join(" ")}`:t,a=n.length>0;return new Promise((t,r)=>{const p=e(i,{stdio:a?["inherit","pipe","pipe"]:"inherit",cwd:s,shell:!0,env:{...process.env,NODE_ENV:"development"}});if(p.on("error",e=>{o(e),r(e)}),a&&p.stdout&&p.stderr){const e=c(process.stdout,n),r=c(process.stderr,n);p.stdout.on("data",t=>e.write(t)),p.stderr.on("data",e=>r.write(e)),p.on("close",s=>{e.flush(),r.flush(),t(null===s?0:s)})}else p.on("close",e=>{t(null===e?0:e)})})})("npm run dev",f,s,(()=>{const e=[];for(const t of i)try{e.push(new RegExp(t))}catch{n(`Invalid dev output filter pattern ignored: ${t}`)}return e})())};class d{async execute(e={}){n("Dev flow started");try{const t=await p(process.cwd(),e);process.exit(t)}catch(t){if(t instanceof Error&&t.message.startsWith("EXIT:"))throw t;o(t),t instanceof Error?console.error(s.red(t.message)):console.error(s.red("Failed to run npm run dev")),process.exit(1)}}}export{d as DevCommand,p as runDevInDir};
@@ -1 +1 @@
1
- import{spawn as e}from"child_process";import n from"chalk";import{debug as o,debugError as r}from"../lib/debug.js";const s=async n=>new Promise(o=>{const r=e(`${n} --version`,{stdio:"ignore",shell:!0});r.on("error",()=>{o(!1)}),r.on("close",e=>{o(0===e)})});class t{async execute(){o("Install flow started");let t=null,a=null;o("Checking for pnpm availability");const l=await s("pnpm");if(o(`pnpm available: ${l}`),l)t="pnpm",a="pnpm";else{o("pnpm not available, checking for npm");const e=await s("npm");o(`npm available: ${e}`),e&&(t="npm",a="npm")}t&&a||(console.error(n.red("Neither pnpm nor npm is available. Please install pnpm (recommended) or npm to continue.")),process.exit(1)),o(`Using package manager: ${t}`),o(`Executing: ${a} install`);try{const n=await(async n=>new Promise((o,s)=>{const t=[],a=[],l=e(`${n} install`,{stdio:["ignore","pipe","pipe"],cwd:process.cwd(),shell:!0,env:{...process.env,NPM_CONFIG_LOGLEVEL:"error"}});l.stdout&&l.stdout.on("data",e=>t.push(e)),l.stderr&&l.stderr.on("data",e=>a.push(e)),l.on("error",e=>{r(e),s(e)}),l.on("close",e=>{const n=null===e?0:e;0!==n&&(t.length&&process.stdout.write(Buffer.concat(t)),a.length&&process.stderr.write(Buffer.concat(a))),o(n)})}))(a);process.exit(n)}catch(i){r(i),i instanceof Error?console.error(n.red(`Failed to run ${a} install: ${i.message}`)):console.error(n.red(`Failed to run ${a} install`)),process.exit(1)}}}export{t as InstallCommand};
1
+ import{spawn as e}from"child_process";import r from"chalk";import{debug as o,debugError as s}from"../lib/debug.js";const n=async r=>new Promise(o=>{const s=e(`${r} --version`,{stdio:"ignore",shell:!0});s.on("error",()=>{o(!1)}),s.on("close",e=>{o(0===e)})}),t=async r=>{const t=await(async()=>await n("pnpm")?"pnpm":await n("npm")?"npm":null)();if(!t)throw new Error("Neither pnpm nor npm is available. Please install pnpm (recommended) or npm to continue.");return o(`Using package manager: ${t}`),o(`Executing: ${t} install in ${r}`),new Promise((o,n)=>{const a=[],c=[],i=e(`${t} install`,{stdio:["ignore","pipe","pipe"],cwd:r,shell:!0,env:{...process.env,NPM_CONFIG_LOGLEVEL:"error"}});i.stdout&&i.stdout.on("data",e=>a.push(e)),i.stderr&&i.stderr.on("data",e=>c.push(e)),i.on("error",e=>{s(e),n(e)}),i.on("close",e=>{const r=null===e?0:e;0!==r&&(a.length&&process.stdout.write(Buffer.concat(a)),c.length&&process.stderr.write(Buffer.concat(c))),o(r)})})};class a{async execute(){o("Install flow started");try{const e=await t(process.cwd());process.exit(e)}catch(e){s(e),e instanceof Error?console.error(r.red(e.message)):console.error(r.red("Failed to run install")),process.exit(1)}}}export{a as InstallCommand,t as runInstallInDir};
@@ -1 +1 @@
1
- const e="@dashnex/cli",a="0.5.51",n="Command-line interface for DashNex framework",o={name:e,version:a,description:n};export{o as default,n as description,e as name,a as version};
1
+ const e="@dashnex/cli",a="0.5.53",n="Command-line interface for DashNex framework",o={name:e,version:a,description:n};export{o as default,n as description,e as name,a as version};
@@ -2,6 +2,14 @@ import { CliCommand } from '@dashnex/types';
2
2
  export interface DevCommandOptions {
3
3
  https?: boolean;
4
4
  }
5
+ /**
6
+ * Run dev server in the given directory. Single source of truth for dev logic.
7
+ * @param cwd - Directory (project root) to run dev in
8
+ * @param options - Dev options (e.g. https)
9
+ * @returns Exit code (0 = success)
10
+ * @throws When not a DashNex project, package.json missing, no dev script, or npm unavailable
11
+ */
12
+ export declare const runDevInDir: (cwd: string, options?: DevCommandOptions) => Promise<number>;
5
13
  export declare class DevCommand implements CliCommand {
6
14
  execute(options?: DevCommandOptions): Promise<void>;
7
15
  }
@@ -1,4 +1,11 @@
1
1
  import { CliCommand } from '@dashnex/types';
2
+ /**
3
+ * Run install in the given directory. Single source of truth for install logic.
4
+ * @param cwd - Directory to run install in
5
+ * @returns Exit code (0 = success)
6
+ * @throws When no package manager (pnpm/npm) is available
7
+ */
8
+ export declare const runInstallInDir: (cwd: string) => Promise<number>;
2
9
  export declare class InstallCommand implements CliCommand {
3
10
  execute(): Promise<void>;
4
11
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "dashnex",
4
- "version": "0.5.51",
4
+ "version": "0.5.53",
5
5
  "description": "Command-line interface for DashNex framework",
6
6
  "homepage": "https://dashnex.io",
7
7
  "type": "module",