-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcompile.js
272 lines (259 loc) · 9.22 KB
/
compile.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
const fs = require("fs");
qx.Class.define("qxl.demobrowser.compile.CompilerApi", {
extend: qx.tool.cli.api.CompilerApi,
members: {
async load() {
this.addListener(
"changeCommand",
function () {
let command = this.getCommand();
if (command instanceof qx.tool.cli.commands.Compile) {
command.addListener("writtenApplication", async (evt) => {
await this.__build(evt.getData());
});
}
if (command instanceof qx.tool.cli.commands.Deploy) {
command.addListener("afterDeploy", async (evt) => {
await this.__deploy(evt.getData());
});
}
},
this
);
return this.base(arguments);
},
/**
let data = {
targetDir: target.getOutputDir(),
deployDir: deployDir,
argv: argv,
application: app
};
*/
__deploy(data) {
console.info(">>> Installing dependencies ...");
const path = this.require("upath");
console.info(">>> deploy files ...");
return Promise.all([
qx.tool.utils.files.Utils.sync(
path.join(data.targetDir, "demobrowser", "demo"),
path.join(data.deployDir, "demobrowser", "demo")
),
qx.tool.utils.files.Utils.sync(
path.join(data.targetDir, "demobrowser", "script"),
path.join(data.deployDir, "demobrowser", "script")
),
]);
},
/**
* Fired when writing of single application is complete; data is an object containing:
* maker {qx.tool.compiler.makers.Maker}
* target {qx.tool.compiler.targets.Target}
* appMeta {qx.tool.compiler.targets.meta.ApplicationMeta}
*/
__build(data) {
let application = data.appMeta.getApplication();
let className = application.getClassName();
if (className !== "qxl.demobrowser.Application") {
return;
}
console.info(">>> Installing dependencies ...");
const path = this.require("upath");
const async = this.require("async");
// needed by DataGenerator
this.require("walker");
console.info(
">>> Generating Demobrowser data... this might take a while"
);
let command = this.getCommand();
let analyser = data.maker.getAnalyser();
const templateDir = application.getTemplatePath();
const outputDir = data.maker.getTarget().getOutputDir();
const sourceDir = analyser.findLibrary("qxl.demobrowser").getRootDir();
let targetClass = command.resolveTargetClass(
command.getTargetType()
);
let app = "demobrowser";
return new qx.Promise((fullfilled) => {
const DataGenerator = require(path.join(
sourceDir,
"tool/lib/DataGenerator"
));
// global vars
const config = {
demoPath: path.join(sourceDir, "source/demo/"),
demoDataJsonFile: path.join(outputDir, app, "script/demodata.json"),
classPath: path.join(sourceDir, "source/class"),
jsSourcePath: path.join(
sourceDir,
"source/class/qxl/demobrowser/demo"
),
demoConfigJsonFile: path.join(outputDir, app, "config.demo.json"),
verbose: command.argv.verbose,
};
let appInfos = [];
let dataGenerator = new DataGenerator(config);
async.series(
[
(cb) => {
console.info("- Start building...");
cb();
},
// catches all the demos from config.demoPath
dataGenerator.catchEntries.bind(dataGenerator),
// Creates json file with all demos
dataGenerator.createJsonDataFile.bind(dataGenerator),
// copy all javascript files to config.scriptDestinationPath
dataGenerator.copyJsFiles.bind(dataGenerator),
(cb) => {
console.info("- Get applications");
let environment = {
"qx.allowUrlVariants": true,
"qx.allowUrlSettings": true,
"qx.contrib": false,
"qx.icontheme": ["Tango", "Oxygen"],
};
analyser.setEnvironmentCheck(environment);
let files = dataGenerator.getFiles(".html");
files.forEach((file) => {
if (file.level === 2) {
let demoCategory = dataGenerator.getDemoCategoryFromFile(
file.path
);
let className =
"qxl.demobrowser.demo." +
demoCategory.category +
"." +
demoCategory.name;
let outDir = path.join(
demoCategory.category,
demoCategory.name
);
let library = analyser.getLibraryFromClassname(className);
if (!library) {
console.error("! no class found for " + file.path);
return;
}
appInfos.push({
app: new qx.tool.compiler.app.Application(className, [
"qx.theme.Indigo",
"qx.theme.IndigoDark",
"qx.theme.Modern",
"qx.theme.Simple",
"qx.theme.Classic",
"qx.theme.TangibleLight",
"qx.theme.TangibleDark",
"qx.log.appender.Native",
"qx.log.appender.Console",
]).set({
theme: "qx.theme.Indigo",
analyser: analyser,
environment: environment,
name: className,
outputPath: path.join(app, "script", outDir),
writeIndexHtmlToRoot: false,
include: [
"qx.theme.Indigo",
"qx.theme.IndigoDark",
"qx.theme.Modern",
"qx.theme.Simple",
"qx.theme.Classic",
"qx.theme.TangibleLight",
"qx.theme.TangibleDark",
],
templatePath: templateDir,
}),
className: className,
fileName: analyser.getClassFilename(className),
});
}
});
cb();
},
(cb) => {
console.info("- Compiling ...");
let target = new targetClass(outputDir);
target.set({
generateIndexHtml: false,
analyser: analyser,
});
async.eachSeries(
appInfos,
(appInfo, cb) => {
let dest = path.join(
target.getOutputDir(),
appInfo.app.getOutputPath(),
"index.js"
);
let src = appInfo.fileName;
this.__fileDateDiffers(src, dest).then((needsWork) => {
if (!needsWork) {
cb();
return;
}
// Calculate dependencies and write it out
appInfo.app.setAnalyser(analyser);
appInfo.app.calcDependencies();
if (command.argv.verbose) {
console.info(
"- Writing class " +
appInfo.app.getClassName() +
" into " +
appInfo.app.getOutputPath()
);
}
target
.generateApplication(
appInfo.app,
appInfo.app.getEnvironment()
)
.then(() => cb())
.catch((err) => {
console.error(err.message);
cb(err);
});
});
},
cb
);
},
(cb) => {
qx.tool.utils.files.Utils.sync(
path.join(sourceDir, "source/demo/"),
path.join(outputDir, app, "demo")
)
.then(() => cb())
.catch((err) => {
console.error(err.message);
cb(err);
});
},
(cb) => {
console.info("- Demo build finished.");
cb();
},
],
fullfilled
);
});
},
async __fileDateDiffers(src, dest) {
let srcStat = await qx.tool.utils.files.Utils.safeStat(src);
if (!srcStat) {
// nothing to coy in this case
return false;
}
if (!fs.existsSync(dest)) {
return true;
}
let destStat = await qx.tool.utils.files.Utils.safeStat(dest);
if (!destStat || srcStat.mtime.getTime() > destStat.mtime.getTime()) {
return true;
}
return false;
},
},
});
module.exports = {
CompilerApi: qxl.demobrowser.compile.CompilerApi,
};