blob: f328b98eb1bd2639037f87089b396f200523938a [file] [log] [blame]
Deepanjan Royd7b03b22018-05-17 09:05:13 -04001/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/**
18 * Configuration file for lite-server. Contains configuration for auto rerunning
19 * ninja on file change.
20 */
21'use strict';
22
23const { spawn } = require('child_process');
24
25// Print without added new line.
26const print = data => process.stdout.write(data);
27const printErr = data => process.stderr.write(data);
28
29const ninjaOutDir = process.env.NINJA_OUT_DIR;
30let ninjaRunning = false;
31
32module.exports = function(bs) {
33 return {
34 files: [
35 {
36 match: ["ui/**", "src/trace_processor/**", "protos/**"],
37 fn: function(event, file) {
38 console.log(`Change detected on ${file}`);
39 if (ninjaRunning) {
40 console.log("Already have a ninja build running. Doing nothing.");
41 return;
42 }
43
44 ninjaRunning = true;
45
46 console.log(`Executing: ninja -C ${ninjaOutDir} ui`);
47 const ninja = spawn('ninja', ['-C', ninjaOutDir, 'ui']);
48 ninja.stdout.on('data', data => print(data.toString()));
49 ninja.stderr.on('data', data => printErr(data.toString()));
50
51 // We can be smarter and load just the file we need. Need to
52 // resolve to the dist/location of the file in that case.
53 // For now, we're reloading the whole page.
54 ninja.on('exit', () => {
55 ninjaRunning = false;
56 bs.reload();
57 });
58 },
59 options: {
60 ignored: ["ui/dist/", "ui/.git/", "ui/node_modules/"],
61 ignoreInitial: true
62 }
63 }
64 ],
65 server: {
66 baseDir: "ui/dist"
67 },
68 };
69};