-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·46 lines (38 loc) · 1.26 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env node
const { readFileSync, existsSync } = require('fs')
const chalk = require('chalk')
const { post } = require('axios')
const graphql = require('./graphql')
process.stdout.write('\033c')
process.stdout.write(
String.fromCharCode(27) + ']0;' + 'graphql-now' + String.fromCharCode(7),
)
console.log(chalk.white('graphql-now ...\n'))
const schemaFile = process.cwd() + '/schema.graphql'
const mocksFile = process.cwd() + '/mocks.js'
const schemaFileExist = existsSync(schemaFile)
const mocksFileExist = existsSync(mocksFile)
if (!schemaFileExist) {
console.log(chalk.yellow('you must provide a schema.graphql at least\n'))
return
}
const [, , deploy] = process.argv
if (deploy === 'deploy') {
const files = {
typeDefs: readFileSync(schemaFile, 'base64'),
mocksFile: readFileSync(mocksFile, 'base64'),
}
post('https://gql.cool/__deploy', files).then(({ data }) =>
console.log(`deployed at ${chalk.green(`gql.cool/${data}`)}`),
)
} else {
const typeFile = readFileSync(schemaFile, 'utf8')
console.log(chalk.green('schema.graphql loaded'))
if (mocksFileExist) {
console.log(chalk.green('mocks.js loaded'))
graphql(schemaFile, mocksFile)
} else {
console.log(chalk.yellow('mocks.js not found'))
graphql(schemaFile)
}
}