mirror of
				https://github.com/JuanCanham/HackMyResume.git
				synced 2025-11-03 22:37:27 +00:00 
			
		
		
		
	Fix generation glitches.
Fix output file name glitch, writing CSS files to destination folder, and an issue where the process would evaporate before PDF/PNG generation could complete.
This commit is contained in:
		@@ -128,7 +128,7 @@ main = module.exports = ( rawArgs, exitCallback ) ->
 | 
			
		||||
  program.parse( args )
 | 
			
		||||
 | 
			
		||||
  if !program.args.length
 | 
			
		||||
    throw { fluenterror: 4 }
 | 
			
		||||
    throw fluenterror: 4
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -256,13 +256,14 @@ execute = ( src, dst, opts, log ) ->
 | 
			
		||||
  # Invoke the verb using promise syntax
 | 
			
		||||
  prom = v.invoke.call v, src, dst, _opts, log
 | 
			
		||||
  prom.then executeSuccess, executeFail
 | 
			
		||||
 | 
			
		||||
  return
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
### Success handler for verb invocations. Calls process.exit by default ###
 | 
			
		||||
executeSuccess = (obj) -> _exitCallback 0; return
 | 
			
		||||
executeSuccess = (obj) ->
 | 
			
		||||
  # Can't call _exitCallback here (process.exit) when PDF is running in BK
 | 
			
		||||
  #_exitCallback 0; return
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -29,7 +29,7 @@ class FRESHTheme
 | 
			
		||||
  ### Open and parse the specified theme. ###
 | 
			
		||||
  open: ( themeFolder ) ->
 | 
			
		||||
 | 
			
		||||
    this.folder = themeFolder;
 | 
			
		||||
    @folder = themeFolder
 | 
			
		||||
 | 
			
		||||
    # Open the [theme-name].json file; should have the same name as folder
 | 
			
		||||
    pathInfo = parsePath themeFolder
 | 
			
		||||
@@ -126,6 +126,7 @@ _loadOne = ( absPath, formatsHash, tplFolder ) ->
 | 
			
		||||
  absPathSafe = absPath.trim().toLowerCase()
 | 
			
		||||
  outFmt = ''
 | 
			
		||||
  act = 'copy'
 | 
			
		||||
  isPrimary = false
 | 
			
		||||
 | 
			
		||||
  # If this is an "explicit" theme, all files of importance are specified in
 | 
			
		||||
  # the "transform" section of the theme.json file.
 | 
			
		||||
@@ -164,6 +165,9 @@ _loadOne = ( absPath, formatsHash, tplFolder ) ->
 | 
			
		||||
    idx = pathInfo.name.lastIndexOf '-'
 | 
			
		||||
    outFmt = if idx == -1 then pathInfo.name else pathInfo.name.substr idx+1
 | 
			
		||||
    act = 'transform' if !@explicit
 | 
			
		||||
    defFormats = require './default-formats'
 | 
			
		||||
    isPrimary = _.some defFormats, (form) ->
 | 
			
		||||
      form.name == outFmt and pathInfo.extname != '.css'
 | 
			
		||||
 | 
			
		||||
  # Make sure we have a valid formatsHash
 | 
			
		||||
  formatsHash[ outFmt ] = formatsHash[outFmt] || {
 | 
			
		||||
@@ -178,6 +182,7 @@ _loadOne = ( absPath, formatsHash, tplFolder ) ->
 | 
			
		||||
  # Create the file representation object
 | 
			
		||||
  obj =
 | 
			
		||||
    action: act
 | 
			
		||||
    primary: isPrimary
 | 
			
		||||
    path: absPath
 | 
			
		||||
    orgPath: PATH.relative tplFolder, absPath
 | 
			
		||||
    ext: pathInfo.extname.slice 1
 | 
			
		||||
 
 | 
			
		||||
@@ -12,7 +12,7 @@ PATH = require 'path'
 | 
			
		||||
SLASH = require 'slash'
 | 
			
		||||
_ = require 'underscore'
 | 
			
		||||
HMSTATUS = require '../core/status-codes'
 | 
			
		||||
 | 
			
		||||
SPAWN = require '../utils/safe-spawn'
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
###*
 | 
			
		||||
@@ -31,11 +31,10 @@ module.exports = class HtmlPdfCLIGenerator extends TemplateGenerator
 | 
			
		||||
 | 
			
		||||
  ###* Generate the binary PDF. ###
 | 
			
		||||
  onBeforeSave: ( info ) ->
 | 
			
		||||
    safe_eng = info.opts.pdf || 'wkhtmltopdf';
 | 
			
		||||
    if safe_eng == 'phantom'
 | 
			
		||||
      safe_eng = 'phantomjs'
 | 
			
		||||
    return info.mk if info.ext != 'html'
 | 
			
		||||
    safe_eng = info.opts.pdf || 'wkhtmltopdf'
 | 
			
		||||
    safe_eng = 'phantomjs' if safe_eng == 'phantom'
 | 
			
		||||
    if _.has engines, safe_eng
 | 
			
		||||
      @SPAWN = require '../utils/safe-spawn'
 | 
			
		||||
      @errHandler = info.opts.errHandler
 | 
			
		||||
      engines[ safe_eng ].call @, info.mk, info.outputFile, @onError
 | 
			
		||||
      return null # halt further processing
 | 
			
		||||
@@ -68,7 +67,8 @@ engines =
 | 
			
		||||
    # Save the markup to a temporary file
 | 
			
		||||
    tempFile = fOut.replace /\.pdf$/i, '.pdf.html'
 | 
			
		||||
    FS.writeFileSync tempFile, markup, 'utf8'
 | 
			
		||||
    @SPAWN 'wkhtmltopdf', [ tempFile, fOut ], false, on_error, @
 | 
			
		||||
    SPAWN 'wkhtmltopdf', [ tempFile, fOut ], false, on_error, @
 | 
			
		||||
    return
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -80,12 +80,12 @@ engines =
 | 
			
		||||
  TODO: Local web server to ease Phantom rendering
 | 
			
		||||
  ###
 | 
			
		||||
  phantomjs: ( markup, fOut, on_error ) ->
 | 
			
		||||
 | 
			
		||||
    # Save the markup to a temporary file
 | 
			
		||||
    tempFile = fOut.replace(/\.pdf$/i, '.pdf.html');
 | 
			
		||||
    tempFile = fOut.replace /\.pdf$/i, '.pdf.html'
 | 
			
		||||
    FS.writeFileSync tempFile, markup, 'utf8'
 | 
			
		||||
    scriptPath = SLASH( PATH.relative( process.cwd(),
 | 
			
		||||
      PATH.resolve( __dirname, '../utils/rasterize.js' ) ) );
 | 
			
		||||
    sourcePath = SLASH( PATH.relative( process.cwd(), tempFile) );
 | 
			
		||||
    destPath = SLASH( PATH.relative( process.cwd(), fOut) );
 | 
			
		||||
    @SPAWN 'phantomjs', [ scriptPath, sourcePath, destPath ], false, on_error, @
 | 
			
		||||
    scriptPath = PATH.relative process.cwd(), PATH.resolve( __dirname, '../utils/rasterize.js' )
 | 
			
		||||
    scriptPath = SLASH scriptPath
 | 
			
		||||
    sourcePath = SLASH PATH.relative( process.cwd(), tempFile)
 | 
			
		||||
    destPath = SLASH PATH.relative( process.cwd(), fOut)
 | 
			
		||||
    SPAWN 'phantomjs', [ scriptPath, sourcePath, destPath ], false, on_error, @
 | 
			
		||||
    return
 | 
			
		||||
 
 | 
			
		||||
@@ -54,8 +54,8 @@ module.exports = class TemplateGenerator extends BaseGenerator
 | 
			
		||||
 | 
			
		||||
    opts =
 | 
			
		||||
      if opts
 | 
			
		||||
      then (this.opts = EXTEND( true, { }, _defaultOpts, opts ))
 | 
			
		||||
      else this.opts
 | 
			
		||||
      then (@opts = EXTEND( true, { }, _defaultOpts, opts ))
 | 
			
		||||
      else @opts
 | 
			
		||||
 | 
			
		||||
    # Sort such that CSS files are processed before others
 | 
			
		||||
    curFmt = opts.themeObj.getFormat( this.format )
 | 
			
		||||
@@ -102,29 +102,33 @@ module.exports = class TemplateGenerator extends BaseGenerator
 | 
			
		||||
    # etc. Process them here.
 | 
			
		||||
    genInfo.files.forEach ( file ) ->
 | 
			
		||||
 | 
			
		||||
      # console.dir _.omit(file.info,'cssData','data','css' )
 | 
			
		||||
 | 
			
		||||
      # Pre-processing
 | 
			
		||||
      file.info.orgPath = file.info.orgPath || ''
 | 
			
		||||
      thisFilePath = PATH.join( outFolder, file.info.orgPath )
 | 
			
		||||
      thisFilePath =
 | 
			
		||||
        if file.info.primary
 | 
			
		||||
        then f
 | 
			
		||||
        else PATH.join outFolder, file.info.orgPath
 | 
			
		||||
 | 
			
		||||
      if file.info.action != 'copy' and @onBeforeSave
 | 
			
		||||
        file.data = this.onBeforeSave
 | 
			
		||||
          theme: opts.themeObj
 | 
			
		||||
          outputFile: thisFilePath
 | 
			
		||||
          mk: file.data
 | 
			
		||||
          opts: this.opts
 | 
			
		||||
          opts: @opts,
 | 
			
		||||
          ext: file.info.ext
 | 
			
		||||
        if !file.data
 | 
			
		||||
          return
 | 
			
		||||
 | 
			
		||||
      # Write the file
 | 
			
		||||
      opts.beforeWrite? thisFilePath
 | 
			
		||||
 | 
			
		||||
      MKDIRP.sync PATH.dirname( thisFilePath )
 | 
			
		||||
 | 
			
		||||
      if file.info.action != 'copy'
 | 
			
		||||
        FS.writeFileSync thisFilePath, file.data, encoding: 'utf8', flags: 'w'
 | 
			
		||||
      else
 | 
			
		||||
        FS.copySync file.info.path, thisFilePath
 | 
			
		||||
 | 
			
		||||
      opts.afterWrite? thisFilePath
 | 
			
		||||
 | 
			
		||||
      # Post-processing
 | 
			
		||||
 
 | 
			
		||||
@@ -9,9 +9,8 @@ exception ###
 | 
			
		||||
module.exports = ( cmd, args, isSync, callback, param ) ->
 | 
			
		||||
 | 
			
		||||
  try
 | 
			
		||||
 | 
			
		||||
    # .spawnSync not available on earlier Node.js, so default to .spawn
 | 
			
		||||
    spawn = require('child_process')[ if isSync then 'spawnSync' else 'spawn'];
 | 
			
		||||
    spawn = require('child_process')[ if isSync then 'spawnSync' else 'spawn']
 | 
			
		||||
    info = spawn cmd, args
 | 
			
		||||
 | 
			
		||||
    # Check for error depending on whether we're sync or async TODO: Promises
 | 
			
		||||
 
 | 
			
		||||
@@ -154,6 +154,7 @@ _build = ( src, dst, opts ) ->
 | 
			
		||||
    @reject results
 | 
			
		||||
  else if !@hasError()
 | 
			
		||||
    @resolve results
 | 
			
		||||
 | 
			
		||||
  results
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -258,12 +259,10 @@ _single = ( targInfo, theme, finished ) ->
 | 
			
		||||
 | 
			
		||||
###* Ensure that user-specified outputs/targets are valid. ###
 | 
			
		||||
_verifyOutputs = ( targets, theme ) ->
 | 
			
		||||
  @stat HMEVENT.verifyOutputs, { targets: targets, theme: theme }
 | 
			
		||||
  @stat HMEVENT.verifyOutputs, targets: targets, theme: theme
 | 
			
		||||
  _.reject targets.map( ( t ) ->
 | 
			
		||||
    pathInfo = parsePath t
 | 
			
		||||
    {
 | 
			
		||||
      format: pathInfo.extname.substr(1)
 | 
			
		||||
    }),
 | 
			
		||||
    format: pathInfo.extname.substr(1) ),
 | 
			
		||||
    (t) -> t.format == 'all' || theme.hasFormat( t.format )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user