forked from ImaginaryVillain/community_lights
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpre-commit
More file actions
42 lines (37 loc) · 1.2 KB
/
pre-commit
File metadata and controls
42 lines (37 loc) · 1.2 KB
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
35
36
37
38
39
40
41
42
#!/usr/bin/env node
const fs = require('fs')
const mvPath = './CommunityLightingMVDemo/data/'
const mzPath = './CommunityLightingMZDemo/data/'
const mvFiles = fs.readdirSync(`${mvPath}`)
const mzFiles = fs.readdirSync(`${mzPath}`)
const { exec } = require('child_process')
let command = '';
try {
mvFiles.forEach(file => {
// Load file, pretty the JSON, and write it back
const mvFilePath = `${mvPath}${file}`
const json = fs.readFileSync(mvFilePath)
fs.writeFileSync(mvFilePath, JSON.stringify(JSON.parse(json), null, 2))
command += ` ${mvFilePath}`
})
mzFiles.forEach(file => {
// Load file, pretty the JSON, and write it back
const mzFilePath = `${mzPath}${file}`
const json = fs.readFileSync(mzFilePath)
fs.writeFileSync(mzFilePath, JSON.stringify(JSON.parse(json), null, 2))
command += ` ${mzFilePath}`
})
// Add the files back to the staging since they changed
exec(`git add ${command}`, (err, stdout, stderr) => {
if (err) {
console.error(err)
process.exit(1)
}
console.log(`stdout: ${stdout}`)
console.log(`stderr: ${stderr}`)
process.exit(0)
})
} catch (err) {
console.error(err)
process.exit(1)
}