Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const extractResourcesToCorrespondingDirectoryStructure = (sourceRootPath, destinationRootPath)=> {
console.log(`Extracting resources from: ${sourceRootPath}`);
dir.subdirs(sourceRootPath, (err, sourceSubDirectoryPaths)=> {
if (err) { throw err; }
const sourceDirectoryPaths = [sourceRootPath].concat(sourceSubDirectoryPaths);
mapLimit(sourceDirectoryPaths, 1,
(sourceDirectoryPath, callback)=> {
const sharedPath = path.relative(sourceRootPath, sourceDirectoryPath);
const destinationDirectoryPath = path.join(destinationRootPath, sharedPath);
mkdirp.sync(destinationDirectoryPath);
resourcesExtract(sourceDirectoryPath, destinationDirectoryPath, (err)=> {
if (err) { return callback(err); }
fs.readdir(sourceDirectoryPath, (err, sourceFnames)=> {
if (err) { return callback(err); }
fs.readdir(destinationDirectoryPath, (err, destinationFnames)=> {
if (err) { return callback(err); }
// resultantResourceFnames = fnames;
// may include directories; i'm assuming they won't match for now
resourceName = inputPath;
inputPath = '';
}
}
// console.log('argv.folder=' + argv.folder + ' inputPath=' + inputPath + ' resourceName=' + resourceName);
var folderPath = !argv.folder || argv.folder === '/' || !inputPath ? [] : inputPath.split(path.sep);
if (folderName) {
folderPath.push(folderName);
}
console.log(' - target folder: ' + (resourceFolder ? (resourceLabel + ' > ' + resourceName) : 'Documents') + ' > ' + folderPath.join(' > '));
var rootParentFolderLabel = resourceFolder ? resourceName : 'Home folder';
// get all files to upload
var folderContent = [];
dir.paths(srcPath, function (err, paths) {
if (err) {
console.log(err);
return reject();
} else {
// the top level folder
if (folderName) {
folderContent.push({
fileFolder: '',
files: []
});
}
// get all sub folders including empty ones
var subdirs = paths.dirs;
for (var i = 0; i < subdirs.length; i++) {
var subdir = subdirs[i];
subdir = subdir.substring(srcPath.length + 1);
function copyDirectory(sourceDir, destDir) {
// gather all files in sourceDir
dir.files(sourceDir, function(err, files) {
if (err) {
if (err.code === 'ENOENT' && err.path === sourceDir) {
console.error(
'Specified directory "' +
sourceDir +
'" does not exist. \nPlease specify an existing directory relative to the root of the project.'
);
return;
}
console.error('Error reading file list', err);
throw err;
}
// Do not copy .DS_Store files
files.filter(function(file) {
clientLibs( function( libs ){
if( libs.length !== 0 ){
var clientlibsPath = libs[0].path.split( "/" );
config.clientlib_root = clientlibsPath
.splice( 0, clientlibsPath.indexOf('clientlibs') + 2 )
.join('/');
fs.writeFileSync( '.ironrc' , JSON.stringify( config, null, 4 ));
} else {
var nodeDir = require('node-dir');
nodeDir.subdirs(shell.pwd().stdout, function (err, subdirs) {
// Files is an array of filename
var index = subdirs.findIndex( function( filePath ){
var pathArray = filePath.split('/');
var foundAt = pathArray.indexOf("clientlibs");
return (foundAt !== -1);
} );
if( subdirs[index] === undefined ){
var etcIndex = subdirs.findIndex( function( filePath ){
var pathArray = filePath.split('/');
var foundAt = pathArray.indexOf("etc");
clientLibs(function (libs) {
if (libs.length !== 0) {
var clientlibsPath = libs[0].path.split("/");
config.clientlib_root = clientlibsPath.splice(0, clientlibsPath.indexOf('clientlibs') + 2).join('/');
fs.writeFileSync('.ironrc', JSON.stringify(config, null, 4));
} else {
var nodeDir = require('node-dir');
nodeDir.subdirs(shell.pwd().stdout, function (err, subdirs) {
// Files is an array of filename
var index = subdirs.findIndex(function (filePath) {
var pathArray = filePath.split('/');
var foundAt = pathArray.indexOf("clientlibs");
return foundAt !== -1;
});
if (subdirs[index] === undefined) {
var etcIndex = subdirs.findIndex(function (filePath) {
var pathArray = filePath.split('/');
var foundAt = pathArray.indexOf("etc");
return foundAt !== -1;
return new Promise((res, rej) => {
dir.readFilesStream(queuedFilesDir,
{ match: /\.json$/,
recursive: false
},
(err, stream, next) => {
if (err) return rej(err);
console.log('found file to process: %s', stream.path);
const lineReader = readline.createInterface({
input: stream,
terminal: false
});
lineReader
.on('line', line => {
let altered = alterTweet(line);
if (altered) {
// TODO: would be better to stream
return new Promise((res, rej) => {
dir.readFilesStream(queuedImagesDir,
{ match: /\.(jpg|jpeg|png)$/,
recursive: false
},
(err, stream, next) => {
if (err) return rej(err);
let f = stream.path,
renamed = f;
console.log('found image to featurize: %s', f);
// mark complete
if (process.env.NODE_ENV === 'production') {
renamed = path.join(processedImagesDir, path.basename(f));
fs.renameSync(f, renamed);
}
triggerFeaturizer(renamed)
.then(key => queue.add(key))
.then(() => next())
fs.exists(directory, function (exists) {
if (!exists) {
return callback(null, []);
}
dir.files(directory, function (err, files) {
if (err) { // TODO: error handling
throw err;
}
if (!options.basePath && !options.ext) {
return files;
}
for (var i = 0; i < files.length; i++) {
if (options.ext && path.extname(files[i]) !== options.ext) {
continue;
}
files[i] = options.basePath ? files[i].replace(options.basePath + '/', '') : files[i];
filtered.push(files[i]);
}
var getMovies = function(cb) {
var videoList = [];
//Recursively get all files in dir
dirExp.files(movieDir, function(err,files) {
if(!files)
return cb(videoList);
// Get supported files with valid extensions (mp4, avi, etc...)
var filteredVideos = files.filter(validExtensionsFilter);
//Per video, construct a useful video object
filteredVideos.forEach(function(val,i,arr){
videoList.push(newVideo(val, movieDir));
});
cb(videoList);
});
}
var size;
// check if the importation is finished
/**
* Description
* @method checkIfDone
* @return
*/
function checkIfDone(){
inserted++;
if(inserted >= size)
callback(null);
}
// get recursively all the files in the folder
dir.files(sails.config.music.folder, function(err, files) {
if(err) return sails.log.warn(err);
if(files){
size = files.length;
for(var i=0;i