Skip to content

Commit

Permalink
fix(write): index models check correctly if path already exist
Browse files Browse the repository at this point in the history
  • Loading branch information
anymaniax committed Nov 23, 2020
1 parent df97884 commit 4457bb3
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/core/writers/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,14 @@ export const writeModel = (
const name = camel(spec.name);
writeFileSync(getPath(path, name), getModel(info, spec));
const indexPath = getPath(path, 'index');
const exportFile = `export * from './${name}';\n`;

readFile(indexPath, function (err, data) {
if (err) throw err;
if (!data.includes(exportFile)) {
const stringData = data.toString();
if (
!stringData.includes(`export * from './${name}'`) &&
!stringData.includes(`export * from "./${name}"`)
) {
appendFileSync(getPath(path, 'index'), `export * from './${name}';\n`);
}
});
Expand Down

0 comments on commit 4457bb3

Please sign in to comment.