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


TypeScript read-pkg-up.sync函数代码示例

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


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

示例1: getModuleVersion

  protected static getModuleVersion (moduleName: string): string {
    const modulePath = path.dirname(
      require.resolve(
        moduleName,
      ),
    )
    const pkg     = readPkgUp.sync({ cwd: modulePath }).pkg
    const version = pkg.version

    return version
  }
开发者ID:zixia,项目名称:wechaty,代码行数:11,代码来源:puppet-manager.ts

示例2: hash

 /**
  * Return hash string of the config and textlint version
  * @returns {string}
  */
 get hash() {
     try {
         const version = pkgConf.sync({ cwd: __dirname }).pkg.version;
         const toString = JSON.stringify(this.toJSON());
         return md5(`${version}-${toString}`);
     } catch (error) {
         // Fallback for some env
         // https://github.com/textlint/textlint/issues/597
         Logger.warn("Use random value as hash because calculating hash value throw error", error);
         return crypto.randomBytes(20).toString("hex");
     }
 }
开发者ID:textlint,项目名称:textlint,代码行数:16,代码来源:config.ts

示例3: constructor

  /**
   *
   *
   * Constructor
   *
   *
   */
  constructor(
    public options: PuppetOptions,
  ) {
    super()
    log.verbose('Puppet', 'constructor(%s)', JSON.stringify(options))

    this.counter = PUPPET_COUNTER++

    this.state    = new StateSwitch(this.constructor.name, log)

    this.options.timeout = this.options.timeout || DEFAULT_WATCHDOG_TIMEOUT

    log.verbose('Puppet', 'constructor() watchdog timeout set to %d seconds', this.options.timeout)
    this.watchdog = new Watchdog(1000 * this.options.timeout, 'Puppet')

    const lruOptions: LRU.Options = {
      max: 10000,
      // length: function (n) { return n * 2},
      dispose: function (key: string, val: Object) {
        log.silly('Puppet', 'constructor() lruOptions.dispose(%s, %s)', key, JSON.stringify(val))
      },
      maxAge: 1000 * 60 * 60,
    }

    this.cacheContactPayload       = new LRU<string, ContactPayload>(lruOptions)
    this.cacheFriendshipPayload = new LRU<string, FriendshipPayload>(lruOptions)
    this.cacheMessagePayload       = new LRU<string, MessagePayload>(lruOptions)
    this.cacheRoomPayload          = new LRU<string, RoomPayload>(lruOptions)
    this.cacheRoomMemberPayload    = new LRU<string, RoomMemberPayload>(lruOptions)

    /**
     * 2. Load the package.json for Puppet Plugin version range matching
     *
     * For: dist/src/puppet/puppet.ts
     *  We need to up 3 times: ../../../package.json
     */
    try {
      const childClassPath = callerResolve('.', __filename)
      log.verbose('Puppet', 'constructor() childClassPath=%s', childClassPath)

      this.childPkg = readPkgUp.sync({ cwd: childClassPath }).pkg
    } finally {
      if (!this.childPkg) {
        throw new Error('Cannot found package.json for Puppet Plugin Module')
      }
    }
    normalize(this.childPkg)
  }
开发者ID:miggame,项目名称:wechaty,代码行数:55,代码来源:puppet.ts

示例4: findPkg

/**
 * Recursively search for a package.json upwards containing given package
 * as a dependency or devDependency.
 * @param {string} fspath file system path to start searching from
 * @param {string} pkgName package's name to search for
 * @returns {string} resolved path to prettier
 */
function findPkg(fspath: string, pkgName: string): string | undefined {
    const res = readPkgUp.sync({ cwd: fspath, normalize: false });
    const { root } = path.parse(fspath);
    if (
        res.pkg &&
        ((res.pkg.dependencies && res.pkg.dependencies[pkgName]) ||
            (res.pkg.devDependencies && res.pkg.devDependencies[pkgName]))
    ) {
        return resolve.sync(pkgName, { basedir: res.path });
    } else if (res.path) {
        const parent = path.resolve(path.dirname(res.path), '..');
        if (parent !== root) {
            return findPkg(parent, pkgName);
        }
    }
    return;
}
开发者ID:JulioC,项目名称:prettier-vscode,代码行数:24,代码来源:requirePkg.ts

示例5:

		list = list.map(key => {
			const item = generatorsMeta[key];
			const name = key.split(':')[0];

			const pkgPath = readPkgUp.sync({cwd: item.resolved});
			if (!pkgPath.pkg) {
				return null;
			}

			const pkg = pkgPath.pkg;
			const generatorVersion: any = pkg.dependencies['yeoman-generator'];
			const generatorMeta: any = _.pick(pkg, 'name', 'version', 'description');

			// Ignore the generator if does not depend on `yeoman-generator`
			if (!generatorVersion) {
				return null;
			}

			// Flag generator to indecate if the generator version is fully supported or not.
			// https://github.com/yeoman/yeoman-app/issues/16#issuecomment-121054821
			generatorMeta.isCompatible = semver.ltr('0.17.6', generatorVersion);

			// Indicator to verify official generators
			generatorMeta.officialGenerator = false;
			if (generatorMeta.repository && generatorMeta.repository.url) {
				generatorMeta.officialGenerator = generatorMeta.repository.url.indexOf('github.com/yeoman/') > -1;
			}

			// Add subgenerators
			generatorMeta.subGenerators = Object.keys(generatorsMeta).reduce((result, key: any) => {
				const split = key.split(':');

				if (split[0] === name) {
					result.push(split[1]);
				}

				return result;
			}, []);

			return generatorMeta;
		});
开发者ID:Bolisov,项目名称:vscode-yo,代码行数:41,代码来源:yo.ts

示例6: hash

 /**
  * Return hash string of the config and textlint version
  * @returns {string}
  */
 get hash() {
     const pkgConf = require("read-pkg-up");
     const version = pkgConf.sync({ cwd: __dirname }).pkg.version;
     const toString = JSON.stringify(this.toJSON());
     return md5(`${version}-${toString}`);
 }
开发者ID:,项目名称:,代码行数:10,代码来源:

示例7: execute

/**
 * Encapsulates all CLI behavior for eslint. Makes it easier to test as well as
 * for other Node.js programs to effectively run the CLI.
 */
export const cli = {
    /**
     * Executes the CLI based on an array of arguments that is passed in.
     * @param {string|Array|Object} args The arguments to process.
     * @param {string} [text] The text to lint (used for TTY).
     * @returns {Promise<number>} The exit code for the operation.
     */
    execute(args: string | Array<any> | object, text?: string): Promise<number> {
        let currentOptions;
        // version from package.json
        const pkgConf = require("read-pkg-up");
        const version = pkgConf.sync({ cwd: __dirname }).pkg.version;
        try {
            currentOptions = options.parse(args);
        } catch (error) {
            Logger.error(error.message);
            return Promise.resolve(1);
        }
        const files = currentOptions._;
        if (currentOptions.version) {
            Logger.log(`v${version}`);
        } else if (currentOptions.init) {
            return createConfigFile({
                dir: process.cwd(),
                verbose: !currentOptions.quiet
            });
        } else if (currentOptions.help || (!files.length && !text)) {
开发者ID:textlint,项目名称:textlint,代码行数:31,代码来源:cli.ts

示例8:

#!/usr/bin/env ts-node
import * as fs    from 'fs'
import * as path  from 'path'
import readPkgUp  from 'read-pkg-up'

const PACKAGE_JSON = path.join(__dirname, '../package.json')

const pkg = readPkgUp.sync({ cwd: __dirname }).pkg

// pkg.publishConfig.tag = 'next'
pkg.publishConfig = {
  access: 'public',
  ...pkg.publishConfig,
  tag: 'next',
}

fs.writeFileSync(PACKAGE_JSON, JSON.stringify(pkg, null, 2))
// console.log(JSON.stringify(pkg, null, 2))

console.log('set package.json:publicConfig.tag to next.')
开发者ID:KiddoLin,项目名称:wechaty,代码行数:20,代码来源:package-publish-config-tag-next.ts


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