1+ const fs = require ( 'fs' ) ;
2+ const path = require ( 'path' ) ;
3+ const os = require ( 'os' ) ;
4+
5+ // Simple list of professional project names
6+ const projects = [
7+ 'React Dashboard' ,
8+ 'Node.js API' ,
9+ 'Mobile App' ,
10+ 'Database Migration' ,
11+ 'UI Components' ,
12+ 'Backend Service' ,
13+ 'Documentation' ,
14+ 'Testing Suite' ,
15+ 'DevOps Setup' ,
16+ 'Data Analytics'
17+ ] ;
18+
19+ // Function to generate test data
20+ function generateTestData ( ) {
21+ const today = new Date ( ) ;
22+ const entries = [ ] ;
23+
24+ // Generate data for the last 90 days
25+ for ( let i = 0 ; i < 90 ; i ++ ) {
26+ const date = new Date ( today ) ;
27+ date . setDate ( date . getDate ( ) - i ) ;
28+ const dateString = date . toISOString ( ) . split ( 'T' ) [ 0 ] ;
29+
30+ // Generate 1-3 entries per day
31+ const entriesCount = Math . floor ( Math . random ( ) * 3 ) + 1 ;
32+
33+ for ( let j = 0 ; j < entriesCount ; j ++ ) {
34+ const project = projects [ Math . floor ( Math . random ( ) * projects . length ) ] ;
35+ // Random time between 30 minutes and 4 hours (in minutes)
36+ const timeSpent = Math . floor ( Math . random ( ) * 210 ) + 30 ;
37+
38+ entries . push ( {
39+ date : dateString ,
40+ project,
41+ timeSpent
42+ } ) ;
43+ }
44+ }
45+
46+ // Add some special test cases
47+ const yesterday = new Date ( today ) ;
48+ yesterday . setDate ( yesterday . getDate ( ) - 1 ) ;
49+ const yesterdayString = yesterday . toISOString ( ) . split ( 'T' ) [ 0 ] ;
50+ const todayString = today . toISOString ( ) . split ( 'T' ) [ 0 ] ;
51+
52+ // Add a long session for yesterday
53+ entries . push ( {
54+ date : yesterdayString ,
55+ project : 'Node.js API' ,
56+ timeSpent : 480 // 8 hours
57+ } ) ;
58+
59+ // Add multiple sessions for today
60+ entries . push ( {
61+ date : todayString ,
62+ project : 'React Dashboard' ,
63+ timeSpent : 120 // 2 hours
64+ } ) ;
65+ entries . push ( {
66+ date : todayString ,
67+ project : 'Documentation' ,
68+ timeSpent : 60 // 1 hour
69+ } ) ;
70+
71+ return entries ;
72+ }
73+
74+ // Function to update the global state
75+ function updateGlobalState ( ) {
76+ const vscodeDir = path . join ( os . homedir ( ) , '.vscode' ) ;
77+ const globalStoragePath = path . join ( vscodeDir , 'globalStorage' ) ;
78+ const extensionId = 'noorashuvo.simple-coding-time-tracker' ;
79+ const extensionStoragePath = path . join ( globalStoragePath , extensionId ) ;
80+ const storagePath = path . join ( extensionStoragePath , 'globalState.json' ) ;
81+
82+ try {
83+ console . log ( 'Generating test data...' ) ;
84+ const testData = generateTestData ( ) ;
85+ console . log ( `Generated ${ testData . length } time entries` ) ;
86+
87+ // Create directories if they don't exist
88+ if ( ! fs . existsSync ( vscodeDir ) ) {
89+ fs . mkdirSync ( vscodeDir ) ;
90+ }
91+ if ( ! fs . existsSync ( globalStoragePath ) ) {
92+ fs . mkdirSync ( globalStoragePath ) ;
93+ }
94+ if ( ! fs . existsSync ( extensionStoragePath ) ) {
95+ fs . mkdirSync ( extensionStoragePath ) ;
96+ }
97+
98+ // Read existing global state or create new one
99+ let globalState = { } ;
100+ if ( fs . existsSync ( storagePath ) ) {
101+ globalState = JSON . parse ( fs . readFileSync ( storagePath , 'utf8' ) ) ;
102+ }
103+
104+ // Update the timeEntries
105+ globalState . timeEntries = testData ;
106+
107+ // Write back to file
108+ fs . writeFileSync ( storagePath , JSON . stringify ( globalState , null , 2 ) ) ;
109+ console . log ( '\n✅ Test data has been generated and saved successfully!' ) ;
110+ console . log ( `📁 Data file location: ${ storagePath } ` ) ;
111+ console . log ( '🔄 Please reload VS Code to see the changes' ) ;
112+ } catch ( error ) {
113+ console . error ( '❌ Error updating global state:' , error ) ;
114+ }
115+ }
116+
117+ // Run the script
118+ updateGlobalState ( ) ;
0 commit comments