8000 fix(dev): use child_process and watchpack by chentsulin · Pull Request #458 · Yoctol/bottender · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix(dev): use child_process and watchpack #458

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"@types/shortid": "^0.0.29",
"@types/update-notifier": "^2.5.0",
"@types/warning": "^3.0.0",
"@types/watchpack": "^1.1.5",
"@typescript-eslint/eslint-plugin": "^2.2.0",
"@typescript-eslint/parser": "^2.2.0",
"chalk": "^2.4.2",
Expand Down
4 changes: 2 additions & 2 deletions packages/bottender/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
"minimist": "^1.2.0",
"mongodb": "^3.3.2",
"ngrok": "^3.2.5",
"nodemon": "^1.19.2",
"p-map": "^3.0.0",
"p-props": "^3.1.0",
"pascal-case": "^2.0.1",
Expand All @@ -67,7 +66,8 @@
"recursive-readdir": "^2.2.2",
"shortid": "^2.2.15",
"update-notifier": "^3.0.1",
"warning": "^4.0.3"
"warning": "^4.0.3",
"watchpack": "^1.6.0"
},
"devDependencies": {
"jest-create-mock-instance": "^1.1.0",
Expand Down
59 changes: 43 additions & 16 deletions packages/bottender/src/cli/providers/sh/dev.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import childProcess from 'child_process';

import Watchpack from 'watchpack';
import ngrok from 'ngrok';
import nodemon from 'nodemon';

import getBottenderConfig from '../../shared/getBottenderConfig';
import { CliContext } from '../..';
Expand All @@ -23,21 +25,46 @@ const dev = async (ctx: CliContext): Promise<void> => {

const { channels } = config;

// watch
nodemon(
`--exec "bottender start ${isConsole ? '--console' : ''} --port ${port}"`
)
// TODO: improve messages
.on('start', () => {
console.log('App has started');
})
.on('quit', () => {
console.log('App has quit');
process.exit();
})
.on('restart', (files: string[]) => {
console.log('App restarted due to: ', files);
});
const createProcess = () =>
childProcess.spawn(
`npx bottender start ${isConsole ? '--console' : ''} --port ${port}`,
{
stdio: 'inherit',
}
);

let cp = createProcess();

const handleExit = (code: number | null) => {
process.exit(code || undefined);
};

cp.on('exit', handleExit);

const wp = new Watchpack({
aggregateTimeout: 1000,
poll: true,
ignored: ['**/.git', '**/node_modules'],
});

wp.watch([], ['.']);

wp.on('aggregated', (changes, removals) => {
console.log('App restarted due to: ', changes, removals);
cp.off('exit', handleExit);
cp.kill('SIGTERM');

cp = createProcess();
});

const useTypeScript = false; // FIXME

if (useTypeScript) {
// watch js and run cp
// watch ts and compile to dist
} else {
// watch all and run cp
}

if (!isConsole) {
const url = await ngrok.connect(port);
Expand Down
Loading
0