resora 0.1.8 → 0.1.9

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/bin/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import{copyFileSync as e,existsSync as t,mkdirSync as n,readFileSync as r,rmSync as i,writeFileSync as a}from"fs";import o,{dirname as s,join as c}from"path";import{createRequire as l}from"module";import{Command as u,Kernel as d}from"@h3ravel/musket";let f=o.resolve(process.cwd(),`node_modules/resora/stubs`);t(f)||(f=o.resolve(process.cwd(),`stubs`));const p=()=>({stubsDir:f,preferredCase:`camel`,paginatedExtras:[`meta`,`links`],paginatedLinks:{first:`first`,last:`last`,prev:`prev`,next:`next`},paginatedMeta:{to:`to`,from:`from`,links:`links`,path:`path`,total:`total`,per_page:`per_page`,last_page:`last_page`,current_page:`current_page`},resourcesDir:`src/resources`,stubs:{config:`resora.config.stub`,resource:`resource.stub`,collection:`resource.collection.stub`}}),m=(e={})=>{let t=p();return Object.assign(t,e,{stubs:Object.assign(t.stubs,e.stubs||{})})};var h=class{command;config={};constructor(e={}){this.config=m(e);let n=l(import.meta.url),r=[c(process.cwd(),`resora.config.ts`),c(process.cwd(),`resora.config.js`),c(process.cwd(),`resora.config.cjs`)];for(let e of r)if(t(e))try{let{default:t}=n(e);Object.assign(this.config,t);break}catch(t){console.error(`Error loading config file at ${e}:`,t)}}init(){let n=c(process.cwd(),`resora.config.js`),i=c(this.config.stubsDir,this.config.stubs.config);return t(n)&&!this.command.option(`force`)&&(this.command.error(`Error: ${n} already exists.`),process.exit(1)),this.ensureDirectory(n),t(n)&&this.command.option(`force`)&&e(n,n.replace(/\.js$/,`.backup.${Date.now()}.js`)),a(n,r(i,`utf-8`)),{path:n}}ensureDirectory(e){let r=s(e);t(r)||n(r,{recursive:!0})}generateFile(e,n,o,s){t(n)&&!s?.force?(this.command.error(`Error: ${n} already exists.`),process.exit(1)):t(n)&&s?.force&&i(n);let c=r(e,`utf-8`);for(let[e,t]of Object.entries(o))c=c.replace(RegExp(`{{${e}}}`,`g`),t);return this.ensureDirectory(n),a(n,c),n}makeResource(e,n){let r=e;n?.collection&&!e.endsWith(`Collection`)&&!e.endsWith(`Resource`)?r+=`Collection`:!n?.collection&&!e.endsWith(`Resource`)&&!e.endsWith(`Collection`)&&(r+=`Resource`);let i=`${r}.ts`,a=c(this.config.resourcesDir,i),o=c(this.config.stubsDir,n?.collection||e.endsWith(`Collection`)?this.config.stubs.collection:this.config.stubs.resource);t(o)||(this.command.error(`Error: Stub file ${o} not found.`),process.exit(1));let s=r.replace(/(Resource|Collection)$/,``)+`Resource`,l=`/**
2
+ import{copyFileSync as e,existsSync as t,mkdirSync as n,readFileSync as r,rmSync as i,writeFileSync as a}from"fs";import o,{dirname as s,join as c}from"path";import{createRequire as l}from"module";import{Command as u,Kernel as d}from"@h3ravel/musket";let f=o.resolve(process.cwd(),`node_modules/resora/stubs`);t(f)||(f=o.resolve(process.cwd(),`stubs`));const p=()=>({stubsDir:f,preferredCase:`camel`,paginatedExtras:[`meta`,`links`],paginatedLinks:{first:`first`,last:`last`,prev:`prev`,next:`next`},paginatedMeta:{to:`to`,from:`from`,links:`links`,path:`path`,total:`total`,per_page:`per_page`,last_page:`last_page`,current_page:`current_page`},resourcesDir:`src/resources`,stubs:{config:`resora.config.stub`,resource:`resource.stub`,collection:`resource.collection.stub`}}),m=(e={})=>{let t=p();return Object.assign(t,e,{stubs:Object.assign(t.stubs,e.stubs||{})})};var h=class{command;config={};constructor(e={}){this.config=m(e)}async loadConfig(e={}){this.config=m(e);let n=l(import.meta.url),r=[c(process.cwd(),`resora.config.ts`),c(process.cwd(),`resora.config.js`),c(process.cwd(),`resora.config.cjs`)];for(let e of r)if(t(e))try{let{default:t}=n(e);Object.assign(this.config,t);break}catch(t){console.error(`Error loading config file at ${e}:`,t)}return this}init(){let n=c(process.cwd(),`resora.config.js`),i=c(this.config.stubsDir,this.config.stubs.config);return t(n)&&!this.command.option(`force`)&&(this.command.error(`Error: ${n} already exists.`),process.exit(1)),this.ensureDirectory(n),t(n)&&this.command.option(`force`)&&e(n,n.replace(/\.js$/,`.backup.${Date.now()}.js`)),a(n,r(i,`utf-8`)),{path:n}}ensureDirectory(e){let r=s(e);t(r)||n(r,{recursive:!0})}generateFile(e,n,o,s){t(n)&&!s?.force?(this.command.error(`Error: ${n} already exists.`),process.exit(1)):t(n)&&s?.force&&i(n);let c=r(e,`utf-8`);for(let[e,t]of Object.entries(o))c=c.replace(RegExp(`{{${e}}}`,`g`),t);return this.ensureDirectory(n),a(n,c),n}makeResource(e,n){let r=e;n?.collection&&!e.endsWith(`Collection`)&&!e.endsWith(`Resource`)?r+=`Collection`:!n?.collection&&!e.endsWith(`Resource`)&&!e.endsWith(`Collection`)&&(r+=`Resource`);let i=`${r}.ts`,a=c(this.config.resourcesDir,i),o=c(this.config.stubsDir,n?.collection||e.endsWith(`Collection`)?this.config.stubs.collection:this.config.stubs.resource);t(o)||(this.command.error(`Error: Stub file ${o} not found.`),process.exit(1));let s=r.replace(/(Resource|Collection)$/,``)+`Resource`,l=`/**
3
3
  * The resource that this collection collects.
4
4
  */
5
5
  collects = ${s}
@@ -26,4 +26,4 @@ import{copyFileSync as e,existsSync as t,mkdirSync as n,readFileSync as r,rmSync
26
26
  | _ // _ \/ __|/ _ \| '__/ _, |
27
27
  | | \ \ __/\__ \ (_) | | | (_| |
28
28
  |_| \_\___||___/\___/|_| \__,_|
29
- `;const y=new h;await d.init(y,{logo:v,name:`Resora CLI`,baseCommands:[_,g],exceptionHandler(e){throw e}});export{};
29
+ `;const y=new h;await d.init(await y.loadConfig(),{logo:v,name:`Resora CLI`,baseCommands:[_,g],exceptionHandler(e){throw e}});export{};
package/dist/index.cjs CHANGED
@@ -94,6 +94,9 @@ var CliApp = class {
94
94
  config = {};
95
95
  constructor(config = {}) {
96
96
  this.config = defineConfig(config);
97
+ }
98
+ async loadConfig(config = {}) {
99
+ this.config = defineConfig(config);
97
100
  const require = (0, module$1.createRequire)(require("url").pathToFileURL(__filename).href);
98
101
  const possibleConfigPaths = [
99
102
  (0, path.join)(process.cwd(), "resora.config.ts"),
@@ -107,6 +110,7 @@ var CliApp = class {
107
110
  } catch (e) {
108
111
  console.error(`Error loading config file at ${configPath}:`, e);
109
112
  }
113
+ return this;
110
114
  }
111
115
  /**
112
116
  * Initialize Resora by creating a default config file in the current directory
package/dist/index.d.cts CHANGED
@@ -229,6 +229,7 @@ declare class CliApp {
229
229
  command: Command;
230
230
  protected config: Config;
231
231
  constructor(config?: Partial<Config>);
232
+ loadConfig(config?: Partial<Config>): Promise<this>;
232
233
  /**
233
234
  * Initialize Resora by creating a default config file in the current directory
234
235
  *
package/dist/index.d.mts CHANGED
@@ -229,6 +229,7 @@ declare class CliApp {
229
229
  command: Command;
230
230
  protected config: Config;
231
231
  constructor(config?: Partial<Config>);
232
+ loadConfig(config?: Partial<Config>): Promise<this>;
232
233
  /**
233
234
  * Initialize Resora by creating a default config file in the current directory
234
235
  *
package/dist/index.mjs CHANGED
@@ -65,6 +65,9 @@ var CliApp = class {
65
65
  config = {};
66
66
  constructor(config = {}) {
67
67
  this.config = defineConfig(config);
68
+ }
69
+ async loadConfig(config = {}) {
70
+ this.config = defineConfig(config);
68
71
  const require = createRequire(import.meta.url);
69
72
  const possibleConfigPaths = [
70
73
  join(process.cwd(), "resora.config.ts"),
@@ -78,6 +81,7 @@ var CliApp = class {
78
81
  } catch (e) {
79
82
  console.error(`Error loading config file at ${configPath}:`, e);
80
83
  }
84
+ return this;
81
85
  }
82
86
  /**
83
87
  * Initialize Resora by creating a default config file in the current directory
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "resora",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "A structured API response layer for Node.js and TypeScript with automatic JSON responses, collection support, and pagination handling.",
5
5
  "keywords": [
6
6
  "api",