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


TypeScript pkg-dir.sync函数代码示例

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


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

示例1: run

async function run(helper: Helper, args: {}) {
	const cwd = process.cwd();
	let rootDir = pkgDir.sync(cwd);
	if (!rootDir) {
		console.warn(noPackageWarning);
		rootDir = cwd;
	}

	const dojoRcPath = join(rootDir, '.dojorc');
	const file = existsSync(dojoRcPath) && readFileSync(dojoRcPath, 'utf8');
	let json: { [name: string]: {} } = {};
	let indent = '\t';

	if (file) {
		indent = detectIndent(file).indent || indent;
		json = JSON.parse(file);
	}

	const groupMap = await loadExternalCommands();
	const values = [];

	for (let [, commandMap] of groupMap.entries()) {
		for (let [, value] of commandMap.entries()) {
			const name = `${value.group}-${value.name}`;
			if (values.indexOf(name) === -1 && json[name] === undefined) {
				json[name] = {};
				values.push(name);
			}
		}
	}

	writeFileSync(dojoRcPath, JSON.stringify(json, null, indent));
	console.log(chalk.white(`Successfully wrote .dojorc to ${dojoRcPath}`));
}
开发者ID:dojo,项目名称:cli,代码行数:34,代码来源:init.ts

示例2: uninstall

export function uninstall(huskyDir: string): void {
  console.log('husky > Uninstalling git hooks')
  const userPkgDir = pkgDir.sync(path.join(huskyDir, '..'))
  const resolvedGitDir = resolveGitDir(userPkgDir)

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

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

  // Remove hooks
  const hooks = getHooks(resolvedGitDir)
  removeHooks(hooks)

  console.log('husky > Done')
}
开发者ID:typicode,项目名称:husky,代码行数:25,代码来源:index.ts

示例3: getLatestCommandVersions

async function getLatestCommandVersions(): Promise<NpmPackageDetails[]> {
	const packagePath = pkgDir.sync(__dirname);
	const packageJsonFilePath = join(packagePath, 'package.json');
	const packageJson: PackageDetails = require(packageJsonFilePath);

	console.log(chalk.yellow('Fetching latest version information...'));

	return await getLatestCommands(packageJson.name);
}
开发者ID:dojo,项目名称:cli,代码行数:9,代码来源:version.ts

示例4: createVersionsString

/**
 * Returns a string describing the command group, module name, and module version of each
 * command referenced in a specified CommandsMap. This is used to print the string.
 *
 * @param {CommandsMap} commandsMap maps of commands to output the versions for
 * @param {boolean} checkOutdated should we check if there is a later stable version available for the command
 * @returns {string} the stdout output
 */
function createVersionsString(groupMap: GroupMap, checkOutdated: boolean): Promise<string> {
	const packagePath = pkgDir.sync(__dirname);
	const myPackageDetails = readPackageDetails(packagePath); // fetch the cli's package details
	const versions: ModuleVersion[] = buildVersions(groupMap);
	if (checkOutdated) {
		return areCommandsOutdated(versions).then(
			(commandVersions: ModuleVersion[]) => createOutput(myPackageDetails, commandVersions),
			(err) => {
				return `Something went wrong trying to fetch command versions: ${err.message}`;
			}
		);
	} else {
		return Promise.resolve(createOutput(myPackageDetails, versions));
	}
}
开发者ID:dojo,项目名称:cli,代码行数:23,代码来源:version.ts

示例5: function

	grunt.registerTask('_link', '', function (this: ITask) {
		const done = this.async();
		const packagePath = pkgDir.sync(process.cwd());
		const targetPath = grunt.config('distDirectory');

		fs.symlink(
			path.join(packagePath, 'node_modules'),
			path.join(targetPath, 'node_modules'),
			'junction',
			() => {}
		);
		fs.symlink(
			path.join(packagePath, 'package.json'),
			path.join(targetPath, 'package.json'),
			'file',
			() => {}
		);

		execa.shell('npm link', { cwd: targetPath })
			.then((result: any) => grunt.log.ok(result.stdout))
			.then(done);
	});
开发者ID:dylans,项目名称:grunt-dojo2,代码行数:22,代码来源:link.ts

示例6: require

} from '../lib/load-data';

import * as log from '../lib/log';

log.setLogLevel(log.LogLevel.none);


const pkgDir = require('pkg-dir');
const fs = require('fs');
const path = require('path');
const mockFs = require('mock-fs');
const mountfs = require('mountfs');
mountfs.patchInPlace();

// test files.
const testDir = path.join(pkgDir.sync(__dirname), 'test');

describe('Load Project ', ()=>{
    const mnt = path.join(__dirname, 'mockfs');
    beforeEach(()=>{
        const mock = mockFs.fs({
            '/proj1': {
                'myst.json': `{
    "data": "data/"
}`,
                'data': {
                    'foo.yaml': `
foobar: 吉野家
foonum: 10`,
                    'bar.json': '{"welcome": "to my bar"}',
                },
开发者ID:uhyo,项目名称:my-static,代码行数:31,代码来源:basic.spec.ts

示例7: assertPresent

import path from 'path';
import pkgDir from 'pkg-dir';
import { TextDocument } from 'vscode-languageserver-types';

import { createFs, createProvider, MinimalDocs } from '../../../src/lib/provider-factory';
import { Completion, Snippet } from '../../../src/lib/completion-types';
import { ProviderPosition, ProviderRange } from '../../../src/lib/completion-providers';
import Provider from '../../../src/lib/provider';
import { fromVscodePath } from '../../../src/lib/utils/uri-utils';
import { Stylable } from '@stylable/core';
import { LocalSyncFs } from '../../../src/lib/local-sync-fs';
import { createDocFs } from '../../../src/lib/server-utils';
import { createBaseHost, createLanguageServiceHost } from '../../../src/lib/utils/temp-language-service-host';
import { ExtendedTsLanguageService } from '../../../src/lib/types';

export const CASES_PATH = path.join(pkgDir.sync(__dirname)!, 'fixtures', 'server-cases');

function assertPresent(
    actualCompletions: Completion[],
    expectedCompletions: Array<Partial<Completion>>,
    prefix: string = ''
) {
    expectedCompletions.forEach(expected => {
        const actual = actualCompletions.find(comp => comp.label === expected.label);
        expect(actual, 'Completion not found: ' + expected.label + ' ' + 'with prefix ' + prefix + ' ').to.not.be.equal(
            undefined
        );
        if (actual) {
            for (const field in expected) {
                if (!Object.prototype.hasOwnProperty.call(expected, field)) {
                    continue;
开发者ID:wix,项目名称:stylable-intelligence,代码行数:31,代码来源:asserters.ts

示例8: require

import { join } from 'path';
const pkgDir = require('pkg-dir');
const packagePath = pkgDir.sync(__dirname);
import { CliConfig } from './interfaces';

export default {
	searchPaths: ['node_modules', join(__dirname, '..', '..'), join(packagePath, 'node_modules')],
	searchPrefixes: ['@dojo/cli', 'dojo-cli'],
	builtInCommandLocation: join(__dirname, '/commands') // better to be relative to this file (like an import) than link to publish structure
} as CliConfig;
开发者ID:dojo,项目名称:cli,代码行数:10,代码来源:config.ts

示例9: require

const pkgDir = require('pkg-dir');
const {join} = require('path');
const createProcessors = require('grunt-dojo2/tasks/util/postcss').createProcessors;

const packagePath = pkgDir.sync(process.cwd());

const fontFiles = 'theme/fonts/*.{svg,ttf,woff}';
const staticExampleFiles = [ '*/example/**', '!*/example/**/*.js' ];
const staticTestFiles = '*/tests/**/*.{html,css,json,xml,js,txt}';

export const copy = {
	'staticDefinitionFiles-dev': {
		cwd: 'src',
		src: [ '<%= staticDefinitionFiles %>' ],
		dest: '<%= devDirectory %>'
	},
	staticTestFiles: {
		expand: true,
		cwd: 'src',
		src: [ staticTestFiles ],
		dest: '<%= devDirectory %>'
	},
	staticExampleFiles: {
		expand: true,
		cwd: 'src',
		src: staticExampleFiles,
		dest: '<%= devDirectory %>'
	},
	devFonts: {
		expand: true,
		cwd: 'src',
开发者ID:bryanforbes,项目名称:widgets,代码行数:31,代码来源:config.ts

示例10: require

import chalk from 'chalk';
import { existsSync, readFileSync, writeFileSync } from 'fs';
import { join } from 'path';
import { Config, ConfigurationHelper, ConfigWrapper } from './interfaces';
import * as readlineSync from 'readline-sync';
import * as detectIndent from 'detect-indent';

const pkgDir = require('pkg-dir');

const appPath = pkgDir.sync(process.cwd());
let dojoRcPath: string;
let packageJsonPath: string;
if (appPath) {
	dojoRcPath = join(appPath, '.dojorc');
	packageJsonPath = join(appPath, 'package.json');
}

let canWriteToPackageJson: boolean | undefined;
const defaultIndent = 2;

function parseConfigs(): ConfigWrapper {
	const configWrapper: ConfigWrapper = {};

	if (existsSync(dojoRcPath)) {
		try {
			const dojoRcFile = readFileSync(dojoRcPath, 'utf8');
			configWrapper.dojoRcIndent = detectIndent(dojoRcFile).indent;
			configWrapper.dojoRcConfig = JSON.parse(dojoRcFile);
		} catch (error) {
			throw Error(chalk.red(`Could not parse the .dojorc  file to get config : ${error}`));
		}
开发者ID:dojo,项目名称:cli,代码行数:31,代码来源:configurationHelper.ts


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