@realtek/core-theme 0.0.209 → 0.0.210
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@realtek/core-theme",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.210",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "RealTek CORE-THEME — shared React component & admin-screen library (AddFormV1, EditFormV1, ListView, DetailViewV1, ...).",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -141,6 +141,19 @@ function log(message) {
|
|
|
141
141
|
console.log(`[core-theme:init-mongodb] ${message}`);
|
|
142
142
|
}
|
|
143
143
|
|
|
144
|
+
function maskMongoUri(mongoUri) {
|
|
145
|
+
try {
|
|
146
|
+
const url = new URL(mongoUri);
|
|
147
|
+
if (url.username || url.password) {
|
|
148
|
+
url.username = '***';
|
|
149
|
+
url.password = '***';
|
|
150
|
+
}
|
|
151
|
+
return url.toString();
|
|
152
|
+
} catch {
|
|
153
|
+
return '<invalid MongoDB URI>';
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
144
157
|
function parseEnvValue(value) {
|
|
145
158
|
const trimmed = String(value ?? '').trim();
|
|
146
159
|
if (
|
|
@@ -203,6 +216,10 @@ function hasCompletedInit() {
|
|
|
203
216
|
return existsSync(getInitMarkerPath());
|
|
204
217
|
}
|
|
205
218
|
|
|
219
|
+
function shouldAutoInitDuringPostinstall() {
|
|
220
|
+
return process.env.CORE_THEME_AUTO_DB_INIT === '1';
|
|
221
|
+
}
|
|
222
|
+
|
|
206
223
|
function writeInitMarker({ mongoUri, dbName }) {
|
|
207
224
|
let mongoHost = 'unknown';
|
|
208
225
|
try {
|
|
@@ -789,7 +806,7 @@ async function initializeDatabase({ mongoUri, dbName }) {
|
|
|
789
806
|
|
|
790
807
|
try {
|
|
791
808
|
await client.db('admin').command({ ping: 1 });
|
|
792
|
-
log(`CONNECTED : ${mongoUri}`);
|
|
809
|
+
log(`CONNECTED : ${maskMongoUri(mongoUri)}`);
|
|
793
810
|
const db = client.db(dbName);
|
|
794
811
|
log(`DATABASE : ${dbName}`);
|
|
795
812
|
|
|
@@ -825,6 +842,13 @@ async function main() {
|
|
|
825
842
|
return;
|
|
826
843
|
}
|
|
827
844
|
|
|
845
|
+
if (options.postinstall && !shouldAutoInitDuringPostinstall()) {
|
|
846
|
+
log('SKIPPED : automatic DB init is disabled during npm install');
|
|
847
|
+
log('RUN MANUALLY : npx core-theme-init-mongodb --db <databaseName>');
|
|
848
|
+
log('AUTO RUN : CORE_THEME_AUTO_DB_INIT=1 MONGO_DB_NAME=<databaseName> npm install @realtek/core-theme');
|
|
849
|
+
return;
|
|
850
|
+
}
|
|
851
|
+
|
|
828
852
|
if (!options.force && hasCompletedInit()) {
|
|
829
853
|
log(`SKIPPED : already initialized (see ${INIT_MARKER_FILENAME})`);
|
|
830
854
|
log('RE-RUN : npx core-theme-init-mongodb --force');
|
|
@@ -838,15 +862,12 @@ async function main() {
|
|
|
838
862
|
return;
|
|
839
863
|
}
|
|
840
864
|
|
|
841
|
-
const mongoUri =
|
|
842
|
-
options.mongoUri ||
|
|
843
|
-
process.env.MONGO_URI ||
|
|
844
|
-
DEFAULT_MONGO_URI;
|
|
865
|
+
const mongoUri = options.mongoUri || process.env.MONGO_URI || DEFAULT_MONGO_URI;
|
|
845
866
|
|
|
846
867
|
const dbName = options.dbName || (options.skipPrompt ? '' : await promptForDbName(options.dbName));
|
|
847
868
|
if (!mongoUri) {
|
|
848
869
|
throw new Error(
|
|
849
|
-
'MongoDB URI is required. Configure DEFAULT_MONGO_URI or set MONGO_URI.'
|
|
870
|
+
'MongoDB URI is required. Configure DEFAULT_MONGO_URI, use --uri <mongodbUri>, or set MONGO_URI.'
|
|
850
871
|
);
|
|
851
872
|
}
|
|
852
873
|
if (!dbName) {
|
|
@@ -863,5 +884,10 @@ async function main() {
|
|
|
863
884
|
|
|
864
885
|
main().catch((error) => {
|
|
865
886
|
console.error(`[core-theme:init-mongodb] FAILED : ${error.message}`);
|
|
887
|
+
if (process.argv.includes('--postinstall')) {
|
|
888
|
+
console.error('[core-theme:init-mongodb] Install will continue. Run `npx core-theme-init-mongodb --db <databaseName>` after install.');
|
|
889
|
+
process.exitCode = 0;
|
|
890
|
+
return;
|
|
891
|
+
}
|
|
866
892
|
process.exitCode = 1;
|
|
867
893
|
});
|