documark / wkhtmltox-binary

[WIP] Cross-platform downloader for the wkhtmltopdf binary.
0 stars 0 forks source link

Draft: Steps for downloading binary. #1

Open mauvm opened 9 years ago

mauvm commented 9 years ago

This module is loaded, a specific version is requested, and a promise will be returned:

var downloader = require('wkhtmltopdf-downloader');

downloader('0.12.2.1').then(success, fail);

This will perform the following steps:

  1. Global: Check if file exists in the temp dir (readlink if symlink) .
  2. If so, resolve promise with path to this file and stop.
  3. Local: Check if file exists in package cache dir.
  4. If so, resolve promise with local path, meanwhile symlink (copy on Windows machine) it into temp dir, and stop. Copying will happen in parallel to make it globally available without losing performance.
  5. Download specific version of wkhtmltopdf binary to package cache dir.
  6. If success, go to step 3.
  7. If failed, reject promise with reason and stop.

Elaboration on step 5:

  1. Determine platform and architecture (32/64bit).
  2. Check if downloader is available for current platform and architecture (fall back to 32bit if necessary).
  3. Execute downloader.
  4. Continue with step 6.

Other things to mention:

mauvm commented 9 years ago

Updated steps:

  1. Local: Check if file exists in package cache dir.if symlink) .
  2. If so, apply callback with path to this file and stop.
  3. Global: Check if file exists in the temp dir (readlink
  4. If so, apply callback with path to local path, meanwhile symlink (copy on Windows machine) it into temp dir, and stop. Copying will happen in parallel to make it globally available without losing performance.
  5. Download specific version of wkhtmltopdf binary to package cache dir.
  6. If success, go to step 3.
  7. If failed, apply callback with error and stop.

Notes:

mauvm commented 9 years ago

Alternative: Install package globally (npm install -g wkhtmltox-binary) for a global cache and locally for a repo/project specific cache. The downside of this is that a document project (and it's package.json) depend on a global package..

EDIT: It could be done with a postinstall hook in package.json:

{
  "scripts": {
    "postinstall": "npm install -g wkhtmltox-binary"
  }
}