-
-
Save kobenguyent/146a2395350813ec8674ad02fef3809e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fs from 'fs' | |
import glob from 'glob' | |
import {camelize, emptyFileContent, writeToFile} from '../utils/FileUtils' | |
const currentWorkingDir = process.cwd() | |
const fileType = '.ts' | |
const indexFile = 'index.ts' | |
const pageObjectsIndexPath = currentWorkingDir + '/src/page-objects/' + indexFile | |
const content = [] | |
glob.sync(currentWorkingDir + '/src/page-objects/**/').forEach(item => { | |
const directory = fs.opendirSync(item) | |
let file | |
while ((file = directory.readSync()) !== null) { | |
if (file && file.name.includes(fileType) === true && !file.name.includes(indexFile)) { | |
const fileName = file.name.split(fileType)[0] | |
if (fileName) { | |
content.push( | |
`export {${camelize(fileName)}} from '${directory.path | |
.split('src')[1] | |
.replace('/page-objects', '.')}${fileName}'`, | |
) | |
} | |
} | |
} | |
directory.closeSync() | |
}) | |
console.log('Exporting the Page Objects...') | |
emptyFileContent(pageObjectsIndexPath) | |
writeToFile(pageObjectsIndexPath, content.sort().join('\n')) | |
console.log(`Exported successfully the Page Objects to ${pageObjectsIndexPath}`) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment