1+ < html >
2+ < head >
3+ < title > DU headless</ title >
4+ </ head >
5+ < body >
6+ < script >
7+
8+ 'use strict' ;
9+
10+ const path = require ( 'path' )
11+ const ipc = require ( 'ipc' )
12+ const du = require ( './js/du' )
13+
14+ const ipc_name = 'du'
15+ ipc . send ( 'register' , ipc_name )
16+
17+ ipc . on ( 'ready' , function ( ) {
18+ console . log ( 'all is ready' )
19+ go ( ) ;
20+ } )
21+
22+ ipc . on ( 'broadcast' , function ( arg ) {
23+ console . log ( '[' + ipc_name + '] broadcast' , arg )
24+ } )
25+
26+ ipc . on ( 'message' , function ( arg ) {
27+ console . log ( '[' + ipc_name + '] message' , arg )
28+ } )
29+
30+ function go ( ) {
31+
32+ let target = '../../..'
33+ var INCREMENTAL_INTERVAL = 30000
34+
35+ let checker
36+ let json = { }
37+ console . time ( 'async2' )
38+
39+ function complete ( counter ) {
40+ // console.log("Scan completed", counter, "files");
41+ console . timeEnd ( 'async2' )
42+ clearTimeout ( checker )
43+
44+ console . log ( json ) ;
45+
46+ // cache
47+ // console.time('write')
48+ // fs.writeFileSync('test.json', JSON.stringify(json))
49+ // console.timeEnd('write')
50+
51+ ipc . send ( 'call' , 'viz' , 'complete' , json )
52+ } ;
53+
54+ function refresh ( ) {
55+ clearTimeout ( checker )
56+ console . log ( 'scanning...' ) ;
57+
58+ ipc . send ( 'call' , 'viz' , 'refresh' , json )
59+ checker = setTimeout ( refresh , INCREMENTAL_INTERVAL )
60+ }
61+
62+ function progress ( path , name ) {
63+ ipc . send ( 'call' , 'viz' , 'progress' , path , name )
64+ }
65+
66+ target = path . resolve ( target )
67+ console . log ( 'Scanning target' , target )
68+
69+ // yay
70+ du ( {
71+ parent : target ,
72+ node : json ,
73+ onprogress : progress ,
74+ // onrefresh: refresh
75+ } , complete )
76+
77+ setTimeout ( refresh , 5000 )
78+ }
79+
80+
81+ // // d3.json("flare.json", onJson);
82+ // // for testing purposes only
83+ // // json = fs.readFileSync('user.json', { encoding: 'utf-8'})
84+ // // loading.style.display = 'none'
85+ // // onJson(null, JSON.parse(json).children[10])
86+ // // onJson(null, JSON.parse(json))
87+ // })
88+
89+
90+ </ script >
91+ < script >
92+ // // redirect log to stdout
93+ // console.log = require('console').log
94+ // // redirect errors to stderr
95+ // window.addEventListener('error', function (e) {
96+ // e.preventDefault()
97+ // require('console').error(e.error.stack || 'Uncaught ' + e.error)
98+ // })
99+
100+ // ipc.on('args', function (args) {
101+ // console.log('yoz i got something!!!')
102+ // // var app
103+ // // if (path.isAbsolute(args[2])) {
104+ // // app = require(args[2])
105+ // // } else {
106+ // // app = require(path.join(process.cwd(), args[2]))
107+ // // }
108+ // // if (typeof app === 'function') app(args.slice(2))
109+ // })
110+ </ script >
111+ </ body >
112+ </ html >
0 commit comments