Skip to content

Commit

Permalink
feat(scripts): show cli output on browser-sync reload
Browse files Browse the repository at this point in the history
See #444
  • Loading branch information
swashata committed Apr 18, 2019
1 parent e63aa9b commit c1885e2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
5 changes: 5 additions & 0 deletions packages/scripts/src/bin/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
printSuccessfullyCompiledMessage,
printCompiledWithWarnMessage,
printFailedCompileMEssage,
printGeneralInfoMessage,
} from './utils';

/**
Expand Down Expand Up @@ -114,6 +115,10 @@ export function serve(options: ProgramOptions | undefined): void {
}
printWatchingMessage();
},
onBsChange(file) {
printGeneralInfoMessage(`changed: ${chalk.bold(file)}`);
printGeneralInfoMessage('reloading browser');
},
});
server.serve();

Expand Down
6 changes: 3 additions & 3 deletions packages/scripts/src/bin/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ ${chalk.bold(gradient.instagram(` \\_/\\_/`))} ${chalk.magenta(
'v'
)}${chalk.bold.magenta(`${pkg.version}`)}`;

export const wpackLogoSmall = gradient.instagram('wpack.io');

export function addTimeStampToLog(log: string): string {
const time = new Date().toTimeString().split(' ')[0];
return `${chalk.dim(`「wpack.io ${time}」`)} ${log}`;
return `${chalk.dim(`「${wpackLogoSmall} ${time}」`)} ${log}`;
}

export const watchSymbol = `${logSymbols.info}`;
Expand Down Expand Up @@ -77,8 +79,6 @@ export function printGeneralInfoMessage(msg: string) {

export const bulletSymbol = chalk.magenta(figures.pointer);

export const wpackLogoSmall = gradient.instagram('wpack.io');

export const wpackLink = `${chalk.blue.underline('https://wpack.io')}`;

export const wpackIntro = `${wpackLogo}\n`;
Expand Down
6 changes: 5 additions & 1 deletion packages/scripts/src/scripts/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ interface Callbacks {
firstCompile(stats: webpack.Stats): void;
onError(err: { errors: string[]; warnings: string[] }): void;
onWarn(warn: { errors: string[]; warnings: string[] }): void;
onBsChange(file: string): void;
}

/**
Expand Down Expand Up @@ -177,7 +178,10 @@ export class Server {
if (this.projectConfig.watch) {
bs.watch(this.projectConfig.watch as string).on(
'change',
bs.reload
(file: string) => {
this.callbacks.onBsChange(file);
bs.reload();
}
);
}
// We don't need to watch for manifest, because if user is changing
Expand Down

0 comments on commit c1885e2

Please sign in to comment.