Example #1
0
// This helper creates a webtask using sandboxjs
function deployWebtask(deployConfig, done) {
  var config  = require(deployConfig.config);

  if (!config.webtaskName) {
    return done(colors.white('=> ') +
      colors.red('error deploying webtask: ') +
      'Missing webtask name, please define the webtaskName key in ' +
      colors.cyan(deployConfig.config));
  }

  if (!config.webtaskToken) {
    return done(colors.white('=> ') +
      colors.red('error deploying webtask: ') +
      'Missing webtask token, please define the webtaskToken key in ' +
      colors.cyan(deployConfig.config));
  }

  var profile = Sandbox.fromToken(config.webtaskToken);

  readFile(deployConfig.source)
    .then(function (code) {
      return profile.create(code.toString(), {
        name:    config.webtaskName,
        secrets: config.secret || {},
        params:  config.param || {},
        parse:   false,
        merge:   false
      });
    })
    .then(function (webtask) {
      console.log(colors.white(' => ') +
        colors.green('webtask successfully deployed to: ') +
        colors.yellow(webtask.url));
    })
    .then(done)
    .catch(function (error) {
      return done(colors.white('=> ') +
        colors.red('error deploying webtask: ') +
        error);
    })
  ;
}
const webtaskConfig = require('../config/webtask.config');
const defaultConfig = require('../config/default.config');
const fs = require('fs');
const _ = require('lodash');

const config = _.assign({}, defaultConfig, webtaskConfig);

if (!config.webtaskName) {
  throw new Error('error deploying webtask: Missing webtask name, please define the webtaskName');
}

if (!config.webtaskToken) {
  throw new Error('error deploying webtask: Missing webtask token, please define the webtaskToken');
}

const profile = Sandbox.fromToken(config.webtaskToken);

fs.readFile('dist/index.js', (err, code) => {
  if (err) {
    throw err;
  }

  profile.create(code.toString(), {
    name: config.webtaskName,
    secrets: config.secret,
    params: config.param
  }, (error, webtask) => {
    if (error) {
      throw error;
    }