forked from alteryx/alteryx-tool-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-gui-html.js
63 lines (47 loc) · 1.93 KB
/
create-gui-html.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
const fs = require('fs')
const readGuiHTML = (result) => new Promise((resolve, reject) => {
if (result === undefined) {
reject(console.error('readGuiHTML: input undefined'))
}
const userObj = result
const JSGuiPath = `${userObj.AlteryxInstallDir}\\HtmlPlugins\\HtmlGuiSdk\\HtmlGuiSdkGui.html`
const directory = `${userObj.ToolDirectory}\\`
const fileName = `${userObj.ToolName}Gui.html`
const filePath = `${directory}${fileName}`
const fileData = fs.readFileSync(JSGuiPath, 'utf8')
userObj.GuiHTMLPath = filePath
userObj.GuiHTMLData = fileData
resolve(userObj)
})
const updateGuiHTML = (result) => new Promise((resolve, reject) => {
if (result === undefined) {
reject(console.error('updateGuiHTML: input undefined'))
}
const userObj = result
const titlePattern = /<title>.*<\/title>/
const scriptPattern = /<script src=.*><\/script>/
const bodyElement = '<body>'
let modifiedHTML = userObj.GuiHTMLData.replace(titlePattern, `<title>${result.ToolName}</title>`)
modifiedHTML = modifiedHTML.replace(scriptPattern, `<script src="${result.AlteryxInstallDir}\\RuntimeData\\HtmlAssets\\Workflows\\js\\engine_dialog_utils.js"></script>`)
modifiedHTML = modifiedHTML.replace(bodyElement, '<body style="visibility: visible">')
userObj.GuiHTMLData = modifiedHTML
resolve(userObj)
})
const writeUpdatedGuiHTML = (result) => new Promise((resolve, reject) => {
if (result === undefined) {
reject(console.error('writeUpdatedGuiHTML: input undefined'))
}
const userObj = result
fs.writeFileSync(userObj.GuiHTMLPath, userObj.GuiHTMLData)
console.log(`${userObj.GuiHTMLPath} has been created.`)
// delete userObj.GuiHTMLPath
// delete userObj.GuiHTMLData
resolve(userObj)
})
// Creates Gui.html file, if successful message displays that file was created
exports.createGuiHTML = (result) => {
const userObj = readGuiHTML(result)
.then(updateGuiHTML)
.then(writeUpdatedGuiHTML)
return userObj
}