Skip to content

Commit

Permalink
update generate script
Browse files Browse the repository at this point in the history
  • Loading branch information
mfix22 committed Dec 4, 2018
1 parent 1679af0 commit 6c53ce8
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions scripts/generate.js
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -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')

0 comments on commit 6c53ce8

Please sign in to comment.