示例#1
0
        files.forEach(function(file) {

            // get info from files
            FS.stat(path.join(__dirname, file))
            .then(function(stats) {

                if (stats.isFile()) {


                    // remove first path
                    var allPaths = file.split(path.sep);
                    var allPath2 = allPaths.splice(1);
                    var destinationPath = path.join(__dirname, 'syntax', allPath2[0], allPath2[1]);

                    // create new "syntax" folder
                    var dirToMake = path.join(__dirname, 'syntax', allPath2[0]);
                    console.log('\n>>---------\n dirToMake:', dirToMake, '\n>>---------\n');
                    FS.makeTree(dirToMake)
                    .then(function() {

                    // write syntax
                    rewriter.writeSyntax(path.join(__dirname, file), destinationPath)
                    .then(function() {
                        allSyntaxes.push(destinationPath);
                    });

                    }).catch(function(err) {
                        reject(err);
                    });
                }
            })
            .catch(function(err) {
                reject(err);
            });
        });
示例#2
0
function getLogInfo ( pathToLog ) {
    return QFS.stat(pathToLog)
        .then(function(stat){
            return Q.all([
                
                QFS.open(pathToLog, {
                    falgs : 'r',
                    end   : 50
                }).then(getReaden),
        
                QFS.open(pathToLog, {
                    falgs : 'r',
                    begin : stat.size - 12, // 9 digits left, so 999 999 999 is max number
                    end   : stat.size
                }).then(getReaden)
        
            ]).spread(function(begin, end){
                var started = begin.replace(/^log\screated\sat\s(\d+)\n[\s\S]+/, '$1'),
                    quantity = end.replace(/[\s\S]*%%(\d+)\n$/, '$1') || 0;
        
                return /^\d+$/.test(started) && /^\d+$/.test(quantity)
                    ? Q.resolve({
                            started  : started,
                            quantity : quantity
                        })
                    : Q.reject('wrong format of the log file') // TODO use log.error
            })
        })
}
示例#3
0
文件: get.js 项目: wwwy3y3/treee
function getTree (path, opts) {
	// get node prop
	var node= genNode(path, opts);

	return Q.when(FS.stat(path))
			.then(function (stat) {
				if(stat.isDirectory()){
					
					// dir
					node.type= 'dir';
					return Q.when(FS.list(path))
							.then(preprocessList(opts))
							.then(function (children) {
								var dependents= children.map(function (child) {
									var childPath = path+'/'+child;
									return getTree(childPath, opts);
								})
								return Q.all(dependents).then(function (nodes) {
									if(!opts.showEmptyChildren && nodes.length>0)
										node.children= nodes;
									return node;
								})
							})
				}else{
					// file
					node.type='file';
					return node;
				}
			});
}
示例#4
0
 return qio.exists(timestampFilePath).then(function(exists){
     if (!exists)
     {
         return null;
     }
     return qio.stat(timestampFilePath);
 });
示例#5
0
function existsAndNonZero(path) {
    return qio.stat(path)
        .then(function(file) {
            return !(file.size === 0);
        }, function() {
            return false;
        });
}
示例#6
0
	genFreeStream(){
		return qfs.stat(this.data.filename).then((o)=>{
			return {
				type: this.data.type,
				size: o.size,
				stream: fs.createReadStream(this.data.filename),
			};
		})
	}
		.then(function(results){
			list = results;
			var promises = [];
			for (var key in list){
				console.log(list[key])
				promises.push(fs.stat(path.join(dirPath,list[key])))
			}
			return q.all(promises);
		})
示例#8
0
 .then(function(exists) {
     return (
         exists ?
             (qfs.stat(filepath)
             .then(function(stat) {
                 return [exists, stat.isFile()];
             })) :
             [exists]);
 })
示例#9
0
 return Tools.series(list, function(file) {
     return FS.stat(path + "/" + file).then(function(stat) {
         var a = `<a rel="${Tools.toHtml(dir + file)}">${Tools.toHtml(file)}</a>`;
         if (stat.isDirectory())
             c.reply += `<li class="directory collapsed">${a}</li>`;
         else if (stat.isFile())
             c.reply += `<li class="file ext_${file.split(".").pop() || ""}">${a}</li>`;
         return Promise.resolve();
     });
 });
  .then(nodePaths => Promise.all(nodePaths.map(nodePath => {
    return fs.stat(nodePath)
    .then(stats => {
      if(!stats.isFile()) {
        return;
      }

      return localizeFile(nodePath);
    });
  })));
示例#11
0
文件: Task.js 项目: kwangkim/CindyJS
 return Q.all(files.map(function(path) {
     return qfs.stat(path)
         .then(function(stat) {
             return stat.lastModified().getTime();
         }, function(err) {
             if (err.code === "ENOENT")
                 return null;
             throw err;
         });
 }));
示例#12
0
文件: node.js 项目: NV/montage
 .then(function () {
     var reelHtml = URL.resolve(module.location, reelModule[2] + ".html");
     return FS.stat(URL.parse(reelHtml).pathname)
     .then(function (stat) {
         if (stat.isFile()) {
             module.extraDependencies = [id + ".html"];
         }
     }, function (error) {
         // not a problem
     });
 });
示例#13
0
PackageCleaner.prototype._statMethod = function(p) {
    return FSQ.stat(p)
        .catch(function(e) {
            // if symlink target not exist, skip this error
            if (e.code === 'ENOENT') {
                console.warn('Warning file "%s" not exist', e.path);
                return { path: '', size: 0 };
            }

            throw new Error(e);
        });
};
示例#14
0
 return Q.all(filenames.map(function(name) {
     var path = Path.join(dirname, name);
     return qfs.stat(path).then(function(stat) {
         var promise;
         if (stat.isFile() && /\.(html|json|js|css|markdown|md)$/.test(name)) {
             promise = self.processFile(path);
         } else if (stat.isDirectory()){
             promise = self.processDirectory(path);
         }
         return promise;
     });
 }));
示例#15
0
文件: node.js 项目: NV/montage
var findPackage = function (path) {
    var directory = FS.directory(path);
    if (directory === path) {
        throw new Error("Can't find package");
    }
    var packageJson = FS.join(directory, "package.json");
    return FS.stat(path)
    .then(function (stat) {
        if (stat.isFile()) {
            return directory;
        } else {
            return findPackage(directory);
        }
    });
};
示例#16
0
                children.forEach(function(path) {

                    pending.push(fs.stat(path).then(
                        function(stats) {
                            if (stats.isFile()) {
                                var name = pathUtils.basename(path).split('.')[0];

                                self.log(Log.DEBUG, 'loading view ' + pathUtils.basename(path));
                                return fs.read(path).then(
                                    function(data) {
                                        self.addView(name, new type(data.toString()));
                                    }
                                )
                            }
                        }
                    ));
                });
示例#17
0
exports.expandPath = function expandPath(path) {
    return fs.stat(path)
        .then(function(stat) {
            if (!stat.isDirectory()) {
                return [path];
            }
            return  fs.listTree(path, function(path) {
                return fs.extension(path) === '.js';
            });
        })
        .fail(function(e) {
            return [];
        })
        .then(function(paths) {
            return paths.map(fs.absolute.bind(fs));
        });
};
示例#18
0
 function getMetaDataChunk(filePath) {
     this.logger.debug("About to parse meta data for the file %s", filePath)
     return qio.stat(filePath)
         .then((stats)=>{
             if (!stats.size) {
                 this.logger.error("Zero bytes in file %s!", filePath)
                 return Q.reject()
             }
             return mp4Utils.extractMetadata(filePath)
                 .then((metaData)=> {
                         metaData.path = filePath
                         metaData.chunkName = path.basename(filePath)
                         this.logger.debug("Extract Metadata for %s: %s", filePath, JSON.stringify(metaData))
                         return Q.resolve(metaData)
                     },
                     (err)=> {
                         this.logger.error("Failed to get metadata for file %s: %s", filePath, ErrorUtils.error2string(err))
                         return Q.reject()
                     })
         })
 }
示例#19
0
 let promises  = testFiles.map((filePath) => {
   qfs.stat(filePath).then((stat) => {
     assert(stat.isFile());
     console.log(`ok: ${filePath}`);
   }, (e) => done(e));
 });
示例#20
0
 .then(function (compiled) {
   return qfs.stat(path.join(mockConfig.publicDir, "script.js"))
     .then(function (stat) {
       assert.isOk(stat.isFile());
     });
 });
示例#21
0
 .then(function (compiled) {
   return qfs.stat(path.join(compiled.posts[0].target, "index.html"))
     .then(function (stat) {
       assert.isOk(stat.isFile());
     });
 });