@toptal/davinci-graphql-codegen 0.1.1-alpha-feature-comm-620-graphql-codegen.1441 → 0.1.2-alpha-feature-comm-745-monolith-support.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # @toptal/davinci-graphql-codegen
2
+
3
+ ## 0.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#1153](https://github.com/toptal/davinci/pull/1153) [`b51f6179`](https://github.com/toptal/davinci/commit/b51f61791640b552b3d861cfe14fcb3e6ebedb56) Thanks [@alexvcasillas](https://github.com/alexvcasillas)! - Release for GraphQL Codegen
@@ -9,26 +9,3 @@ cliEngine.loadCommands([
9
9
  codegenGenerateSchemaCreator,
10
10
  codegenGenerateOperationsCreator
11
11
  ])
12
-
13
- cliEngine.help(
14
- () => `
15
- Commands:
16
-
17
- help [command...] Provides help for a given command
18
- exit Exits application
19
- generate-operations generate graphql operation types based off generated schemas
20
- generate-schema generate graphql schemas
21
- `
22
- )
23
-
24
- const args = cliEngine.bootstrap({ use: 'minimist' })
25
-
26
- // eslint-disable-next-line @typescript-eslint/no-shadow
27
- cliEngine.catchErrorCommand((args, cb) => {
28
- cliEngine.execCommand(`${args.commands.join(' ')}`)
29
- cb()
30
- })
31
-
32
- if (args._ && args._.length) {
33
- cliEngine.execCommand(`${args._.join(' ')}`)
34
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toptal/davinci-graphql-codegen",
3
- "version": "0.1.1-alpha-feature-comm-620-graphql-codegen.1441+6a5ae6bf",
3
+ "version": "0.1.2-alpha-feature-comm-745-monolith-support.1+989f544e",
4
4
  "description": "Codegen",
5
5
  "author": "Toptal",
6
6
  "license": "ISC",
@@ -28,9 +28,9 @@
28
28
  "@graphql-codegen/typescript-operations": "^2.1.4",
29
29
  "@graphql-codegen/typescript-resolvers": "^2.2.1",
30
30
  "@graphql-typed-document-node/core": "^3.1.0",
31
- "@toptal/davinci-cli-shared": "1.5.1-alpha-feature-comm-620-graphql-codegen.87+6a5ae6bf",
31
+ "@toptal/davinci-cli-shared": "1.5.1-alpha-feature-comm-745-monolith-support.111+989f544e",
32
32
  "chalk": "^4.1.2",
33
33
  "graphql": "^15.7.1"
34
34
  },
35
- "gitHead": "6a5ae6bf6d03c85803bd8892e2ee922df3f4f337"
35
+ "gitHead": "989f544e0c1e14ccd4d1f8a5d559cb091697d864"
36
36
  }
@@ -1,12 +1,11 @@
1
1
  const { generateOperations } = require('../generate')
2
2
  const readConfig = require('../read-config')
3
- const processArgs = require('../services/process-args')
3
+ const processArgs = require('../utils/process-args')
4
4
 
5
5
  const args = processArgs(process.argv.slice(2))
6
6
  const operation = args.operation
7
7
 
8
- // eslint-disable-next-line func-style
9
- async function codegenGenerateOperations() {
8
+ const codegenGenerateOperations = async () => {
10
9
  const codegen = await readConfig()
11
10
 
12
11
  switch (operation) {
@@ -1,14 +1,19 @@
1
+ const chalk = require('chalk')
2
+
1
3
  const { generateSchema } = require('../generate')
2
4
  const readConfig = require('../read-config')
3
- const processArgs = require('../services/process-args')
5
+ const processArgs = require('../utils/process-args')
4
6
 
5
7
  const args = processArgs(process.argv.slice(2))
8
+
9
+ console.log(args)
10
+
6
11
  const operation = args.operation
7
12
  const projectId = args.projectId || 'toptal-hub'
13
+ const configDir = args.configDir
8
14
 
9
- // eslint-disable-next-line func-style
10
- async function codegenGenerateSchema() {
11
- const codegen = await readConfig()
15
+ const codegenGenerateSchema = async () => {
16
+ const codegen = await readConfig(configDir)
12
17
 
13
18
  switch (operation) {
14
19
  case 'generate-schema': {
@@ -30,6 +35,14 @@ async function codegenGenerateSchema() {
30
35
  const codegenGenerateSchemaCreator = {
31
36
  command: 'generate-schema',
32
37
  description: 'generate graphql schemas',
38
+ options: [
39
+ {
40
+ label: `Custom dir where ${chalk.green(
41
+ 'codegen.json'
42
+ )} config file is located`,
43
+ name: '--configDir'
44
+ }
45
+ ],
33
46
  action: () => {
34
47
  codegenGenerateSchema()
35
48
  }
@@ -0,0 +1,3 @@
1
+ const config = require('./config')
2
+
3
+ module.exports = config
@@ -3,8 +3,8 @@ const { generate } = require('@graphql-codegen/cli')
3
3
  const {
4
4
  commonOperationTypesConfig,
5
5
  autoGenerationComments
6
- } = require('../shared-config/shared-config')
7
- const getRelativeFilePath = require('../services/get-relative-file-path')
6
+ } = require('../config/config')
7
+ const getRelativeFilePath = require('../utils/get-relative-file-path')
8
8
 
9
9
  const generateOperations = async ({ schema, documents }) => {
10
10
  const docsPath = getRelativeFilePath(documents)
@@ -12,7 +12,10 @@ const generateOperations = async ({ schema, documents }) => {
12
12
  // @toptal/modularity-template-graphql/talent -> talent
13
13
  const target = schema.split('/').pop()
14
14
  // @toptal/modularity-template-graphql/talent -> @toptal/modularity-template-graphql/talent
15
- const schemaPath = schema.split('/').slice(0, 2).join('/')
15
+ const schemaPath = schema
16
+ .split('/')
17
+ .slice(0, 2)
18
+ .join('/')
16
19
 
17
20
  await generate(
18
21
  {
@@ -4,8 +4,9 @@ const chalk = require('chalk')
4
4
  const {
5
5
  commonSchemaTypesConfig,
6
6
  autoGenerationComments
7
- } = require('../shared-config/shared-config')
7
+ } = require('../config/config')
8
8
  const schemaLoader = require('../services/schema-loader')
9
+ const { isSchemaFromHttp } = require('../utils/detect-schema-source')
9
10
 
10
11
  const generateSchema = async ({ schema, target, projectId }) => {
11
12
  const {
@@ -23,7 +24,7 @@ const generateSchema = async ({ schema, target, projectId }) => {
23
24
  // plugins: ['introspection']
24
25
  // },
25
26
  [destinationPathTs]: {
26
- schema: schema.startsWith('https://')
27
+ schema: isSchemaFromHttp(schema)
27
28
  ? schema
28
29
  : require.resolve(schemaPath),
29
30
  plugins: [
@@ -1,13 +1,25 @@
1
1
  const chalk = require('chalk')
2
2
 
3
- const getRelativeFilePath = require('../services/get-relative-file-path')
4
- const toArray = require('../services/to-array')
3
+ const getRelativeFilePath = require('../utils/get-relative-file-path')
4
+ const toArray = require('../utils/to-array')
5
5
 
6
- const readConfig = async () => {
7
- console.log(`🔍 Searching for ${chalk.bold('codegen.json')} file`)
8
- let codegenConfig
6
+ const readConfig = async configDir => {
7
+ let codegenPath
8
+
9
+ if (configDir) {
10
+ console.log(
11
+ `🔍 Searching for ${chalk.bold('codegen.json')} file in [${chalk.green(
12
+ configDir
13
+ )}] custom directory`
14
+ )
15
+
16
+ codegenPath = getRelativeFilePath(`${configDir}/codegen.json`)
17
+ } else {
18
+ console.log(`🔍 Searching for ${chalk.bold('codegen.json')} file`)
9
19
 
10
- const codegenPath = getRelativeFilePath('codegen.json')
20
+ codegenPath = getRelativeFilePath('codegen.json')
21
+ }
22
+ let codegenConfig
11
23
 
12
24
  try {
13
25
  codegenConfig = require(codegenPath)
@@ -1,7 +1,7 @@
1
1
  const { Storage } = require('@google-cloud/storage')
2
2
 
3
- const getRelativeFilePath = require('../services/get-relative-file-path')
4
- const parseGSURI = require('./parse-gs-uri')
3
+ const getRelativeFilePath = require('../utils/get-relative-file-path')
4
+ const parseGSURI = require('../utils/parse-gs-uri')
5
5
 
6
6
  const gsSchemaLoader = async (projectId, source, destination) => {
7
7
  // Creates a Google Storage Client
@@ -1,14 +1,23 @@
1
- const { existsSync, copyFileSync } = require('fs')
1
+ const chalk = require('chalk')
2
+ const { existsSync, copyFileSync, mkdirSync } = require('fs')
2
3
 
3
4
  const gsSchemaLoader = require('./gs-schema-loader')
4
- const getRelativeFilePath = require('./get-relative-file-path')
5
+ const getRelativeFilePath = require('../utils/get-relative-file-path')
5
6
  const {
6
7
  isSchemaFromBucket,
7
8
  isLocalSchema,
8
9
  isSchemaFromHttp
9
- } = require('./detect-schema-source')
10
+ } = require('../utils/detect-schema-source')
10
11
 
11
12
  module.exports = async (schema, target, projectId) => {
13
+ if (!existsSync(target)) {
14
+ console.log("📁 Destination target doesn't exist, creating one for you...")
15
+ mkdirSync(target)
16
+ console.log(
17
+ `✅ Successfully created [${chalk.green(target)}] target folder`
18
+ )
19
+ }
20
+
12
21
  const schemaPath = isSchemaFromHttp(schema)
13
22
  ? schema
14
23
  : getRelativeFilePath(`${target}/schema.graphql`)
File without changes
File without changes
@@ -2,20 +2,17 @@ const processArgs = args => {
2
2
  const obj = {}
3
3
 
4
4
  args.forEach(arg => {
5
- if (arg.includes('generate:')) {
5
+ if (arg.includes('generate-')) {
6
6
  obj.operation = arg
7
7
 
8
8
  return
9
9
  }
10
10
 
11
11
  // Eg: Parts -> ['projectId', 'toptal-hub']
12
- const parts = arg
12
+ const [key, value] = arg
13
13
  .split(/(?:--)([a-zA-Z]*)(?:=)([a-zA-Z-]*)/i)
14
14
  .filter(Boolean)
15
15
 
16
- const key = parts[0]
17
- const value = parts[1]
18
-
19
16
  obj[key] = value
20
17
  })
21
18
 
File without changes
@@ -1,3 +0,0 @@
1
- const sharedConfig = require('./shared-config')
2
-
3
- module.exports = sharedConfig