This repository was archived by the owner on May 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathbuild.js
More file actions
140 lines (114 loc) · 4.15 KB
/
build.js
File metadata and controls
140 lines (114 loc) · 4.15 KB
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
134
135
136
137
138
139
140
const fs = require("fs");
const path = require("path");
const newLine = require("os").EOL;
const configuration = process.argv[2] || "local";
const version = require("./package.json").version;
// File and Directory Constants
const resDir = path.join(__dirname, "res");
const configDir = path.join(__dirname, "config");
const jsDir = path.join(__dirname, "js");
const publicDir = path.join(__dirname, "public");
const getTemplateFilePath = fileName => path.join(resDir, "template-" + fileName);
const settingsFileName = "settings.json";
const customizationFileName = "customization.js";
const settingsFilePath = path.join(configDir, settingsFileName);
const customizationFilePath = path.join(configDir, customizationFileName);
if(!fs.existsSync(configDir)) {
console.log("No configuration files found. Generating new settings from defaults.");
fs.mkdirSync(configDir);
fs.copyFileSync(getTemplateFilePath(settingsFileName), settingsFilePath);
fs.copyFileSync(getTemplateFilePath(customizationFileName), customizationFilePath);
}
if(configuration === "--init") {
return;
}
// Parse and import application settings
const settingsFile = require(settingsFilePath);
const settings = Object.assign(settingsFile.default, settingsFile[configuration]);
const revision = (new Date()).toISOString().replace(/^(\d+).(\d+).(\d+)T(\d+).(\d+).*/, "$1$2$3$4$5");
// Generate the Preload Bundle File
const buildFiles = [
"window.js",
"notify.js",
"manifest.js",
"screensnippet.js",
"main.js",
"utils.js",
"events.js",
"download-bar.js"
];
let fileContents = [
'/*',
'* WARNING: This file is auto-generated, any changes made to this',
'* file will be overwritten by the build script!',
'*/',
'',
`window.fin.symphony = ${JSON.stringify({version, revision, settings}, null, 2)};`
].join(newLine) + newLine;
fileContents += buildFiles
.map(filePath => [
'/*',
'* --------------------------------',
`* ${filePath}`,
'* --------------------------------',
'*/',
'',
fs.readFileSync(path.join(jsDir, filePath), "utf8")
].join(newLine))
.join(newLine);
const bundlePath = path.join(publicDir, "bundle.js");
fs.writeFileSync(bundlePath, fileContents, "utf8");
// Copy over the Customization Preload
const customizationFileOutputPath = path.join(publicDir, "customization.js");
fs.copyFileSync(customizationFilePath, customizationFileOutputPath);
// Generate App Manifest
let manifest = require(getTemplateFilePath("app.json"));
Object.assign(manifest, {
licenseKey: settings.licenseKey,
assetsUrl: settings.assetsUrl
});
Object.assign(manifest.startup_app, {
url: settings.podUrl,
uuid: settings.appUuid,
name: settings.name,
description: settings.description,
icon: settings.iconUrl,
preload: [
{
url: `${settings.targetUrl}bundle.js`,
madatory: true
},
{
url: `${settings.targetUrl}customization.js`,
mandatory: false
}
]
});
Object.assign(manifest.shortcut, {
icon: settings.shortcutIconUrl,
name: settings.name,
description: settings.description,
company: settings.company,
"uninstall-shortcut": settings.allowUninstall
});
if(settings.navigationWhitelist.length > 0) {
manifest.startup_app.contentNavigation = { whitelist: settings.navigationWhitelist };
}
manifest.runtime.arguments += settings.runtimeArguments; // Arguments are appended, not overwritten
manifest.appAssets[0].src = `${settings.targetUrl}OF-ScreenSnippet.zip`;
fs.writeFileSync(
path.join(publicDir, "app.json"),
JSON.stringify(manifest, null, 2)
);
// Generate Launcher Page
const launchAppUrl = `${settings.targetUrl}symphony-launch.html`;
let launchManifest = require(path.join(publicDir, "symphony-launch.json"));
launchManifest.startup_app.url = launchAppUrl;
launchManifest.startup_app.uuid = 'Symphony-OpenFin-Landing';
launchManifest.dialogSettings.logo = settings.iconUrl;
fs.writeFileSync(
path.join(publicDir, "symphony-launch.json"),
JSON.stringify(launchManifest, null, 2)
);
console.log(`Build Configuration "${configuration}" Complete!`)
console.log(`Deploy /public to: ${settings.targetUrl}`);