@arkstack/console 0.1.28 → 0.1.30

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,93 @@
1
+ import path, { isAbsolute, join } from "node:path";
2
+ import { CliApp } from "resora";
3
+ import { existsSync } from "node:fs";
4
+
5
+ //#region dist/config.js
6
+ const defaultConfig = (app) => {
7
+ return {
8
+ resourcesDir: "dist/app/http/resources",
9
+ localStubsDir: `node_modules/@arkstack/driver-${app.getDriver().name ?? "h3"}/stubs`,
10
+ stubs: {
11
+ resource: "resource.stub",
12
+ collection: "resource.collection.stub",
13
+ controller: "controller.stub",
14
+ api: "controller.api.stub",
15
+ model: "controller.model.stub",
16
+ apiResource: "controller.api.resource.stub"
17
+ }
18
+ };
19
+ };
20
+
21
+ //#endregion
22
+ //#region dist/app.js
23
+ const resolveStubsDir = (config, options, core) => {
24
+ const configuredDir = config?.localStubsDir;
25
+ if (configuredDir) return isAbsolute(configuredDir) ? configuredDir : join(process.cwd(), configuredDir);
26
+ if (!options?.stubsDir) {
27
+ const driver = core?.getDriver().name ?? "h3";
28
+ let stubsDir = path.resolve(process.cwd(), `node_modules/@arkstack/driver-${driver}/stubs`);
29
+ if (!existsSync(stubsDir)) stubsDir = path.resolve(process.cwd(), "stubs");
30
+ return stubsDir;
31
+ }
32
+ return options?.stubsDir;
33
+ };
34
+ var ArkstackConsoleApp = class extends CliApp {
35
+ core;
36
+ options;
37
+ constructor(core, options) {
38
+ super();
39
+ this.core = core;
40
+ this.options = options;
41
+ this.mergeConfig();
42
+ }
43
+ makeController = (name, opts) => {
44
+ this.mergeConfig();
45
+ const normalized = name.endsWith("Controller") ? name.replace(/controller/i, "") : name;
46
+ let controllerName = normalized.endsWith("Controller") ? normalized : `${normalized}Controller`;
47
+ const outputPath = join(path.resolve(process.cwd(), "src", "app/http/controllers"), `${controllerName}.${opts?.ext ?? "ts"}`);
48
+ const stubsDir = resolveStubsDir(this.config, this.options, this.core);
49
+ if (!stubsDir) {
50
+ console.error("Error: stubsDir is not configured. Set stubsDir in resora.config.js.");
51
+ process.exit(1);
52
+ }
53
+ const stubPath = join(stubsDir, opts.model ? this.config.stubs.model : opts.api ? this.config.stubs.api : this.config.stubs.controller);
54
+ if (!existsSync(stubPath)) {
55
+ console.error(`Error: Stub file ${stubPath} not found.`);
56
+ process.exit(1);
57
+ }
58
+ controllerName = controllerName.split("/").pop();
59
+ this.generateFile(stubPath, outputPath, {
60
+ ControllerName: controllerName,
61
+ Model: opts.model?.pascalCase(),
62
+ ModelName: opts.model?.camelCase(),
63
+ Name: controllerName.replace(/controller/i, "")
64
+ }, opts);
65
+ return outputPath;
66
+ };
67
+ /**
68
+ * Normalize a file path by removing the current working directory from it.
69
+ *
70
+ * @param p
71
+ * @returns
72
+ */
73
+ normalizePath = (p) => {
74
+ return p.replace(process.cwd(), "");
75
+ };
76
+ /**
77
+ * Recursively merge defaultConfig with config from resora.config.js, giving
78
+ * precedence to resora.
79
+ */
80
+ mergeConfig = () => {
81
+ this.config = {
82
+ ...defaultConfig(this.core),
83
+ ...this.config,
84
+ stubs: {
85
+ ...defaultConfig(this.core).stubs,
86
+ ...this.config?.stubs
87
+ }
88
+ };
89
+ };
90
+ };
91
+
92
+ //#endregion
93
+ export { resolveStubsDir as n, ArkstackConsoleApp as t };
package/dist/app.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { CliApp } from "resora";
2
2
 
3
- //#region src/app.d.ts
3
+ //#region src/types.d.ts
4
4
  interface Core {
5
5
  [k: string]: any;
6
6
  getDriver: () => {
@@ -11,6 +11,8 @@ interface Core {
11
11
  interface ConsoleAppOptions {
12
12
  stubsDir?: string;
13
13
  }
14
+ //#endregion
15
+ //#region src/app.d.ts
14
16
  declare const resolveStubsDir: (config: {
15
17
  localStubsDir?: string;
16
18
  } | undefined, options?: ConsoleAppOptions, core?: Core) => string;
@@ -19,7 +21,18 @@ declare class ArkstackConsoleApp<TCore extends Core> extends CliApp {
19
21
  private readonly options;
20
22
  constructor(core: TCore, options: ConsoleAppOptions);
21
23
  makeController: (name: string, opts: any) => string;
24
+ /**
25
+ * Normalize a file path by removing the current working directory from it.
26
+ *
27
+ * @param p
28
+ * @returns
29
+ */
22
30
  normalizePath: (p: string) => string;
31
+ /**
32
+ * Recursively merge defaultConfig with config from resora.config.js, giving
33
+ * precedence to resora.
34
+ */
35
+ mergeConfig: () => void;
23
36
  }
24
37
  //#endregion
25
- export { ArkstackConsoleApp, ConsoleAppOptions, resolveStubsDir };
38
+ export { ArkstackConsoleApp, resolveStubsDir };
package/dist/app.js CHANGED
@@ -1,54 +1,3 @@
1
- import path, { isAbsolute, join } from "node:path";
2
- import { CliApp } from "resora";
3
- import { existsSync } from "node:fs";
1
+ import { n as resolveStubsDir, t as ArkstackConsoleApp } from "./app-DtecNuLP.js";
4
2
 
5
- //#region dist/app.js
6
- const resolveStubsDir = (config, options, core) => {
7
- const configuredDir = config?.localStubsDir;
8
- if (configuredDir) return isAbsolute(configuredDir) ? configuredDir : join(process.cwd(), configuredDir);
9
- if (!options?.stubsDir) {
10
- const driver = core?.getDriver().name ?? "h3";
11
- let stubsDir = path.resolve(process.cwd(), `node_modules/@arkstack/driver-${driver}/stubs`);
12
- if (!existsSync(stubsDir)) stubsDir = path.resolve(process.cwd(), "stubs");
13
- return stubsDir;
14
- }
15
- return options?.stubsDir;
16
- };
17
- var ArkstackConsoleApp = class extends CliApp {
18
- core;
19
- options;
20
- constructor(core, options) {
21
- super();
22
- this.core = core;
23
- this.options = options;
24
- }
25
- makeController = (name, opts) => {
26
- const normalized = name.endsWith("Controller") ? name.replace(/controller/i, "") : name;
27
- let controllerName = normalized.endsWith("Controller") ? normalized : `${normalized}Controller`;
28
- const outputPath = join(path.resolve(process.cwd(), "src", "app/http/controllers"), `${controllerName}.${opts?.ext ?? "ts"}`);
29
- const stubsDir = resolveStubsDir(this.config, this.options, this.core);
30
- if (!stubsDir) {
31
- console.error("Error: stubsDir is not configured. Set stubsDir in resora.config.js.");
32
- process.exit(1);
33
- }
34
- const stubPath = join(stubsDir, opts.model ? this.config.stubs.model : opts.api ? this.config.stubs.api : this.config.stubs.controller);
35
- if (!existsSync(stubPath)) {
36
- console.error(`Error: Stub file ${stubPath} not found.`);
37
- process.exit(1);
38
- }
39
- controllerName = controllerName.split("/").pop();
40
- this.generateFile(stubPath, outputPath, {
41
- ControllerName: controllerName,
42
- Model: opts.model?.pascalCase(),
43
- ModelName: opts.model?.camelCase(),
44
- Name: controllerName.replace(/controller/i, "")
45
- }, opts);
46
- return outputPath;
47
- };
48
- normalizePath = (p) => {
49
- return p.replace(process.cwd(), "");
50
- };
51
- };
52
-
53
- //#endregion
54
3
  export { ArkstackConsoleApp, resolveStubsDir };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { ArkstackConsoleApp } from "./app.js";
2
+ import { t as ArkstackConsoleApp } from "./app-DtecNuLP.js";
3
3
  import { fileURLToPath, pathToFileURL } from "node:url";
4
4
  import { join } from "node:path";
5
5
  import { MakeResource } from "resora";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkstack/console",
3
- "version": "0.1.28",
3
+ "version": "0.1.30",
4
4
  "type": "module",
5
5
  "description": "Console package for Arkstack providing console-specific implementations of core Arkstack features such as routing, middleware, and database integration.",
6
6
  "homepage": "https://arkstack.toneflix.net",
@@ -49,8 +49,8 @@
49
49
  "@h3ravel/musket": "^0.10.1",
50
50
  "chalk": "^5.6.2",
51
51
  "resora": "^0.2.14",
52
- "@arkstack/common": "^0.1.28",
53
- "@arkstack/contract": "^0.1.28"
52
+ "@arkstack/common": "^0.1.30",
53
+ "@arkstack/contract": "^0.1.30"
54
54
  },
55
55
  "scripts": {
56
56
  "build": "tsdown",