当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript find-up.sync函数代码示例

本文整理汇总了TypeScript中find-up.sync函数的典型用法代码示例。如果您正苦于以下问题:TypeScript sync函数的具体用法?TypeScript sync怎么用?TypeScript sync使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了sync函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: constructor

 constructor({ config }: { config?: RunOptions } = {}) {
   if (!config) {
     config = {
       mock: false,
     }
   }
   const parentFilename = module.parent!.parent!
     ? module.parent!.parent!.filename
     : module.parent!.filename
   if (!config.initPath) {
     config.initPath = parentFilename
   }
   if (!config.root) {
     const findUp = require('find-up')
     config.root = path.dirname(
       findUp.sync('package.json', {
         cwd: parentFilename,
       }),
     )
   }
   this.config = new Config(config)
   this.notifier = updateNotifier({
     pkg: this.config.pjson,
     updateCheckInterval: 1,
   })
   this.initRaven()
 }
开发者ID:dhruvcodeword,项目名称:prisma,代码行数:27,代码来源:CLI.ts

示例2: resolveRoot

export function resolveRoot(cwd: string, subs: string[]): string | null {
  let home = os.homedir()
  let { root } = path.parse(cwd)
  let p = findUp.sync(subs, { cwd })
  p = p == null ? null : path.dirname(p)
  if (p == null || p == home || p == root) return cwd
  return p
}
开发者ID:demelev,项目名称:coc.nvim,代码行数:8,代码来源:fs.ts

示例3: getRoot

export function getRoot() {
  const parentFilename = module.parent!.parent!
    ? module.parent!.parent!.filename
    : module.parent!.filename
  const findUp = require('find-up')
  return path.dirname(
    findUp.sync('package.json', {
      cwd: parentFilename,
    }),
  )
}
开发者ID:dhruvcodeword,项目名称:prisma,代码行数:11,代码来源:util.ts

示例4: loadFile

export const load = (
  name: string,
  defaultConfig: any = {},
  noCache?: boolean
) => {
  let file = {}
  const filepath = findup.sync(finds(name))

  if (filepath) {
    file = loadFile(filepath, defaultConfig, noCache)
  }

  return defaultConfig !== null ? merge(defaultConfig, file) : file
}
开发者ID:leslieSie,项目名称:docz,代码行数:14,代码来源:index.ts

示例5: function

export default function(cwd: string | undefined): string | null {
  const foundPath = findUp.sync('.git', { cwd })

  if (foundPath) {
    const stats = fs.lstatSync(foundPath)

    // If it's a .git file resolve path
    if (stats.isFile()) {
      // Expect following format
      // git: pathToGit
      // On Windows pathToGit can contain ':' (example "gitdir: C:/Some/Path")
      const gitFileData = fs.readFileSync(foundPath, 'utf-8')
      const gitDir = gitFileData
        .split(':')
        .slice(1)
        .join(':')
        .trim()
      const resolvedGitDir = path.resolve(path.dirname(foundPath), gitDir)

      // For git-worktree, check if commondir file exists and return that path
      const pathCommonDir = path.join(resolvedGitDir, 'commondir')
      if (fs.existsSync(pathCommonDir)) {
        const commondir = fs.readFileSync(pathCommonDir, 'utf-8').trim()
        const resolvedCommonGitDir = path.join(resolvedGitDir, commondir)
        return resolvedCommonGitDir
      }

      return resolvedGitDir
    }

    // Else return path to .git directory
    return foundPath
  }

  return null
}
开发者ID:typicode,项目名称:husky,代码行数:36,代码来源:resolveGitDir.ts

示例6: require

#!/usr/bin/env node

import '@babel/register';
import findUp from 'find-up';
import start, { StartOptions } from './scripts/start';
import build, { BuildOptions } from './scripts/build';

require('yargs') // eslint-disable-line
  .command(
    'start',
    'Start webpack dev server',
    () => {},
    (argv: StartOptions) => {
      start(argv);
    }
  )
  .command(
    'build',
    'Build application',
    () => {},
    (argv: BuildOptions) => {
      build(argv);
    }
  )
  .option('config', {
    alias: 'c',
    default: findUp.sync('medpack.js'),
  }).argv;
开发者ID:heydoctor,项目名称:medpack,代码行数:28,代码来源:cli.ts

示例7: install

export function install(
  huskyDir: string,
  requireRunNodePath: string = require.resolve('run-node/run-node'),
  isCI: boolean
): void {
  console.log('husky > Setting up git hooks')

  // First directory containing user's package.json
  const userPkgDir = pkgDir.sync(path.join(huskyDir, '..'))

  if (userPkgDir === undefined) {
    console.log("Can't find package.json, skipping Git hooks installation.")
    console.log(
      'Please check that your project has a package.json or create it and reinstall husky.'
    )
    return
  }

  // Get conf from package.json or .huskyrc
  const conf = getConf(userPkgDir)
  // Get directory containing .git directory or in the case of Git submodules, the .git file
  const gitDirOrFile = findUp.sync('.git', { cwd: userPkgDir })
  // Resolve git directory (e.g. .git/ or .git/modules/path/to/submodule)
  const resolvedGitDir = resolveGitDir(userPkgDir)

  // Checks
  if (process.env.HUSKY_SKIP_INSTALL === 'true') {
    console.log(
      "HUSKY_SKIP_INSTALL environment variable is set to 'true',",
      'skipping Git hooks installation.'
    )
    return
  }

  if (gitDirOrFile === null || gitDirOrFile === undefined) {
    console.log("Can't find .git, skipping Git hooks installation.")
    console.log(
      "Please check that you're in a cloned repository",
      "or run 'git init' to create an empty Git repository and reinstall husky."
    )
    return
  }

  if (resolvedGitDir === null) {
    console.log(
      "Can't find resolved .git directory, skipping Git hooks installation."
    )
    return
  }

  if (isCI && conf.skipCI) {
    console.log('CI detected, skipping Git hooks installation.')
    return
  }

  if (isInNodeModules(huskyDir)) {
    console.log(
      'Trying to install from node_modules directory, skipping Git hooks installation.'
    )
    return
  }

  // Create hooks directory if doesn't exist
  if (!fs.existsSync(path.join(resolvedGitDir, 'hooks'))) {
    fs.mkdirSync(path.join(resolvedGitDir, 'hooks'))
  }

  // Create hooks
  // Get root dir based on the first .git directory of file found
  const rootDir = path.dirname(gitDirOrFile)

  const hooks = getHooks(resolvedGitDir)
  const script = getScript(rootDir, huskyDir, requireRunNodePath)
  createHooks(hooks, script)

  console.log(`husky > Done`)
  console.log('husky > Like husky? You can support the project on Patreon:')
  console.log(
    'husky > \x1b[36m%s\x1b[0m 🐕',
    'https://www.patreon.com/typicode'
  )
}
开发者ID:typicode,项目名称:husky,代码行数:82,代码来源:index.ts


注:本文中的find-up.sync函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。