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