-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.js
133 lines (105 loc) · 4.11 KB
/
index.js
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
Copyright 2020 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// TODO, for first gen to second gen, display migration guide.
import { appToRun } from './app-to-run.js';
function bindListeners() {
const inputs = document.querySelectorAll('.input');
for(const input of inputs) {
input.addEventListener('input', appToRunDOM);
}
const sqlcheckbox = document.getElementById('gae-cloudsql-use');
sqlcheckbox.addEventListener('change', () => {
if(sqlcheckbox.checked) {
document.getElementById('gae-cloudsql-instance-container').style.display = 'block';
} else {
document.getElementById('gae-cloudsql-instance-container').style.display = 'none';
}
});
// Drag and drop
const dropzone = document.getElementById("dropzone");
dropzone.ondragover = dropzone.ondragenter = (e) => {
e.stopPropagation();
e.preventDefault();
}
dropzone.ondrop = (e) => {
e.stopPropagation();
e.preventDefault();
handleFiles(e.dataTransfer.files);
}
// File selector
document.getElementById("yaml-selector").addEventListener("change", (e) => {
handleFiles(e.target.files);
}, false);
function handleFiles(files) {
if(files.length) {
let reader = new FileReader();
reader.onload = e => {
document.getElementById('appyaml').value = e.target.result;
appToRunDOM();
};
reader.readAsText(files[0]);
}
}
}
function appToRunDOM() {
let gaeService = {};
let appyaml = document.getElementById('appyaml').value;
gaeService['app.yaml'] = jsyaml.safeLoad(appyaml);
gaeService['project-id'] = document.getElementById('project-id').value;
gaeService['region'] = document.getElementById('region').value;
if(document.getElementById('gae-cloudsql-use').value) {
gaeService['cloudsql-instance'] = document.getElementById('gae-cloudsql-instance').value;
};
let runService = appToRun(gaeService);
if(runService['warnings']) {
document.getElementById('warnings').style.display = 'block';
document.getElementById('warnings').innerHTML = '';
for (const warning of runService['warnings']) {
const item = document.createElement('li');
item.innerText = warning.message;
if(warning.link) {
const link = document.createElement('a');
link.innerText = warning.link.text;
link.href = warning.link.href;
item.appendChild(link);
}
document.getElementById('warnings').appendChild(item);
}
document.createElement('li');
} else {
document.getElementById('warnings').style.display = 'none';
document.getElementById('warnings').innerHTML = '';
}
if(runService.migrate_to_second_gen || runService.migrate_off_app_engine_apis) {
document.getElementById('to-run').style.display = 'none';
} else {
document.getElementById('to-run').style.display = 'block';
}
document.getElementById('serviceyaml').value = jsyaml.safeDump(runService['service.yaml']);
if(runService['Dockerfile']) {
document.getElementById('dockerfile-container').style.display = 'block';
document.getElementById('dockerfile').value = runService['Dockerfile'];
} else {
document.getElementById('dockerfile-container').style.display = 'none';
}
if(runService['Procfile']) {
document.getElementById('procfile-container').style.display = 'block';
document.getElementById('procfile').value = runService['Procfile'];
} else {
document.getElementById('procfile-container').style.display = 'none';
}
document.getElementById('gcloud').innerText = runService['gcloud'];
document.getElementById('make-public').innerText = runService['make-public'];
}
bindListeners();
appToRunDOM();