Skip to content

Commit

Permalink
fix: Normalize file paths for model names in generate function
Browse files Browse the repository at this point in the history
  • Loading branch information
7nohe committed May 19, 2024
1 parent 1be3cee commit f396103
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export async function generate(options: CLIOptions) {
// Generate models
for (const modelPath of modelPaths) {
const modelName = modelPath
.replace(/\\/g, "/")
.replace(options.modelPath.replace(/\\/g, "/") + "/", "")
.replace(path.extname(modelPath), "") // remove .php extension
.split("/")
Expand Down Expand Up @@ -65,8 +66,10 @@ export async function generate(options: CLIOptions) {

// Read model data from JSON file
try {
const jsonPath = path.resolve(tmpDir, `${modelName}.json`);
console.log(`Reading ${jsonPath}`);
const modelJson = JSON.parse(
fs.readFileSync(path.resolve(tmpDir, `${modelName}.json`), "utf8")
fs.readFileSync(jsonPath, "utf8")
) as LaravelModelType;
modelData.push(modelJson);
} catch {
Expand Down

0 comments on commit f396103

Please sign in to comment.