-
Notifications
You must be signed in to change notification settings - Fork 234
/
app.ts
110 lines (100 loc) · 2.82 KB
/
app.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import { Linter, Editor, HtmlFormatter, ErrorReportingEditor, PlainReporter } from './app-linter/index';
console.log(`
Welcome to __ __
_________ ____/ /__ / /_ ______ ___ _____
/ ___/ __ \\/ __ / _ \\/ / / / /_ / / _ \\/ ___/
/ /__/ /_/ / /_/ / __/ / /_/ / / /_/ __/ /
\\___/\\____/\\__,_/\\___/_/\\__, / /___/\\___/_/
/____/\n`);
console.log(`Your code is being processed in a Web Worker.
You can see the errors in the web user interface
as well as in the console of your browser.\n\n`);
const sampleCode =
localStorage.getItem('code') ||
`// Welcome to Codelyzer!
//
// Codelyzer is a tool great for teams and individuals, which helps you
// write consistent code, and discover potential errors.
//
// It processes your TypeScript, templates, template expressions and
// even inline styles! Most rules are inspired by the Angular style guide.
// They have a URL associated with them that is going to link to the exact
// section in angular.io/styleguide.
//
// Give it a try!
@Component({
selector: 'hero-cmp',
template: \`
<h1>Hello <span>{{ her.name }}</span></h1>
\`,
styles: [
\`
h1 spam {
color: red;
}
\`
]
})
class Hero {
private hero: Hero;
ngOnInit() {
console.log('Initialized');
}
}
`;
const editor = new ErrorReportingEditor(
'CodeMirror-lint-markers',
(window as any).CodeMirror(document.getElementById('editor'), {
value: sampleCode,
gutters: ['CodeMirror-lint-markers'],
mode: 'javascript',
theme: 'material',
lineNumbers: true
}) as Editor,
new PlainReporter(new HtmlFormatter(), document.getElementById('warnings-header')!, document.getElementById('warnings')!)
);
let unlocked = true;
editor.on('change', () => {
if (!unlocked) {
return;
} else {
setTimeout(() => {
localStorage.setItem('code', editor.getValue());
unlocked = true;
}, 1000);
unlocked = false;
}
});
// Start the linter
new Linter({
workerBundle: './dist/worker.bundle.js',
textEditor: editor,
onError(e: any) {
if (checkbox.checked) {
(window as any).Raven.captureMessage(JSON.stringify({ error: e, code: editor.getValue() }));
}
}
}).init();
const dataCallback = () => {
if (checkbox.checked) {
return JSON.stringify({ code: editor.getValue() });
}
return undefined;
};
// Sentry config
const checkbox = document.getElementById('reporting') as HTMLInputElement;
if (checkbox.checked) {
(window as any).Raven.config('https://7e471773c9324277a73eaef6eb874b0f@sentry.io/109396', {
dataCallback
}).install();
}
checkbox.onchange = (e: any) => {
if (!checkbox.checked) {
(window as any).Raven.uninstall();
} else {
(window as any).Raven.config('https://7e471773c9324277a73eaef6eb874b0f@sentry.io/109396', {
dataCallback
}).install();
}
console.log(checkbox.checked);
};