本文整理汇总了TypeScript中fs.accessSync函数的典型用法代码示例。如果您正苦于以下问题:TypeScript accessSync函数的具体用法?TypeScript accessSync怎么用?TypeScript accessSync使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了accessSync函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: copyFile
export function copyFile(src: string, dest: string, overwrite = true): boolean {
try {
copyFileSync(src, dest, overwrite ? undefined : constants.COPYFILE_EXCL)
} catch (e) {
switch (e.code) {
case "ENOENT":
// 区分是源文件不存在还是目标目录不存在
try {
accessSync(src)
} catch (e2) {
throw e
}
try {
accessSync(dest)
} catch (e3) {
if (e3.code === "ENOENT") {
ensureDirExists(dest)
return copyFile(src, dest, false)
} else {
e = e3
}
}
throw e
case "EEXIST":
return false
default:
throw e
}
}
return true
}
示例2: task
task('e2e.watchProd', (done: Function) => {
const folderInfo = getFolderInfo();
let e2eTestPath = SRC_ROOT;
if (folderInfo.componentName && folderInfo.componentTest) {
e2eTestPath = join(`${SRC_ROOT}/components/${folderInfo.componentName}/test/${folderInfo.componentTest}/app.module.ts`);
}
try {
accessSync(e2eTestPath, F_OK);
} catch (e) {
done(new Error(`Could not find e2e test: ${e2eTestPath}`));
return;
}
if (e2eComponentsExists(folderInfo)) {
// already generated the e2e directory
e2eWatch(folderInfo.componentName, folderInfo.componentTest);
} else {
// generate the e2e directory
console.log('Generate e2e builds first...');
e2eBuild(() => {
e2eWatch(folderInfo.componentName, folderInfo.componentTest);
});
}
});
示例3: activate
function activate(context) {
red_extensionPath = context.extensionPath;
red_pkg = JSON.parse(fs.readFileSync(red_extensionPath + '/package.json', 'utf8'));
red_pkg.contributes.commands.forEach(function(element1,index1,array1){
red_pkg.contributes.keybindings.some(function(element2,index2,array3){ //forEach can not use break
if (element1.command == element2.command) {
if (element1.command != 'red_menu') {
red_menu.push(element1.title + ' (' + element2.key + ')');
}
context.subscriptions.push(vscode.commands.registerCommand( element1.command, function(){handle_command(element1.command);} ));
return true;
}
});
});
if ('win32' == process.platform) {
_exe = '.exe';
}
red_bin_path = red_extensionPath + '/bin/' + process.platform + '/';
//fs.existsSync(red_bin_path) || fs.mkdirSync(red_bin_path);
//mkdirpSync(red_bin_path);
red_bin_path = red_bin_path + 'red' + _exe;
try {
fs.accessSync(red_bin_path, fs.X_OK);
red_bin_exist = true;
} catch (e) {
//
}
}
示例4: task
task('demos.watchProd', (done: Function) => {
const folderInfo = getFolderInfo();
let demoTestPath = DEMOS_SRC_ROOT;
if (folderInfo.componentName && folderInfo.componentTest) {
demoTestPath = join(DEMOS_SRC_ROOT, folderInfo.componentName, 'app.module.ts');
}
try {
accessSync(demoTestPath, F_OK);
} catch (e) {
done(new Error(`Could not find demos test: ${demoTestPath}`));
return;
}
if (demosComponentsExists(folderInfo)) {
// already generated the demos directory
demosWatch(folderInfo.componentName, folderInfo.componentTest);
} else {
// generate the demos directory
console.log('Generate demo builds first...');
demosBuild(() => {
demosWatch(folderInfo.componentName, folderInfo.componentTest);
});
}
});
示例5: join
export = (done: any) => {
let checkFile = join(process.cwd(), 'tools', 'config.js');
// need to require the build.toolchain task as it won't be able to run after we run clear.files
let buildTools = require('./build.tools');
let cleanTools = require('./clean.tools');
let rebuild = false;
try {
fs.accessSync(checkFile, fs.F_OK);
util.log('Gulpfile has previously been compiled, rebuilding toolchain');
rebuild = true;
} catch (e) {
util.log('Tools not compiled, skipping rebuild');
done();
}
// continue here to prevent other errors being caught...
if (rebuild) {
util.log('Running \'clean.tools\' from check.tools');
cleanTools();
util.log('Running \'build.tools\' from check.tools');
let build = buildTools();
build.on('end', done);
}
};
示例6: getProfileDir
/**
* Returns either true and the path of the profile directory or false and an error message
*/
function getProfileDir(config: LaunchConfiguration): [boolean, string] {
let profileDir: string;
if (config.profileDir) {
profileDir = config.profileDir;
} else {
profileDir = path.join(os.tmpdir(), 'vscode-firefox-debug-profile');
}
try {
let stat = fs.statSync(profileDir);
if (stat.isDirectory) {
// directory exists - check permissions
try {
fs.accessSync(profileDir, fs.R_OK | fs.W_OK);
return [true, profileDir];
} catch (e) {
return [false, `The profile directory ${profileDir} exists but can't be accessed`];
}
} else {
return [false, `${profileDir} is not a directory`];
}
} catch (e) {
// directory doesn't exist - create it and set the necessary user preferences
try {
fs.mkdirSync(profileDir);
fs.writeFileSync(path.join(profileDir, 'prefs.js'), firefoxUserPrefs);
return [true, profileDir];
} catch (e) {
return [false, `Error trying to create profile directory ${profileDir}: ${e}`];
}
}
}
示例7: listJsFilesAndDirectories
function listJsFilesAndDirectories(dirPath: string): FileDirList {
try {
fs.accessSync(dirPath, fs.constants.R_OK);
}
catch (err) {
return {
dirs: [],
files: []
};
}
dirPath = dirPath.replace(/\\/g, '/');
if (dirPath[dirPath.length - 1] != '/')
dirPath += '/';
let listing = fs.readdirSync(dirPath);
let dirs: string[] = [];
let files: string[] = [];
_.forEach(listing, (l) => {
if (fs.statSync(path.join(dirPath, l)).isDirectory()) {
if (!l.startsWith('node_modules') && !l.startsWith('bower_components') && !l.startsWith('.'))
dirs.push(path.join(dirPath, l));
}
else if (l.endsWith('.js') || l.endsWith('.json')) {
files.push(path.join(dirPath, l));
}
});
return {
dirs: dirs,
files: files
};
}
示例8: _getRecommendedTextColor
private static _getRecommendedTextColor(): string {
let color = '#AAAAAA';
let path = '';
switch (process.platform) {
case 'darwin':
path = `${process.env.HOME}/Library/Application Support/Code/storage.json`;
break;
case 'win32':
path = `${process.env.APPDATA}\\Code\\storage.json`;
break;
default:
path = `${process.env.HOME}/.config/Code/storage.json`
break;
}
try {
fs.accessSync(path);
let json = fs.readFileSync(path, 'utf8');
let storage = JSON.parse(json);
color = (storage.theme.indexOf('vs-dark') > -1) ? '#FFFFFF' : '#000000';
}
catch (error) { }
return color;
}
示例9: task
task('e2e.watchProd', ['e2e.copyExternalDependencies', 'e2e.sass', 'e2e.fonts'], (done: Function) => {
const folderInfo = getFolderInfo();
let e2eTestPath = SRC_COMPONENTS_ROOT;
if (folderInfo.componentName && folderInfo.componentTest) {
e2eTestPath = join(SRC_COMPONENTS_ROOT, folderInfo.componentName, 'test', folderInfo.componentTest, 'app-module.ts');
}
try {
accessSync(e2eTestPath, F_OK);
} catch (e) {
done(new Error(`Could not find e2e test: ${e2eTestPath}`));
return;
}
if (e2eComponentsExists()) {
// already generated the e2e directory
e2eWatch(folderInfo.componentName, folderInfo.componentTest);
} else {
// generate the e2e directory
console.log('Generated e2e builds first...');
e2eBuild(() => {
e2eWatch(folderInfo.componentName, folderInfo.componentTest);
});
}
});
示例10: fromFileSync
export function fromFileSync(filename:string) : NiftiStream {
accessSync(filename, R_OK);
let stream:NodeJS.ReadableStream = createReadStream(filename);
if (filename.substr(-'.gz'.length) === '.gz') {
stream = stream.pipe(createGunzip());
}
return new NiftiStream(stream);
}