-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-node.js
34 lines (30 loc) · 870 Bytes
/
gatsby-node.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**
* Implement Gatsby's Node APIs in this file.
*
* See: https://www.gatsbyjs.org/docs/node-apis/
*/
const fs = require("fs")
const path = require("path")
const dirPath = path.join(__dirname, "/src")
const projectIdsFile = `${dirPath}/components/_projects-ids.scss`
fs.readdir(`${dirPath}/static`, function(err, files) {
if (err) {
console.error("Could not list the directory.", err)
process.exit(1)
}
if (fs.existsSync(projectIdsFile)) {
fs.unlinkSync(projectIdsFile)
}
fs.writeFile(projectIdsFile, "$projects_ids:", function(err) {
if (err) {
console.log(err)
}
})
files.forEach(function(file, index) {
const fileName = file.substring(0, file.length - 4)
if (fileName === ".DS_S") return
fs.appendFile(projectIdsFile, `"${fileName}", `, function(err) {
if (err) return console.log(err)
})
})
})