OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 "use strict"; | 5 "use strict"; |
6 | 6 |
7 const fs = require('fs'); | 7 const fs = require('fs'); |
8 const path = require('path'); | 8 const path = require('path'); |
9 | 9 |
10 const utils = require('../utils'); | 10 const utils = require('../utils'); |
11 | 11 |
12 const FRONTEND_PATH = path.resolve(__dirname, '..', '..', 'front_end'); | 12 const FRONTEND_PATH = path.resolve(__dirname, '..', '..', 'front_end'); |
13 const OUT = path.resolve(__dirname, 'out', 'dependencies.dot'); | 13 const OUT = path.resolve(__dirname, 'out', 'dependencies.dot'); |
14 | 14 |
15 function main() { | 15 function main() { |
16 const modules = new Set(); | 16 const modules = new Set(); |
chenwilliam
2017/01/11 19:03:33
const OUT_DIR = path.resolve(__dirname, 'out');
i
| |
17 const moduleToDependencyList = ['digraph dependencies {']; | 17 const moduleToDependencyList = ['digraph dependencies {']; |
18 moduleToDependencyList.push('fixedsize = true;') | |
18 fs.readdirSync(FRONTEND_PATH).forEach(function(file) { | 19 fs.readdirSync(FRONTEND_PATH).forEach(function(file) { |
19 const moduleJSONPath = path.join(FRONTEND_PATH, file, 'module.json'); | 20 const moduleJSONPath = path.join(FRONTEND_PATH, file, 'module.json'); |
20 if (fs.statSync(path.join(FRONTEND_PATH, file)).isDirectory() && | 21 if (fs.statSync(path.join(FRONTEND_PATH, file)).isDirectory() && |
21 utils.isFile(moduleJSONPath)) { | 22 utils.isFile(moduleJSONPath)) { |
22 const module = file; | 23 const module = file; |
24 if (module === 'audits2_worker') | |
25 return; | |
23 modules.add(module); | 26 modules.add(module); |
24 const moduleJSON = require(moduleJSONPath); | 27 const moduleJSON = require(moduleJSONPath); |
28 let moduleSize = 0; | |
29 | |
30 let resources = (moduleJSON.scripts || []).concat((moduleJSON.resources || [])); | |
31 for (let script of resources) { | |
32 if (fs.existsSync(path.join(FRONTEND_PATH, module, script))) { | |
33 console.log(path.join(FRONTEND_PATH, module, script)); | |
34 moduleSize += fs.statSync(path.join(FRONTEND_PATH, module, script)).si ze; | |
35 } | |
36 } | |
37 moduleSize /= 200000; | |
38 moduleSize = Math.max(0.5, moduleSize); | |
39 let fontSize = Math.max(moduleSize*14, 14); | |
40 | |
41 moduleToDependencyList.push(`${module} [width=${moduleSize}, height=${modu leSize} fontsize=${fontSize}];`); | |
42 | |
25 if (moduleJSON.dependencies) { | 43 if (moduleJSON.dependencies) { |
26 for (let d of moduleJSON.dependencies) { | 44 for (let d of moduleJSON.dependencies) { |
27 moduleToDependencyList.push(` ${module} -> ${d}`); | 45 moduleToDependencyList.push(` ${module} -> ${d}`); |
28 } | 46 } |
29 } | 47 } |
30 } | 48 } |
31 }); | 49 }); |
32 moduleToDependencyList.push('}'); | 50 moduleToDependencyList.push('}'); |
33 const content = moduleToDependencyList.join('\n'); | 51 const content = moduleToDependencyList.join('\n'); |
34 fs.writeFileSync(OUT, content); | 52 fs.writeFileSync(OUT, content); |
35 } | 53 } |
36 | 54 |
37 if (require.main === module) | 55 if (require.main === module) |
38 main(); | 56 main(); |
OLD | NEW |