blob: 8ab44ae0fbacfb81b6ea6d345921625b60ed0ca8 [file] [log] [blame]
Joel Einbinder08b53b82018-05-15 15:29:11 +00001// Copyright 2018 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// This file generates jsconfig.json to improve VSCode autocomplete in the DevTools codebase.
6const fs = require('fs');
7const path = require('path');
8const utils = require('./utils');
9
10const FRONTEND_PATH = path.resolve(__dirname, '..', 'front_end');
11
12const modulePaths = [];
13for (let dir of fs.readdirSync(FRONTEND_PATH)) {
14 if (!utils.isDir(path.resolve(FRONTEND_PATH, dir)))
15 continue;
16 const modulePath = path.resolve(dir, 'module.json');
17 if (utils.isFile(path.resolve(FRONTEND_PATH, dir, 'module.json')))
18 modulePaths.push(dir);
19}
20const modules = new Map();
21for (const modulePath of modulePaths) {
22 const moduleObject = JSON.parse(fs.readFileSync(path.resolve(FRONTEND_PATH, modulePath, 'module.json')));
23 modules.set(modulePath, moduleObject);
24}
25
26for (const [name, moduleJSON] of modules) {
27 const jsconfig = {
28 compilerOptions: {
29 target: 'esnext',
30 lib: ['esnext', 'dom']
31 },
32 include: [
33 '**/*',
34 '../Runtime.js',
35 '../externs.js'
36 ],
37 exclude: (moduleJSON.skip_compilation || [])
38 };
39 for (const dependency of dependencyChain(name)) {
40 jsconfig.include.push('../' + dependency + '/**/*');
41 for (const file of modules.get(dependency).skip_compilation || [])
42 jsconfig.exclude.push(path.posix.join('..',dependency, file));
43 }
44 fs.writeFileSync(path.resolve(FRONTEND_PATH, name, 'jsconfig.json'), JSON.stringify(jsconfig, undefined, 2));
45}
46
47/**
48 * @param {string} moduleName
49 * @return {!Set<string>}
50 */
51function dependencyChain(moduleName) {
52 const dependencies = new Set();
53 for (const dependency of modules.get(moduleName).dependencies || []){
54 dependencies.add(dependency);
55 for (const innerDependency of dependencyChain(dependency))
56 dependencies.add(innerDependency);
57 }
58 return dependencies;
59}