Skip to content

Commit

Permalink
mod: clear old type defs before codegen
Browse files Browse the repository at this point in the history
improve eslint defs
  • Loading branch information
piglovesyou committed May 6, 2019
1 parent bc2085b commit 7f19a67
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ module.exports = {
'@typescript-eslint/no-unused-vars': [
'error',
{
vars: 'all',
vars: 'local',
args: 'after-used',
ignoreRestSiblings: false,
argsIgnorePattern: '^_',
Expand Down
31 changes: 16 additions & 15 deletions tools/codegen.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import { ApolloServer } from 'apollo-server';
import getPort from 'get-port';
import rimraf from 'rimraf';
import { spawn } from './lib/cp';
import webpackConfig from './webpack.config';
import runWebpack from './lib/runWebpack';
import run from './run';
import clean from './clean';
import webpackConfig from './webpack.config';

/* eslint @typescript-eslint/no-unused-vars:0 */
const [_, serverConfig] = webpackConfig;
const [, serverConfig] = webpackConfig;

/**
* Generate Flow declarations from GraphQL. Since it requires
* a running GraphQL server, it launches a server for the use.
*/
export default async function codegen() {
await runWebpack(
const promiseRemoveOldTypes = new Promise(resolve =>
rimraf('{./,src/**/}__generated__', resolve),
);

const promiseCompileSchemaJs = await runWebpack(
{
...serverConfig,
entry: './src/data/schema',
Expand All @@ -27,7 +29,13 @@ export default async function codegen() {
serverConfig.stats,
);

const port = await getPort();
const promisePort = getPort();

const [port] = await Promise.all([
promisePort,
promiseRemoveOldTypes,
promiseCompileSchemaJs,
]);

// eslint-disable-next-line global-require, import/no-dynamic-require, import/no-unresolved
const builtSchema = require('../build/schema').default;
Expand All @@ -49,12 +57,5 @@ export default async function codegen() {
},
);

await new Promise(resolve => {
httpServer.close(() => {
console.info('Server closed');
resolve();
});
});

await run(clean);
await new Promise(resolve => httpServer.close(resolve));
}
3 changes: 1 addition & 2 deletions tools/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* LICENSE.txt file in the root directory of this source tree.
*/

/* eslint-disable global-require, import/no-unresolved */

import path from 'path';
import express, { Request, Response, Application } from 'express';
import browserSync from 'browser-sync';
Expand Down Expand Up @@ -147,6 +145,7 @@ async function start() {
let hot: any;
function reloadApp() {
delete require.cache[require.resolve('../build/server')];
// eslint-disable-next-line global-require
const compiled = require('../build/server');
app = compiled.default;
hot = compiled.hot;
Expand Down

0 comments on commit 7f19a67

Please sign in to comment.