Skip to content
This repository was archived by the owner on Dec 12, 2021. It is now read-only.

Commit a56c5c1

Browse files
committed
some stuff
FIX: Storage WIP: debug option
1 parent 31a156a commit a56c5c1

File tree

5 files changed

+135
-46
lines changed

5 files changed

+135
-46
lines changed

CHANGELOG.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,30 @@
33

44
----------------
55

6-
## v1.0.0
6+
## v1.1.0
7+
8+
#### Features
9+
- Debug functionalities *(for easier bug reporting)*
10+
- Edit option added
11+
#### Improvements
12+
- Path resolvement
13+
#### Patches
14+
- Error while reading stored files
15+
16+
---
17+
18+
## v1.0.0 / v1.0.1
719
**Stable release**
820
#### Features
921
- Snippet class:
10-
- Title
11-
- Tags *(not used currently)*
12-
- Content
13-
- Language
14-
- UID
15-
- Version
22+
- + UID
23+
- + Version
1624
- Automated snippet migration to newer version
1725
#### Improvements
1826
- Performance
1927
- `LICENSE.md` / `README.md`
2028
- Icon styling
21-
- Delete prompt with list
29+
- Delete prompt with dropdown-list
2230
#### Patches
2331
- UID generation
2432
- Storage fixes for new snippet conventions

lib/debug.json

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
{
22
"allowDebug": true,
3-
"debug": {
4-
"warn":"Snippet Injector launched in Debug-Mode. This will reveal several information about the package here.",
5-
"info": "You can safely ignore this since it doesn't change the default package behavior.\nTo disable this outputs, run the 'snippet-injector:toggledebug' command within Atom."
3+
"warn": "Snippet Injector launched in Debug-Mode. This will reveal several information about the package here.\n\nYou can safely ignore this since it doesn't change the default package behavior.\nTo disable this outputs, run the 'snippet-injector:toggledebug' command within Atom.",
4+
"groupTitle": {
5+
"main": "Snippet Injector - DEBUG INFO",
6+
"timings": "Method durations",
7+
"objectLogging": "Package state"
68
},
7-
"groupTitle": "Snippet Injector - DEBUG INFO",
89
"default": {
910
"timings": false,
10-
"object-logging": false
11+
"objectLogging": false
1112
},
12-
"usrPref": null
13-
}
13+
"usrPref": {
14+
"timings": false,
15+
"objectLogging": false
16+
}
17+
}

lib/snippet-injector.js

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,24 @@ export default {
1616

1717
activate(state) {
1818
this.debug = JSON.parse(fs.readFileSync(path.join(__dirname,'debug.json')));
19-
console.info(this.debug);
19+
if(this.debug.allowDebug) {
20+
if(this.debug.usrPref === null) {
21+
this.debug.usrPref = this.debug.default;
22+
}
2023

21-
console.groupCollapsed("Snippet Injector - DEBUG");
22-
console.time("snippet-injector:activate duration");
24+
// Make the debug config available for each submodule
25+
window.snippet_injector_debug = this.debug;
26+
27+
if(this.debug.usrPref.timings || this.debug.usrPref.objectLogging) {
28+
console.warn(this.debug.warn);
29+
console.groupCollapsed(this.debug.groupTitle.main);
30+
31+
if(this.debug.usrPref.timings) {
32+
console.group(this.debug.groupTitle.timings);
33+
console.time("snippet-injector:activate duration");
34+
}
35+
}
36+
}
2337

2438
this.storage = new Storage({dir: '/storage/snippet-injector/snippets/'});
2539
this.storage.migrate();
@@ -31,12 +45,31 @@ export default {
3145
'snippet-injector:delete': () => this.delete()
3246
}));
3347

34-
console.timeEnd("snippet-injector:activate duration");
35-
console.groupEnd();
48+
if(this.debug.allowDebug) {
49+
if(this.debug.usrPref.timings) {
50+
console.timeEnd("snippet-injector:activate duration");
51+
console.groupEnd();
52+
}
53+
54+
if(this.debug.usrPref.objectLogging) {
55+
console.group(this.debug.groupTitle.objectLogging);
56+
console.log({
57+
subscriptions: this.subscriptions,
58+
storage: this.storage,
59+
debugConfig: this.debug
60+
});
61+
console.groupEnd();
62+
}
63+
64+
if(this.debug.usrPref.timings || this.debug.usrPref.objectLogging) {
65+
console.groupEnd();
66+
}
67+
}
3668
},
3769

3870
deactivate() {
3971
this.subscriptions.dispose();
72+
fs.writeFileSync(path.join(__dirname,'debug.json'),JSON.stringify(this.debug,null,2));
4073
},
4174

4275
serialize() {

lib/storage.js

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ export default class Storage {
3030
destroy() {}
3131

3232
init(directory) {
33-
console.time("storage:init duration");
33+
if(window.snippet_injector_debug.allowDebug && window.snippet_injector_debug.usrPref.timings) {
34+
console.time("storage:init duration");
35+
}
3436

3537
var store = this.storageDir;
3638
var divider;
@@ -57,19 +59,27 @@ export default class Storage {
5759
});
5860
this.dir = temp;
5961

60-
console.timeEnd("storage:init duration");
62+
if(window.snippet_injector_debug.allowDebug && window.snippet_injector_debug.usrPref.timings) {
63+
console.timeEnd("storage:init duration");
64+
}
6165
}
6266

6367
store(snippet) {
64-
console.time("storage:store duration");
68+
if(window.snippet_injector_debug.allowDebug && window.snippet_injector_debug.usrPref.timings) {
69+
console.time("storage:store duration");
70+
}
6571

6672
if(Util.isset(snippet,Snippet)) {
67-
fs.writeFileSync(this.storageDir+this.dir+snippet.getUID().split(' ').join('-')+'.json',JSON.stringify(snippet));
73+
fs.writeFileSync(this.storageDir+this.dir+snippet.getUID().split(' ').join('-')+'.json',JSON.stringify(snippet,null,2));
6874
var temp = fs.existsSync(this.storageDir+this.dir+snippet.getUID().split(' ').join('-')+'.json');
69-
console.timeEnd("storage:store duration");
75+
if(window.snippet_injector_debug.allowDebug && window.snippet_injector_debug.usrPref.timings) {
76+
console.timeEnd("storage:store duration");
77+
}
7078
return temp;
7179
} else {
72-
console.timeEnd("storage:store duration");
80+
if(window.snippet_injector_debug.allowDebug && window.snippet_injector_debug.usrPref.timings) {
81+
console.timeEnd("storage:store duration");
82+
}
7383
return false;
7484
}
7585
}
@@ -78,9 +88,13 @@ export default class Storage {
7888
if(this.dir === '') {
7989
throw new TypeError('Storage directory has not been initialized.');
8090
} else {
81-
console.time("storage:retrieveFiles duration");
91+
if(window.snippet_injector_debug.allowDebug && window.snippet_injector_debug.usrPref.timings) {
92+
console.time("storage:retrieveFiles duration");
93+
}
8294
var temp = fs.readdirSync(this.storageDir+this.dir);
83-
console.timeEnd("storage:retrieveFiles duration");
95+
if(window.snippet_injector_debug.allowDebug && window.snippet_injector_debug.usrPref.timings) {
96+
console.timeEnd("storage:retrieveFiles duration");
97+
}
8498
return temp;
8599
}
86100
}
@@ -89,9 +103,13 @@ export default class Storage {
89103
if(this.dir === '') {
90104
throw new TypeError('Storage directory has not been initialized.');
91105
} else {
92-
console.time("storage:retrieveFile duration");
106+
if(window.snippet_injector_debug.allowDebug && window.snippet_injector_debug.usrPref.timings) {
107+
console.time("storage:retrieveFile duration");
108+
}
93109
var temp = fs.readFileSync(this.storageDir+this.dir+uid.split(' ').join('-')+'.json');
94-
console.timeEnd("storage:retrieveFile duration");
110+
if(window.snippet_injector_debug.allowDebug && window.snippet_injector_debug.usrPref.timings) {
111+
console.timeEnd("storage:retrieveFile duration");
112+
}
95113
return temp;
96114
}
97115
}
@@ -114,13 +132,19 @@ export default class Storage {
114132
if(this.dir === '') {
115133
throw new TypeError('Storage directory has not been initialized.');
116134
} else {
117-
console.time("storage:deleteFile duration");
135+
if(window.snippet_injector_debug.allowDebug && window.snippet_injector_debug.usrPref.timings) {
136+
console.time("storage:deleteFile duration");
137+
}
118138
if(fs.existsSync(this.storageDir+this.dir+uid.split(' ').join('-')+'.json')) {
119139
fs.unlinkSync(this.storageDir+this.dir+uid.split(' ').join('-')+'.json');
120-
console.timeEnd("storage:deleteFile duration");
140+
if(window.snippet_injector_debug.allowDebug && window.snippet_injector_debug.usrPref.timings) {
141+
console.timeEnd("storage:deleteFile duration");
142+
}
121143
return true;
122144
} else {
123-
console.timeEnd("storage:deleteFile duration");
145+
if(window.snippet_injector_debug.allowDebug && window.snippet_injector_debug.usrPref.timings) {
146+
console.timeEnd("storage:deleteFile duration");
147+
}
124148
return false;
125149
}
126150
}
@@ -130,7 +154,9 @@ export default class Storage {
130154
if(this.dir === '') {
131155
throw new TypeError('Storage directory has not been initialized.');
132156
} else {
133-
console.time("storage:migrate duration");
157+
if(window.snippet_injector_debug.allowDebug && window.snippet_injector_debug.usrPref.timings) {
158+
console.time("storage:migrate duration");
159+
}
134160

135161
var files = this.retrieveFiles();
136162
if(files.length > 0) {
@@ -170,7 +196,9 @@ export default class Storage {
170196
}
171197
}
172198

173-
console.timeEnd("storage:migrate duration");
199+
if(window.snippet_injector_debug.allowDebug && window.snippet_injector_debug.usrPref.timings) {
200+
console.timeEnd("storage:migrate duration");
201+
}
174202
}
175203
}
176204
}

lib/util.js

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ export default class Util {
2626
} else if(typeof callback !== 'function') {
2727
throw TypeError('Param \'callback\' has to be a function.');
2828
} else {
29-
console.time("util.js:promptUser duration");
29+
if(window.snippet_injector_debug.allowDebug && window.snippet_injector_debug.usrPref.timings) {
30+
console.time("util.js:promptUser duration");
31+
}
3032

3133
const inputPrompt = document.createElement('div');
3234
inputPrompt.id = 'input-prompt';
@@ -81,7 +83,9 @@ export default class Util {
8183

8284
modal.show();
8385

84-
console.timeEnd("util.js:promptUser duration");
86+
if(window.snippet_injector_debug.allowDebug && window.snippet_injector_debug.usrPref.timings) {
87+
console.timeEnd("util.js:promptUser duration");
88+
}
8589
}
8690
}
8791

@@ -91,7 +95,9 @@ export default class Util {
9195
} else if(typeof callback !== 'function') {
9296
throw TypeError('Param \'callback\' has to be a function.');
9397
} else {
94-
console.time("util.js:promptSearch duration");
98+
if(window.snippet_injector_debug.allowDebug && window.snippet_injector_debug.usrPref.timings) {
99+
console.time("util.js:promptSearch duration");
100+
}
95101

96102
const searchPrompt = document.createElement('div');
97103
searchPrompt.id = 'search-prompt';
@@ -174,9 +180,9 @@ export default class Util {
174180
}
175181
$('#search-prompt').find('.list-item').on('click',function(e) {
176182
if($(e.target).hasClass('value')) {
177-
var value = $(e.target).text();
183+
var value = $(e.target).data('id');
178184
} else {
179-
var value = $(e.target).find('.value').text();
185+
var value = $(e.target).find('.value').data('id');
180186
}
181187
modal.destroy();
182188
callback(value);
@@ -186,7 +192,9 @@ export default class Util {
186192

187193
modal.show();
188194

189-
console.timeEnd("util.js:promptSearch duration");
195+
if(window.snippet_injector_debug.allowDebug && window.snippet_injector_debug.usrPref.timings) {
196+
console.timeEnd("util.js:promptSearch duration");
197+
}
190198
}
191199
}
192200

@@ -196,7 +204,9 @@ export default class Util {
196204
} else if(typeof callback !== 'function') {
197205
throw TypeError('Param \'callback\' has to be a function.');
198206
} else {
199-
console.time("util.js:promptDelete duration");
207+
if(window.snippet_injector_debug.allowDebug && window.snippet_injector_debug.usrPref.timings) {
208+
console.time("util.js:promptDelete duration");
209+
}
200210

201211
const deletePrompt = document.createElement('div');
202212
deletePrompt.id = 'delete-prompt';
@@ -248,7 +258,9 @@ export default class Util {
248258

249259
modal.show();
250260

251-
console.timeEnd("util.js:promptDelete duration");
261+
if(window.snippet_injector_debug.allowDebug && window.snippet_injector_debug.usrPref.timings) {
262+
console.timeEnd("util.js:promptDelete duration");
263+
}
252264
}
253265
}
254266

@@ -305,7 +317,9 @@ export default class Util {
305317
}
306318

307319
static generateUID(options) {
308-
console.time("util.js:generateUID duration");
320+
if(window.snippet_injector_debug.allowDebug && window.snippet_injector_debug.usrPref.timings) {
321+
console.time("util.js:generateUID duration");
322+
}
309323

310324
var uid = '';
311325
if(typeof options === 'object') {
@@ -327,15 +341,17 @@ export default class Util {
327341
uid = this._gen();
328342
}
329343

330-
console.timeEnd("util.js:generateUID duration");
344+
if(window.snippet_injector_debug.allowDebug && window.snippet_injector_debug.usrPref.timings) {
345+
console.timeEnd("util.js:generateUID duration");
346+
}
331347
return uid;
332348
}
333349

334350
static getRandomInt(min, max) {
335351
var min = Math.ceil(min);
336352
var max = Math.floor(max);
337353
var temp = Math.floor(Math.random() * (max - min)) + min;
338-
return ;
354+
return temp;
339355
}
340356

341357
static getPackageVersion() {

0 commit comments

Comments
 (0)