@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.
Files changed (2) hide show
  1. package/cli.ts +16 -17
  2. 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 relative to current working directory
88
- const resolvedPath = filePath.startsWith('.') || filePath.startsWith('/')
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(resolvedPath);
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
- const resolvedDir = dirPath.startsWith('.') || dirPath.startsWith('/')
113
- ? dirPath
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(resolvedDir);
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(resolvedDir, file);
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
- const resolvedPath = path.startsWith('.') || path.startsWith('/')
147
- ? path
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(resolvedPath);
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: options.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: ${options.outputDir}`);
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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@doviui/dev-db",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "TypeScript-first mock database generator for rapid application development",
5
5
  "main": "index.ts",
6
6
  "module": "index.ts",