resora 0.1.5 → 0.1.7
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 +7 -5
- package/dist/index.cjs +21 -2
- package/dist/index.d.cts +49 -4
- package/dist/index.d.mts +49 -4
- package/dist/index.mjs +21 -2
- package/package.json +1 -1
- package/stubs/resora.config.stub +5 -0
package/bin/index.mjs
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import e,
|
|
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{fileURLToPath as u}from"url";import{Command as d,Kernel as f}from"@h3ravel/musket";const p=o.dirname(u(import.meta.url));let m=o.resolve(p,`../node_modules/resora/stubs`);t(m)||(m=o.resolve(p,`../stubs`));const h=(e={})=>Object.assign({resourcesDir:`src/resources`,stubsDir:m,stubs:{config:`resora.config.stub`,resource:`resource.stub`,collection:`resource.collection.stub`}},e,{stubs:Object.assign({config:`resora.config.stub`,resource:`resource.stub`,collection:`resource.collection.stub`},e.stubs||{})});var g=class{command;config={};constructor(e={}){this.config=h(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,h(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=`/**
|
|
3
3
|
* The resource that this collection collects.
|
|
4
4
|
*/
|
|
5
|
-
collects = ${
|
|
6
|
-
`,u=`import ${
|
|
5
|
+
collects = ${s}
|
|
6
|
+
`,u=`import ${s} from './${s}'\n`,d=(!!n?.collection||e.endsWith(`Collection`))&&t(c(this.config.resourcesDir,`${s}.ts`)),f=this.generateFile(o,a,{ResourceName:r,CollectionResourceName:r.replace(/(Resource|Collection)$/,``)+`Resource`,"collects = Resource":d?l:``,"import = Resource":d?u:``},n);return{name:r,path:f}}},_=class extends d{signature=`init
|
|
7
|
+
{--force : Force overwrite if config file already exists (existing file will be backed up) }
|
|
8
|
+
`;description=`Initialize Resora`;async handle(){this.app.command=this,this.app.init(),this.success(`Resora initialized`)}},v=class extends d{signature=`#create:
|
|
7
9
|
{resource : Generates a new resource file.
|
|
8
10
|
| {name : Name of the resource to create}
|
|
9
11
|
| {--c|collection : Make a resource collection}
|
|
@@ -17,11 +19,11 @@ import e,{dirname as t,join as n}from"path";import{existsSync as r,mkdirSync as
|
|
|
17
19
|
| {prefix : prefix of the resources to create, "Admin" will create AdminResource, AdminCollection}
|
|
18
20
|
| {--force : Create the resource or collection file even if it already exists.}
|
|
19
21
|
}
|
|
20
|
-
`;description=`Create a new resource or resource collection file`;async handle(){this.app.command=this;let e=``,t=this.dictionary.name||this.dictionary.baseCommand;if([`resource`,`collection`].includes(t)&&!this.argument(`name`))return void this.error(`Error: Name argument is required.`);if(t===`all`&&!this.argument(`prefix`))return void this.error(`Error: Prefix argument is required.`);switch(t){case`resource`:({path:e}=this.app.makeResource(this.argument(`name`),this.options()));break;case`collection`:({path:e}=this.app.makeResource(this.argument(`name`)+`Collection`,this.options()));break;case`all`:{let t=this.app.makeResource(this.argument(`prefix`),{force:this.option(`force`)}),n=this.app.makeResource(this.argument(`prefix`)+`Collection`,{collection:!0,force:this.option(`force`)});e=`${t.path}, ${n.path}`;break}default:this.fail(`Unknown action: ${t}`)}this.success(`Created: ${e}`)}},
|
|
22
|
+
`;description=`Create a new resource or resource collection file`;async handle(){this.app.command=this;let e=``,t=this.dictionary.name||this.dictionary.baseCommand;if([`resource`,`collection`].includes(t)&&!this.argument(`name`))return void this.error(`Error: Name argument is required.`);if(t===`all`&&!this.argument(`prefix`))return void this.error(`Error: Prefix argument is required.`);switch(t){case`resource`:({path:e}=this.app.makeResource(this.argument(`name`),this.options()));break;case`collection`:({path:e}=this.app.makeResource(this.argument(`name`)+`Collection`,this.options()));break;case`all`:{let t=this.app.makeResource(this.argument(`prefix`),{force:this.option(`force`)}),n=this.app.makeResource(this.argument(`prefix`)+`Collection`,{collection:!0,force:this.option(`force`)});e=`${t.path}, ${n.path}`;break}default:this.fail(`Unknown action: ${t}`)}this.success(`Created: ${e}`)}},y=String.raw`
|
|
21
23
|
_____
|
|
22
24
|
| __ \
|
|
23
25
|
| |__) |___ ___ ___ _ __ __ _
|
|
24
26
|
| _ // _ \/ __|/ _ \| '__/ _, |
|
|
25
27
|
| | \ \ __/\__ \ (_) | | | (_| |
|
|
26
28
|
|_| \_\___||___/\___/|_| \__,_|
|
|
27
|
-
`;const
|
|
29
|
+
`;const b=new g;await f.init(b,{logo:y,name:`Resora CLI`,baseCommands:[v,_],exceptionHandler(e){throw e}});export{};
|
package/dist/index.cjs
CHANGED
|
@@ -26,9 +26,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
}) : target, mod));
|
|
27
27
|
|
|
28
28
|
//#endregion
|
|
29
|
+
let fs = require("fs");
|
|
29
30
|
let path = require("path");
|
|
30
31
|
path = __toESM(path);
|
|
31
|
-
let fs = require("fs");
|
|
32
32
|
let module$1 = require("module");
|
|
33
33
|
let url = require("url");
|
|
34
34
|
let _h3ravel_musket = require("@h3ravel/musket");
|
|
@@ -60,17 +60,19 @@ const defineConfig = (userConfig = {}) => {
|
|
|
60
60
|
resourcesDir: "src/resources",
|
|
61
61
|
stubsDir,
|
|
62
62
|
stubs: {
|
|
63
|
+
config: "resora.config.stub",
|
|
63
64
|
resource: "resource.stub",
|
|
64
65
|
collection: "resource.collection.stub"
|
|
65
66
|
}
|
|
66
67
|
}, userConfig, { stubs: Object.assign({
|
|
68
|
+
config: "resora.config.stub",
|
|
67
69
|
resource: "resource.stub",
|
|
68
70
|
collection: "resource.collection.stub"
|
|
69
71
|
}, userConfig.stubs || {}) });
|
|
70
72
|
};
|
|
71
73
|
|
|
72
74
|
//#endregion
|
|
73
|
-
//#region src/cli/
|
|
75
|
+
//#region src/cli/CliApp.ts
|
|
74
76
|
var CliApp = class {
|
|
75
77
|
command;
|
|
76
78
|
config = {};
|
|
@@ -91,6 +93,23 @@ var CliApp = class {
|
|
|
91
93
|
}
|
|
92
94
|
}
|
|
93
95
|
/**
|
|
96
|
+
* Initialize Resora by creating a default config file in the current directory
|
|
97
|
+
*
|
|
98
|
+
* @returns
|
|
99
|
+
*/
|
|
100
|
+
init() {
|
|
101
|
+
const outputPath = (0, path.join)(process.cwd(), "resora.config.js");
|
|
102
|
+
const stubPath = (0, path.join)(this.config.stubsDir, this.config.stubs.config);
|
|
103
|
+
if ((0, fs.existsSync)(outputPath) && !this.command.option("force")) {
|
|
104
|
+
this.command.error(`Error: ${outputPath} already exists.`);
|
|
105
|
+
process.exit(1);
|
|
106
|
+
}
|
|
107
|
+
this.ensureDirectory(outputPath);
|
|
108
|
+
if ((0, fs.existsSync)(outputPath) && this.command.option("force")) (0, fs.copyFileSync)(outputPath, outputPath.replace(/\.js$/, `.backup.${Date.now()}.js`));
|
|
109
|
+
(0, fs.writeFileSync)(outputPath, (0, fs.readFileSync)(stubPath, "utf-8"));
|
|
110
|
+
return { path: outputPath };
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
94
113
|
* Utility to ensure directory exists
|
|
95
114
|
*
|
|
96
115
|
* @param filePath
|
package/dist/index.d.cts
CHANGED
|
@@ -165,17 +165,21 @@ interface Cursor {
|
|
|
165
165
|
}
|
|
166
166
|
interface Config {
|
|
167
167
|
/**
|
|
168
|
-
* @description The directory where resource files are stored. This is the location where the generated resource files will be saved. It should be a valid path on the file system.
|
|
168
|
+
* @description The directory where resource files are stored. This is the location where the generated resource files will be saved. It should be a valid path on the file system relative to the project root.
|
|
169
169
|
*/
|
|
170
170
|
resourcesDir: string;
|
|
171
171
|
/**
|
|
172
|
-
* @description The directory where stub files are stored. Stub files are templates used for generating resource files. This should also be a valid path on the file system where the stub templates are located.
|
|
172
|
+
* @description The directory where stub files are stored. Stub files are templates used for generating resource files. This should also be a valid path on the file system relative to the project root where the stub templates are located.
|
|
173
173
|
*/
|
|
174
174
|
stubsDir: string;
|
|
175
175
|
/**
|
|
176
176
|
* @description An object that defines the stub file names for different types of resources.
|
|
177
177
|
*/
|
|
178
178
|
stubs: {
|
|
179
|
+
/**
|
|
180
|
+
* @description The stub file name for the configuration file. This stub will be used when generating the default configuration file.
|
|
181
|
+
*/
|
|
182
|
+
config: string;
|
|
179
183
|
/**
|
|
180
184
|
* @description The stub file name for a resource. This stub will be used when generating a resource file.
|
|
181
185
|
*/
|
|
@@ -185,13 +189,54 @@ interface Config {
|
|
|
185
189
|
*/
|
|
186
190
|
collection: string;
|
|
187
191
|
};
|
|
192
|
+
/**
|
|
193
|
+
* @description This option allows you to specify the case style that should be used for the keys in API responses returned by the resources.
|
|
194
|
+
*/
|
|
195
|
+
preferredCase: 'camel' | 'snake' | 'pascal' | 'kebab';
|
|
196
|
+
/**
|
|
197
|
+
* @description This option allows you to specify the extra properties that should be included in the response body when a resource is paginated. You can choose to include either 'meta', 'links', or both, or you can provide custom property names for these extras.
|
|
198
|
+
*/
|
|
199
|
+
paginatedExtras: ['meta', 'links'] | {
|
|
200
|
+
meta?: string | undefined;
|
|
201
|
+
links?: string | undefined;
|
|
202
|
+
};
|
|
203
|
+
/**
|
|
204
|
+
* @description This option allows you to specify the property names that should be used for pagination links in the response body when a resource is paginated. You can provide custom property names for the pagination links, and if not specified, the default property names will be used.
|
|
205
|
+
*/
|
|
206
|
+
paginatedLinks: {
|
|
207
|
+
first?: string | undefined;
|
|
208
|
+
last?: string | undefined;
|
|
209
|
+
prev?: string | undefined;
|
|
210
|
+
next?: string | undefined;
|
|
211
|
+
};
|
|
212
|
+
/**
|
|
213
|
+
* @description This option allows you to specify the property names that should be used for pagination metadata in the response body when a resource is paginated. You can provide custom property names for properties, and if not specified, the default property names will be used.
|
|
214
|
+
*/
|
|
215
|
+
paginatedMeta: {
|
|
216
|
+
to?: string | undefined;
|
|
217
|
+
from?: string | undefined;
|
|
218
|
+
links?: string | undefined;
|
|
219
|
+
path?: string | undefined;
|
|
220
|
+
total?: string | undefined;
|
|
221
|
+
per_page?: string | undefined;
|
|
222
|
+
last_page?: string | undefined;
|
|
223
|
+
current_page?: string | undefined;
|
|
224
|
+
};
|
|
188
225
|
}
|
|
189
226
|
//#endregion
|
|
190
|
-
//#region src/cli/
|
|
227
|
+
//#region src/cli/CliApp.d.ts
|
|
191
228
|
declare class CliApp {
|
|
192
229
|
command: Command;
|
|
193
|
-
|
|
230
|
+
protected config: Config;
|
|
194
231
|
constructor(config?: Partial<Config>);
|
|
232
|
+
/**
|
|
233
|
+
* Initialize Resora by creating a default config file in the current directory
|
|
234
|
+
*
|
|
235
|
+
* @returns
|
|
236
|
+
*/
|
|
237
|
+
init(): {
|
|
238
|
+
path: string;
|
|
239
|
+
};
|
|
195
240
|
/**
|
|
196
241
|
* Utility to ensure directory exists
|
|
197
242
|
*
|
package/dist/index.d.mts
CHANGED
|
@@ -165,17 +165,21 @@ interface Cursor {
|
|
|
165
165
|
}
|
|
166
166
|
interface Config {
|
|
167
167
|
/**
|
|
168
|
-
* @description The directory where resource files are stored. This is the location where the generated resource files will be saved. It should be a valid path on the file system.
|
|
168
|
+
* @description The directory where resource files are stored. This is the location where the generated resource files will be saved. It should be a valid path on the file system relative to the project root.
|
|
169
169
|
*/
|
|
170
170
|
resourcesDir: string;
|
|
171
171
|
/**
|
|
172
|
-
* @description The directory where stub files are stored. Stub files are templates used for generating resource files. This should also be a valid path on the file system where the stub templates are located.
|
|
172
|
+
* @description The directory where stub files are stored. Stub files are templates used for generating resource files. This should also be a valid path on the file system relative to the project root where the stub templates are located.
|
|
173
173
|
*/
|
|
174
174
|
stubsDir: string;
|
|
175
175
|
/**
|
|
176
176
|
* @description An object that defines the stub file names for different types of resources.
|
|
177
177
|
*/
|
|
178
178
|
stubs: {
|
|
179
|
+
/**
|
|
180
|
+
* @description The stub file name for the configuration file. This stub will be used when generating the default configuration file.
|
|
181
|
+
*/
|
|
182
|
+
config: string;
|
|
179
183
|
/**
|
|
180
184
|
* @description The stub file name for a resource. This stub will be used when generating a resource file.
|
|
181
185
|
*/
|
|
@@ -185,13 +189,54 @@ interface Config {
|
|
|
185
189
|
*/
|
|
186
190
|
collection: string;
|
|
187
191
|
};
|
|
192
|
+
/**
|
|
193
|
+
* @description This option allows you to specify the case style that should be used for the keys in API responses returned by the resources.
|
|
194
|
+
*/
|
|
195
|
+
preferredCase: 'camel' | 'snake' | 'pascal' | 'kebab';
|
|
196
|
+
/**
|
|
197
|
+
* @description This option allows you to specify the extra properties that should be included in the response body when a resource is paginated. You can choose to include either 'meta', 'links', or both, or you can provide custom property names for these extras.
|
|
198
|
+
*/
|
|
199
|
+
paginatedExtras: ['meta', 'links'] | {
|
|
200
|
+
meta?: string | undefined;
|
|
201
|
+
links?: string | undefined;
|
|
202
|
+
};
|
|
203
|
+
/**
|
|
204
|
+
* @description This option allows you to specify the property names that should be used for pagination links in the response body when a resource is paginated. You can provide custom property names for the pagination links, and if not specified, the default property names will be used.
|
|
205
|
+
*/
|
|
206
|
+
paginatedLinks: {
|
|
207
|
+
first?: string | undefined;
|
|
208
|
+
last?: string | undefined;
|
|
209
|
+
prev?: string | undefined;
|
|
210
|
+
next?: string | undefined;
|
|
211
|
+
};
|
|
212
|
+
/**
|
|
213
|
+
* @description This option allows you to specify the property names that should be used for pagination metadata in the response body when a resource is paginated. You can provide custom property names for properties, and if not specified, the default property names will be used.
|
|
214
|
+
*/
|
|
215
|
+
paginatedMeta: {
|
|
216
|
+
to?: string | undefined;
|
|
217
|
+
from?: string | undefined;
|
|
218
|
+
links?: string | undefined;
|
|
219
|
+
path?: string | undefined;
|
|
220
|
+
total?: string | undefined;
|
|
221
|
+
per_page?: string | undefined;
|
|
222
|
+
last_page?: string | undefined;
|
|
223
|
+
current_page?: string | undefined;
|
|
224
|
+
};
|
|
188
225
|
}
|
|
189
226
|
//#endregion
|
|
190
|
-
//#region src/cli/
|
|
227
|
+
//#region src/cli/CliApp.d.ts
|
|
191
228
|
declare class CliApp {
|
|
192
229
|
command: Command;
|
|
193
|
-
|
|
230
|
+
protected config: Config;
|
|
194
231
|
constructor(config?: Partial<Config>);
|
|
232
|
+
/**
|
|
233
|
+
* Initialize Resora by creating a default config file in the current directory
|
|
234
|
+
*
|
|
235
|
+
* @returns
|
|
236
|
+
*/
|
|
237
|
+
init(): {
|
|
238
|
+
path: string;
|
|
239
|
+
};
|
|
195
240
|
/**
|
|
196
241
|
* Utility to ensure directory exists
|
|
197
242
|
*
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { copyFileSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "fs";
|
|
1
2
|
import path, { dirname, join } from "path";
|
|
2
|
-
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "fs";
|
|
3
3
|
import { createRequire } from "module";
|
|
4
4
|
import { fileURLToPath } from "url";
|
|
5
5
|
import { Command } from "@h3ravel/musket";
|
|
@@ -31,17 +31,19 @@ const defineConfig = (userConfig = {}) => {
|
|
|
31
31
|
resourcesDir: "src/resources",
|
|
32
32
|
stubsDir,
|
|
33
33
|
stubs: {
|
|
34
|
+
config: "resora.config.stub",
|
|
34
35
|
resource: "resource.stub",
|
|
35
36
|
collection: "resource.collection.stub"
|
|
36
37
|
}
|
|
37
38
|
}, userConfig, { stubs: Object.assign({
|
|
39
|
+
config: "resora.config.stub",
|
|
38
40
|
resource: "resource.stub",
|
|
39
41
|
collection: "resource.collection.stub"
|
|
40
42
|
}, userConfig.stubs || {}) });
|
|
41
43
|
};
|
|
42
44
|
|
|
43
45
|
//#endregion
|
|
44
|
-
//#region src/cli/
|
|
46
|
+
//#region src/cli/CliApp.ts
|
|
45
47
|
var CliApp = class {
|
|
46
48
|
command;
|
|
47
49
|
config = {};
|
|
@@ -62,6 +64,23 @@ var CliApp = class {
|
|
|
62
64
|
}
|
|
63
65
|
}
|
|
64
66
|
/**
|
|
67
|
+
* Initialize Resora by creating a default config file in the current directory
|
|
68
|
+
*
|
|
69
|
+
* @returns
|
|
70
|
+
*/
|
|
71
|
+
init() {
|
|
72
|
+
const outputPath = join(process.cwd(), "resora.config.js");
|
|
73
|
+
const stubPath = join(this.config.stubsDir, this.config.stubs.config);
|
|
74
|
+
if (existsSync(outputPath) && !this.command.option("force")) {
|
|
75
|
+
this.command.error(`Error: ${outputPath} already exists.`);
|
|
76
|
+
process.exit(1);
|
|
77
|
+
}
|
|
78
|
+
this.ensureDirectory(outputPath);
|
|
79
|
+
if (existsSync(outputPath) && this.command.option("force")) copyFileSync(outputPath, outputPath.replace(/\.js$/, `.backup.${Date.now()}.js`));
|
|
80
|
+
writeFileSync(outputPath, readFileSync(stubPath, "utf-8"));
|
|
81
|
+
return { path: outputPath };
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
65
84
|
* Utility to ensure directory exists
|
|
66
85
|
*
|
|
67
86
|
* @param filePath
|
package/package.json
CHANGED