1
- qx . Class . define ( "qxl.demobrowser.compile.LibraryApi" , {
2
- extend : qx . tool . cli . api . LibraryApi ,
1
+ const fs = require ( "fs" ) ;
2
+ let path ;
3
+ let async ;
4
+
5
+ qx . Class . define ( "qxl.demobrowser.compile.CompilerApi" , {
6
+ extend : qx . tool . cli . api . CompilerApi ,
3
7
4
8
members : {
5
9
async load ( ) {
6
- let command = this . getCompilerApi ( ) . getCommand ( ) ;
7
- if ( command instanceof qx . tool . cli . commands . Compile ) {
8
- command . addListener ( "writtenApplication" , ( e ) => this . __appCompiling ( e . getData ( ) ) ) ;
9
- }
10
+ this . addListener ( "changeCommand" , function ( ) {
11
+ let command = this . getCommand ( ) ;
12
+ if ( command instanceof qx . tool . cli . commands . Compile ) {
13
+ command . addListener ( "writtenApplication" , async ( evt ) => {
14
+ await this . __build ( evt . getData ( ) ) ;
15
+ } ) ;
16
+ }
17
+ if ( command instanceof qx . tool . cli . commands . Deploy ) {
18
+ command . addListener ( "afterDeploy" , async ( evt ) => {
19
+ await this . __deploy ( evt . getData ( ) ) ;
20
+ } ) ;
21
+ }
22
+ } , this ) ;
23
+ return this . base ( arguments ) ;
24
+ } ,
25
+
26
+ /**
27
+ let data = {
28
+ targetDir: target.getOutputDir(),
29
+ deployDir: deployDir,
30
+ argv: argv,
31
+ application: app
32
+ };
33
+ */
34
+ __deploy ( data ) {
35
+ console . info ( ">>> Installing dependencies ..." ) ;
36
+ const path = this . require ( "upath" ) ;
37
+ console . info ( ">>> deploy files ..." ) ;
38
+ return Promise . all ( [
39
+ qx . tool . utils . files . Utils . sync ( path . join ( data . targetDir , "demobrowser" , "demo" ) , path . join ( data . deployDir , "demobrowser" , "demo" ) ) ,
40
+ qx . tool . utils . files . Utils . sync ( path . join ( data . targetDir , "demobrowser" , "script" ) , path . join ( data . deployDir , "demobrowser" , "script" ) )
41
+ ] ) ;
10
42
} ,
11
-
12
- __appCompiling ( application ) {
43
+
44
+ /**
45
+ * Fired when writing of single application is complete; data is an object containing:
46
+ * maker {qx.tool.compiler.makers.Maker}
47
+ * target {qx.tool.compiler.targets.Target}
48
+ * appMeta {qx.tool.compiler.targets.meta.ApplicationMeta}
49
+ */
50
+ __build ( data ) {
51
+ let application = data . appMeta . getApplication ( ) ;
13
52
let className = application . getClassName ( ) ;
14
53
if ( className !== "qxl.demobrowser.Application" ) {
15
54
return ;
16
55
}
17
56
18
- let command = this . getCompilerApi ( ) . getCommand ( ) ;
19
- let maker = command . getMakersForApp ( application . getName ( ) ) [ 0 ] ;
20
- let analyser = maker . getAnalyser ( ) ;
57
+ console . info ( ">>> Installing dependencies ..." ) ;
58
+ const path = this . require ( "upath" ) ;
59
+ const async = this . require ( "async" ) ;
60
+ // needed by DataGenerator
61
+ this . require ( 'walker' ) ;
62
+ console . info ( ">>> Generating Demobrowser data... this might take a while" ) ;
63
+ let command = this . getCommand ( ) ;
64
+ let analyser = data . maker . getAnalyser ( ) ;
21
65
const templateDir = command . getTemplateDir ( ) ;
22
- const outputDir = maker . getTarget ( ) . getOutputDir ( ) ;
66
+ const outputDir = data . maker . getTarget ( ) . getOutputDir ( ) ;
23
67
const sourceDir = analyser . findLibrary ( "qxl.demobrowser" ) . getRootDir ( ) ;
24
68
let targetClass = command . resolveTargetClass ( command . _getConfig ( ) . targetType ) ;
69
+ let app = "demobrowser" ;
25
70
26
- return new qx . Promise ( ( fullfiled ) => {
27
- let app = application . getName ( ) ;
28
-
29
- const path = this . require ( "upath" ) ;
30
- const async = this . require ( "async" ) ;
31
-
32
- // needed by DataGenerator
33
- this . require ( 'walker' ) ;
34
- this . require ( 'mkdirp' ) ;
35
-
71
+ return new qx . Promise ( fullfilled => {
36
72
const DataGenerator = require ( path . join ( sourceDir , "tool/lib/DataGenerator" ) ) ;
37
73
// global vars
38
74
const config = {
39
- demoPath : path . join ( sourceDir , "source/demo/" ) ,
75
+ demoPath : path . join ( sourceDir , "source/demo/" ) ,
40
76
demoDataJsonFile : path . join ( outputDir , app , "script/demodata.json" ) ,
41
- classPath : path . join ( sourceDir , "source/class" ) ,
42
- jsSourcePath : path . join ( sourceDir , "source/class/qxl/demobrowser/demo" ) ,
77
+ classPath : path . join ( sourceDir , "source/class" ) ,
78
+ jsSourcePath : path . join ( sourceDir , "source/class/qxl/demobrowser/demo" ) ,
43
79
demoConfigJsonFile : path . join ( outputDir , app , "config.demo.json" ) ,
44
80
verbose : command . argv . verbose
45
81
} ;
46
82
let appInfos = [ ] ;
47
83
let dataGenerator = new DataGenerator ( config ) ;
48
84
async . series ( [
49
85
( cb ) => {
50
- console . info ( "\nDEMO BUILD STARTED " ) ;
86
+ console . info ( "- Start building... " ) ;
51
87
cb ( ) ;
52
88
} ,
53
89
// catches all the demos from config.demoPath
@@ -57,7 +93,7 @@ qx.Class.define("qxl.demobrowser.compile.LibraryApi", {
57
93
// copy all javascript files to config.scriptDestinationPath
58
94
dataGenerator . copyJsFiles . bind ( dataGenerator ) ,
59
95
( cb ) => {
60
- console . info ( "\nget apps " ) ;
96
+ console . info ( "- Get applications " ) ;
61
97
let environment = {
62
98
"qx.allowUrlVariants" : true ,
63
99
"qx.allowUrlSettings" : true ,
@@ -70,10 +106,10 @@ qx.Class.define("qxl.demobrowser.compile.LibraryApi", {
70
106
if ( file . level === 2 ) {
71
107
let demoCategory = dataGenerator . getDemoCategoryFromFile ( file . path ) ;
72
108
let className = 'qxl.demobrowser.demo.' + demoCategory . category + '.' + demoCategory . name ;
73
- let outDir = path . join ( demoCategory . category , demoCategory . name ) ;
109
+ let outDir = path . join ( demoCategory . category , demoCategory . name ) ;
74
110
let library = analyser . getLibraryFromClassname ( className ) ;
75
111
if ( ! library ) {
76
- console . info ( " no class found for " + file . path ) ;
112
+ console . error ( "! no class found for " + file . path ) ;
77
113
return ;
78
114
}
79
115
appInfos . push ( {
@@ -82,6 +118,8 @@ qx.Class.define("qxl.demobrowser.compile.LibraryApi", {
82
118
"qx.theme.Modern" ,
83
119
"qx.theme.Simple" ,
84
120
"qx.theme.Classic" ,
121
+ "qx.theme.TangibleLight" ,
122
+ "qx.theme.TangibleDark" ,
85
123
"qx.log.appender.Native" ,
86
124
"qx.log.appender.Console"
87
125
] ) . set ( {
@@ -95,58 +133,86 @@ qx.Class.define("qxl.demobrowser.compile.LibraryApi", {
95
133
"qx.theme.Indigo" ,
96
134
"qx.theme.Modern" ,
97
135
"qx.theme.Simple" ,
98
- "qx.theme.Classic"
136
+ "qx.theme.Classic" ,
137
+ "qx.theme.TangibleLight" ,
138
+ "qx.theme.TangibleDark"
99
139
] ,
100
140
templatePath : templateDir
101
141
} ) ,
102
- className : className
142
+ className : className ,
143
+ fileName : analyser . getClassFilename ( className )
103
144
} ) ;
104
145
}
105
146
} ) ;
106
147
cb ( ) ;
107
148
} ,
108
149
( cb ) => {
109
- console . info ( "DEMO BUILD START COMPILE " ) ;
150
+ console . info ( "- Compiling ... " ) ;
110
151
let target = new targetClass ( outputDir ) ;
111
152
target . set ( {
112
153
generateIndexHtml : false ,
113
154
analyser : analyser
114
155
} ) ;
115
156
async . eachSeries ( appInfos ,
116
157
( appInfo , cb ) => {
117
- // Calculate dependencies and write it out
118
- appInfo . app . setAnalyser ( analyser ) ;
119
- appInfo . app . calcDependencies ( ) ;
120
- if ( command . argv . verbose ) {
121
- console . info ( "Writing class " + appInfo . app . getClassName ( ) + " into " + appInfo . app . getOutputPath ( ) ) ;
122
- }
123
- target . generateApplication ( appInfo . app , appInfo . app . getEnvironment ( ) )
124
- . then ( ( ) => cb ( ) )
125
- . catch ( ( err ) => {
126
- console . error ( err . message ) ;
127
- cb ( err ) ;
128
- } ) ;
158
+ let dest = path . join ( target . getOutputDir ( ) , appInfo . app . getOutputPath ( ) , "index.js" ) ;
159
+ let src = appInfo . fileName ;
160
+ this . __fileDateDiffers ( src , dest ) . then ( ( needsWork ) => {
161
+ if ( ! needsWork ) {
162
+ cb ( ) ;
163
+ return ;
164
+ }
165
+ // Calculate dependencies and write it out
166
+ appInfo . app . setAnalyser ( analyser ) ;
167
+ appInfo . app . calcDependencies ( ) ;
168
+ if ( command . argv . verbose ) {
169
+ console . info ( "- Writing class " + appInfo . app . getClassName ( ) + " into " + appInfo . app . getOutputPath ( ) ) ;
170
+ }
171
+ target . generateApplication ( appInfo . app , appInfo . app . getEnvironment ( ) )
172
+ . then ( ( ) => cb ( ) )
173
+ . catch ( ( err ) => {
174
+ console . error ( err . message ) ;
175
+ cb ( err ) ;
176
+ } ) ;
177
+ } ) ;
129
178
} ,
130
179
cb )
131
180
} ,
132
181
( cb ) => {
133
- qx . tool . utils . files . Utils . sync ( path . join ( sourceDir , "source/demo/" ) , path . join ( outputDir , app , "demo" ) )
182
+ qx . tool . utils . files . Utils . sync ( path . join ( sourceDir , "source/demo/" ) , path . join ( outputDir , app , "demo" ) )
134
183
. then ( ( ) => cb ( ) )
135
184
. catch ( ( err ) => {
136
185
console . error ( err . message ) ;
137
186
cb ( err ) ;
138
187
} ) ;
139
188
} ,
140
189
( cb ) => {
141
- console . info ( "\nDEMO BUILD FINISHED " ) ;
190
+ console . info ( "- Demo build finished. " ) ;
142
191
cb ( ) ;
143
192
}
144
- ] , fullfiled ) ;
193
+ ] , fullfilled ) ;
145
194
} ) ;
195
+ } ,
196
+
197
+ async __fileDateDiffers ( src , dest ) {
198
+ let srcStat = await qx . tool . utils . files . Utils . safeStat ( src ) ;
199
+ if ( ! srcStat ) {
200
+ // nothing to coy in this case
201
+ return false ;
202
+ }
203
+ if ( ! fs . existsSync ( dest ) ) {
204
+ return true ;
205
+ }
206
+ let destStat = await qx . tool . utils . files . Utils . safeStat ( dest ) ;
207
+ if ( ! destStat || ( srcStat . mtime . getTime ( ) > destStat . mtime . getTime ( ) ) ) {
208
+ return true ;
209
+ }
210
+ return false ;
146
211
}
212
+
147
213
}
148
214
} ) ;
149
215
150
216
module . exports = {
151
- LibraryApi : qxl . demobrowser . compile . LibraryApi
217
+ CompilerApi : qxl . demobrowser . compile . CompilerApi
152
218
} ;
0 commit comments