Paul Lewis | 64ba20b | 2020-06-29 16:17:21 +0100 | [diff] [blame] | 1 | // 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 | |
| 5 | const fs = require('fs'); |
| 6 | const path = require('path'); |
| 7 | const childProcess = require('child_process'); |
| 8 | const cwd = process.cwd(); |
| 9 | const env = process.env; |
| 10 | const frontEnd = path.join(cwd, 'front_end'); |
| 11 | |
| 12 | // Extract the target if it's provided. |
| 13 | let target = 'Default'; |
| 14 | const targetArg = process.argv.find(value => value.startsWith('--target=')); |
| 15 | if (targetArg) { |
| 16 | target = targetArg.slice('--target='.length); |
| 17 | } |
| 18 | |
| 19 | let isBuilding = false; |
| 20 | let filesChangedDuringBuild = false; |
| 21 | const onFileChange = () => { |
| 22 | if (isBuilding) { |
| 23 | filesChangedDuringBuild = true; |
| 24 | return; |
| 25 | } |
| 26 | |
| 27 | filesChangedDuringBuild = false; |
| 28 | isBuilding = true; |
| 29 | |
Paul Lewis | ee1b328 | 2020-07-02 10:48:47 +0100 | [diff] [blame] | 30 | const autoninja = childProcess.spawn( |
| 31 | 'autoninja', ['-C', `out/${target}`, 'devtools_frontend_resources'], {cwd, env, stdio: 'inherit'}); |
Paul Lewis | 64ba20b | 2020-06-29 16:17:21 +0100 | [diff] [blame] | 32 | 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 Lewis | ee1b328 | 2020-07-02 10:48:47 +0100 | [diff] [blame] | 42 | console.log(`Watching for changes in ${frontEnd}; building to out/${target}`); |
Paul Lewis | 64ba20b | 2020-06-29 16:17:21 +0100 | [diff] [blame] | 43 | fs.watch(`${frontEnd}`, {recursive: true}, onFileChange); |