Skip to content

Commit 2da7e99

Browse files
Fix checking an existence of page in the app (#78)
* Fix checking an existence of page in the app * Fix lint
1 parent ae812a2 commit 2da7e99

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

commands/application.react.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,10 @@ const createPathToPage = (pageName) => {
162162
createPagesIndex();
163163
}
164164

165-
if(fs.existsSync(newPagePath)) {
166-
console.error('The page already exists');
167-
process.exit();
165+
if(!fs.existsSync(newPagePath)) {
166+
fs.mkdirSync(newPagePath);
168167
}
169168

170-
fs.mkdirSync(newPagePath);
171-
172169
return newPagePath;
173170
};
174171

utility/template-creator.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,16 @@ const applyTemplateToFile = (filePath, templateOptions) => {
1212
return content;
1313
};
1414

15-
const addPageToApp = (pageName, pathToPage, templatePagesPath) => {
15+
const addPageToApp = (pageName, pageDir, templatePagesPath) => {
1616
fs.readdirSync(templatePagesPath).forEach((pageItem) => {
17+
const pagePath = path.join(pageDir, `${pageName}${extname(pageItem)}`);
18+
if(fs.existsSync(pagePath)) {
19+
console.error('The page already exists');
20+
process.exit();
21+
}
1722
const templateOption = { pageName, title: stringUtils.humanize(pageName) };
1823
const content = applyTemplateToFile(path.join(templatePagesPath, pageItem), templateOption);
19-
fs.writeFileSync(path.join(pathToPage, `${pageName}${extname(pageItem)}`), content);
24+
fs.writeFileSync(pagePath, content);
2025
});
2126
};
2227

0 commit comments

Comments
 (0)