本文整理汇总了TypeScript中fs.exists函数的典型用法代码示例。如果您正苦于以下问题:TypeScript exists函数的具体用法?TypeScript exists怎么用?TypeScript exists使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了exists函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: lint
mc.registerTask(function lint(params: any, callback: (err: Error, res: any) => void) {
mc.assertType(params, 'object', 'params');
mc.assertType(params.filePath, 'string', 'params.filePath');
mc.assertType(params.options, 'object', 'params.options');
fs.exists(params.filePath, (exist) => {
if (!exist) {
return callback(null, null);
}
fs.readFile(params.filePath, 'utf8', (err, contents) => {
if (err) {
callback(err, null);
return;
}
let linter = new Linter(params.filePath, contents, params.options);
let result = linter.lint();
result.output = result.output.split('\n').reduce((memo: string[], line: string) => {
if (line !== '') {
memo.push(line + '\n');
}
return memo;
}, []).join('');
callback(err, result);
});
});
});
开发者ID:DefinitelyTyped,项目名称:definition-tester,代码行数:28,代码来源:TSLintWorker.ts
示例2: instrument
function instrument(tscPath: string, prepareCode: string, cleanupCode = "") {
const bak = `${tscPath}.bak`;
fs.exists(bak, (backupExists: boolean) => {
let filename = tscPath;
if (backupExists) {
filename = bak;
}
fs.readFile(filename, "utf-8", (err: any, tscContent: string) => {
if (err) throw err;
fs.writeFile(bak, tscContent, (err: any) => {
if (err) throw err;
fs.readFile(path.resolve(path.dirname(tscPath) + "/loggedIO.js"), "utf-8", (err: any, loggerContent: string) => {
if (err) throw err;
const invocationLine = "ts.executeCommandLine(ts.sys.args);";
const index1 = tscContent.indexOf(invocationLine);
if (index1 < 0) {
throw new Error(`Could not find ${invocationLine}`);
}
const index2 = index1 + invocationLine.length;
const newContent = tscContent.substr(0, index1) + loggerContent + prepareCode + invocationLine + cleanupCode + tscContent.substr(index2) + "\r\n";
fs.writeFile(tscPath, newContent);
});
});
});
});
}
开发者ID:01alchemist,项目名称:TypeScript,代码行数:31,代码来源:instrumenter.ts
示例3: removeFilesFromDir
export function removeFilesFromDir(dir:string, callback:AsyncCallback) {
dir = path.resolve(dir);
fs.exists(dir, (exists:bool) => {
if (!exists) return callback('path does not exists: ' + dir, null);
async.waterfall([
(callback:AsyncCallback) => {
return fs.stat(dir, callback);
},
(stats, callback:AsyncCallback) => {
if (!stats.isDirectory()) {
return callback('path is not a directory: ' + dir, null);
}
return fs.readdir(dir, callback);
},
(files:string[], callback:AsyncCallback) => {
//check each file
async.forEach(files, (file:string, callback:AsyncCallback) => {
var full = path.join(dir, file);
fs.stat(full, (err, stats)=> {
if (err) return callback(err, null);
if (stats.isFile()) {
return fs.unlink(full, callback);
}
return callback(null, null);
})
}, callback);
}
], callback);
});
}
开发者ID:Bartvds,项目名称:tsd-deftools,代码行数:33,代码来源:helper.ts
示例4: verifyUser
export function verifyUser (req, res, next) {
const fp = getUserFilePath(req.params.username);
fs.exists(fp, yes => {
if(yes) next();
else res.redirect('/error/' + req.params.username);
});
};
开发者ID:wpcfan,项目名称:calltalent_server,代码行数:7,代码来源:helpers.ts
示例5: makeSubpath
form.parse(req, (err, fields:Fields, files:Files)=> {
if (!files) {
res.end(JSON.stringify({ok: false, error: "no_file_data"}));
}
var file = files["file"];
var tmpPath = file.path;
var subDir = makeSubpath(token);
var newDir = '/thumbs/' + subDir;
var newPath = newDir + "/" + jpgFile;
fs.exists(newDir, (exists:boolean)=> {
if (!exists) {
// console.log("Folder " + newDir + " not exist");
mkdirp(newDir, (err)=> {
if (err) {
res.end(JSON.stringify({ok: false, error: "cant_create_subdir"}));
console.error(err);
} else {
moveFile(tmpPath, newPath);
}
});
} else {
moveFile(tmpPath, newPath);
}
});
res.writeHead(200, {'content-type': 'text/plain'});
res.end(JSON.stringify({ok: true, url: subDir + "/" + jpgFile}));
});
开发者ID:terbooter,项目名称:LVK-thumbs,代码行数:31,代码来源:app.ts
示例6: exists
export function exists(path:string) {
var d = Q.defer()
fs.exists(path, function(exists) {
d.resolve(exists)
})
return d.promise
}
开发者ID:davidparsson,项目名称:tpm,代码行数:7,代码来源:q-fs.ts
示例7: serverRequestHandler
/**
* serverRequestHandler
*
* @param serverRequest
* @param serverResponse
*/
private serverRequestHandler(serverRequest : Http.ServerRequest, serverResponse : Http.ServerResponse) : void {
console.log("Receive an HTTP request");
let clientFilePath : string = Path.join(__dirname, "../../resources/public");
let requestPath : string = Url.parse(serverRequest.url).pathname;
let filePath : string;
if (requestPath === "/") {
filePath = Path.join(clientFilePath, "/index.html");
} else {
filePath = Path.join(clientFilePath, requestPath);
}
console.log("Static file requested : ", filePath);
FileSystem.exists(filePath, exist => {
if (exist) {
let readStream : FileSystem.ReadStream = FileSystem.createReadStream(filePath);
serverResponse.writeHead(200);
readStream.pipe(serverResponse);
} else {
serverResponse.writeHead(404, {
"Content-Type": "text/plain"
});
serverResponse.write("404 Not Found\n");
serverResponse.end();
}
});
}
开发者ID:Gog0,项目名称:NodeCrawler,代码行数:31,代码来源:HttpServer.ts
示例8: file_exists
private static file_exists(filepath:string):Promise {
var fs = require('fs'), def = when.defer()
fs.exists(filepath, (exists)=> {
def.resolve(exists)
})
return def.promise
}
开发者ID:silentorb,项目名称:vineyard-cellar,代码行数:7,代码来源:cellar.ts
示例9: function
UploadSummaryCommand.prototype.runCommandAsync = function () {
var _this = this;
var filename = this.command.message;
if (!filename) {
return Q(null);
}
var deferred = Q.defer();
fs.exists(filename, function (exists) {
if (!exists) {
deferred.resolve(null);
}
var projectId = _this.executionContext.variables[ctxm.WellKnownVariables.projectId];
var type = "DistributedTask.Core.Summary";
var name = "CustomMarkDownSummary-" + path.basename(filename);
var hubName = _this.executionContext.jobInfo.description;
var webapi = _this.executionContext.getWebApi();
var taskClient = webapi.getQTaskApi();
fs.stat(filename, function (err, stats) {
if (err) {
deferred.reject(err);
}
else {
var headers = {};
headers["Content-Length"] = stats.size;
var stream = fs.createReadStream(filename);
taskClient.createAttachment(headers, stream, projectId, hubName, _this.executionContext.jobInfo.planId, _this.executionContext.jobInfo.timelineId, _this.executionContext.recordId, type, name).then(function () { return deferred.resolve(null); }, function (err) { return deferred.reject(err); });
}
});
});
return deferred.promise;
};
开发者ID:ElleCox,项目名称:vso-agent,代码行数:31,代码来源:task.uploadsummary.ts
示例10: instrument
function instrument(tscPath: string, prepareCode: string, cleanupCode: string = '') {
var bak = tscPath + '.bak';
fs.exists(bak, (backupExists: boolean) => {
var filename = tscPath;
if (backupExists) {
filename = bak;
}
fs.readFile(filename, 'utf-8', (err: any, tscContent: string) => {
if (err) throw err;
fs.writeFile(bak, tscContent, (err: any) => {
if (err) throw err;
fs.readFile(path.resolve(path.dirname(tscPath) + '/loggedIO.js'), 'utf-8', (err: any, loggerContent: string) => {
if (err) throw err;
var invocationLine = 'ts.executeCommandLine(sys.args);';
var index1 = tscContent.indexOf(invocationLine);
var index2 = index1 + invocationLine.length;
var newContent = tscContent.substr(0, index1) + loggerContent + prepareCode + invocationLine + cleanupCode + tscContent.substr(index2) + '\r\n';
fs.writeFile(tscPath, newContent);
});
});
});
});
}
开发者ID:UCSD-PL,项目名称:rs-benchmarks,代码行数:27,代码来源:instrumenter.ts
注:本文中的fs.exists函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论