From 6c53ce837dd40178e7afb29e424c6a964616dc45 Mon Sep 17 00:00:00 2001 From: Mike Fix Date: Tue, 4 Dec 2018 14:14:07 -0800 Subject: [PATCH] update generate script --- scripts/generate.js | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/scripts/generate.js b/scripts/generate.js index 0e23000..d13f6e3 100644 --- a/scripts/generate.js +++ b/scripts/generate.js @@ -1,7 +1,7 @@ #!/usr/bin/env node const fs = require('fs-extra') const slug = require('to-slug-case') -const logSymbols = require('log-symbols'); +const logSymbols = require('log-symbols') const args = process.argv.slice(2) @@ -20,49 +20,43 @@ const pkgJsonTemplate = { version: '0.0.0', description: `GraphQL Normalized ${args.map(cap).join(' ')} Type`, main: 'index.js', - keywords: [ - 'graphql', - 'normalized', - 'types', - 'scalar', - 'gin-n-tonic', - type - ], + keywords: ['graphql', 'normalized', 'types', 'scalar', 'gin-n-tonic', type], license: 'MIT', - dependencies: { - }, + dependencies: {}, peerDependencies: { - 'graphql': '*' + graphql: '*' } } -const indexTemplate = -`const { GraphQLScalarType } = require('graphql') +const indexTemplate = `const { GraphQLScalarType } = require('graphql') const parse = v => { // Feel free to handle this however you would like! } +const serialize = v => { + // Feel free to handle this however you would like! +} + + module.exports = new GraphQLScalarType({ name: '${args.map(cap).join('')}', description: '', - serialize: parse, + serialize, parseValue: parse, parseLiteral(ast) { return parse(ast.value); } })` -const indexSpecTemplate = -`const type = require('.') +const indexSpecTemplate = `const type = require('.') test('${type}', () => { expect(dl._scalarConfig.parseValue()) })` - fs.writeFileSync(`${path}/index.js`, indexTemplate) fs.writeFileSync(`${path}/index.spec.js`, indexSpecTemplate) -fs.writeJsonSync(`${path}/package.json`, pkgJsonTemplate, {spaces: 2}) +fs.writeJsonSync(`${path}/package.json`, pkgJsonTemplate, { spaces: 2 }) console.log('\n', logSymbols.success, args.map(cap).join(''), 'type created!', '\n')