Exemple #1
0
def buildSuite(src_suite, src_module, dest):
  """
  Build jasmine suite.
  Params:
    src - src test.module
    dest - desination build path
  """
  dest_module = os.path.abspath(os.path.normpath(dest + '/module.js'))
  tmpModule = generateTmpFilename()
  dest_suite = os.path.abspath(os.path.normpath(dest + '/test.js'))
  # copy third_party jasmine folder
  shutil.copytree(
      os.path.join(settings.THIRD_PARTY_PATH, 'jasmine'),
      os.path.join(dest, 'jasmine'))
  # copy jasmine_suite.html template
  compileTemplate(
      os.path.join(settings.TEMPLATES_PATH, 'jasmine_suite.html'),
      os.path.normpath(dest + '/suite.html'),
      {}, {})
  # compile coffee module
  compileCoffeeModule(os.path.abspath(src_module), tmpModule)
  # cat with third_party
  cat([settings.JSON2, tmpModule], dest_module)
  # compile coffee test suite
  compileCoffeeModule(os.path.abspath(src_suite), dest_suite)
Exemple #2
0
  def buildApps(self):
    # recreate tmp path
    if os.path.exists(settings.TMP_PATH):
      shutil.rmtree(settings.TMP_PATH)
    os.mkdir(settings.TMP_PATH)

    # build wender client library
    wenderModule = os.path.join(settings.WENDER_PATH, 'client/wender_coffee/wender.module')
    wenderCoffee = generateTmpFilename()
    collectCoffeeModule(wenderModule, wenderCoffee)

    compiler = Compiler()

    # build login app

    for conf in self.confapps:
      module = compiler.compile(':'.join(self.confsite.paths), conf.name)

      # add orm structs
      mainFunc = module.functions.get('main', None)
      if mainFunc:
        ormFn = core.FunctionCallNode('wender.orm.setStructs')
        # add structs param
        ormFn.addParameter(self.structs)
        # insert to main method orm.addStructs
        mainFunc.bodyNodes.insert(0, ormFn)

      # self.genJsApp(conf, module)
      self.compileApp(module, wenderCoffee)
Exemple #3
0
  def compileApp(self, module, wenderCoffee):
    scssPath = os.path.abspath(os.path.normpath(
        module.path + ('/../style/%s' % module.name)))
    imgPath = os.path.abspath(os.path.normpath(
        module.path + '/../style/img'))
    imgTmpPath = os.path.join(settings.TMP_PATH, 'img')
    # generate dest filenames
    loaderTemplate = os.path.join(settings.TEMPLATES_PATH, 'app_loader.coffee')
    loaderCoffee = generateTmpFilename()
    loaderJs = generateTmpFilename()
    loaderJsMap = generateTmpFilename()
    loaderCompressJs = generateTmpFilename()
    loaderThirdPartyJs = generateTmpFilename()

    appCoffee = generateTmpFilename()
    appJs = generateTmpFilename()
    appCompressJs = generateTmpFilename()

    loaderScss = os.path.join(scssPath, 'loader.scss')
    loaderCss = generateTmpFilename()
    loaderCssMap = generateTmpFilename()
    loaderCompressCss = generateTmpFilename()

    mergedCoffee = generateTmpFilename()

    mainScss = os.path.join(scssPath, 'main.scss')
    mainCss = generateTmpFilename()
    mainCssMap = generateTmpFilename()
    mainCompressCss = generateTmpFilename()

    srcApp = os.path.join(settings.TEMPLATES_PATH, 'app.html')
    templateName = 'app-%s.html' % module.name
    destApp = generateTmpFilename()
    destCompressApp = generateTmpFilename()
    # create app loader coffee from template
    compileTemplate(loaderTemplate, loaderCoffee, {
        'css': "{{ static_url('theme/%s.css') }}" % module.name,
        'js': "{{ static_url('app/%s.js') }}" % module.name,
        'app_name': module.name,
        'message': '{{ message }}',
        }, {})

    cat([wenderCoffee, loaderCoffee], mergedCoffee)
    compileCoffee(mergedCoffee, loaderJs)

    # cat loaderJs with json2
    cat([settings.JSON2, loaderJs], loaderThirdPartyJs)

    # compile app loader coffee to js
    # compileCoffee(loaderCoffee, loaderJs)

    # compile sass style
    scssToCss(loaderScss, loaderCss)
    scssToCss(mainScss, mainCss)

    # copy img from style to tmp path
    shutil.copytree(imgPath, imgTmpPath)

    # compile mut module to appCoffee
    moduleCode = genCoffeeModuleCode(module)
    with open(appCoffee, 'w') as f: f.write(moduleCode)
    # compile appCoffee to appJs
    compileCoffee(appCoffee, appJs)

    # debug(dem)
    print appCoffee

    # compress loaderCss
    # compressCssJs(loaderCss, loaderJs)
    compressCss(loaderCss, loaderCssMap, loaderCompressCss, not self.isDebug)

    # compress mainCss
    compressCss(mainCss, mainCssMap, mainCompressCss, not self.isDebug)

    if not self.isDebug:
      # compress loaderJs
      compressJs(loaderThirdPartyJs, loaderCssMap, loaderCompressJs, loaderJsMap)

      # compress appJs
      compressJs(appJs, '', appCompressJs, '')
    else:
      shutil.copy(loaderThirdPartyJs, loaderCompressJs)
      shutil.copy(appJs, appCompressJs)

    # create app html template
    compileTemplate(srcApp, destApp, {
        'lang': '{{ lang }}',
        'title': '{{ title }}',
        }, {
        'loader_css': loaderCompressCss,
        'loader_js': loaderCompressJs,
        })

    if not self.isDebug:
      # compress app-name.html
      compressHtml(destApp, destCompressApp)
    else:
      shutil.copy(destApp, destCompressApp)

    shutil.copy(destCompressApp, os.path.join(self.confsite.build_path, 'templates/%s' % templateName))
    shutil.copy(mainCompressCss, os.path.join(self.confsite.build_path, 'static/theme/%s.css' % module.name))
    shutil.copy(appCompressJs, os.path.join(self.confsite.build_path, 'static/app/%s.js' % module.name))

    # remove tmp files
    safeRemoveFile(loaderCoffee)
    safeRemoveFile(loaderJs)
    safeRemoveFile(loaderThirdPartyJs)
    safeRemoveFile(loaderJsMap)
    safeRemoveFile(loaderCompressJs)
    safeRemoveFile(mergedCoffee)
    # safeRemoveFile(appCoffee)
    safeRemoveFile(appJs)
    safeRemoveFile(loaderCss)
    safeRemoveFile(loaderCssMap)
    safeRemoveFile(loaderCompressCss)
    safeRemoveFile(mainCss)
    safeRemoveFile(mainCssMap)
    safeRemoveFile(mainCompressCss)
    safeRemoveFile(destApp)
    shutil.rmtree(imgTmpPath)