@doviui/dev-db 0.2.0 → 0.2.1
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/cli.ts +16 -17
- package/package.json +1 -1
package/cli.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { MockDataGenerator } from './src/generator';
|
|
|
8
8
|
import { SchemaValidator } from './src/validator';
|
|
9
9
|
import type { Schema } from './src/types';
|
|
10
10
|
import { readdirSync, statSync } from 'fs';
|
|
11
|
-
import { join, extname } from 'path';
|
|
11
|
+
import { join, extname, resolve } from 'path';
|
|
12
12
|
|
|
13
13
|
const HELP_TEXT = `
|
|
14
14
|
@doviui/dev-db - Generate realistic mock JSON databases
|
|
@@ -84,12 +84,10 @@ function parseArgs(args: string[]): CLIOptions {
|
|
|
84
84
|
|
|
85
85
|
async function loadSchemaFromFile(filePath: string): Promise<Schema> {
|
|
86
86
|
try {
|
|
87
|
-
// Resolve path
|
|
88
|
-
const
|
|
89
|
-
? filePath
|
|
90
|
-
: `./${filePath}`;
|
|
87
|
+
// Resolve path to absolute path based on current working directory
|
|
88
|
+
const absolutePath = resolve(process.cwd(), filePath);
|
|
91
89
|
|
|
92
|
-
const module = await import(
|
|
90
|
+
const module = await import(absolutePath);
|
|
93
91
|
const schema = module.default || module.schema;
|
|
94
92
|
|
|
95
93
|
if (!schema) {
|
|
@@ -109,11 +107,10 @@ async function loadSchemaFromFile(filePath: string): Promise<Schema> {
|
|
|
109
107
|
|
|
110
108
|
async function loadSchemaFromDirectory(dirPath: string): Promise<Schema> {
|
|
111
109
|
try {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
: `./${dirPath}`;
|
|
110
|
+
// Resolve path to absolute path based on current working directory
|
|
111
|
+
const absoluteDir = resolve(process.cwd(), dirPath);
|
|
115
112
|
|
|
116
|
-
const files = readdirSync(
|
|
113
|
+
const files = readdirSync(absoluteDir);
|
|
117
114
|
const schemaFiles = files.filter(file => {
|
|
118
115
|
const ext = extname(file);
|
|
119
116
|
return ext === '.ts' || ext === '.js';
|
|
@@ -126,7 +123,7 @@ async function loadSchemaFromDirectory(dirPath: string): Promise<Schema> {
|
|
|
126
123
|
const mergedSchema: Schema = {};
|
|
127
124
|
|
|
128
125
|
for (const file of schemaFiles) {
|
|
129
|
-
const filePath = join(
|
|
126
|
+
const filePath = join(absoluteDir, file);
|
|
130
127
|
const schema = await loadSchemaFromFile(filePath);
|
|
131
128
|
|
|
132
129
|
// Merge schemas
|
|
@@ -143,11 +140,10 @@ async function loadSchemaFromDirectory(dirPath: string): Promise<Schema> {
|
|
|
143
140
|
}
|
|
144
141
|
|
|
145
142
|
async function loadSchema(path: string): Promise<Schema> {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
: `./${path}`;
|
|
143
|
+
// Resolve path to absolute path based on current working directory
|
|
144
|
+
const absolutePath = resolve(process.cwd(), path);
|
|
149
145
|
|
|
150
|
-
const stats = statSync(
|
|
146
|
+
const stats = statSync(absolutePath);
|
|
151
147
|
|
|
152
148
|
if (stats.isDirectory()) {
|
|
153
149
|
return loadSchemaFromDirectory(path);
|
|
@@ -182,14 +178,17 @@ async function main() {
|
|
|
182
178
|
process.exit(1);
|
|
183
179
|
}
|
|
184
180
|
|
|
181
|
+
// Resolve output directory to absolute path
|
|
182
|
+
const absoluteOutputDir = resolve(process.cwd(), options.outputDir);
|
|
183
|
+
|
|
185
184
|
const generator = new MockDataGenerator(schema, {
|
|
186
|
-
outputDir:
|
|
185
|
+
outputDir: absoluteOutputDir,
|
|
187
186
|
seed: options.seed,
|
|
188
187
|
});
|
|
189
188
|
|
|
190
189
|
await generator.generate();
|
|
191
190
|
|
|
192
|
-
console.log(`Generated mock data in: ${
|
|
191
|
+
console.log(`Generated mock data in: ${absoluteOutputDir}`);
|
|
193
192
|
} catch (error) {
|
|
194
193
|
console.error('Error:', error instanceof Error ? error.message : error);
|
|
195
194
|
process.exit(1);
|