axe-api 1.4.0-beta-5 → 1.4.0-beta-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.
@@ -0,0 +1,37 @@
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+ const { getPaths } = require("../../helpers");
4
+ require("colors");
5
+
6
+ const TEMPLATE = `/**
7
+ * This is a hook file! You can add your business logic to here.
8
+ *
9
+ * @link https://axe-api.com/learn/hooks-and-events.html
10
+ */
11
+
12
+ console.log("Add your hooks to this file: {NAME}");`;
13
+
14
+ module.exports = async function (hookArray) {
15
+ const { hooks } = getPaths();
16
+
17
+ for (const name of hookArray) {
18
+ const directory = path.join(hooks, name);
19
+
20
+ if (fs.existsSync(directory) === false) {
21
+ fs.mkdirSync(directory);
22
+ }
23
+
24
+ const fileName = path.join(directory, "index.ts");
25
+ const displayName = fileName.replace(process.cwd(), "");
26
+
27
+ if (fs.existsSync(fileName)) {
28
+ console.log(`The hook is already defined: ${displayName}`.red);
29
+ continue;
30
+ }
31
+
32
+ const content = TEMPLATE.replace("{NAME}", name);
33
+ fs.writeFileSync(fileName, content);
34
+
35
+ console.log(`The hook is defined: ${displayName}`.green);
36
+ }
37
+ };
@@ -0,0 +1,33 @@
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+ const { getPaths } = require("../../helpers");
4
+ require("colors");
5
+
6
+ const TEMPLATE = `import { Model } from "axe-api";
7
+
8
+ class {NAME} extends Model {
9
+
10
+ }
11
+
12
+ export default {NAME};
13
+ `;
14
+
15
+ module.exports = async function (modelArray) {
16
+ const { models, lastVersion } = getPaths();
17
+
18
+ for (const name of modelArray) {
19
+ const content = TEMPLATE.replaceAll(`{NAME}`, name);
20
+ const fileName = path.join(models, `${name}.ts`);
21
+
22
+ if (fs.existsSync(fileName)) {
23
+ console.log(
24
+ `The model is already defined: app/${lastVersion}/${name}.ts`.red,
25
+ );
26
+ continue;
27
+ }
28
+
29
+ fs.writeFileSync(fileName, content);
30
+
31
+ console.log(`The model is defined: app/${lastVersion}/${name}.ts`.green);
32
+ }
33
+ };
@@ -3,7 +3,7 @@ const rimraf = require("rimraf");
3
3
  const fs = require("fs");
4
4
  require("colors");
5
5
 
6
- module.exports = async function (name, options) {
6
+ module.exports = async function (name) {
7
7
  let errors = null;
8
8
 
9
9
  console.log(`Directory name would be: ${name}`.green);
package/cli/helpers.js ADDED
@@ -0,0 +1,42 @@
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+
4
+ const getPaths = () => {
5
+ let root = path.join(process.cwd());
6
+
7
+ if (fs.existsSync(path.join(root, "dev-kit"))) {
8
+ root = path.join(root, "dev-kit");
9
+ }
10
+
11
+ const app = path.join(root, "app");
12
+ const migrations = path.join(root, "migrations");
13
+
14
+ const versions = fs.readdirSync(app).filter((item) => item !== "config.ts");
15
+ const lastVersion = versions.at(-1);
16
+
17
+ const version = path.join(app, lastVersion);
18
+
19
+ const events = path.join(version, "Events");
20
+ const handlers = path.join(version, "Handlers");
21
+ const hooks = path.join(version, "Hooks");
22
+ const middlewares = path.join(version, "Middlewars");
23
+ const models = path.join(version, "Models");
24
+ const serialization = path.join(version, "Serialization");
25
+
26
+ return {
27
+ app,
28
+ migrations,
29
+ lastVersion,
30
+ version,
31
+ events,
32
+ handlers,
33
+ hooks,
34
+ middlewares,
35
+ models,
36
+ serialization,
37
+ };
38
+ };
39
+
40
+ module.exports = {
41
+ getPaths,
42
+ };
package/cli/index.js CHANGED
@@ -1,8 +1,10 @@
1
1
  const { Command } = require("commander");
2
2
  const program = new Command();
3
3
  const newCommand = require("./Commands/NewCommand");
4
+ const createModelCommand = require("./Commands/Models/CreateModelCommand");
5
+ const createHooksCommand = require("./Commands/Hooks/CreateHooksCommand");
4
6
 
5
- program.name("axe-magic").description("AXE API CLI tool").version("2.0.0");
7
+ program.name("axe-magic").description("AXE API CLI tool").version("3.0.0");
6
8
 
7
9
  program
8
10
  .command("new")
@@ -10,6 +12,18 @@ program
10
12
  .argument("<project-name>", "The name of the project")
11
13
  .action(newCommand);
12
14
 
15
+ program
16
+ .command("model:create")
17
+ .description("Create model files")
18
+ .argument("<models...>", "Model names")
19
+ .action(createModelCommand);
20
+
21
+ program
22
+ .command("hooks:create")
23
+ .description("Create hooks files for models")
24
+ .argument("<models...>", "Model names")
25
+ .action(createHooksCommand);
26
+
13
27
  module.exports = {
14
28
  cli: () => program.parse(),
15
29
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "axe-api",
3
- "version": "1.4.0-beta-5",
3
+ "version": "1.4.0-beta-7",
4
4
  "description": "AXE API is a simple tool to create Rest APIs quickly.",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -28,9 +28,6 @@
28
28
  }
29
29
  ],
30
30
  "license": "MIT",
31
- "bin": {
32
- "axe": "bin/axe"
33
- },
34
31
  "publishConfig": {
35
32
  "access": "public"
36
33
  },
@@ -77,7 +74,11 @@
77
74
  "pino": "^8.18.0",
78
75
  "pino-pretty": "^11.0.0",
79
76
  "pluralize": "^8.0.0",
80
- "validatorjs": "^3.22.1"
77
+ "validatorjs": "^3.22.1",
78
+ "commander": "^12.0.0",
79
+ "shelljs": "^0.8.5",
80
+ "rimraf": "^5.0.5",
81
+ "colors": "^1.4.0"
81
82
  },
82
83
  "devDependencies": {
83
84
  "@babel/core": "^7.23.9",
@@ -94,8 +95,6 @@
94
95
  "@typescript-eslint/eslint-plugin": "^7.0.1",
95
96
  "@typescript-eslint/parser": "^7.0.1",
96
97
  "babel-jest": "^29.7.0",
97
- "colors": "^1.4.0",
98
- "commander": "^12.0.0",
99
98
  "cors": "^2.8.5",
100
99
  "eslint": "^8.56.0",
101
100
  "eslint-config-standard": "^17.1.0",
@@ -115,11 +114,9 @@
115
114
  "pg": "^8.11.3",
116
115
  "prettier": "^3.2.5",
117
116
  "redis": "^4.6.13",
118
- "rimraf": "^5.0.5",
119
117
  "robust-validator": "^1.1.0",
120
118
  "serve-static": "^1.15.0",
121
119
  "set-value": ">=4.1.0",
122
- "shelljs": "^0.8.5",
123
120
  "sqlite3": "^5.1.7",
124
121
  "ts-node": "^10.9.2",
125
122
  "tsx": "^4.7.1",