Skip to content

Commit

Permalink
get available port on codegen (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
piglovesyou authored Apr 5, 2019
1 parent 33716d9 commit 67e8565
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"@types/eslint-plugin-prettier": "^2.2.0",
"@types/express": "^4.16.1",
"@types/express-jwt": "^0.0.42",
"@types/get-port": "^4.2.0",
"@types/glob": "^7.1.1",
"@types/graphql": "^14.2.0",
"@types/history": "^4.7.2",
Expand Down Expand Up @@ -131,6 +132,7 @@
"eslint-plugin-react": "^7.12.4",
"file-loader": "^3.0.1",
"front-matter": "^3.0.1",
"get-port": "^4.2.0",
"glob": "^7.1.3",
"husky": "^1.3.1",
"identity-obj-proxy": "^3.0.0",
Expand Down
7 changes: 5 additions & 2 deletions tools/codegen.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ApolloServer } from 'apollo-server';
import getPort from 'get-port';
import { spawn } from './lib/cp';
import webpackConfig from './webpack.config';
import runWebpack from './lib/runWebpack';
Expand Down Expand Up @@ -26,15 +27,17 @@ export default async function codegen() {
serverConfig.stats,
);

const port = await getPort();

// eslint-disable-next-line global-require, import/no-dynamic-require, import/no-unresolved
const builtSchema = require('../build/schema').default;
const server = new ApolloServer(builtSchema);
const { server: httpServer } = await server.listen({ port: 3900 });
const { server: httpServer } = await server.listen({ port });

await spawn('yarn', [
'apollo', 'client:codegen',
'--target', 'typescript',
'--endpoint', 'http://localhost:3900/graphql',
'--endpoint', `http://localhost:${port}/graphql`,
], {
stdio: 'inherit',
});
Expand Down
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1624,6 +1624,13 @@
dependencies:
"@types/node" "*"

"@types/get-port@^4.2.0":
version "4.2.0"
resolved "https://registry.yarnpkg.com/@types/get-port/-/get-port-4.2.0.tgz#4fc44616c737d37d3ee7926d86fa975d0afba5e4"
integrity sha512-Iv2FAb5RnIk/eFO2CTu8k+0VMmIR15pKbcqRWi+s3ydW+aKXlN2yemP92SrO++ERyJx+p6Ie1ggbLBMbU1SjiQ==
dependencies:
get-port "*"

"@types/glob@*", "@types/glob@^7.1.1":
version "7.1.1"
resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.1.1.tgz#aa59a1c6e3fbc421e07ccd31a944c30eba521575"
Expand Down Expand Up @@ -6368,6 +6375,11 @@ get-own-enumerable-property-symbols@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/get-own-enumerable-property-symbols/-/get-own-enumerable-property-symbols-2.0.1.tgz#5c4ad87f2834c4b9b4e84549dc1e0650fb38c24b"

get-port@*, get-port@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/get-port/-/get-port-4.2.0.tgz#e37368b1e863b7629c43c5a323625f95cf24b119"
integrity sha512-/b3jarXkH8KJoOMQc3uVGHASwGLPq3gSFJ7tgJm2diza+bydJPTGOibin2steecKeOylE8oY2JERlVWkAJO6yw==

get-stdin@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-4.0.1.tgz#b968c6b0a04384324902e8bf1a5df32579a450fe"
Expand Down

0 comments on commit 67e8565

Please sign in to comment.