Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (i >= 0) files.splice(i, 1);
updateBundle();
} else {
updateBundle();
}
});
}
}
}
finder(dir, {
isDirectory: function () {
return true
}
});
findit.sync(dir, finder);
var bodies;
var getBodies =
function () {
bodies =
files.reduce(function (acc, file) {
var rel = file.slice(dir.length + 1);
opts.removeExtension
&& (rel = rel.substr(0, rel.length - opts.extension.length));
acc[rel] = fs.readFileSync(file, 'utf8');
module.exports.files[rel] = acc[rel];
return acc;
}, {});
}
// populate exports.files first
getBodies();
buildProject(function() {
var fileName;
util.debug('--- Starting Web Server ---');
startServer();
util.debug('--- Watching directory for changes ---');
setInterval(function() {
if (buildIsRequested) {
buildIsRequested = false;
buildProject(null);
}
}, 50); // Debounce a bit
var findIt = require('findit');
addFilesToMap([curDir + '/ProjectConfig.js', curDir + '/index.html']);
addFilesToMap(findIt.sync(curDir + '/lib'));
addFilesToMap(findIt.sync(curDir + '/staticResources'));
for (fileName in filesMap) {
if (!filesMap.hasOwnProperty(fileName)) {
continue;
}
fs.watchFile(fileName, {}, function(cur, prev) {
if (cur.mtime > prev.mtime) {
buildIsRequested = true;
}
});
}
});
fs2.readDirSync = function (p, resolve, filter) {
// findit.sync returns a list of directories already.
var files = findit.sync(p);
if ( typeof filter === 'function') {
// Apply the filter, if any.
files = files.filter(filter);
}
// Convert the list from findit into an object structure.
return fs2.filesArrayToObject(files, resolve);
};
Model.bootstrap = function() {
var file, files, klass, _i, _len, _results;
files = require('findit').sync("" + Metro.root + "/app/models");
_results = [];
for (_i = 0, _len = files.length; _i < _len; _i++) {
file = files[_i];
klass = Metro.Asset.File.basename(file).split(".")[0];
klass = _.camelize("_" + klass);
_results.push(global[klass] = require(file));
}
return _results;
};
return Model;
grunt.registerMultiTask('dust', 'Prerender and combine dust files', function() {
var files = findit.sync(this.data.src),
compiled_data = '',
current_file = '',
current_data = '',
template_name = '',
i = 0;
for(i = 0; i < files.length; i += 1) {
current_file = files[i];
if(current_file.match('.html')) {
current_data = grunt.file.read(current_file);
template_name = current_file.replace(this.data.src+'/','').replace('.html','').replace('\/','_');
try {
compiled_data += dust.compile(current_data,template_name);
} catch (e) {
console.log('Dust error in: ' + current_file, e.toString());
return false;
}
var pkg = {};
try {
pkg = JSON.parse(body);
}
catch (err) {
if (opts && opts.listen) {
opts.listen.emit('syntaxError', basedir + '/package.json');
}
}
topPkg = normalizePkg(pkg, basedir, opts || {});
}
var extensions = [ '.js', '.coffee' ];
var files = findit.sync(basedir)
.filter(function (file) {
return file.split('/').every(function (p) {
return !p.match(/^\.[^.]/)
})
})
.filter(function (file) {
return Hash.valuesAt(topPkg.directories, [ 'bin', 'test', 'example' ])
.every(function (ds) {
return ds.every(function (d) {
return file.indexOf(d + '/') !== 0;
})
})
;
})
;
paths.forEach(function(path) {
files = findit.sync(path);
files.forEach(function(file) {
if (fileNameMatcher.test(file)) {
try {
ast = parser.parse(fsModule.read(file));
}
catch (e) {
throw new Error(require('util').format(
"Failed parsing file: %s\nReason: %s\nLine: %s\nColumn: %s",
file, e.message, e.line, e.col
));
}
match = this.walkAst(ast, defineMatcher, true);
if (match) {
_.each( _.keys( files ), function( fileName ) {
var fileStats = files[ fileName ];
if( fileStats.isDirectory() ) {
if( ! _.isUndefined( dirOptions.directoriesToIgnore ) && dirOptions.directoriesToIgnore.test( fileName ) ) return;
if( dirOptions.directoriesToFlatten.test( fileName ) ) {
var assetFiles = _.filter( findit.sync( walker.fullPath( fileName ) ), function( fileName ) {
return File.isAssetFileName( fileName );
} );
var subdirectoryFiles = _.map( assetFiles, function( fileName ) {
return fileName.substring( directory.length + 1 );
} );
fileDependencies = _.union( fileDependencies, subdirectoryFiles );
}
else {
_.extend( parcelRegistry, createRegistryForDirectory( walker.fullPath( fileName ), rootDir, dirOptions ) );
}
}
else if( fileStats.isFile() ) {
if( ! _.isUndefined( dirOptions.filesToIgnore ) && dirOptions.filesToIgnore.test( fileName ) ) return;
_.each( _.keys( files ), function( fileName ) {
var fileStats = files[ fileName ];
if( fileStats.isDirectory() ) {
if( _.contains( bundleOptions.directoriesToIgnore, fileName ) ) {
return;
}
else if( ! dirOptions.allowNestedBundles || ( ( _.isArray( bundleOptions.directoriesToFlatten ) && _.contains( bundleOptions.directoriesToFlatten, fileName ) ) ||
( _.isRegExp( bundleOptions.directoriesToFlatten ) && bundleOptions.directoriesToFlatten.test( fileName ) ) ) ) {
var assetFiles = _.filter( findit.sync( walker.fullPath( fileName ) ), function( fileName ) {
return File.isAssetFileName( fileName ) ;
} );
var subdirectoryFiles = _.map( assetFiles, function( assetFile ) {
return assetFile.substring( directory.length + 1 );
} );
//if prioritizeSubdirectories is true, append the subdirectoryFiles at the beginning.
//otherwise append them at the end
if( bundleOptions.prioritizeFlattenedDirectories ) {
fileDependencies = _.union( subdirectoryFiles, fileDependencies );
}
else
fileDependencies = _.union( fileDependencies, subdirectoryFiles );
}