@bejibun/core 0.1.43 → 0.1.45

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 CHANGED
@@ -3,6 +3,25 @@ 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
+
6
25
  ## [v0.1.43](https://github.com/crenata/bejibun-core/compare/v0.1.42...v0.1.43) - 2025-10-21
7
26
 
8
27
  ### 🩹 Fixes
package/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  <div align="center">
2
2
 
3
+ <img src="https://github.com/crenata/bejibun/blob/master/public/images/bejibun.png?raw=true" width="150" alt="Bejibun" />
4
+
3
5
  ![GitHub top language](https://img.shields.io/github/languages/top/crenata/bejibun-core)
4
6
  ![GitHub all releases](https://img.shields.io/github/downloads/crenata/bejibun-core/total)
5
7
  ![GitHub issues](https://img.shields.io/github/issues/crenata/bejibun-core)
@@ -17,11 +19,7 @@ Core of Bejibun Framework.
17
19
  Install the package.
18
20
 
19
21
  ```bash
20
- # Using Bun
21
22
  bun add @bejibun/core
22
-
23
- # Using Bejibun
24
- bun ace install @bejibun/core
25
23
  ```
26
24
 
27
25
  ### Ace
@@ -34,16 +32,20 @@ Ace for your commander
34
32
  Author: Havea Crenata <havea.crenata@gmail.com>
35
33
 
36
34
  Options:
37
- -v, --version Show the current version
38
- -h, --help display help for command
35
+ -v, --version Show the current version
36
+ -h, --help display help for command
39
37
 
40
38
  Commands:
41
- db:seed Run database seeders
42
- migrate:fresh [options] Rollback all migrations and re-run migrations
43
- migrate:latest Run latest migration
44
- migrate:rollback Rollback the latest migrations
45
- migrate:status List migrations status
46
- help [command] display help for command
39
+ db:seed Run database seeders
40
+ install <packages...> Install package dependencies
41
+ maintenance:down [options] Turn app into maintenance mode
42
+ maintenance:up Turn app into live mode
43
+ migrate:fresh [options] Rollback all migrations and re-run migrations
44
+ migrate:latest Run latest migration
45
+ migrate:rollback [options] Rollback the latest migrations
46
+ migrate:status [options] List migrations status
47
+ package:configure [options] Configure package after installation
48
+ help [command] display help for command
47
49
 
48
50
  Examples:
49
51
  $ bun ace --help
@@ -80,7 +82,7 @@ If you find this project helpful and want to support it, you can donate via PayP
80
82
 
81
83
  Or if you are prefer using crypto :
82
84
 
83
- | EVM | Solana |
84
- | --- | ------ |
85
+ | EVM | Solana |
86
+ | ------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
85
87
  | <img src="https://github.com/crenata/bejibun/blob/master/public/images/EVM.png?raw=true" width="150" /> | <img src="https://github.com/crenata/bejibun/blob/master/public/images/SOL.png?raw=true" width="150" /> |
86
- | 0xdABe8750061410D35cE52EB2a418c8cB004788B3 | GAnoyvy9p3QFyxikWDh9hA3fmSk2uiPLNWyQ579cckMn |
88
+ | 0xdABe8750061410D35cE52EB2a418c8cB004788B3 | GAnoyvy9p3QFyxikWDh9hA3fmSk2uiPLNWyQ579cckMn |
package/bootstrap.js CHANGED
@@ -1,3 +1,3 @@
1
+ import Database from "@bejibun/database";
1
2
  import BaseModel from "./bases/BaseModel";
2
- import { initDatabase } from "./config/database";
3
- BaseModel.knex(initDatabase());
3
+ BaseModel.knex(Database.knex());
@@ -1,4 +1,4 @@
1
- export default class DbSeedCommand {
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<string>>
23
+ * @var $arguments Array<Array<any>>
24
24
  */
25
- protected $arguments: Array<Array<string>>;
25
+ protected $arguments: Array<Array<any>>;
26
26
  handle(options: any, args: Array<string>): Promise<void>;
27
27
  }
@@ -0,0 +1,51 @@
1
+ import App from "@bejibun/app";
2
+ import Logger from "@bejibun/logger";
3
+ import { isEmpty } from "@bejibun/utils";
4
+ export default class InstallCommand {
5
+ /**
6
+ * The name and signature of the console command.
7
+ *
8
+ * @var $signature string
9
+ */
10
+ $signature = "install";
11
+ /**
12
+ * The console command description.
13
+ *
14
+ * @var $description string
15
+ */
16
+ $description = "Install package dependencies";
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
+ ["<packages...>", "Install package dependencies"]
30
+ ];
31
+ async handle(options, args) {
32
+ if (isEmpty(args)) {
33
+ Logger.setContext("APP").error("There is no packages provided.");
34
+ return;
35
+ }
36
+ for (const pack of args) {
37
+ Bun.spawnSync(["bun", "add", pack], {
38
+ cwd: App.Path.rootPath(),
39
+ stdin: "inherit",
40
+ stdout: "inherit",
41
+ stderr: "inherit"
42
+ });
43
+ Bun.spawnSync(["bun", "ace", "package:configure", "--package", pack], {
44
+ cwd: App.Path.rootPath(),
45
+ stdin: "inherit",
46
+ stdout: "inherit",
47
+ stderr: "inherit"
48
+ });
49
+ }
50
+ }
51
+ }
@@ -2,22 +2,38 @@ import App from "@bejibun/app";
2
2
  import { defineValue, isEmpty } from "@bejibun/utils";
3
3
  export default class Kernel {
4
4
  static registerCommands(program) {
5
- const rootCommands = Array.from(new Bun.Glob("**/*.ts").scanSync({
6
- absolute: true,
7
- cwd: App.Path.commandsPath()
8
- }));
9
- const internalCommands = Array.from(new Bun.Glob("**/*").scanSync({
10
- absolute: true,
11
- cwd: __dirname
12
- }));
13
- const files = internalCommands.concat(rootCommands).filter(value => (/\.(m?js|ts)$/.test(value) &&
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) &&
14
26
  !value.endsWith(".d.ts") &&
15
- !value.includes("Kernel"))).reverse();
27
+ !value.includes("Kernel")));
28
+ const instances = [];
16
29
  for (const file of files) {
17
30
  const { default: CommandClass } = require(file);
18
31
  const instance = new CommandClass();
19
32
  if (isEmpty(instance.$signature) || typeof instance.handle !== "function")
20
33
  continue;
34
+ instances.push(instance);
35
+ }
36
+ for (const instance of instances.sort((a, b) => a.$signature.localeCompare(b.$signature))) {
21
37
  const cmd = program
22
38
  .command(instance.$signature)
23
39
  .description(defineValue(instance.$description, ""));
@@ -34,7 +50,7 @@ export default class Kernel {
34
50
  cmd.action(async (...args) => {
35
51
  const commandObj = args[args.length - 1];
36
52
  const options = typeof commandObj.opts === "function" ? commandObj.opts() : commandObj;
37
- const positionalArgs = args.slice(0, -1);
53
+ const positionalArgs = args[0];
38
54
  await instance.handle(options, positionalArgs);
39
55
  });
40
56
  }
@@ -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<string>>
23
+ * @var $arguments Array<Array<any>>
24
24
  */
25
- protected $arguments: Array<Array<string>>;
25
+ protected $arguments: Array<Array<any>>;
26
26
  handle(options: any, args: Array<string>): Promise<void>;
27
27
  }
@@ -25,7 +25,7 @@ export default class MaintenanceDownCommand {
25
25
  /**
26
26
  * The arguments of the console command.
27
27
  *
28
- * @var $arguments Array<Array<string>>
28
+ * @var $arguments Array<Array<any>>
29
29
  */
30
30
  $arguments = [];
31
31
  async handle(options, args) {
@@ -20,8 +20,8 @@ export default class MaintenanceUpCommand {
20
20
  /**
21
21
  * The arguments of the console command.
22
22
  *
23
- * @var $arguments Array<Array<string>>
23
+ * @var $arguments Array<Array<any>>
24
24
  */
25
- protected $arguments: Array<Array<string>>;
25
+ protected $arguments: Array<Array<any>>;
26
26
  handle(options: any, args: Array<string>): Promise<void>;
27
27
  }
@@ -1,3 +1,4 @@
1
+ import App from "@bejibun/app";
1
2
  import AppConfig from "@bejibun/app/config/app";
2
3
  import Logger from "@bejibun/logger";
3
4
  export default class MaintenanceUpCommand {
@@ -22,11 +23,11 @@ export default class MaintenanceUpCommand {
22
23
  /**
23
24
  * The arguments of the console command.
24
25
  *
25
- * @var $arguments Array<Array<string>>
26
+ * @var $arguments Array<Array<any>>
26
27
  */
27
28
  $arguments = [];
28
29
  async handle(options, args) {
29
- if (await Bun.file(AppConfig.maintenance.file).exists())
30
+ if (await App.Maintenance.isMaintenanceMode())
30
31
  await Bun.file(AppConfig.maintenance.file).delete();
31
32
  Logger.setContext("APP").info("Application turned into live mode.");
32
33
  }
@@ -1,4 +1,4 @@
1
- export default class MigrateFreshCommand {
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 MigrateFreshCommand {
20
20
  /**
21
21
  * The arguments of the console command.
22
22
  *
23
- * @var $arguments Array<Array<string>>
23
+ * @var $arguments Array<Array<any>>
24
24
  */
25
- protected $arguments: Array<Array<string>>;
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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bejibun/core",
3
- "version": "0.1.43",
3
+ "version": "0.1.45",
4
4
  "author": "Havea Crenata <havea.crenata@gmail.com>",
5
5
  "repository": {
6
6
  "type": "git",
@@ -10,16 +10,14 @@
10
10
  "module": "index.js",
11
11
  "dependencies": {
12
12
  "@bejibun/app": "^0.1.19",
13
- "@bejibun/cors": "^0.1.12",
14
- "@bejibun/logger": "^0.1.18",
15
- "@bejibun/utils": "^0.1.14",
13
+ "@bejibun/cors": "^0.1.14",
14
+ "@bejibun/database": "^0.1.11",
15
+ "@bejibun/logger": "^0.1.19",
16
+ "@bejibun/utils": "^0.1.16",
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",
@@ -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,27 +0,0 @@
1
- export default class MigrateLatestCommand {
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,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
- }
@@ -1,4 +0,0 @@
1
- import type { Knex } from "knex";
2
- declare const config: Knex.Config;
3
- export declare const initDatabase: () => Knex;
4
- export default config;
@@ -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.Path.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;