UNPKG

@graphql-codegen/time

Version:

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

27 lines (26 loc) 968 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.plugin = void 0; const tslib_1 = require("tslib"); const path_1 = require("path"); // eslint-disable-next-line n/no-restricted-import -- todo: replace moment in v3 const moment_1 = tslib_1.__importDefault(require("moment")); 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 && (0, path_1.extname)(outputFile); let commentPrefix = '//'; if ((outputFileExtension || '').toLowerCase() === '.graphql') { commentPrefix = '#'; } return commentPrefix + ' ' + message + (0, moment_1.default)().format(format) + '\n'; }; exports.plugin = plugin;