forked from qooxdoo/qxl.demobrowser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompile.js
152 lines (144 loc) · 5.7 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
qx.Class.define("qxl.demobrowser.compile.LibraryApi", {
extend: qx.tool.cli.api.LibraryApi,
members: {
async load() {
let command = this.getCompilerApi().getCommand();
if (command instanceof qx.tool.cli.commands.Compile) {
command.addListener("writtenApplication", (e) => this.__appCompiling(e.getData()));
}
},
__appCompiling(application) {
let className = application.getClassName();
if (className !== "qxl.demobrowser.Application") {
return;
}
let command = this.getCompilerApi().getCommand();
let maker = command.getMakersForApp(application.getName())[0];
let analyser = maker.getAnalyser();
const templateDir = command.getTemplateDir();
const outputDir = maker.getTarget().getOutputDir();
const sourceDir = analyser.findLibrary("qxl.demobrowser").getRootDir();
let targetClass = command.resolveTargetClass(command._getConfig().targetType);
return new qx.Promise((fullfiled) => {
let app = application.getName();
const path = this.require("upath");
const async = this.require("async");
// needed by DataGenerator
this.require('walker');
this.require('mkdirp');
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("\nDEMO BUILD STARTED");
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("\nget apps");
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.info("no class found for " + file.path);
return;
}
appInfos.push({
app: new qx.tool.compiler.app.Application(className, [
"qx.theme.Indigo",
"qx.theme.Modern",
"qx.theme.Simple",
"qx.theme.Classic",
"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.Modern",
"qx.theme.Simple",
"qx.theme.Classic"
],
templatePath: templateDir
}),
className: className
});
}
});
cb();
},
(cb) => {
console.info("DEMO BUILD START COMPILE");
let target = new targetClass(outputDir);
target.set({
generateIndexHtml: false,
analyser: analyser
});
async.eachSeries(appInfos,
(appInfo, cb) => {
// 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("\nDEMO BUILD FINISHED");
cb();
}
], fullfiled);
});
}
}
});
module.exports = {
LibraryApi: qxl.demobrowser.compile.LibraryApi
};