blob: 9898fbcd4b69aa0f83593b82409b9dca19859649 [file] [log] [blame]
Paul Lewis64ba20b2020-06-29 16:17:21 +01001// Copyright 2020 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5const fs = require('fs');
6const path = require('path');
7const childProcess = require('child_process');
8const cwd = process.cwd();
9const env = process.env;
10const frontEnd = path.join(cwd, 'front_end');
11
12// Extract the target if it's provided.
13let target = 'Default';
14const targetArg = process.argv.find(value => value.startsWith('--target='));
15if (targetArg) {
16 target = targetArg.slice('--target='.length);
17}
18
19let isBuilding = false;
20let filesChangedDuringBuild = false;
21const onFileChange = () => {
22 if (isBuilding) {
23 filesChangedDuringBuild = true;
24 return;
25 }
26
27 filesChangedDuringBuild = false;
28 isBuilding = true;
29
Paul Lewisee1b3282020-07-02 10:48:47 +010030 const autoninja = childProcess.spawn(
31 'autoninja', ['-C', `out/${target}`, 'devtools_frontend_resources'], {cwd, env, stdio: 'inherit'});
Paul Lewis64ba20b2020-06-29 16:17:21 +010032 autoninja.on('close', () => {
33 if (filesChangedDuringBuild) {
34 console.warn('Warning: files changed during build, you may wish to trigger a fresh rebuild.');
35 }
36
37 isBuilding = false;
38 });
39};
40
41// Watch the front_end folder and build on any change.
Paul Lewisee1b3282020-07-02 10:48:47 +010042console.log(`Watching for changes in ${frontEnd}; building to out/${target}`);
Paul Lewis64ba20b2020-06-29 16:17:21 +010043fs.watch(`${frontEnd}`, {recursive: true}, onFileChange);