resora 0.1.1 → 0.1.2
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 +49 -3
- package/package.json +1 -1
package/bin/index.mjs
CHANGED
|
@@ -3,8 +3,7 @@ import path, { dirname, join } from "path";
|
|
|
3
3
|
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "fs";
|
|
4
4
|
import { createRequire } from "module";
|
|
5
5
|
import { fileURLToPath } from "url";
|
|
6
|
-
import { Kernel } from "@h3ravel/musket";
|
|
7
|
-
import path$1 from "node:path";
|
|
6
|
+
import { Command, Kernel } from "@h3ravel/musket";
|
|
8
7
|
|
|
9
8
|
//#region src/utility.ts
|
|
10
9
|
const __dirname = /* @__PURE__ */ path.dirname(fileURLToPath(import.meta.url));
|
|
@@ -116,6 +115,53 @@ var CliApp = class {
|
|
|
116
115
|
}
|
|
117
116
|
};
|
|
118
117
|
|
|
118
|
+
//#endregion
|
|
119
|
+
//#region src/cli/commands/MakeResource.ts
|
|
120
|
+
var MakeResource = class extends Command {
|
|
121
|
+
signature = `#create:
|
|
122
|
+
{resource : Generates a new resource file.
|
|
123
|
+
| {name : Name of the resource to create}
|
|
124
|
+
| {--c|collection : Make a resource collection}
|
|
125
|
+
| {--force : Create the resource or collection file even if it already exists.}
|
|
126
|
+
}
|
|
127
|
+
{collection : Create a new resource collection file.
|
|
128
|
+
| {name : Name of the resource collection to create}
|
|
129
|
+
| {--force : Create the resource or collection file even if it already exists.}
|
|
130
|
+
}
|
|
131
|
+
{all : Create both resource and collection files.
|
|
132
|
+
| {prefix : prefix of the resources to create, "Admin" will create AdminResource, AdminCollection}
|
|
133
|
+
| {--force : Create the resource or collection file even if it already exists.}
|
|
134
|
+
}
|
|
135
|
+
`;
|
|
136
|
+
description = "Create a new resource or resource collection file";
|
|
137
|
+
async handle() {
|
|
138
|
+
this.app.command = this;
|
|
139
|
+
let path = "";
|
|
140
|
+
const action = this.dictionary.name || this.dictionary.baseCommand;
|
|
141
|
+
if (["resource", "collection"].includes(action) && !this.argument("name")) return void this.error("Error: Name argument is required.");
|
|
142
|
+
if (action === "all" && !this.argument("prefix")) return void this.error("Error: Prefix argument is required.");
|
|
143
|
+
switch (action) {
|
|
144
|
+
case "resource":
|
|
145
|
+
({path} = this.app.makeResource(this.argument("name"), this.options()));
|
|
146
|
+
break;
|
|
147
|
+
case "collection":
|
|
148
|
+
({path} = this.app.makeResource(this.argument("name") + "Collection", this.options()));
|
|
149
|
+
break;
|
|
150
|
+
case "all": {
|
|
151
|
+
const o1 = this.app.makeResource(this.argument("prefix"), { force: this.option("force") });
|
|
152
|
+
const o2 = this.app.makeResource(this.argument("prefix") + "Collection", {
|
|
153
|
+
collection: true,
|
|
154
|
+
force: this.option("force")
|
|
155
|
+
});
|
|
156
|
+
path = `${o1.path}, ${o2.path}`;
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
default: this.fail(`Unknown action: ${action}`);
|
|
160
|
+
}
|
|
161
|
+
this.success(`Created: ${path}`);
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
|
|
119
165
|
//#endregion
|
|
120
166
|
//#region src/cli/logo.ts
|
|
121
167
|
var logo_default = String.raw`
|
|
@@ -133,7 +179,7 @@ const app = new CliApp();
|
|
|
133
179
|
await Kernel.init(app, {
|
|
134
180
|
logo: logo_default,
|
|
135
181
|
name: "Resora CLI",
|
|
136
|
-
|
|
182
|
+
baseCommands: [MakeResource],
|
|
137
183
|
exceptionHandler(exception) {
|
|
138
184
|
throw exception;
|
|
139
185
|
}
|
package/package.json
CHANGED