UNPKG

@graphql-codegen/time

Version:

GraphQL Code Generator plugin for adding the current time for an output file

22 lines (21 loc) 755 B
import { extname } from 'path'; // eslint-disable-next-line n/no-restricted-import -- todo: replace moment in v3 import moment from 'moment'; export const plugin = async (schema, documents, config, { outputFile }) => { let format; let message = 'Generated on '; if (config && typeof config === 'object') { if (config.format) { format = config.format; } if (config.message) { message = config.message; } } const outputFileExtension = outputFile && extname(outputFile); let commentPrefix = '//'; if ((outputFileExtension || '').toLowerCase() === '.graphql') { commentPrefix = '#'; } return commentPrefix + ' ' + message + moment().format(format) + '\n'; };