Skip to content

Instantly share code, notes, and snippets.

@kobenguyent
Created March 30, 2023 10:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kobenguyent/146a2395350813ec8674ad02fef3809e to your computer and use it in GitHub Desktop.
Save kobenguyent/146a2395350813ec8674ad02fef3809e to your computer and use it in GitHub Desktop.
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