@h3ravel/config 1.29.0-alpha.16 → 2.0.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/dist/index.d.ts +2 -2
- package/dist/index.js +4 -3
- package/package.json +6 -9
- package/dist/index.cjs +0 -180
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/// <reference path="./app.globals.d.ts" />
|
|
2
|
-
import { Command } from "@h3ravel/musket";
|
|
3
2
|
import { DotNestedKeys, DotNestedValue } from "@h3ravel/shared";
|
|
4
|
-
import {
|
|
3
|
+
import { Command } from "@h3ravel/musket";
|
|
5
4
|
import { ServiceProvider } from "@h3ravel/support";
|
|
5
|
+
import { IApplication } from "@h3ravel/contracts";
|
|
6
6
|
|
|
7
7
|
//#region src/Commands/ConfigPublishCommand.d.ts
|
|
8
8
|
declare class ConfigPublishCommand extends Command {
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { EnvParser, FileSystem, Logger } from "@h3ravel/shared";
|
|
1
|
+
import { EnvParser, FileSystem, Logger, importFile } from "@h3ravel/shared";
|
|
2
2
|
import { readFile, readdir, writeFile } from "node:fs/promises";
|
|
3
3
|
import { Command } from "@h3ravel/musket";
|
|
4
|
+
import * as supportModule from "@h3ravel/support";
|
|
4
5
|
import { ServiceProvider, Str, safeDot, setNested } from "@h3ravel/support";
|
|
5
6
|
import npath from "node:path";
|
|
6
7
|
import { Registerer } from "@h3ravel/core";
|
|
@@ -84,10 +85,10 @@ var ConfigRepository = class {
|
|
|
84
85
|
globalThis.env ??= this.app.make("env");
|
|
85
86
|
Registerer.register(this.app);
|
|
86
87
|
const files = (await readdir(configPath)).filter((e) => {
|
|
87
|
-
return
|
|
88
|
+
return /\.(c|m)?(j|t)sx?$/.test(e) && !e.includes(".d.");
|
|
88
89
|
});
|
|
89
90
|
for (let i = 0; i < files.length; i++) {
|
|
90
|
-
const configModule = await
|
|
91
|
+
const configModule = await importFile(npath.join(configPath, files[i]), { virtualModules: { "@h3ravel/support": supportModule } });
|
|
91
92
|
const name = files[i].replaceAll(/\.ts|\.js/g, "");
|
|
92
93
|
if (typeof configModule.default === "function") this.configs[name] = configModule.default(this.app);
|
|
93
94
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@h3ravel/config",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Environment/config loading and management system for H3ravel.",
|
|
5
5
|
"h3ravel": {
|
|
6
6
|
"providers": [
|
|
@@ -8,9 +8,7 @@
|
|
|
8
8
|
]
|
|
9
9
|
},
|
|
10
10
|
"type": "module",
|
|
11
|
-
"main": "./dist/index.cjs",
|
|
12
11
|
"types": "./dist/index.d.ts",
|
|
13
|
-
"module": "./dist/index.js",
|
|
14
12
|
"exports": {
|
|
15
13
|
".": {
|
|
16
14
|
"import": "./dist/index.js",
|
|
@@ -41,19 +39,18 @@
|
|
|
41
39
|
"laravel"
|
|
42
40
|
],
|
|
43
41
|
"dependencies": {
|
|
44
|
-
"@h3ravel/shared": "^
|
|
45
|
-
"@h3ravel/support": "^
|
|
42
|
+
"@h3ravel/shared": "^2.0.0",
|
|
43
|
+
"@h3ravel/support": "^2.0.0",
|
|
46
44
|
"@h3ravel/musket": "^1.29.0-alpha.15"
|
|
47
45
|
},
|
|
48
46
|
"devDependencies": {
|
|
49
|
-
"
|
|
50
|
-
"@h3ravel/
|
|
51
|
-
"@h3ravel/contracts": "^1.29.0-alpha.16",
|
|
47
|
+
"@h3ravel/core": "^2.0.0",
|
|
48
|
+
"@h3ravel/contracts": "^2.0.0",
|
|
52
49
|
"typescript": "^6.0.0"
|
|
53
50
|
},
|
|
54
51
|
"scripts": {
|
|
55
52
|
"build": "tsdown --config-loader unrun",
|
|
56
|
-
"dev": "
|
|
53
|
+
"dev": "tsdown --watch --config-loader unrun",
|
|
57
54
|
"start": "node dist/index.js",
|
|
58
55
|
"lint": "eslint . --ext .ts",
|
|
59
56
|
"test": "jest --passWithNoTests",
|
package/dist/index.cjs
DELETED
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
//#region \0rolldown/runtime.js
|
|
3
|
-
var __create = Object.create;
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
-
key = keys[i];
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
-
get: ((k) => from[k]).bind(null, key),
|
|
14
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
20
|
-
value: mod,
|
|
21
|
-
enumerable: true
|
|
22
|
-
}) : target, mod));
|
|
23
|
-
//#endregion
|
|
24
|
-
let _h3ravel_shared = require("@h3ravel/shared");
|
|
25
|
-
let node_fs_promises = require("node:fs/promises");
|
|
26
|
-
let _h3ravel_musket = require("@h3ravel/musket");
|
|
27
|
-
let _h3ravel_support = require("@h3ravel/support");
|
|
28
|
-
let node_path = require("node:path");
|
|
29
|
-
node_path = __toESM(node_path, 1);
|
|
30
|
-
let _h3ravel_core = require("@h3ravel/core");
|
|
31
|
-
//#region src/Commands/ConfigPublishCommand.ts
|
|
32
|
-
var ConfigPublishCommand = class extends _h3ravel_musket.Command {
|
|
33
|
-
/**
|
|
34
|
-
* The name and signature of the console command.
|
|
35
|
-
*
|
|
36
|
-
* @var string
|
|
37
|
-
*/
|
|
38
|
-
signature = `config:publish
|
|
39
|
-
{name? : The name of the configuration file to publish}
|
|
40
|
-
{--all : Publish all configuration files}
|
|
41
|
-
{--force : Overwrite any existing configuration files}
|
|
42
|
-
`;
|
|
43
|
-
/**
|
|
44
|
-
* The console command description.
|
|
45
|
-
*
|
|
46
|
-
* @var string
|
|
47
|
-
*/
|
|
48
|
-
description = "Publish configuration files to your application";
|
|
49
|
-
/**
|
|
50
|
-
* List available config files
|
|
51
|
-
*/
|
|
52
|
-
configs = ["hashing"];
|
|
53
|
-
/**
|
|
54
|
-
* Create a new seeder class
|
|
55
|
-
*/
|
|
56
|
-
async handle() {
|
|
57
|
-
if (this.option("all")) await Promise.all(this.configs.map((e) => this.publish(e)));
|
|
58
|
-
else {
|
|
59
|
-
const name = this.argument("name");
|
|
60
|
-
if (!name) _h3ravel_shared.Logger.error("ERORR: enter a configuration name or pass the --all flag to publish all available configurations.");
|
|
61
|
-
await this.publish(name);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Create a new seeder class
|
|
66
|
-
*/
|
|
67
|
-
async publish(name) {
|
|
68
|
-
const force = this.option("force");
|
|
69
|
-
const path = base_path(`src/config/${_h3ravel_support.Str.snake(name)}.ts`);
|
|
70
|
-
if (!force && await _h3ravel_shared.FileSystem.fileExists(path)) this.error(`ERORR: ${name} already exists`);
|
|
71
|
-
const dbPkgPath = _h3ravel_shared.FileSystem.findModulePkg("@h3ravel/config", this.kernel.cwd) ?? "";
|
|
72
|
-
const stubPath = node_path.default.join(dbPkgPath, this.getStubName(name));
|
|
73
|
-
if (!await _h3ravel_shared.FileSystem.fileExists(stubPath)) this.error(`ERORR: Config [${name}] does not exist`);
|
|
74
|
-
await (0, node_fs_promises.writeFile)(path, await (0, node_fs_promises.readFile)(stubPath, "utf-8"));
|
|
75
|
-
this.info(`INFO: Config ${_h3ravel_shared.Logger.log(`[${node_path.default.relative(process.cwd(), path)}]`, "bold", false)} published successfully.`);
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Get the configuration file to publish
|
|
79
|
-
*
|
|
80
|
-
* @param name
|
|
81
|
-
* @returns
|
|
82
|
-
*/
|
|
83
|
-
getStubName(name) {
|
|
84
|
-
return `dist/stubs/${name}.stub`;
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
//#endregion
|
|
88
|
-
//#region src/ConfigRepository.ts
|
|
89
|
-
var ConfigRepository = class {
|
|
90
|
-
app;
|
|
91
|
-
loaded = false;
|
|
92
|
-
configs = {};
|
|
93
|
-
constructor(app) {
|
|
94
|
-
this.app = app;
|
|
95
|
-
}
|
|
96
|
-
get(key, def) {
|
|
97
|
-
return (0, _h3ravel_support.safeDot)(this.configs, key) ?? def;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Modify the defined configurations
|
|
101
|
-
*/
|
|
102
|
-
set(key, value) {
|
|
103
|
-
(0, _h3ravel_support.setNested)(this.configs, key, value);
|
|
104
|
-
}
|
|
105
|
-
async load() {
|
|
106
|
-
if (!this.loaded) {
|
|
107
|
-
const configPath = this.app.getPath("config");
|
|
108
|
-
globalThis.env ??= this.app.make("env");
|
|
109
|
-
_h3ravel_core.Registerer.register(this.app);
|
|
110
|
-
const files = (await (0, node_fs_promises.readdir)(configPath)).filter((e) => {
|
|
111
|
-
return !e.includes(".d.ts") && !e.includes(".d.cts") && !e.includes(".map");
|
|
112
|
-
});
|
|
113
|
-
for (let i = 0; i < files.length; i++) {
|
|
114
|
-
const configModule = await import(node_path.default.join(configPath, files[i]));
|
|
115
|
-
const name = files[i].replaceAll(/\.ts|\.js/g, "");
|
|
116
|
-
if (typeof configModule.default === "function") this.configs[name] = configModule.default(this.app);
|
|
117
|
-
}
|
|
118
|
-
this.loaded = true;
|
|
119
|
-
}
|
|
120
|
-
return this;
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
//#endregion
|
|
124
|
-
//#region src/EnvLoader.ts
|
|
125
|
-
var EnvLoader = class {
|
|
126
|
-
app;
|
|
127
|
-
constructor(app) {
|
|
128
|
-
this.app = app;
|
|
129
|
-
}
|
|
130
|
-
get(key, def) {
|
|
131
|
-
return (0, _h3ravel_support.safeDot)(_h3ravel_shared.EnvParser.parse(process.env), key) ?? def;
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
//#endregion
|
|
135
|
-
//#region src/Helpers.ts
|
|
136
|
-
var Helpers = class {};
|
|
137
|
-
//#endregion
|
|
138
|
-
//#region src/Providers/ConfigServiceProvider.ts
|
|
139
|
-
/**
|
|
140
|
-
* Loads configuration and environment files.
|
|
141
|
-
*
|
|
142
|
-
* Load .env and merge with config files.
|
|
143
|
-
* Bind ConfigRepository to the container.
|
|
144
|
-
*
|
|
145
|
-
* Auto-Registered
|
|
146
|
-
*/
|
|
147
|
-
var ConfigServiceProvider = class extends _h3ravel_support.ServiceProvider {
|
|
148
|
-
static priority = 998;
|
|
149
|
-
async register() {
|
|
150
|
-
/**
|
|
151
|
-
* Create singleton to load env
|
|
152
|
-
*/
|
|
153
|
-
this.app.singleton("env", () => {
|
|
154
|
-
const env = new EnvLoader(this.app).get;
|
|
155
|
-
globalThis.env ??= env;
|
|
156
|
-
return env;
|
|
157
|
-
});
|
|
158
|
-
/**
|
|
159
|
-
* Initialize the configuration through the repository
|
|
160
|
-
*/
|
|
161
|
-
const repo = new ConfigRepository(this.app);
|
|
162
|
-
await repo.load();
|
|
163
|
-
/**
|
|
164
|
-
* Create singleton to load configurations
|
|
165
|
-
*/
|
|
166
|
-
this.app.singleton("config", () => {
|
|
167
|
-
return repo;
|
|
168
|
-
});
|
|
169
|
-
this.app.make("http.app").use((e) => {
|
|
170
|
-
repo.set("app.url", e.url.origin);
|
|
171
|
-
});
|
|
172
|
-
this.registerCommands([ConfigPublishCommand]);
|
|
173
|
-
}
|
|
174
|
-
};
|
|
175
|
-
//#endregion
|
|
176
|
-
exports.ConfigPublishCommand = ConfigPublishCommand;
|
|
177
|
-
exports.ConfigRepository = ConfigRepository;
|
|
178
|
-
exports.ConfigServiceProvider = ConfigServiceProvider;
|
|
179
|
-
exports.EnvLoader = EnvLoader;
|
|
180
|
-
exports.Helpers = Helpers;
|