ts-morph#QuoteKind TypeScript Examples
The following examples show how to use
ts-morph#QuoteKind.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: options.ts From gengen with MIT License | 6 votes |
generatorsOptions: ProjectOptions = {
compilerOptions: {
target: ScriptTarget.ES2018,
module: ModuleKind.CommonJS,
strict: true,
esModuleInterop: true
},
manipulationSettings: {
newLineKind: NewLineKind.CarriageReturnLineFeed,
quoteKind: QuoteKind.Single,
insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces: true,
indentationText: IndentationText.FourSpaces
}
}
Example #2
Source File: generate.ts From prisma-nestjs-graphql with MIT License | 4 votes |
export async function generate(
args: GeneratorOptions & {
skipAddOutputSourceFiles?: boolean;
connectCallback?: (
emitter: AwaitEventEmitter,
eventArguments: EventArguments,
) => void | Promise<void>;
},
) {
const { connectCallback, generator, skipAddOutputSourceFiles, dmmf } = args;
const generatorOutputValue = generator.output?.value;
ok(generatorOutputValue, 'Missing generator configuration: output');
const eventEmitter = new AwaitEventEmitter();
eventEmitter.on('Warning', warning);
eventEmitter.on('Model', modelData);
eventEmitter.on('EnumType', registerEnum);
eventEmitter.on('OutputType', outputType);
eventEmitter.on('ModelOutputType', modelOutputType);
eventEmitter.on('AggregateOutput', createAggregateInput);
eventEmitter.on('InputType', inputType);
eventEmitter.on('ArgsType', argsType);
eventEmitter.on('GenerateFiles', generateFiles);
const config = createConfig(generator.config);
for (const message of config.$warnings) {
eventEmitter.emitSync('Warning', message);
}
const project = new Project({
tsConfigFilePath: config.tsConfigFilePath,
skipAddingFilesFromTsConfig: true,
skipLoadingLibFiles: !config.emitCompiled,
manipulationSettings: {
quoteKind: QuoteKind.Single,
},
});
if (!skipAddOutputSourceFiles) {
project.addSourceFilesAtPaths([
`${generatorOutputValue}/**/*.ts`,
`!${generatorOutputValue}/**/*.d.ts`,
]);
}
config.combineScalarFilters && combineScalarFilters(eventEmitter);
config.noAtomicOperations && noAtomicOperations(eventEmitter);
config.reExport !== ReExport.None && reExport(eventEmitter);
config.emitSingle && emitSingle(eventEmitter);
config.purgeOutput && purgeOutput(eventEmitter);
config.requireSingleFieldsInWhereUniqueInput &&
requireSingleFieldsInWhereUniqueInput(eventEmitter);
const models = new Map<string, Model>();
const modelNames: string[] = [];
const modelFields = new Map<string, Map<string, Field>>();
const fieldSettings = new Map<string, Map<string, ObjectSettings>>();
const getModelName = createGetModelName(modelNames);
const getSourceFile = factoryGetSourceFile({
output: generatorOutputValue,
project,
getModelName,
outputFilePattern: config.outputFilePattern,
eventEmitter,
});
const {
datamodel,
schema: { inputObjectTypes, outputObjectTypes, enumTypes },
} = JSON.parse(JSON.stringify(dmmf)) as DMMF.Document;
const removeTypes = new Set<string>();
const eventArguments: EventArguments = {
models,
config,
modelNames,
modelFields,
fieldSettings,
project,
output: generatorOutputValue,
getSourceFile,
eventEmitter,
typeNames: new Set<string>(),
enums: mapKeys(datamodel.enums, x => x.name),
getModelName,
removeTypes,
classTransformerTypeModels: new Set(),
};
if (connectCallback) {
await connectCallback(eventEmitter, eventArguments);
}
await eventEmitter.emit('Begin', eventArguments);
for (const model of datamodel.models) {
await eventEmitter.emit('Model', model, eventArguments);
}
// Types behaves like model
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
for (const model of datamodel.types || []) {
await eventEmitter.emit('Model', model, eventArguments);
}
await eventEmitter.emit('PostBegin', eventArguments);
for (const enumType of enumTypes.prisma.concat(enumTypes.model || [])) {
await eventEmitter.emit('EnumType', enumType, eventArguments);
}
for (const outputType of outputObjectTypes.model) {
await eventEmitter.emit('ModelOutputType', outputType, eventArguments);
}
const queryOutputTypes: OutputType[] = [];
for (const outputType of outputObjectTypes.prisma) {
if (['Query', 'Mutation'].includes(outputType.name)) {
queryOutputTypes.push(outputType);
continue;
}
await eventEmitter.emit('OutputType', outputType, eventArguments);
}
const inputTypes = inputObjectTypes.prisma.concat(inputObjectTypes.model || []);
for (const inputType of inputTypes) {
const event = {
...eventArguments,
inputType,
fileType: 'input',
classDecoratorName: 'InputType',
};
if (inputType.fields.length === 0) {
removeTypes.add(inputType.name);
continue;
}
await eventEmitter.emit('BeforeInputType', event);
await eventEmitter.emit('InputType', event);
}
for (const outputType of queryOutputTypes) {
for (const field of outputType.fields) {
await eventEmitter.emit('ArgsType', field, eventArguments);
}
}
await eventEmitter.emit('BeforeGenerateFiles', eventArguments);
await eventEmitter.emit('GenerateFiles', eventArguments);
await eventEmitter.emit('End', eventArguments);
for (const name of Object.keys(eventEmitter._events)) {
eventEmitter.off(name);
}
}