Skip to content

Commit

Permalink
chore: exclude .DS_Store file from the build process (#11780)
Browse files Browse the repository at this point in the history
  • Loading branch information
HuiSF committed Aug 10, 2023
1 parent 9073cba commit 5fe82fe
Showing 1 changed file with 25 additions and 22 deletions.
47 changes: 25 additions & 22 deletions scripts/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,45 @@
const fs = require('fs');
const path = require('path');

const excludeFilesRegExp = /^\.DS_Store$/;

/**
* get an array of the files under the give path
*/
function iterateFiles(source) {
let fileList = [];
return new Promise((res, rej) => {
fs.readdir(source, function(err, files) {
fs.readdir(source, function (err, files) {
if (err) {
console.error('Could not list the directory.', err);
return rej(err);
}

Promise.all(
files.map(file => {
const filePath = path.join(source, file);
return new Promise((res, rej) => {
fs.stat(filePath, (error, stat) => {
if (error) {
console.error('Error stating file.', error);
return rej(error);
}
files
.filter(file => !excludeFilesRegExp.test(file))
.map(file => {
const filePath = path.join(source, file);
return new Promise((res, rej) => {
fs.stat(filePath, (error, stat) => {
if (error) {
console.error('Error stating file.', error);
return rej(error);
}

if (stat.isFile()) {
fileList.push(filePath);
return res();
} else if (stat.isDirectory()) {
iterateFiles(filePath).then(list => {
fileList = fileList.concat(list);
if (stat.isFile()) {
fileList.push(filePath);
return res();
} else if (stat.isDirectory()) {
iterateFiles(filePath).then(list => {
fileList = fileList.concat(list);
return res();
});
} else {
return res();
});
} else {
return res();
}
}
});
});
});
})
})
).then(() => {
return res(fileList);
});
Expand Down

0 comments on commit 5fe82fe

Please sign in to comment.