當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。