lib/make.js
/**
 * Main creation sanitization logic
 *
 * @param {object} options The options to produce the document
 * @returns {Promise}
 */
Main creation sanitization logic
@param {object} options The options to produce the document
@returns {Promise}
Main creation sanitization logic @param { object } options The options to produce the document @returns { Promise }
async function make (options = {}) {
  const format = String(options.format).toLowerCase() 
  if (!outputFormat[format]) { 
    return process.logger.fatal(
      _`Format unknown: ${format}`,
      _`Expect any of: ${Object.keys(outputFormat).join(`, `)}`
    )
  }
  const { ext, create } = outputFormat[format]
  const output = path.resolve(options.output).replace(/\.___$/, ext) 
  if (ext !== path.extname(output)) { 
    process.logger.debug.warn(_`OUTPUT: ${output}`)
    return process.logger.fatal(_`The filename extension for the output should be '${ext}', got '${path.extname(output)}' instead`)
  }
  process.logger.info(_`Creating a ${format} document`)
  await create(output)
  if (options.pack) {
    if (!pack[options.pack]) { 
      process.logger.error(_`Unknown pack format: ${options.pack}`)
      process.logger.error(_`Expect any of: ${Object.keys(pack).join(`, `)}`)
      return
    }
    if (ext === `.pdf`) {
      await pack[options.pack](output, output)
    } else {
      await pack[options.pack](process.env.STUFF_FOLDER_SRC, output)
    }
    await remove(output)
  }
}
async function make ( options = { } ) { const format = String ( options . format ) . toLowerCase ( ) if ( ! outputFormat [ format ] ) { return process . logger . fatal ( _ ` ${ format } ` , _ ` ${ Object . keys ( outputFormat ) . join ( ` ` ) } ` ) } const { ext , create } = outputFormat [ format ] const output = path . resolve ( options . output ) . replace ( / \.___$ / , ext ) if ( ext !== path . extname ( output ) ) { process . logger . debug . warn ( _ ` ${ output } ` ) return process . logger . fatal ( _ ` ${ ext } ${ path . extname ( output ) } ` ) } process . logger . info ( _ ` ${ format } ` ) await create ( output ) if ( options . pack ) { if ( ! pack [ options . pack ] ) { process . logger . error ( _ ` ${ options . pack } ` ) process . logger . error ( _ ` ${ Object . keys ( pack ) . join ( ` ` ) } ` ) return } if ( ext === ` ` ) { await pack [ options . pack ] ( output , output ) } else { await pack [ options . pack ] ( process . env . STUFF_FOLDER_SRC , output ) } await remove ( output ) } }
Main creation sanitization logic
 @param {object} options The options to produce the document
 @returns {Promise}
Main creation sanitization logic @param { object } options The options to produce the document @returns { Promise }
// Let's check the expected format // Sanitize // Oups! // Let's check output filename validity // Sanitize // Oups! // We are good to create the expected output // Let's check if we can pack the output // Meh! // If the source have been packed, we remove the original // source. Only the archive must remain available.