@bejibun/core 0.1.42 → 0.1.44
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/CHANGELOG.md +37 -0
- package/README.md +12 -12
- package/bases/BaseModel.js +1 -1
- package/bootstrap.js +2 -2
- package/builders/RouterBuilder.js +1 -1
- package/commands/{db/DbSeedCommand.d.ts → InstallCommand.d.ts} +3 -3
- package/commands/InstallCommand.js +45 -0
- package/commands/Kernel.d.ts +0 -1
- package/commands/Kernel.js +28 -24
- package/commands/maintenance/MaintenanceDownCommand.d.ts +2 -2
- package/commands/maintenance/MaintenanceDownCommand.js +3 -3
- package/commands/{migrate/MigrateFreshCommand.d.ts → maintenance/MaintenanceUpCommand.d.ts} +3 -3
- package/commands/maintenance/MaintenanceUpCommand.js +34 -0
- package/commands/{migrate/MigrateLatestCommand.d.ts → package/PackageConfigureCommand.d.ts} +3 -3
- package/commands/package/PackageConfigureCommand.js +46 -0
- package/middlewares/MaintenanceMiddleware.d.ts +4 -0
- package/middlewares/MaintenanceMiddleware.js +16 -0
- package/package.json +5 -7
- package/server.d.ts +1 -1
- package/server.js +11 -8
- package/commands/db/DbSeedCommand.js +0 -51
- package/commands/migrate/MigrateFreshCommand.js +0 -67
- package/commands/migrate/MigrateLatestCommand.js +0 -50
- package/commands/migrate/MigrateRollbackCommand.d.ts +0 -27
- package/commands/migrate/MigrateRollbackCommand.js +0 -65
- package/commands/migrate/MigrateStatusCommand.d.ts +0 -27
- package/commands/migrate/MigrateStatusCommand.js +0 -59
- package/config/database.d.ts +0 -4
- package/config/database.js +0 -36
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,43 @@ All notable changes to this project will be documented in this file.
|
|
|
3
3
|
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
+
## [v0.1.44](https://github.com/crenata/bejibun-core/compare/v0.1.43...v0.1.44) - 2025-10-22
|
|
7
|
+
|
|
8
|
+
### 🩹 Fixes
|
|
9
|
+
|
|
10
|
+
### 📖 Changes
|
|
11
|
+
What's New :
|
|
12
|
+
- Move related database into `@bejibun/database`
|
|
13
|
+
- Adding `install <packages...>` to install package dependencies
|
|
14
|
+
- Adding `package:configure` to run package configuration file
|
|
15
|
+
- Now, everyone can build their own package for Bejibun framework
|
|
16
|
+
|
|
17
|
+
### ❤️Contributors
|
|
18
|
+
- Havea Crenata ([@crenata](https://github.com/crenata))
|
|
19
|
+
- Ghulje ([@ghulje](https://github.com/ghulje))
|
|
20
|
+
|
|
21
|
+
**Full Changelog**: https://github.com/crenata/bejibun-core/blob/master/CHANGELOG.md
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## [v0.1.43](https://github.com/crenata/bejibun-core/compare/v0.1.42...v0.1.43) - 2025-10-21
|
|
26
|
+
|
|
27
|
+
### 🩹 Fixes
|
|
28
|
+
|
|
29
|
+
### 📖 Changes
|
|
30
|
+
What's New :
|
|
31
|
+
- Adding `maintenance:down` to turn app into maintenance mode
|
|
32
|
+
- Adding `maintenance:up` to turn app into live mode
|
|
33
|
+
- Adding maintenance middleware
|
|
34
|
+
|
|
35
|
+
### ❤️Contributors
|
|
36
|
+
- Havea Crenata ([@crenata](https://github.com/crenata))
|
|
37
|
+
- Ghulje ([@ghulje](https://github.com/ghulje))
|
|
38
|
+
|
|
39
|
+
**Full Changelog**: https://github.com/crenata/bejibun-core/blob/master/CHANGELOG.md
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
6
43
|
## [v0.1.42](https://github.com/crenata/bejibun-core/compare/v0.1.41...v0.1.42) - 2025-10-21
|
|
7
44
|
|
|
8
45
|
### 🩹 Fixes
|
package/README.md
CHANGED
|
@@ -17,11 +17,7 @@ Core of Bejibun Framework.
|
|
|
17
17
|
Install the package.
|
|
18
18
|
|
|
19
19
|
```bash
|
|
20
|
-
# Using Bun
|
|
21
20
|
bun add @bejibun/core
|
|
22
|
-
|
|
23
|
-
# Using Bejibun
|
|
24
|
-
bun ace install @bejibun/core
|
|
25
21
|
```
|
|
26
22
|
|
|
27
23
|
### Ace
|
|
@@ -34,16 +30,20 @@ Ace for your commander
|
|
|
34
30
|
Author: Havea Crenata <havea.crenata@gmail.com>
|
|
35
31
|
|
|
36
32
|
Options:
|
|
37
|
-
-v, --version
|
|
38
|
-
-h, --help
|
|
33
|
+
-v, --version Show the current version
|
|
34
|
+
-h, --help display help for command
|
|
39
35
|
|
|
40
36
|
Commands:
|
|
41
|
-
db:seed
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
migrate:
|
|
46
|
-
|
|
37
|
+
db:seed Run database seeders
|
|
38
|
+
install <packages...> Install package dependencies
|
|
39
|
+
maintenance:down [options] Turn app into maintenance mode
|
|
40
|
+
maintenance:up Turn app into live mode
|
|
41
|
+
migrate:fresh [options] Rollback all migrations and re-run migrations
|
|
42
|
+
migrate:latest Run latest migration
|
|
43
|
+
migrate:rollback [options] Rollback the latest migrations
|
|
44
|
+
migrate:status [options] List migrations status
|
|
45
|
+
package:configure [options] Configure package after installation
|
|
46
|
+
help [command] display help for command
|
|
47
47
|
|
|
48
48
|
Examples:
|
|
49
49
|
$ bun ace --help
|
package/bases/BaseModel.js
CHANGED
|
@@ -26,7 +26,7 @@ export default class BaseModel extends Model {
|
|
|
26
26
|
static QueryBuilder = BunQueryBuilder;
|
|
27
27
|
static get namespace() {
|
|
28
28
|
const filePath = fileURLToPath(import.meta.url);
|
|
29
|
-
const rel = relative(App.rootPath(), filePath);
|
|
29
|
+
const rel = relative(App.Path.rootPath(), filePath);
|
|
30
30
|
const withoutExt = rel.replace(/\.[tj]s$/, "");
|
|
31
31
|
const namespaces = withoutExt.split(sep);
|
|
32
32
|
namespaces.pop();
|
package/bootstrap.js
CHANGED
|
@@ -110,7 +110,7 @@ export default class RouterBuilder {
|
|
|
110
110
|
if (isEmpty(controllerName) || isEmpty(methodName)) {
|
|
111
111
|
throw new RouterInvalidException(`Invalid router controller definition: ${definition}.`);
|
|
112
112
|
}
|
|
113
|
-
const controllerPath = path.resolve(App.rootPath(), this.baseNamespace);
|
|
113
|
+
const controllerPath = path.resolve(App.Path.rootPath(), this.baseNamespace);
|
|
114
114
|
const location = Bun.resolveSync(`./${controllerName}.ts`, controllerPath);
|
|
115
115
|
let ControllerClass;
|
|
116
116
|
try {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export default class
|
|
1
|
+
export default class InstallCommand {
|
|
2
2
|
/**
|
|
3
3
|
* The name and signature of the console command.
|
|
4
4
|
*
|
|
@@ -20,8 +20,8 @@ export default class DbSeedCommand {
|
|
|
20
20
|
/**
|
|
21
21
|
* The arguments of the console command.
|
|
22
22
|
*
|
|
23
|
-
* @var $arguments Array<Array<
|
|
23
|
+
* @var $arguments Array<Array<any>>
|
|
24
24
|
*/
|
|
25
|
-
protected $arguments: Array<Array<
|
|
25
|
+
protected $arguments: Array<Array<any>>;
|
|
26
26
|
handle(options: any, args: Array<string>): Promise<void>;
|
|
27
27
|
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import App from "@bejibun/app";
|
|
2
|
+
export default class InstallCommand {
|
|
3
|
+
/**
|
|
4
|
+
* The name and signature of the console command.
|
|
5
|
+
*
|
|
6
|
+
* @var $signature string
|
|
7
|
+
*/
|
|
8
|
+
$signature = "install";
|
|
9
|
+
/**
|
|
10
|
+
* The console command description.
|
|
11
|
+
*
|
|
12
|
+
* @var $description string
|
|
13
|
+
*/
|
|
14
|
+
$description = "Install package dependencies";
|
|
15
|
+
/**
|
|
16
|
+
* The options or optional flag of the console command.
|
|
17
|
+
*
|
|
18
|
+
* @var $options Array<Array<any>>
|
|
19
|
+
*/
|
|
20
|
+
$options = [];
|
|
21
|
+
/**
|
|
22
|
+
* The arguments of the console command.
|
|
23
|
+
*
|
|
24
|
+
* @var $arguments Array<Array<any>>
|
|
25
|
+
*/
|
|
26
|
+
$arguments = [
|
|
27
|
+
["<packages...>", "Install package dependencies"]
|
|
28
|
+
];
|
|
29
|
+
async handle(options, args) {
|
|
30
|
+
for (const pack of args) {
|
|
31
|
+
Bun.spawnSync(["bun", "add", pack], {
|
|
32
|
+
cwd: App.Path.rootPath(),
|
|
33
|
+
stdin: "inherit",
|
|
34
|
+
stdout: "inherit",
|
|
35
|
+
stderr: "inherit"
|
|
36
|
+
});
|
|
37
|
+
Bun.spawnSync(["bun", "ace", "package:configure", "--package", pack], {
|
|
38
|
+
cwd: App.Path.rootPath(),
|
|
39
|
+
stdin: "inherit",
|
|
40
|
+
stdout: "inherit",
|
|
41
|
+
stderr: "inherit"
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
package/commands/Kernel.d.ts
CHANGED
package/commands/Kernel.js
CHANGED
|
@@ -1,17 +1,39 @@
|
|
|
1
1
|
import App from "@bejibun/app";
|
|
2
2
|
import { defineValue, isEmpty } from "@bejibun/utils";
|
|
3
|
-
import { readdirSync } from "fs";
|
|
4
|
-
import path from "path";
|
|
5
3
|
export default class Kernel {
|
|
6
4
|
static registerCommands(program) {
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
const paths = [
|
|
6
|
+
{
|
|
7
|
+
absolute: true,
|
|
8
|
+
cwd: App.Path.commandsPath()
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
absolute: true,
|
|
12
|
+
cwd: __dirname
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
absolute: true,
|
|
16
|
+
cwd: "node_modules/@bejibun/database/commands"
|
|
17
|
+
}
|
|
18
|
+
];
|
|
19
|
+
const files = paths
|
|
20
|
+
.map(value => Array.from(new Bun.Glob("**/*").scanSync({
|
|
21
|
+
absolute: value.absolute,
|
|
22
|
+
cwd: value.cwd
|
|
23
|
+
})))
|
|
24
|
+
.flat()
|
|
25
|
+
.filter(value => (/\.(m?js|ts)$/.test(value) &&
|
|
26
|
+
!value.endsWith(".d.ts") &&
|
|
27
|
+
!value.includes("Kernel")));
|
|
28
|
+
const instances = [];
|
|
10
29
|
for (const file of files) {
|
|
11
30
|
const { default: CommandClass } = require(file);
|
|
12
31
|
const instance = new CommandClass();
|
|
13
32
|
if (isEmpty(instance.$signature) || typeof instance.handle !== "function")
|
|
14
33
|
continue;
|
|
34
|
+
instances.push(instance);
|
|
35
|
+
}
|
|
36
|
+
for (const instance of instances.sort((a, b) => a.$signature.localeCompare(b.$signature))) {
|
|
15
37
|
const cmd = program
|
|
16
38
|
.command(instance.$signature)
|
|
17
39
|
.description(defineValue(instance.$description, ""));
|
|
@@ -28,27 +50,9 @@ export default class Kernel {
|
|
|
28
50
|
cmd.action(async (...args) => {
|
|
29
51
|
const commandObj = args[args.length - 1];
|
|
30
52
|
const options = typeof commandObj.opts === "function" ? commandObj.opts() : commandObj;
|
|
31
|
-
const positionalArgs = args
|
|
53
|
+
const positionalArgs = args[0];
|
|
32
54
|
await instance.handle(options, positionalArgs);
|
|
33
55
|
});
|
|
34
56
|
}
|
|
35
57
|
}
|
|
36
|
-
static commands(directory) {
|
|
37
|
-
const entries = readdirSync(directory, {
|
|
38
|
-
withFileTypes: true
|
|
39
|
-
});
|
|
40
|
-
const files = [];
|
|
41
|
-
for (const entry of entries) {
|
|
42
|
-
const fullPath = path.join(directory, entry.name);
|
|
43
|
-
if (entry.isDirectory()) {
|
|
44
|
-
files.push(...this.commands(fullPath));
|
|
45
|
-
}
|
|
46
|
-
else if (/\.(m?js|ts)$/.test(entry.name) &&
|
|
47
|
-
!entry.name.endsWith(".d.ts") &&
|
|
48
|
-
!entry.name.includes("Kernel")) {
|
|
49
|
-
files.push(fullPath);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return files;
|
|
53
|
-
}
|
|
54
58
|
}
|
|
@@ -20,8 +20,8 @@ export default class MaintenanceDownCommand {
|
|
|
20
20
|
/**
|
|
21
21
|
* The arguments of the console command.
|
|
22
22
|
*
|
|
23
|
-
* @var $arguments Array<Array<
|
|
23
|
+
* @var $arguments Array<Array<any>>
|
|
24
24
|
*/
|
|
25
|
-
protected $arguments: Array<Array<
|
|
25
|
+
protected $arguments: Array<Array<any>>;
|
|
26
26
|
handle(options: any, args: Array<string>): Promise<void>;
|
|
27
27
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import AppConfig from "@bejibun/app/config/app";
|
|
2
2
|
import Logger from "@bejibun/logger";
|
|
3
3
|
import { DateTime } from "luxon";
|
|
4
4
|
export default class MaintenanceDownCommand {
|
|
@@ -25,11 +25,11 @@ export default class MaintenanceDownCommand {
|
|
|
25
25
|
/**
|
|
26
26
|
* The arguments of the console command.
|
|
27
27
|
*
|
|
28
|
-
* @var $arguments Array<Array<
|
|
28
|
+
* @var $arguments Array<Array<any>>
|
|
29
29
|
*/
|
|
30
30
|
$arguments = [];
|
|
31
31
|
async handle(options, args) {
|
|
32
|
-
await Bun.write(
|
|
32
|
+
await Bun.write(AppConfig.maintenance.file, JSON.stringify({
|
|
33
33
|
message: "🚧 We're doing maintenance. Please check back soon.",
|
|
34
34
|
status: 503,
|
|
35
35
|
allows: options.allows,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export default class
|
|
1
|
+
export default class MaintenanceUpCommand {
|
|
2
2
|
/**
|
|
3
3
|
* The name and signature of the console command.
|
|
4
4
|
*
|
|
@@ -20,8 +20,8 @@ export default class MigrateFreshCommand {
|
|
|
20
20
|
/**
|
|
21
21
|
* The arguments of the console command.
|
|
22
22
|
*
|
|
23
|
-
* @var $arguments Array<Array<
|
|
23
|
+
* @var $arguments Array<Array<any>>
|
|
24
24
|
*/
|
|
25
|
-
protected $arguments: Array<Array<
|
|
25
|
+
protected $arguments: Array<Array<any>>;
|
|
26
26
|
handle(options: any, args: Array<string>): Promise<void>;
|
|
27
27
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import App from "@bejibun/app";
|
|
2
|
+
import AppConfig from "@bejibun/app/config/app";
|
|
3
|
+
import Logger from "@bejibun/logger";
|
|
4
|
+
export default class MaintenanceUpCommand {
|
|
5
|
+
/**
|
|
6
|
+
* The name and signature of the console command.
|
|
7
|
+
*
|
|
8
|
+
* @var $signature string
|
|
9
|
+
*/
|
|
10
|
+
$signature = "maintenance:up";
|
|
11
|
+
/**
|
|
12
|
+
* The console command description.
|
|
13
|
+
*
|
|
14
|
+
* @var $description string
|
|
15
|
+
*/
|
|
16
|
+
$description = "Turn app into live mode";
|
|
17
|
+
/**
|
|
18
|
+
* The options or optional flag of the console command.
|
|
19
|
+
*
|
|
20
|
+
* @var $options Array<Array<any>>
|
|
21
|
+
*/
|
|
22
|
+
$options = [];
|
|
23
|
+
/**
|
|
24
|
+
* The arguments of the console command.
|
|
25
|
+
*
|
|
26
|
+
* @var $arguments Array<Array<any>>
|
|
27
|
+
*/
|
|
28
|
+
$arguments = [];
|
|
29
|
+
async handle(options, args) {
|
|
30
|
+
if (await App.Maintenance.isMaintenanceMode())
|
|
31
|
+
await Bun.file(AppConfig.maintenance.file).delete();
|
|
32
|
+
Logger.setContext("APP").info("Application turned into live mode.");
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export default class
|
|
1
|
+
export default class PackageConfigureCommand {
|
|
2
2
|
/**
|
|
3
3
|
* The name and signature of the console command.
|
|
4
4
|
*
|
|
@@ -20,8 +20,8 @@ export default class MigrateLatestCommand {
|
|
|
20
20
|
/**
|
|
21
21
|
* The arguments of the console command.
|
|
22
22
|
*
|
|
23
|
-
* @var $arguments Array<Array<
|
|
23
|
+
* @var $arguments Array<Array<any>>
|
|
24
24
|
*/
|
|
25
|
-
protected $arguments: Array<Array<
|
|
25
|
+
protected $arguments: Array<Array<any>>;
|
|
26
26
|
handle(options: any, args: Array<string>): Promise<void>;
|
|
27
27
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import App from "@bejibun/app";
|
|
2
|
+
import Logger from "@bejibun/logger";
|
|
3
|
+
import { defineValue, isEmpty } from "@bejibun/utils";
|
|
4
|
+
export default class PackageConfigureCommand {
|
|
5
|
+
/**
|
|
6
|
+
* The name and signature of the console command.
|
|
7
|
+
*
|
|
8
|
+
* @var $signature string
|
|
9
|
+
*/
|
|
10
|
+
$signature = "package:configure";
|
|
11
|
+
/**
|
|
12
|
+
* The console command description.
|
|
13
|
+
*
|
|
14
|
+
* @var $description string
|
|
15
|
+
*/
|
|
16
|
+
$description = "Configure package after installation";
|
|
17
|
+
/**
|
|
18
|
+
* The options or optional flag of the console command.
|
|
19
|
+
*
|
|
20
|
+
* @var $options Array<Array<any>>
|
|
21
|
+
*/
|
|
22
|
+
$options = [
|
|
23
|
+
["-p, --package <name>", "Run package configuration file. e.g. --package=@bejibun/database"]
|
|
24
|
+
];
|
|
25
|
+
/**
|
|
26
|
+
* The arguments of the console command.
|
|
27
|
+
*
|
|
28
|
+
* @var $arguments Array<Array<any>>
|
|
29
|
+
*/
|
|
30
|
+
$arguments = [];
|
|
31
|
+
async handle(options, args) {
|
|
32
|
+
if (isEmpty(options.package)) {
|
|
33
|
+
Logger.setContext("APP").error("Package is not provided, please use --package.");
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
await import(App.Path.rootPath(`node_modules/${options.package}/configure`));
|
|
38
|
+
Logger.setContext("APP").info("The package has been successfully configured.");
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
if (error?.message.includes("Cannot find module"))
|
|
42
|
+
return;
|
|
43
|
+
Logger.setContext("APP").error(defineValue(error?.message, "Whoops, something went wrong.")).trace(error);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import App from "@bejibun/app";
|
|
2
|
+
import Response from "../facades/Response";
|
|
3
|
+
export default class MaintenanceMiddleware {
|
|
4
|
+
handle(handler) {
|
|
5
|
+
return async (request) => {
|
|
6
|
+
if (await App.Maintenance.isMaintenanceMode()) {
|
|
7
|
+
const maintenance = await App.Maintenance.getData();
|
|
8
|
+
return Response
|
|
9
|
+
.setMessage(maintenance.message)
|
|
10
|
+
.setStatus(maintenance.status)
|
|
11
|
+
.send();
|
|
12
|
+
}
|
|
13
|
+
return handler(request);
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bejibun/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.44",
|
|
4
4
|
"author": "Havea Crenata <havea.crenata@gmail.com>",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -9,17 +9,15 @@
|
|
|
9
9
|
"main": "index.js",
|
|
10
10
|
"module": "index.js",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@bejibun/app": "^0.1.
|
|
13
|
-
"@bejibun/cors": "^0.1.
|
|
12
|
+
"@bejibun/app": "^0.1.19",
|
|
13
|
+
"@bejibun/cors": "^0.1.12",
|
|
14
|
+
"@bejibun/database": "^0.1.1",
|
|
14
15
|
"@bejibun/logger": "^0.1.18",
|
|
15
16
|
"@bejibun/utils": "^0.1.14",
|
|
16
17
|
"@vinejs/vine": "^3.0.1",
|
|
17
18
|
"commander": "^14.0.1",
|
|
18
|
-
"knex": "^3.1.0",
|
|
19
19
|
"luxon": "^3.7.2",
|
|
20
|
-
"objection": "^3.1.5"
|
|
21
|
-
"ora": "^9.0.0",
|
|
22
|
-
"pg": "^8.16.3"
|
|
20
|
+
"objection": "^3.1.5"
|
|
23
21
|
},
|
|
24
22
|
"devDependencies": {
|
|
25
23
|
"@types/bun": "latest",
|
package/server.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
package/server.js
CHANGED
|
@@ -2,8 +2,9 @@ import App from "@bejibun/app";
|
|
|
2
2
|
import Logger from "@bejibun/logger";
|
|
3
3
|
import RuntimeException from "./exceptions/RuntimeException";
|
|
4
4
|
import Router from "./facades/Router";
|
|
5
|
-
import "./
|
|
6
|
-
|
|
5
|
+
import MaintenanceMiddleware from "./middlewares/MaintenanceMiddleware";
|
|
6
|
+
import(App.Path.rootPath("bootstrap.ts"));
|
|
7
|
+
const exceptionHandlerPath = App.Path.appPath("exceptions/handler.ts");
|
|
7
8
|
let ExceptionHandler;
|
|
8
9
|
try {
|
|
9
10
|
ExceptionHandler = require(exceptionHandlerPath).default;
|
|
@@ -11,7 +12,7 @@ try {
|
|
|
11
12
|
catch {
|
|
12
13
|
throw new RuntimeException(`Missing exception handler class [${exceptionHandlerPath}].`);
|
|
13
14
|
}
|
|
14
|
-
const apiRoutesPath = App.routesPath("api.ts");
|
|
15
|
+
const apiRoutesPath = App.Path.routesPath("api.ts");
|
|
15
16
|
let ApiRoutes;
|
|
16
17
|
try {
|
|
17
18
|
ApiRoutes = require(apiRoutesPath).default;
|
|
@@ -19,7 +20,7 @@ try {
|
|
|
19
20
|
catch {
|
|
20
21
|
throw new RuntimeException(`Missing api file on routes directory [${apiRoutesPath}].`);
|
|
21
22
|
}
|
|
22
|
-
const webRoutesPath = App.routesPath("web.ts");
|
|
23
|
+
const webRoutesPath = App.Path.routesPath("web.ts");
|
|
23
24
|
let WebRoutes;
|
|
24
25
|
try {
|
|
25
26
|
WebRoutes = require(webRoutesPath).default;
|
|
@@ -37,10 +38,12 @@ const server = Bun.serve({
|
|
|
37
38
|
error: new ExceptionHandler().handle,
|
|
38
39
|
port: Bun.env.APP_PORT,
|
|
39
40
|
routes: {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
"/": require(App.Path.publicPath("index.html")),
|
|
42
|
+
...Router.middleware(new MaintenanceMiddleware()).group([
|
|
43
|
+
Router.namespace("app/exceptions").any("/*", "Handler@route"),
|
|
44
|
+
ApiRoutes,
|
|
45
|
+
WebRoutes
|
|
46
|
+
])
|
|
44
47
|
}
|
|
45
48
|
});
|
|
46
49
|
Logger.setContext("APP").info(`🚀 Server running at ${server.url.origin}`);
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import Chalk from "@bejibun/logger/facades/Chalk";
|
|
2
|
-
import ora from "ora";
|
|
3
|
-
import path from "path";
|
|
4
|
-
import { initDatabase } from "../../config/database";
|
|
5
|
-
export default class DbSeedCommand {
|
|
6
|
-
/**
|
|
7
|
-
* The name and signature of the console command.
|
|
8
|
-
*
|
|
9
|
-
* @var $signature string
|
|
10
|
-
*/
|
|
11
|
-
$signature = "db:seed";
|
|
12
|
-
/**
|
|
13
|
-
* The console command description.
|
|
14
|
-
*
|
|
15
|
-
* @var $description string
|
|
16
|
-
*/
|
|
17
|
-
$description = "Run database seeders";
|
|
18
|
-
/**
|
|
19
|
-
* The options or optional flag of the console command.
|
|
20
|
-
*
|
|
21
|
-
* @var $options Array<Array<any>>
|
|
22
|
-
*/
|
|
23
|
-
$options = [];
|
|
24
|
-
/**
|
|
25
|
-
* The arguments of the console command.
|
|
26
|
-
*
|
|
27
|
-
* @var $arguments Array<Array<string>>
|
|
28
|
-
*/
|
|
29
|
-
$arguments = [];
|
|
30
|
-
async handle(options, args) {
|
|
31
|
-
const database = initDatabase();
|
|
32
|
-
const spinner = ora(Chalk.setValue("Seeding...")
|
|
33
|
-
.info()
|
|
34
|
-
.show()).start();
|
|
35
|
-
try {
|
|
36
|
-
const logs = (await database.seed.run()).flat();
|
|
37
|
-
spinner.succeed("Seeding finished");
|
|
38
|
-
if (logs.length > 0)
|
|
39
|
-
logs.forEach((seeder) => spinner.succeed(path.basename(seeder)));
|
|
40
|
-
else
|
|
41
|
-
spinner.succeed("No seeders were run.");
|
|
42
|
-
}
|
|
43
|
-
catch (error) {
|
|
44
|
-
spinner.fail(`Seeding failed : ${error.message}`);
|
|
45
|
-
}
|
|
46
|
-
finally {
|
|
47
|
-
await database.destroy();
|
|
48
|
-
spinner.stop();
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import Logger from "@bejibun/logger";
|
|
2
|
-
import Chalk from "@bejibun/logger/facades/Chalk";
|
|
3
|
-
import { ask, isNotEmpty } from "@bejibun/utils";
|
|
4
|
-
import ora from "ora";
|
|
5
|
-
import { initDatabase } from "../../config/database";
|
|
6
|
-
export default class MigrateFreshCommand {
|
|
7
|
-
/**
|
|
8
|
-
* The name and signature of the console command.
|
|
9
|
-
*
|
|
10
|
-
* @var $signature string
|
|
11
|
-
*/
|
|
12
|
-
$signature = "migrate:fresh";
|
|
13
|
-
/**
|
|
14
|
-
* The console command description.
|
|
15
|
-
*
|
|
16
|
-
* @var $description string
|
|
17
|
-
*/
|
|
18
|
-
$description = "Rollback all migrations and re-run migrations";
|
|
19
|
-
/**
|
|
20
|
-
* The options or optional flag of the console command.
|
|
21
|
-
*
|
|
22
|
-
* @var $options Array<Array<any>>
|
|
23
|
-
*/
|
|
24
|
-
$options = [
|
|
25
|
-
["-f, --force", "Skip command confirmation"]
|
|
26
|
-
];
|
|
27
|
-
/**
|
|
28
|
-
* The arguments of the console command.
|
|
29
|
-
*
|
|
30
|
-
* @var $arguments Array<Array<string>>
|
|
31
|
-
*/
|
|
32
|
-
$arguments = [];
|
|
33
|
-
async handle(options, args) {
|
|
34
|
-
const database = initDatabase();
|
|
35
|
-
const bypass = isNotEmpty(options.force);
|
|
36
|
-
let confirm = "Y";
|
|
37
|
-
if (!bypass)
|
|
38
|
-
confirm = await ask(Chalk.setValue("This will DROP ALL tables and re-run ALL migrations. Are you want to continue? (Y/N): ")
|
|
39
|
-
.inline()
|
|
40
|
-
.error()
|
|
41
|
-
.show());
|
|
42
|
-
if (confirm.toUpperCase() === "Y") {
|
|
43
|
-
if (!bypass)
|
|
44
|
-
Logger.empty();
|
|
45
|
-
const spinner = ora(Chalk.setValue("Rollback...")
|
|
46
|
-
.info()
|
|
47
|
-
.show()).start();
|
|
48
|
-
try {
|
|
49
|
-
await database.migrate.rollback({}, true);
|
|
50
|
-
spinner.succeed("Rolled back all migrations");
|
|
51
|
-
const [batchNo, logs] = await database.migrate.latest();
|
|
52
|
-
spinner.succeed(`Batch ${batchNo} finished`);
|
|
53
|
-
if (logs.length > 0)
|
|
54
|
-
logs.forEach((migration) => spinner.succeed(migration));
|
|
55
|
-
else
|
|
56
|
-
spinner.succeed("No migrations were run.");
|
|
57
|
-
}
|
|
58
|
-
catch (error) {
|
|
59
|
-
spinner.fail(`Migration failed : ${error.message}`);
|
|
60
|
-
}
|
|
61
|
-
finally {
|
|
62
|
-
await database.destroy();
|
|
63
|
-
spinner.stop();
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import Chalk from "@bejibun/logger/facades/Chalk";
|
|
2
|
-
import ora from "ora";
|
|
3
|
-
import { initDatabase } from "../../config/database";
|
|
4
|
-
export default class MigrateLatestCommand {
|
|
5
|
-
/**
|
|
6
|
-
* The name and signature of the console command.
|
|
7
|
-
*
|
|
8
|
-
* @var $signature string
|
|
9
|
-
*/
|
|
10
|
-
$signature = "migrate:latest";
|
|
11
|
-
/**
|
|
12
|
-
* The console command description.
|
|
13
|
-
*
|
|
14
|
-
* @var $description string
|
|
15
|
-
*/
|
|
16
|
-
$description = "Run latest migration";
|
|
17
|
-
/**
|
|
18
|
-
* The options or optional flag of the console command.
|
|
19
|
-
*
|
|
20
|
-
* @var $options Array<Array<any>>
|
|
21
|
-
*/
|
|
22
|
-
$options = [];
|
|
23
|
-
/**
|
|
24
|
-
* The arguments of the console command.
|
|
25
|
-
*
|
|
26
|
-
* @var $arguments Array<Array<string>>
|
|
27
|
-
*/
|
|
28
|
-
$arguments = [];
|
|
29
|
-
async handle(options, args) {
|
|
30
|
-
const database = initDatabase();
|
|
31
|
-
const spinner = ora(Chalk.setValue("Migrating...")
|
|
32
|
-
.info()
|
|
33
|
-
.show()).start();
|
|
34
|
-
try {
|
|
35
|
-
const [batchNo, logs] = await database.migrate.latest();
|
|
36
|
-
spinner.succeed(`Batch ${batchNo} finished`);
|
|
37
|
-
if (logs.length > 0)
|
|
38
|
-
logs.forEach((migration) => spinner.succeed(migration));
|
|
39
|
-
else
|
|
40
|
-
spinner.succeed("No migrations were run.");
|
|
41
|
-
}
|
|
42
|
-
catch (error) {
|
|
43
|
-
spinner.fail(`Migration failed : ${error.message}`);
|
|
44
|
-
}
|
|
45
|
-
finally {
|
|
46
|
-
await database.destroy();
|
|
47
|
-
spinner.stop();
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export default class MigrateRollbackCommand {
|
|
2
|
-
/**
|
|
3
|
-
* The name and signature of the console command.
|
|
4
|
-
*
|
|
5
|
-
* @var $signature string
|
|
6
|
-
*/
|
|
7
|
-
protected $signature: string;
|
|
8
|
-
/**
|
|
9
|
-
* The console command description.
|
|
10
|
-
*
|
|
11
|
-
* @var $description string
|
|
12
|
-
*/
|
|
13
|
-
protected $description: string;
|
|
14
|
-
/**
|
|
15
|
-
* The options or optional flag of the console command.
|
|
16
|
-
*
|
|
17
|
-
* @var $options Array<Array<any>>
|
|
18
|
-
*/
|
|
19
|
-
protected $options: Array<Array<any>>;
|
|
20
|
-
/**
|
|
21
|
-
* The arguments of the console command.
|
|
22
|
-
*
|
|
23
|
-
* @var $arguments Array<Array<string>>
|
|
24
|
-
*/
|
|
25
|
-
protected $arguments: Array<Array<string>>;
|
|
26
|
-
handle(options: any, args: Array<string>): Promise<void>;
|
|
27
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import Logger from "@bejibun/logger";
|
|
2
|
-
import Chalk from "@bejibun/logger/facades/Chalk";
|
|
3
|
-
import { ask, isNotEmpty } from "@bejibun/utils";
|
|
4
|
-
import ora from "ora";
|
|
5
|
-
import { initDatabase } from "../../config/database";
|
|
6
|
-
export default class MigrateRollbackCommand {
|
|
7
|
-
/**
|
|
8
|
-
* The name and signature of the console command.
|
|
9
|
-
*
|
|
10
|
-
* @var $signature string
|
|
11
|
-
*/
|
|
12
|
-
$signature = "migrate:rollback";
|
|
13
|
-
/**
|
|
14
|
-
* The console command description.
|
|
15
|
-
*
|
|
16
|
-
* @var $description string
|
|
17
|
-
*/
|
|
18
|
-
$description = "Rollback the latest migrations";
|
|
19
|
-
/**
|
|
20
|
-
* The options or optional flag of the console command.
|
|
21
|
-
*
|
|
22
|
-
* @var $options Array<Array<any>>
|
|
23
|
-
*/
|
|
24
|
-
$options = [
|
|
25
|
-
["-f, --force", "Skip command confirmation"]
|
|
26
|
-
];
|
|
27
|
-
/**
|
|
28
|
-
* The arguments of the console command.
|
|
29
|
-
*
|
|
30
|
-
* @var $arguments Array<Array<string>>
|
|
31
|
-
*/
|
|
32
|
-
$arguments = [];
|
|
33
|
-
async handle(options, args) {
|
|
34
|
-
const database = initDatabase();
|
|
35
|
-
const bypass = isNotEmpty(options.force);
|
|
36
|
-
let confirm = "Y";
|
|
37
|
-
if (!bypass)
|
|
38
|
-
confirm = await ask(Chalk.setValue("This will ROLLBACK latest migrations. Are you want to continue? (Y/N): ")
|
|
39
|
-
.inline()
|
|
40
|
-
.error()
|
|
41
|
-
.show());
|
|
42
|
-
if (confirm.toUpperCase() === "Y") {
|
|
43
|
-
if (!bypass)
|
|
44
|
-
Logger.empty();
|
|
45
|
-
const spinner = ora(Chalk.setValue("Rollback...")
|
|
46
|
-
.info()
|
|
47
|
-
.show()).start();
|
|
48
|
-
try {
|
|
49
|
-
const [batchNo, logs] = await database.migrate.rollback();
|
|
50
|
-
spinner.succeed(`Batch ${batchNo} finished`);
|
|
51
|
-
if (logs.length > 0)
|
|
52
|
-
logs.forEach((migration) => spinner.succeed(migration));
|
|
53
|
-
else
|
|
54
|
-
spinner.succeed("No migrations were rolled back.");
|
|
55
|
-
}
|
|
56
|
-
catch (error) {
|
|
57
|
-
spinner.fail(`Rollback failed : ${error.message}`);
|
|
58
|
-
}
|
|
59
|
-
finally {
|
|
60
|
-
await database.destroy();
|
|
61
|
-
spinner.stop();
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export default class MigrateStatusCommand {
|
|
2
|
-
/**
|
|
3
|
-
* The name and signature of the console command.
|
|
4
|
-
*
|
|
5
|
-
* @var $signature string
|
|
6
|
-
*/
|
|
7
|
-
protected $signature: string;
|
|
8
|
-
/**
|
|
9
|
-
* The console command description.
|
|
10
|
-
*
|
|
11
|
-
* @var $description string
|
|
12
|
-
*/
|
|
13
|
-
protected $description: string;
|
|
14
|
-
/**
|
|
15
|
-
* The options or optional flag of the console command.
|
|
16
|
-
*
|
|
17
|
-
* @var $options Array<Array<any>>
|
|
18
|
-
*/
|
|
19
|
-
protected $options: Array<Array<any>>;
|
|
20
|
-
/**
|
|
21
|
-
* The arguments of the console command.
|
|
22
|
-
*
|
|
23
|
-
* @var $arguments Array<Array<string>>
|
|
24
|
-
*/
|
|
25
|
-
protected $arguments: Array<Array<string>>;
|
|
26
|
-
handle(options: any, args: Array<string>): Promise<void>;
|
|
27
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import Logger from "@bejibun/logger";
|
|
2
|
-
import Chalk from "@bejibun/logger/facades/Chalk";
|
|
3
|
-
import ora from "ora";
|
|
4
|
-
import { initDatabase } from "../../config/database";
|
|
5
|
-
export default class MigrateStatusCommand {
|
|
6
|
-
/**
|
|
7
|
-
* The name and signature of the console command.
|
|
8
|
-
*
|
|
9
|
-
* @var $signature string
|
|
10
|
-
*/
|
|
11
|
-
$signature = "migrate:status";
|
|
12
|
-
/**
|
|
13
|
-
* The console command description.
|
|
14
|
-
*
|
|
15
|
-
* @var $description string
|
|
16
|
-
*/
|
|
17
|
-
$description = "List migrations status";
|
|
18
|
-
/**
|
|
19
|
-
* The options or optional flag of the console command.
|
|
20
|
-
*
|
|
21
|
-
* @var $options Array<Array<any>>
|
|
22
|
-
*/
|
|
23
|
-
$options = [
|
|
24
|
-
["-f, --force", "Skip command confirmation"]
|
|
25
|
-
];
|
|
26
|
-
/**
|
|
27
|
-
* The arguments of the console command.
|
|
28
|
-
*
|
|
29
|
-
* @var $arguments Array<Array<string>>
|
|
30
|
-
*/
|
|
31
|
-
$arguments = [];
|
|
32
|
-
async handle(options, args) {
|
|
33
|
-
const database = initDatabase();
|
|
34
|
-
const spinner = ora(Chalk.setValue("Fetching...")
|
|
35
|
-
.info()
|
|
36
|
-
.show()).start();
|
|
37
|
-
try {
|
|
38
|
-
const [completed, pending] = await database.migrate.list();
|
|
39
|
-
spinner.succeed("Completed Migrations :");
|
|
40
|
-
if (completed.length > 0)
|
|
41
|
-
completed.forEach((migration) => spinner.succeed(migration.name));
|
|
42
|
-
else
|
|
43
|
-
spinner.succeed("No migrations were completed.");
|
|
44
|
-
Logger.empty();
|
|
45
|
-
spinner.succeed("Pending Migrations :");
|
|
46
|
-
if (pending.length > 0)
|
|
47
|
-
pending.forEach((migration) => spinner.succeed(migration.file));
|
|
48
|
-
else
|
|
49
|
-
spinner.succeed("No migrations were pending.");
|
|
50
|
-
}
|
|
51
|
-
catch (error) {
|
|
52
|
-
spinner.fail(`Fetching failed : ${error.message}`);
|
|
53
|
-
}
|
|
54
|
-
finally {
|
|
55
|
-
await database.destroy();
|
|
56
|
-
spinner.stop();
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
package/config/database.d.ts
DELETED
package/config/database.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import App from "@bejibun/app";
|
|
2
|
-
import fs from "fs";
|
|
3
|
-
import knex from "knex";
|
|
4
|
-
const config = {
|
|
5
|
-
client: "pg",
|
|
6
|
-
connection: {
|
|
7
|
-
host: "127.0.0.1",
|
|
8
|
-
port: 5432,
|
|
9
|
-
user: "postgres",
|
|
10
|
-
password: "",
|
|
11
|
-
database: "bejibun"
|
|
12
|
-
},
|
|
13
|
-
migrations: {
|
|
14
|
-
extension: "ts",
|
|
15
|
-
directory: "./database/migrations",
|
|
16
|
-
tableName: "migrations"
|
|
17
|
-
},
|
|
18
|
-
pool: {
|
|
19
|
-
min: 0,
|
|
20
|
-
max: 1
|
|
21
|
-
},
|
|
22
|
-
seeds: {
|
|
23
|
-
extension: "ts",
|
|
24
|
-
directory: "./database/seeders"
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
export const initDatabase = () => {
|
|
28
|
-
const configPath = App.configPath("database.ts");
|
|
29
|
-
let _config;
|
|
30
|
-
if (fs.existsSync(configPath))
|
|
31
|
-
_config = require(configPath).default;
|
|
32
|
-
else
|
|
33
|
-
_config = config;
|
|
34
|
-
return knex(_config);
|
|
35
|
-
};
|
|
36
|
-
export default config;
|