next-anvil 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,16 @@
1
+ ISC License
2
+
3
+ Copyright (c) 2024, Juan Sanchez
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
+
package/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # Anvil CLI
2
+
3
+ CLI tool for the Anvil framework - a Next.js framework for creating admin dashboards.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install -g anvil
9
+ ```
10
+
11
+ Or use it locally in your project:
12
+
13
+ ```bash
14
+ npm install --save-dev anvil
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ### Create a Resource
20
+
21
+ Generate a new resource with form and table components:
22
+
23
+ ```bash
24
+ anvil forge:resource <name>
25
+ ```
26
+
27
+ Example:
28
+ ```bash
29
+ anvil forge:resource product
30
+ ```
31
+
32
+ This will create:
33
+ - `src/lib/resources/products/index.ts`
34
+ - `src/lib/resources/products/form.ts`
35
+ - `src/lib/resources/products/table.ts`
36
+
37
+ Run Prisma migrations:
38
+
39
+ ```bash
40
+ anvil db:migrate
41
+ ```
42
+
43
+ This executes `npx prisma migrate dev && npx prisma generate`.
44
+
45
+ ## Requirements
46
+
47
+ - Node.js 18.0.0 or higher
48
+ - A Next.js project
49
+ - Prisma configured (`db:migrate` commands)
50
+
51
+ ## License
52
+
53
+ ISC
54
+
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=anvil.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anvil.d.ts","sourceRoot":"","sources":["../../bin/anvil.ts"],"names":[],"mappings":""}
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const commander_1 = require("commander");
5
+ const resource_js_1 = require("./commands/forge/resource.js");
6
+ const child_process_1 = require("child_process");
7
+ const program = new commander_1.Command();
8
+ program.name("anvil").description("Anvil framework CLI").version("0.1.0");
9
+ program
10
+ .command("forge:resource <name>")
11
+ .description("Create a new resource")
12
+ .action(resource_js_1.forgeResource);
13
+ program
14
+ .command("db:migrate")
15
+ .description("Run database migrations")
16
+ .action(() => {
17
+ (0, child_process_1.execSync)("npx prisma migrate dev && npx prisma generate", {
18
+ stdio: "inherit",
19
+ });
20
+ });
21
+ program.parse();
22
+ //# sourceMappingURL=anvil.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anvil.js","sourceRoot":"","sources":["../../bin/anvil.ts"],"names":[],"mappings":";;AAAA,yCAAoC;AACpC,8DAA6D;AAC7D,iDAAyC;AAEzC,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAC;AAE9B,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,WAAW,CAAC,qBAAqB,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;AAE1E,OAAO;KACJ,OAAO,CAAC,uBAAuB,CAAC;KAChC,WAAW,CAAC,uBAAuB,CAAC;KACpC,MAAM,CAAC,2BAAa,CAAC,CAAC;AAGzB,OAAO;KACJ,OAAO,CAAC,YAAY,CAAC;KACrB,WAAW,CAAC,yBAAyB,CAAC;KACtC,MAAM,CAAC,GAAG,EAAE;IACX,IAAA,wBAAQ,EAAC,+CAA+C,EAAE;QACxD,KAAK,EAAE,SAAS;KACjB,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEL,OAAO,CAAC,KAAK,EAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function forgeResource(name: string): Promise<void>;
2
+ //# sourceMappingURL=resource.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../../../../bin/commands/forge/resource.ts"],"names":[],"mappings":"AASA,wBAAsB,aAAa,CAAC,IAAI,EAAE,MAAM,iBAoC/C"}
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.forgeResource = forgeResource;
7
+ const promises_1 = __importDefault(require("fs/promises"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const pluralize_esm_1 = __importDefault(require("pluralize-esm"));
10
+ const resource_1 = require("../../templates/resource");
11
+ async function forgeResource(name) {
12
+ const singular = name.charAt(0).toUpperCase() + name.slice(1);
13
+ const plural = (0, pluralize_esm_1.default)(singular);
14
+ const pluralLower = plural.toLowerCase();
15
+ const singularLower = singular.toLowerCase();
16
+ const resourceDir = path_1.default.join(process.cwd(), "src/lib/resources", pluralLower);
17
+ if (await promises_1.default
18
+ .access(resourceDir)
19
+ .then(() => true)
20
+ .catch(() => false)) {
21
+ console.log(`${singular} Resource already exists`);
22
+ return;
23
+ }
24
+ await promises_1.default.mkdir(resourceDir, { recursive: true });
25
+ await Promise.all([
26
+ promises_1.default.writeFile(path_1.default.join(resourceDir, "index.ts"), (0, resource_1.indexTemplate)(singular)),
27
+ promises_1.default.writeFile(path_1.default.join(resourceDir, "form.ts"), (0, resource_1.formTemplate)(singular)),
28
+ promises_1.default.writeFile(path_1.default.join(resourceDir, "table.ts"), (0, resource_1.tableTemplate)()),
29
+ ]);
30
+ console.log(`✅ ${singular} Resource created at src/lib/resources/${pluralLower}/`);
31
+ console.log(` - index.ts`);
32
+ console.log(` - form.ts`);
33
+ console.log(` - table.ts`);
34
+ }
35
+ //# sourceMappingURL=resource.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resource.js","sourceRoot":"","sources":["../../../../bin/commands/forge/resource.ts"],"names":[],"mappings":";;;;;AASA,sCAoCC;AA7CD,2DAA6B;AAC7B,gDAAwB;AACxB,kEAAsC;AACtC,uDAIkC;AAE3B,KAAK,UAAU,aAAa,CAAC,IAAY;IAC9C,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC9D,MAAM,MAAM,GAAG,IAAA,uBAAS,EAAC,QAAQ,CAAC,CAAC;IACnC,MAAM,WAAW,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC;IACzC,MAAM,aAAa,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;IAE7C,MAAM,WAAW,GAAG,cAAI,CAAC,IAAI,CAC3B,OAAO,CAAC,GAAG,EAAE,EACb,mBAAmB,EACnB,WAAW,CACZ,CAAC;IAEF,IACE,MAAM,kBAAE;SACL,MAAM,CAAC,WAAW,CAAC;SACnB,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC;SAChB,KAAK,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EACrB,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,GAAG,QAAQ,0BAA0B,CAAC,CAAC;QACnD,OAAO;IACT,CAAC;IAED,MAAM,kBAAE,CAAC,KAAK,CAAC,WAAW,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAEjD,MAAM,OAAO,CAAC,GAAG,CAAC;QAChB,kBAAE,CAAC,SAAS,CAAC,cAAI,CAAC,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,EAAE,IAAA,wBAAa,EAAC,QAAQ,CAAC,CAAC;QACzE,kBAAE,CAAC,SAAS,CAAC,cAAI,CAAC,IAAI,CAAC,WAAW,EAAE,SAAS,CAAC,EAAE,IAAA,uBAAY,EAAC,QAAQ,CAAC,CAAC;QACvE,kBAAE,CAAC,SAAS,CAAC,cAAI,CAAC,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,EAAE,IAAA,wBAAa,GAAE,CAAC;KAClE,CAAC,CAAC;IAEH,OAAO,CAAC,GAAG,CACT,KAAK,QAAQ,0CAA0C,WAAW,GAAG,CACtE,CAAC;IACF,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAC7B,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IAC5B,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;AAC/B,CAAC"}
@@ -0,0 +1,4 @@
1
+ export declare function indexTemplate(singular: string): string;
2
+ export declare function formTemplate(singular: string): string;
3
+ export declare function tableTemplate(): string;
4
+ //# sourceMappingURL=resource.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../../../bin/templates/resource.ts"],"names":[],"mappings":"AAAA,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,UAY7C;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,UAe5C;AAED,wBAAgB,aAAa,WAY5B"}
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.indexTemplate = indexTemplate;
4
+ exports.formTemplate = formTemplate;
5
+ exports.tableTemplate = tableTemplate;
6
+ function indexTemplate(singular) {
7
+ return `
8
+ import { defineResource } from "@/lib/anvil/resource";
9
+ import form from "./form";
10
+ import table from "./table";
11
+
12
+ export default defineResource({
13
+ model: "${singular}",
14
+ form,
15
+ table,
16
+ });
17
+ `;
18
+ }
19
+ function formTemplate(singular) {
20
+ return `
21
+ import { defineFormSchema } from "@/lib/anvil/form";
22
+ import { text } from "@/lib/anvil/fields";
23
+
24
+ export default defineFormSchema({
25
+ fields: {
26
+ name: text({
27
+ label: "Name",
28
+ required: true,
29
+ placeholder: "Enter ${singular} name",
30
+ }),
31
+ },
32
+ });
33
+ `;
34
+ }
35
+ function tableTemplate() {
36
+ return `
37
+ import { defineTableSchema } from "@/lib/anvil/table";
38
+
39
+ export default defineTableSchema({
40
+ columns: [
41
+ { name: "id", label: "ID", visible: "never" },
42
+ { name: "name", label: "Name" },
43
+ { name: "createdAt", label: "Created At" },
44
+ ],
45
+ });
46
+ `;
47
+ }
48
+ //# sourceMappingURL=resource.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resource.js","sourceRoot":"","sources":["../../../bin/templates/resource.ts"],"names":[],"mappings":";;AAAA,sCAYC;AAED,oCAeC;AAED,sCAYC;AA3CD,SAAgB,aAAa,CAAC,QAAgB;IAC5C,OAAO;;;;;;YAMG,QAAQ;;;;GAIjB,CAAC;AACJ,CAAC;AAED,SAAgB,YAAY,CAAC,QAAgB;IAC3C,OAAO;;;;;;;;;4BASmB,QAAQ;;;;GAIjC,CAAC;AACJ,CAAC;AAED,SAAgB,aAAa;IAC3B,OAAO;;;;;;;;;;GAUN,CAAC;AACJ,CAAC"}
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "next-anvil",
3
+ "version": "0.1.0",
4
+ "description": "CLI tool for the Anvil framework - a Next.js framework for creating admin dashboards",
5
+ "license": "ISC",
6
+ "author": "Juan Sanchez <juan.sanchez@stallionstudios.net>",
7
+ "type": "commonjs",
8
+ "main": "dist/bin/anvil.js",
9
+ "bin": {
10
+ "anvil": "dist/bin/anvil.js"
11
+ },
12
+ "files": [
13
+ "dist",
14
+ "README.md",
15
+ "LICENSE"
16
+ ],
17
+ "scripts": {
18
+ "build": "tsc && node scripts/postbuild.js",
19
+ "prepublishOnly": "npm run build",
20
+ "test": "echo \"Error: no test specified\" && exit 1"
21
+ },
22
+ "keywords": [
23
+ "anvil",
24
+ "cli",
25
+ "nextjs",
26
+ "admin",
27
+ "dashboard",
28
+ "framework",
29
+ "prisma"
30
+ ],
31
+ "dependencies": {
32
+ "bcryptjs": "^3.0.3",
33
+ "commander": "^14.0.2",
34
+ "dotenv": "^16.4.5",
35
+ "pluralize-esm": "^9.0.5"
36
+ },
37
+ "devDependencies": {
38
+ "@types/bcryptjs": "^2.4.6",
39
+ "@types/node": "^20.0.0",
40
+ "tsx": "^4.7.0",
41
+ "typescript": "^5.0.0"
42
+ },
43
+ "engines": {
44
+ "node": ">=18.0.0"
45
+ }
46
+ }