Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const filter = (filePath) => {
// The filePath is absolute, but should be relative as micromatch will
// match against the relative path of the routes. Matching against
// an absolute path requires the use of path.join which causes issues on Windows:
// https://github.com/micromatch/micromatch/issues/95
filePath = path.relative(srcPath, filePath)
const fileName = path.parse(filePath).base
const isIgnored = mm.any(filePath, ignoredFiles)
const isJunk = junk.is(fileName)
// Copy file when it's not ignored or not junk
const copy = isIgnored === false && isJunk === false
if (opts.verbose === true) {
if (copy === false) log(`{cyan:Skipping file: {grey:${ filePath }`)
if (copy === true) log(`{cyan:Copying file: {grey:${ filePath }`)
}
// Return true to include, false to exclude
return copy
}
fs.readdirSync(file.path).map(fileInDirectory => {
// Get stats for each file in directory so we can add the size of the file in the object instead of the size of the folder.
const fileName = fileInDirectory;
const filePath = `${file.path}/${fileInDirectory}`;
const fileInDirectoryStats = fs.statSync(filePath);
const fileSize = fileInDirectoryStats.size;
const fileExtention = fileName.substr(fileName.lastIndexOf(".") + 1);
if (Junk.is(fileInDirectory)) {
// Check if file is junk (Think on files like DS_Store ect..)
return false;
} else {
// Map and push the file object in array
const fileObject = {
extention: fileExtention,
size: fileSize,
name: fileName,
path: filePath,
status: "loading"
};
// Push
files.push(fileObject);
}
});
const eventHandler = function(bs, event, filePath) {
const fileName = path.parse(filePath).base
const fileExtension = path.extname(filePath)
// Ignore change when filePath is junk
if (junk.is(fileName) === true) return
// Flush the cache no matter what event was send by Chokidar.
// This ensures that we serve the latest files when the user reloads the site.
cache.flush(filePath)
const styleExtensions = [
'.css',
'.scss',
'.sass',
'.less'
]
// Reload stylesheets when the file extension is a known style extension
if (styleExtensions.includes(fileExtension) === true) return bs.reload('*.css')
const imageExtensions = [
recursive( gameFilesPath, ( gameFilesError, gameFiles ) => {
if ( gameFilesError ) {
console.log( `No game files found for ${ gameData.identifier } ` );
gameFiles = [];
}
for ( const filename of gameFiles ) {
if ( junk.is( path.parse( filename ).base ) ) {
continue;
}
if ( filename.includes( 'styles.css' ) ) {
gameData.styles = fs.readFileSync( filename );
}
if ( filename.includes( 'assets/logo.png' ) ) {
gameData.logo = '<img class="header-logo" src="assets/logo.png">';
}
savefile( path.join( gameData.identifier, filename.replace( gameFilesPath, '' ) ), fs.readFileSync( filename ) );
}
if ( !gameData.logo ) {
gameData.logo = gameData.shortName;
function junkFilter(relativePath) {
var filename = path.basename(relativePath);
return !junk.is(filename);
}
}) {
if (!this.device) return this.throwMtpError();
try {
if (!existsSync(folderPath)) {
return Promise.resolve({
data: null,
error: MTP_ERROR_FLAGS.LOCAL_FOLDER_NOT_FOUND
});
}
const files = readdirSync(folderPath);
for (let i = 0; i < files.length; i += 1) {
const file = files[i];
if (!junk.is(file)) {
const fullPath = join(folderPath, file);
const stats = lstatSync(fullPath);
const isFolder = stats.isDirectory();
const fileInfo = {
id: quickHash(fullPath),
name: file,
size: stats.size,
isFolder,
path: fullPath,
children: []
};
if (isWritable(fullPath)) {
const lastIndex = fileTreeStructure.push(fileInfo) - 1;
if (isFolder && recursive) {
function junkFilter(relativePath) {
var filename = path.basename(relativePath);
return !junk.is(filename);
}