forked from garevna/js-lessons
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
22 lines (16 loc) · 788 Bytes
/
Copy pathtest.js
File metadata and controls
22 lines (16 loc) · 788 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
const fs = require('fs')
const path = require('path')
const dirPath = path.join(__dirname, 'public', 'lessons')
const dirEntries = fs.readdirSync(dirPath, { withFileTypes: true })
const folders = dirEntries
.filter(dirent => dirent.isDirectory())
folders.forEach(folder => {
const folderPath = path.join(dirPath, folder.name)
const files = fs.readdirSync(folderPath, { withFileTypes: true })
const list = JSON.stringify(files.map(file => file.name.split('.').slice(0, -1).join('')))
fs.writeFileSync(path.join(__dirname, `public/files/${folder.name}.json`), list, { encoding: 'utf-8' })
if (folder.name === 'ru') {
const toSave = `export const pages = ${list}`
fs.writeFileSync(path.join(__dirname, 'src/configs/pages.js'), toSave, { encoding: 'utf-8' })
}
})