Class: AdaptrexBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/adaptrex/builder.rb

Overview

Package all that pages

Instance Method Summary collapse

Constructor Details

#initialize(adaptrexConfig, appConfig) ⇒ AdaptrexBuilder

Returns a new instance of AdaptrexBuilder.



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
# File 'lib/adaptrex/builder.rb', line 22

def initialize(adaptrexConfig, appConfig)
  weblib = adaptrexConfig.weblibPath

  if appConfig.pages.length == 0
    puts "There are no apps (pages) to be compiled".warn
    return
  end
  
  #  Loop through each app and compile
  appConfig.pages.each do|key,val|
    appPath = key
    parts = val.split(",")
    appName = parts[0]
    sdkType = parts[1]

    puts "Compiling " + appName + " (" + appPath + ")"

    if sdkType == "ext"
      sdkVersion = appConfig.extVersion
      sdkPath = weblib + "/" + sdkVersion
      includes = "ExtDependencies.js"
    else
      sdkVersion = appConfig.touchVersion
      sdkPath = weblib + "/" + sdkVersion
      includes = "TouchDependencies.js"

      #   Sencha Touch 2.1.0 has a bug that prevents compilation.  The file containing
      #   the bug is not required for the bootstrap file so we move it to a temp file
      #   during the compilation and restore it
      tmpDir = Dir.tmpdir
      FileUtils.mv(sdkPath + "/src/ux/auth2", tmpDir + "_senchatouch_auth2")
    end

          
    begin
      if not createGhosts?(weblib, sdkPath, appPath) then return end

      if sdkType == "ext" then sdkFile = "ext" else sdkFile = "sencha-touch" end
      
      cmd = [
        "sencha -d -sdk " + sdkPath + " compile",
          " -classpath ",
            "adaptrex/ghosts.js," + 
            appPath + "/app.js,",
            appPath + "/app,",
            weblib + "/" + appConfig.adaptrexVersion + "/" + sdkType + "/src,",
            sdkPath + "/src",
          " exclude -all",
          " and include -r -f " + appPath + "/app.js",
          " and exclude -f " + sdkPath + "/src",
          " and exclude -f adaptrex/ghosts.js",
          " and concat " + appPath + "/build/app-all-debug.js",
          " and concat -compress " + appPath + "/build/app-all.js",
          " and save appset",
          " and exclude -all",
          " and include -r -f " + appPath + "/app.js",
          " and include -na Adaptrex.override",
          " and include -r -f " + includes,
          " and exclude -s appset",
          " and exclude -f " + includes,
          " and concat " + appPath + "/build/app-" + sdkFile + "-debug.js",
          " and concat -compress " + appPath + "/build/app-" + sdkFile + ".js"
        ].join("")
      compileOutput = `#{cmd}`
      
      if compileOutput.include?"[ERR]"
        puts((appName + " (" + appPath + ")").err)
        puts "See the output from Sencha Cmd for more information".indent
        puts "-----\n" + cmd + "\n-----\n" + compileOutput + "-----\n\n"
      else
        print((appName + " (" + appPath + ")").success)
        puts ""
      end

    ensure
      #   Move the broken auth2 ux back to the original Sencha Touch source folder
      if not sdkType == "ext"
        FileUtils.mv(tmpDir + "_senchatouch_auth2", sdkPath + "/src/ux/auth2")
      end
    end
  end
end

Instance Method Details

#createGhosts?(weblib, sdkPath, appPath) ⇒ Boolean

Returns:

  • (Boolean)


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
# File 'lib/adaptrex/builder.rb', line 109

def createGhosts?(weblib,sdkPath,appPath)
  ghosts = "adaptrex/ghosts.js"
  if not File.exist?(ghosts) then File.open(ghosts, "w") {} end
  
  cmd = [ 
    "sencha -d -sdk=" + sdkPath + " compile" +
      " -classpath",
        " adaptrex/ghosts.js," + 
        appPath + "/app.js,",
        appPath + "/app,",
        #weblib + "/" + appConfig.adaptrexVersion + "/" + sdkType + "/src,",
        sdkPath + "/src",
      " exclude -a"
    ].join("")
  compileOutput = `#{cmd}`
  
  if compileOutput.include?"[ERR]"
    if compileOutput.include?$failPattern
      failedClass = compileOutput.split($failPattern)[1].split("\n")[0].strip
      if (failedClass.include?".store." or failedClass.include?".model.")
        ghostsFile = File.open(ghosts,"a")
        ghostsFile.puts("Ext.define('" + failedClass + "',{})")
        ghostsFile.close()
        return createGhosts?(weblib,sdkPath,appPath)
      end
    end
    false
  end
  
  true
end