本文整理汇总了TypeScript中prettier.resolveConfig函数的典型用法代码示例。如果您正苦于以下问题:TypeScript resolveConfig函数的具体用法?TypeScript resolveConfig怎么用?TypeScript resolveConfig使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了resolveConfig函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: graphQLTypes
export async function graphQLTypes(): Promise<void> {
const schemaStr = await readFile(GRAPHQL_SCHEMA_PATH, 'utf8')
const schema = buildSchema(schemaStr)
const result = (await graphql(schema, introspectionQuery)) as { data: IntrospectionQuery }
const formatOptions = (await resolveConfig(__dirname, { config: __dirname + '/../prettier.config.js' }))!
const typings =
'export type ID = string\n\n' +
generateNamespace(
'',
result,
{
typeMap: {
...DEFAULT_TYPE_MAP,
ID: 'ID',
},
},
{
generateNamespace: (name: string, interfaces: string) => interfaces,
interfaceBuilder: (name: string, body: string) =>
'export ' + DEFAULT_OPTIONS.interfaceBuilder(name, body),
enumTypeBuilder: (name: string, values: string) =>
'export ' + DEFAULT_OPTIONS.enumTypeBuilder(name, values),
typeBuilder: (name: string, body: string) => 'export ' + DEFAULT_OPTIONS.typeBuilder(name, body),
wrapList: (type: string) => `${type}[]`,
postProcessor: (code: string) => format(code, { ...formatOptions, parser: 'typescript' }),
}
)
await writeFile(__dirname + '/src/graphql/schema.ts', typings)
}
开发者ID:JoYiRis,项目名称:sourcegraph,代码行数:30,代码来源:gulpfile.ts
示例2: parser
const isFormatted = prettier.check('foo ( );', { semi: false });
const result = prettier.formatWithCursor(' 1', { cursorOffset: 2 });
const customFormatted = prettier.format('lodash ( )', {
parser(text, { babylon }) {
const ast = babylon(text);
const statement = ast.program.body[0] as ExpressionStatement;
const expression = statement.expression as CallExpression;
const identifier = expression.callee as Identifier;
identifier.name = '_';
return ast;
},
});
prettier.resolveConfig('path/to/somewhere').then(options => {
if (options !== null) {
const formatted = prettier.format('hello world', options);
}
});
if (prettier.getFileInfo.sync('./tsconfig.json').inferredParser !== 'json') {
throw new Error('Bad parser');
}
prettier.getFileInfo('./tsconfig.json').then(result => {
if (result.inferredParser !== 'json') {
throw new Error('Bad parser');
}
});
开发者ID:DanielRosenwasser,项目名称:DefinitelyTyped,代码行数:30,代码来源:prettier-tests.ts
注:本文中的prettier.resolveConfig函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论