@realtek/core-theme 0.0.65 → 0.0.66

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.65",
3
+ "version": "0.0.66",
4
4
  "type": "module",
5
5
  "description": "RealTek CORE-THEME — shared React component & admin-screen library (AddFormV1, EditFormV1, ListView, DetailViewV1, ...).",
6
6
  "license": "UNLICENSED",
@@ -1,12 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import process from 'node:process';
4
- import { existsSync, readFileSync } from 'node:fs';
4
+ import { existsSync, readFileSync, writeFileSync } from 'node:fs';
5
5
  import { resolve as resolvePath } from 'node:path';
6
6
  import { createInterface } from 'node:readline/promises';
7
7
  import { stdin as input, stdout as output } from 'node:process';
8
8
  import { MongoClient, ObjectId } from 'mongodb';
9
9
 
10
+ const INIT_MARKER_FILENAME = '.core-theme-mongodb-init.json';
10
11
  const DEFAULT_MONGO_URI = '';
11
12
  const DEFAULT_ADMIN_EMAIL = 'admin@example.com';
12
13
  const DEFAULT_ADMIN_PASSWORD_HASH = '$2a$10$N9qo8uLOickgx2ZMRZoMyeIjZAgcfl7p92ldGxad68LJZdL17lhWy';
@@ -100,6 +101,7 @@ function parseArgs(argv) {
100
101
  const options = {
101
102
  postinstall: false,
102
103
  skipPrompt: false,
104
+ force: false,
103
105
  dbName: process.env.MONGO_DB_NAME || process.env.MONGO_DATABASE || process.env.DB_NAME || '',
104
106
  mongoUri: process.env.MONGO_URI || '',
105
107
  };
@@ -110,6 +112,8 @@ function parseArgs(argv) {
110
112
  options.postinstall = true;
111
113
  } else if (arg === '--yes' || arg === '-y') {
112
114
  options.skipPrompt = true;
115
+ } else if (arg === '--force' || arg === '-f') {
116
+ options.force = true;
113
117
  } else if (arg === '--db' || arg === '--db-name') {
114
118
  options.dbName = argv[index + 1] || '';
115
119
  index += 1;
@@ -182,6 +186,34 @@ function loadProjectEnv() {
182
186
  return loaded;
183
187
  }
184
188
 
189
+ function getProjectRoot() {
190
+ return process.env.INIT_CWD || process.cwd();
191
+ }
192
+
193
+ function getInitMarkerPath() {
194
+ return resolvePath(getProjectRoot(), INIT_MARKER_FILENAME);
195
+ }
196
+
197
+ function hasCompletedInit() {
198
+ return existsSync(getInitMarkerPath());
199
+ }
200
+
201
+ function writeInitMarker({ mongoUri, dbName }) {
202
+ let mongoHost = 'unknown';
203
+ try {
204
+ mongoHost = new URL(mongoUri).host || mongoHost;
205
+ } catch {
206
+ // ignore malformed URI, marker is informational only
207
+ }
208
+
209
+ const markerPath = getInitMarkerPath();
210
+ writeFileSync(
211
+ markerPath,
212
+ `${JSON.stringify({ dbName, mongoHost, initializedAt: new Date().toISOString() }, null, 2)}\n`,
213
+ );
214
+ return markerPath;
215
+ }
216
+
185
217
  async function promptForDbName(defaultDbName) {
186
218
  const rl = createInterface({ input, output });
187
219
  try {
@@ -756,6 +788,12 @@ async function main() {
756
788
  return;
757
789
  }
758
790
 
791
+ if (!options.force && hasCompletedInit()) {
792
+ log(`SKIPPED : already initialized (see ${INIT_MARKER_FILENAME})`);
793
+ log('RE-RUN : npx core-theme-init-mongodb --force');
794
+ return;
795
+ }
796
+
759
797
  if (options.postinstall && !process.stdin.isTTY && !options.dbName) {
760
798
  log('SKIPPED : npm install is not interactive');
761
799
  log('RUN MANUALLY : npx core-theme-init-mongodb --db <databaseName>');
@@ -779,6 +817,8 @@ async function main() {
779
817
  log('STARTING MONGODB ADMIN SEED');
780
818
  loadedEnvFiles.forEach((path) => log(`ENV LOADED : ${path}`));
781
819
  await initializeDatabase({ mongoUri, dbName });
820
+ const markerPath = writeInitMarker({ mongoUri, dbName });
821
+ log(`MARKER WRITTEN : ${markerPath}`);
782
822
  log('MONGODB ADMIN SEED COMPLETED');
783
823
  }
784
824