|
1 | 1 | #!/usr/bin/env node |
2 | | - |
3 | 2 | const fs = require('fs'); |
4 | 3 | const path = require('path'); |
| 4 | +const _ = require('lodash'); |
5 | 5 | const fse = require('fs-extra'); |
6 | 6 | const yaml = require('js-yaml'); |
7 | 7 | const toml = require('@iarna/toml'); |
@@ -77,11 +77,19 @@ function writeFiles(encodedFiles) { |
77 | 77 | for (let i = 0; i < encodedFiles.length; i++) { |
78 | 78 | const fullPath = path.join(process.cwd(), encodedFiles[i].filePath); |
79 | 79 | fse.ensureDirSync(path.dirname(fullPath)); |
80 | | - if (fs.existsSync(fullPath) && ['yml', 'yaml', 'toml', 'json'].includes(path.extname(fullPath).substring(1))) { |
81 | | - encodedFiles[i].data = mergeFile(fullPath, encodedFiles[i].data); |
| 80 | + let fileContentChanged = true; |
| 81 | + if (fs.existsSync(fullPath)) { |
| 82 | + if (['yml', 'yaml', 'toml', 'json'].includes(path.extname(fullPath).substring(1))) { |
| 83 | + encodedFiles[i].data = mergeFile(fullPath, encodedFiles[i].data); |
| 84 | + } |
| 85 | + fileContentChanged = !_.isEqual(encodedFiles[i].data, fs.readFileSync(fullPath, 'utf8')); |
| 86 | + } |
| 87 | + if (fileContentChanged) { |
| 88 | + console.log('creating file', fullPath); |
| 89 | + fs.writeFileSync(fullPath, encodedFiles[i].data); |
| 90 | + } else { |
| 91 | + console.log('content unchanged, skipping write', fullPath); |
82 | 92 | } |
83 | | - console.log('creating file', fullPath); |
84 | | - fs.writeFileSync(fullPath, encodedFiles[i].data); |
85 | 93 | } |
86 | 94 | } |
87 | 95 |
|
|
0 commit comments