本文整理匯總了TypeScript中fs-extra-promise.existsSync函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript existsSync函數的具體用法?TypeScript existsSync怎麽用?TypeScript existsSync使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了existsSync函數的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: Error
return fs.lstatAsync(filePathOrFolder).then(stats => {
// If a file path was passed, assume its the launch file.
if (stats.isFile()) {
return filePathOrFolder;
}
// Otherwise, search the specified folder.
let candidate: string;
candidate = path.join(filePathOrFolder, runFileName);
if (fs.existsSync(candidate)) {
return candidate;
}
candidate = path.join(filePathOrFolder, omnisharpFileName);
if (fs.existsSync(candidate)) {
return candidate;
}
candidate = path.join(filePathOrFolder, omnisharpExeFileName);
if (fs.existsSync(candidate)) {
return candidate;
}
throw new Error(`Could not fnd launch file in ${filePathOrFolder}. Expected '${runFileName}', '${omnisharpFileName}', or '${omnisharpExeFileName}'.`);
});
示例2: formatByTimestamp
function formatByTimestamp() {
const FIVE_MINUTES = 1000 * 60 * 5
const timestampPath = jd('timestamp.txt')
const now = new Date()
if (fsep.existsSync(timestampPath)) {
const oldTimestamp = fsep.readFileSync(timestampPath).toString()
const oldDate = new Date(oldTimestamp)
const difference = now.valueOf() - oldDate.valueOf()
if (difference > FIVE_MINUTES) {
log('Running 5 minute code format')
updateTimestamp()
soFormatDefinitely()
} else {
log(ms(FIVE_MINUTES - difference) + ' to next format')
return
}
}
updateTimestamp()
function updateTimestamp() {
fsep.writeFileSync(timestampPath, now.toISOString())
}
}
示例3:
executableFiles.forEach(element => {
let executableFile = path.join(filePath, element);
if (candidate === undefined && fs.existsSync(executableFile)) {
candidate = executableFile;
return candidate;
}
});
示例4: optionallyModifyWebpackConfig
function optionallyModifyWebpackConfig(
options: WebpackConfig | WebpackConfig[],
command: Command
) {
const path = join(process.cwd(), 'ws.config.js');
const exists = existsSync(path);
if (exists) {
const modifyWebpackConfig = __non_webpack_require__(path);
modifyWebpackConfig(command, options);
}
}
示例5: Error
return fs.lstatAsync(filePath).then(stats => {
// If a file path was passed, assume its the launch file.
if (stats.isFile()) {
return filePath;
}
// Otherwise, search the specified folder.
let candidate: string;
candidate = path.join(filePath, 'OmniSharp.exe');
if (fs.existsSync(candidate)) {
return candidate;
}
candidate = path.join(filePath, 'OmniSharp');
if (fs.existsSync(candidate)) {
return candidate;
}
throw new Error(`Could not find OmniSharp launch file in ${filePath}.`);
});
示例6: addAssetsIfNecessary
export function addAssetsIfNecessary(server: OmnisharpServer) {
if (!vscode.workspace.rootPath) {
return;
}
// If there is no project.json, we won't bother to prompt the user for tasks.json.
const projectJsonPath = path.join(vscode.workspace.rootPath, 'project.json');
if (!fs.existsSync(projectJsonPath)) {
return;
}
return serverUtils.requestWorkspaceInformation(server).then(info => {
// If there are no .NET Core projects, we won't bother offering to add assets.
if ('DotNet' in info && info.DotNet.Projects.length > 0) {
return getOperations().then(operations => {
if (!hasOperations(operations)) {
return;
}
promptToAddAssets().then(addAssets => {
if (!addAssets) {
return;
}
const paths = getPaths();
return fs.ensureDirAsync(paths.vscodeFolder).then(() => {
return Promise.all([
addTasksJsonIfNecessary(info.DotNet, paths, operations),
addLaunchJsonIfNecessary(info.DotNet, paths, operations)
]);
});
});
});
}
});
}
示例7: validate
export function validate(pkg: any): PackageConfig {
if (!pkg.ws) {
throw `Your ${yellow('package.json')} needs a ${yellow(
'ws'
)} config. It could look like this:${sampleConfig}`;
}
if (!pkg.ws.type) {
throw `You need to specify a ${yellow(
'type'
)}. This can be any of the following values: ${yellow(TYPES.join(', '))}.`;
}
if (!TYPES.some((type) => type === pkg.ws.type)) {
throw `Your type ${yellow(
pkg.ws.type
)} doesn't match any of the valid values: ${yellow(TYPES.join(', '))}.`;
}
if (!pkg.name) {
throw `You need to specify a ${yellow('name')} in your package.json.`;
}
if (!pkg.ws.srcDir) {
pkg.ws.srcDir = 'src';
}
if (!pkg.ws.testsDir) {
pkg.ws.testsDir = 'tests';
}
if (!pkg.ws.distDir) {
pkg.ws.distDir = 'dist';
}
if (!pkg.ws.distTestsDir) {
pkg.ws.distTestsDir = 'dist-tests';
}
if (!pkg.ws.distReleaseDir) {
pkg.ws.distReleaseDir = 'dist-release';
}
if (pkg.ws.i18n && !pkg.ws.i18n.dir) {
pkg.ws.i18n.dir = 'i18n';
}
if (pkg.ws.i18n && !pkg.ws.i18n.distDir) {
pkg.ws.i18n.distDir = 'dist-i18n';
}
// check if this project is using typescript (and tsx)
const tsconfigRoot = join(process.cwd(), 'tsconfig.json');
const tsconfigSrc = join(process.cwd(), pkg.ws.srcDir, 'tsconfig.json');
if (existsSync(tsconfigSrc)) {
pkg.ws.tsconfigPath = tsconfigSrc;
} else if (existsSync(tsconfigRoot)) {
pkg.ws.tsconfigPath = tsconfigRoot;
}
if (pkg.ws.tsconfigPath) {
const { config } = readConfigFile(pkg.ws.tsconfigPath, sys.readFile);
const host = {
useCaseSensitiveFileNames: false,
readDirectory: sys.readDirectory,
fileExists: sys.fileExists,
readFile: sys.readFile
};
const { options } = parseJsonConfigFileContent(
config,
host,
basename(pkg.ws.tsconfigPath)
);
if (options) {
pkg.ws.tsconfig = options;
if (options.jsx) {
pkg.ws.entryExtension = 'tsx';
} else {
pkg.ws.entryExtension = 'ts';
}
}
} else {
pkg.ws.entryExtension = 'js';
}
// entry files
pkg.ws.srcEntry = `./${pkg.ws.srcDir}/index.${pkg.ws.entryExtension}`;
pkg.ws.srcI18nEntry = `./${pkg.ws.srcDir}/index.i18n.${
pkg.ws.entryExtension
}`;
pkg.ws.unitEntry = `./${pkg.ws.testsDir}/unit.${pkg.ws.entryExtension}`;
pkg.ws.e2eEntry = `./${pkg.ws.testsDir}/e2e.${pkg.ws.entryExtension}`;
if (!pkg.ws.publicPath) {
pkg.ws.publicPath = '';
}
// defaults for browsers
if (!pkg.ws.targets) {
pkg.ws.targets = {};
}
//.........這裏部分代碼省略.........