daily pastebin goal
38%
SHARE
TWEET

Untitled

a guest Aug 10th, 2018 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use strict';
  2.  
  3. const fs = require('fs');
  4. const path = require('path');
  5.  
  6. /**
  7.  * Utility base plugin for our serverless-plugin needs. To be inherited
  8.  * from in actual serverless plugins.
  9.  */
  10. class BasePlugin {
  11.  
  12.     getFirstFunction() {
  13.         // this only supports one function (the first one)
  14.         // since the webpack individually packaging does not allow to
  15.         // hook in for each function separately
  16.         const functions = this.serverless.service.functions;
  17.         return functions[Object.keys(functions)[0]];
  18.     }
  19.  
  20.     writeFileTemporarily(file, content) {
  21.         var that = this;
  22.  
  23.         var absPathToRemove = path.resolve(file);
  24.         process.on('exit', function() {
  25.             that.debugLog("Removing " + file);
  26.  
  27.             // delete immediately using unlinkSync() since async often does not work in an exit handler
  28.             if (fs.existsSync(absPathToRemove)) {
  29.                 fs.unlinkSync(absPathToRemove);
  30.             }
  31.         });
  32.  
  33.         fs.writeFileSync(file, content);
  34.         that.debugLog("Created " + file);
  35.     }
  36.  
  37.     debugLog(msg) {
  38.         if (this.options.verbose) {
  39.             this.log(msg);
  40.         }
  41.     }
  42.  
  43.     log(msg) {
  44.         this.serverless.cli.log(msg);
  45.     }
  46.  
  47. }
  48.  
  49. module.exports = BasePlugin;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top