コード例 #1
0
    it('should display function metrics if function option is specified', () => {
      awsMetrics.options.function = 'function1';

      const metrics = [
        [
          {
            ResponseMetadata: {
              RequestId: '1f50045b-b569-11e6-86c6-eb54d1aaa755-func1',
            },
            Label: 'Invocations',
            Datapoints: [{ Sum: 12 }, { Sum: 8 }],
          },
          {
            ResponseMetadata: {
              RequestId: '1f59059b-b569-11e6-aa18-c7bab68810d2-func1',
            },
            Label: 'Throttles',
            Datapoints: [{ Sum: 15 }, { Sum: 15 }],
          },
          {
            ResponseMetadata: {
              RequestId: '1f50c7b1-b569-11e6-b1b6-ab86694b617b-func1',
            },
            Label: 'Errors',
            Datapoints: [{ Sum: 0 }],
          },
          {
            ResponseMetadata: {
              RequestId: '1f63db14-b569-11e6-8501-d98a275ce164-func1',
            },
            Label: 'Duration',
            Datapoints: [{ Average: 1000 }],
          },
        ],
      ];

      let expectedMessage = '';
      expectedMessage += `${chalk.yellow.underline(awsMetrics.options.function)}\n`;
      expectedMessage += 'January 1, 1970 12:00 AM - January 2, 1970 12:00 AM\n\n';
      expectedMessage += `${chalk.yellow('Invocations: 20 \n')}`;
      expectedMessage += `${chalk.yellow('Throttles: 30 \n')}`;
      expectedMessage += `${chalk.yellow('Errors: 0 \n')}`;
      expectedMessage += `${chalk.yellow('Duration (avg.): 1000ms')}`;

      return awsMetrics.showMetrics(metrics).then((message) => {
        expect(consoleLogStub.calledOnce).to.equal(true);
        expect(message).to.equal(expectedMessage);
      });
    });
コード例 #2
0
ファイル: display.test.js プロジェクト: asprouse/serverless
  it('should display CloudFormation outputs when verbose output is requested', () => {
    awsInfo.options.verbose = true;

    awsInfo.gatheredData.outputs = [
      {
        Description: 'Lambda function info',
        OutputKey: 'Function1FunctionArn',
        OutputValue: 'arn:function1',
      },
      {
        Description: 'Lambda function info',
        OutputKey: 'Function2FunctionArn',
        OutputValue: 'arn:function2',
      },
    ];

    let expectedMessage = '';

    expectedMessage += `${chalk.yellow.underline('Service Information')}\n`;
    expectedMessage += `${chalk.yellow('service:')} my-first\n`;
    expectedMessage += `${chalk.yellow('stage:')} dev\n`;
    expectedMessage += `${chalk.yellow('region:')} eu-west-1`;
    expectedMessage += `\n${chalk.yellow('api keys:')}`;
    expectedMessage += '\n  None';
    expectedMessage += `\n${chalk.yellow('endpoints:')}`;
    expectedMessage += '\n  None';
    expectedMessage += `\n${chalk.yellow('functions:')}`;
    expectedMessage += '\n  None';
    expectedMessage += `${chalk.yellow.underline('\n\nStack Outputs\n')}`;
    expectedMessage += `${chalk.yellow('Function1FunctionArn')}: ${'arn:function1'}\n`;
    expectedMessage += `${chalk.yellow('Function2FunctionArn')}: ${'arn:function2'}\n`;

    const message = awsInfo.display();
    expect(consoleLogStub.calledOnce).to.equal(true);
    expect(message).to.equal(expectedMessage);
  });
コード例 #3
0
ファイル: CLI.js プロジェクト: enanale/serverless
  generateVerboseHelp() {
    this.consoleLog('');
    this.consoleLog(chalk.yellow.underline('Commands by plugin'));
    this.consoleLog('');

    let pluginCommands = {};

    // add commands to pluginCommands based on command's plugin
    const addToPluginCommands = (cmd) => {
      const pcmd = _.clone(cmd);

      // remove subcommand from clone
      delete pcmd.commands;

      // check if a plugin entry is alreay present in pluginCommands. Use the
      // existing one or create a new plugin entry.
      if (_.has(pluginCommands, pcmd.pluginName)) {
        pluginCommands[pcmd.pluginName] = pluginCommands[pcmd.pluginName].concat(pcmd);
      } else {
        pluginCommands[pcmd.pluginName] = [pcmd];
      }

      // check for subcommands
      if ('commands' in cmd) {
        _.forEach(cmd.commands, (d) => {
          addToPluginCommands(d);
        });
      }
    };

    // fill up pluginCommands with commands in loadedCommands
    _.forEach(this.loadedCommands, (details) => {
      addToPluginCommands(details);
    });

    // sort plugins alphabetically
    pluginCommands = _(pluginCommands).toPairs().sortBy(0).fromPairs()
      .value();

    _.forEach(pluginCommands, (details, plugin) => {
      this.consoleLog(plugin);
      _.forEach(details, (cmd) => {
        // display command usage with single(1) indent
        this.displayCommandUsage(cmd, cmd.key.split(':').join(' '), 1);
      });
      this.consoleLog('');
    });
  }
コード例 #4
0
ファイル: migrate.js プロジェクト: nauchcrug/backend
function migrate(opts) {
    if (!opts.name) throw new Error('Filename required');
    const {
        name,
        verbose = false
    } = opts;

    const file = path.resolve(this.getPath(name));
    console.log(chalk.yellow.underline(`Migration file path: ${file}`));

    const sql = new QueryFile(file, {
        compress: true,
        minify: true,

    });

    db.none(sql)
        .then(data => {
            console.log(chalk.cyan(`Result ${data}`));
        })
        .catch(err => {
            console.error(verbose
                ? chalk.red(err.stack)
                : chalk.red.bold(err.message)
            );

            process.exit(1);
        });

    /*fs.readFile(file, {encoding: 'utf-8'}, (err, data) => {
        if (err) throw err;
        console.log(chalk.blue('Migrating...'));
        db.query(data)
            .then(data => {
                console.log(`Result: ${data}`);
            })
            .catch((err) => {
                console.error(verbose
                    ? chalk.red(err.stack)
                    : chalk.red.bold(err.message)
                );

                process.exit(1);
            });
    });*/

}
コード例 #5
0
ファイル: display.test.js プロジェクト: asprouse/serverless
  it('should display general service info', () => {
    let expectedMessage = '';

    expectedMessage += `${chalk.yellow.underline('Service Information')}\n`;
    expectedMessage += `${chalk.yellow('service:')} my-first\n`;
    expectedMessage += `${chalk.yellow('stage:')} dev\n`;
    expectedMessage += `${chalk.yellow('region:')} eu-west-1`;
    expectedMessage += `\n${chalk.yellow('api keys:')}`;
    expectedMessage += '\n  None';
    expectedMessage += `\n${chalk.yellow('endpoints:')}`;
    expectedMessage += '\n  None';
    expectedMessage += `\n${chalk.yellow('functions:')}`;
    expectedMessage += '\n  None';

    const message = awsInfo.display();
    expect(consoleLogStub.calledOnce).to.equal(true);
    expect(message).to.equal(expectedMessage);
  });
コード例 #6
0
ファイル: config.js プロジェクト: ESS-LLP/frappe
function get_rollup_options_for_css(output_file, input_files) {
	const output_path = path.resolve(assets_path, output_file);
	const minimize_css = output_path.startsWith('css/') && production;

	const plugins = [
		// enables array of inputs
		multi_entry(),
		// less -> css
		postcss({
			extract: output_path,
			use: [['less', {
				// import other less/css files starting from these folders
				paths: [
					path.resolve(get_public_path('frappe'), 'less')
				]
			}], 'sass'],
			include: [
				path.resolve(bench_path, '**/*.less'),
				path.resolve(bench_path, '**/*.scss'),
				path.resolve(bench_path, '**/*.css')
			],
			minimize: minimize_css
		})
	];

	return {
		inputOptions: {
			input: input_files,
			plugins: plugins,
			onwarn(warning) {
				// skip warnings
				if (['EMPTY_BUNDLE'].includes(warning.code)) return;

				// console.warn everything else
				log(chalk.yellow.underline(warning.code), ':', warning.message);
			}
		},
		outputOptions: {
			// this file is always empty, remove it later?
			file: path.resolve(assets_path, `css/rollup.manifest.css`),
			format: 'cjs'
		}
	};
}
コード例 #7
0
ファイル: CLI.js プロジェクト: Exodia/serverless
                (secondLevelCommandObject, secondLevelCommand) => {
                  if (secondLevelCommand === commands[1]) {
                    if (secondLevelCommandObject.lifecycleEvents) {
                      // print the name of the plugin
                      this.consoleLog(chalk.yellow.underline(`Plugin: ${plugin.constructor.name}`));
                      // print the command with the corresponding usage
                      const commandsDots = _.repeat('.', dotsLength - secondLevelCommand.length);
                      const commandsUsage = secondLevelCommandObject.usage;
                      this.consoleLog(`${chalk
                        .yellow(secondLevelCommand)} ${chalk
                        .dim(commandsDots)} ${commandsUsage}`);
                      // print all options
                      _.forEach(secondLevelCommandObject.options, (optionsObject, option) => {
                        let optionsDots = _.repeat('.', dotsLength - option.length);
                        const optionsUsage = optionsObject.usage;

                        if (optionsObject.required) {
                          optionsDots = optionsDots.slice(0, optionsDots.length - 17);
                        } else {
                          optionsDots = optionsDots.slice(0, optionsDots.length - 7);
                        }
                        if (optionsObject.shortcut) {
                          optionsDots = optionsDots.slice(0, optionsDots.length - 5);
                        }

                        const optionInfo = `    --${option}`;
                        let shortcutInfo = '';
                        let requiredInfo = '';
                        if (optionsObject.shortcut) {
                          shortcutInfo = ` / -${optionsObject.shortcut}`;
                        }
                        if (optionsObject.required) {
                          requiredInfo = ' (required)';
                        }

                        const thingsToLog = `${optionInfo}${shortcutInfo}${requiredInfo} ${
                          chalk.dim(optionsDots)} ${optionsUsage}`;
                        this.consoleLog(chalk.yellow(thingsToLog));
                      });
                    }
                  }
                });
コード例 #8
0
ファイル: display.test.js プロジェクト: asprouse/serverless
  it('should display API keys if given', () => {
    awsInfo.gatheredData.info.apiKeys = [{ name: 'keyOne', value: '1234' }];

    let expectedMessage = '';

    expectedMessage += `${chalk.yellow.underline('Service Information')}\n`;
    expectedMessage += `${chalk.yellow('service:')} my-first\n`;
    expectedMessage += `${chalk.yellow('stage:')} dev\n`;
    expectedMessage += `${chalk.yellow('region:')} eu-west-1`;
    expectedMessage += `\n${chalk.yellow('api keys:')}`;
    expectedMessage += '\n  keyOne: 1234';
    expectedMessage += `\n${chalk.yellow('endpoints:')}`;
    expectedMessage += '\n  None';
    expectedMessage += `\n${chalk.yellow('functions:')}`;
    expectedMessage += '\n  None';

    const message = awsInfo.display();
    expect(consoleLogStub.calledOnce).to.equal(true);
    expect(message).to.equal(expectedMessage);
  });
コード例 #9
0
ファイル: display.test.js プロジェクト: enanale/serverless
  it('should display a warning if 150+ resources', () => {
    let expectedMessage = '';

    expectedMessage += `${chalk.yellow.underline('Service Information')}\n`;
    expectedMessage += `${chalk.yellow('service:')} my-first\n`;
    expectedMessage += `${chalk.yellow('stage:')} dev\n`;
    expectedMessage += `${chalk.yellow('region:')} eu-west-1\n`;
    expectedMessage += `${chalk.yellow('stack:')} my-first-dev\n`;
    expectedMessage += `${chalk.yellow('resources:')} 150`;
    expectedMessage += `\n${chalk.red('WARNING:')}\n`;
    expectedMessage += '  You have 150 resources in your service.\n';
    expectedMessage += '  CloudFormation has a hard limit of 200 resources in a service.\n';
    expectedMessage += '  For advice on avoiding this limit, check out this link: http://bit.ly/2IiYB38.';

    awsInfo.gatheredData.info.resourceCount = 150;

    const message = awsInfo.displayServiceInfo();
    expect(consoleLogStub.calledOnce).to.equal(true);
    expect(message).to.equal(expectedMessage);
  });
コード例 #10
0
ファイル: print.js プロジェクト: mcalmels/tarifa
function outline(/* format, [ args ... ]*/) {
    var args = Array.prototype.slice.call(arguments, 0);
    console.log(chalk.yellow.underline(util.format.apply(this, args)));
}
コード例 #11
0
ファイル: config.js プロジェクト: ESS-LLP/frappe
function get_rollup_options_for_js(output_file, input_files) {

	const node_resolve_paths = [].concat(
		// node_modules of apps directly importable
		apps_list.map(app => path.resolve(get_app_path(app), '../node_modules')).filter(fs.existsSync),
		// import js file of any app if you provide the full path
		apps_list.map(app => path.resolve(get_app_path(app), '..')).filter(fs.existsSync)
	);

	const plugins = [
		// enables array of inputs
		multi_entry(),
		// .html -> .js
		frappe_html(),
		// ignore css imports
		ignore_css(),
		// .vue -> .js
		vue.default(),
		// ES6 -> ES5
		buble({
			objectAssign: 'Object.assign',
			transforms: {
				dangerousForOf: true,
				classes: false
			},
			exclude: [path.resolve(bench_path, '**/*.css'), path.resolve(bench_path, '**/*.less')]
		}),
		commonjs(),
		node_resolve({
			customResolveOptions: {
				paths: node_resolve_paths
			}
		}),
		production && uglify()
	];

	return {
		inputOptions: {
			input: input_files,
			plugins: plugins,
			context: 'window',
			external: ['jquery'],
			onwarn({ code, message, loc, frame }) {
				// skip warnings
				if (['EVAL', 'SOURCEMAP_BROKEN', 'NAMESPACE_CONFLICT'].includes(code)) return;

				if ('UNRESOLVED_IMPORT' === code) {
					log(chalk.yellow.underline(code), ':', message);
					const command = chalk.yellow('bench setup requirements');
					log(`Cannot find some dependencies. You may have to run "${command}" to install them.`);
					log();
					return;
				}

				if (loc) {
					log(`${loc.file} (${loc.line}:${loc.column}) ${message}`);
					if (frame) log(frame);
				} else {
					log(chalk.yellow.underline(code), ':', message);
				}
			}
		},
		outputOptions: {
			file: path.resolve(assets_path, output_file),
			format: 'iife',
			name: 'Rollup',
			globals: {
				'jquery': 'window.jQuery'
			},
			sourcemap: true
		}
	};
}
コード例 #12
0
ファイル: index.js プロジェクト: awartani/serverless
  /**
   * Display service information
   */
  display(info) {
    let message = `
${chalk.yellow.underline('Service Information')}
${chalk.yellow('service:')} ${info.service}
${chalk.yellow('stage:')} ${info.stage}
${chalk.yellow('region:')} ${info.region}`;

    // Display API Keys
    let apiKeysMessage = `\n${chalk.yellow('api keys:')}`;

    if (info.apiKeys && info.apiKeys.length > 0) {
      info.apiKeys.forEach((apiKeyInfo) => {
        apiKeysMessage = apiKeysMessage.concat(`\n  ${apiKeyInfo.name}: ${apiKeyInfo.value}`);
      });
    } else {
      apiKeysMessage = apiKeysMessage.concat(`\n  None`);
    }

    message = message.concat(`${apiKeysMessage}`);

    // Display Endpoints
    let endpointsMessage = `\n${chalk.yellow('endpoints:')}`;

    if (info.endpoint) {
      _.forEach(this.serverless.service.functions, (functionObject) => {
        functionObject.events.forEach(event => {
          if (event.http) {
            let method;
            let path;

            if (typeof event.http === 'object') {
              method = event.http.method.toUpperCase();
              path = event.http.path;
            } else if (typeof event.http === 'string') {
              method = event.http.split(' ')[0].toUpperCase();
              path = event.http.split(' ')[1];
            }

            endpointsMessage = endpointsMessage.concat(`\n  ${method} - ${info.endpoint}/${path}`);
          }
        });
      });
    } else {
      endpointsMessage = endpointsMessage.concat(`\n  None`);
    }

    message = message.concat(endpointsMessage);

    // Display Functions
    let functionsMessage = `\n${chalk.yellow('functions:')}`;

    if (info.functions && info.functions.length > 0) {
      info.functions.forEach((f) => {
        functionsMessage = functionsMessage.concat(`\n  ${f.name}: ${f.arn}`);
      });
    } else {
      functionsMessage = functionsMessage.concat(`\n  None`);
    }

    message = message.concat(`${functionsMessage}\n`);

    this.serverless.cli.consoleLog(message);
    return message;
  }
コード例 #13
0
ファイル: display.js プロジェクト: asprouse/serverless
'use strict';

const chalk = require('chalk');
const _ = require('lodash');

module.exports = {
  display() {
    const info = this.gatheredData.info;

    let message = '';

    message += `${chalk.yellow.underline('Service Information')}\n`;
    message += `${chalk.yellow('service:')} ${info.service}\n`;
    message += `${chalk.yellow('stage:')} ${info.stage}\n`;
    message += `${chalk.yellow('region:')} ${info.region}`;

    // Display API Keys
    let apiKeysMessage = `\n${chalk.yellow('api keys:')}`;

    if (info.apiKeys && info.apiKeys.length > 0) {
      info.apiKeys.forEach((apiKeyInfo) => {
        apiKeysMessage += `\n  ${apiKeyInfo.name}: ${apiKeyInfo.value}`;
      });
    } else {
      apiKeysMessage += '\n  None';
    }

    message += apiKeysMessage;

    // Display Endpoints
    let endpointsMessage = `\n${chalk.yellow('endpoints:')}`;
コード例 #14
0
ファイル: index.js プロジェクト: alexsavio/mvg-cli
process.stdout.write("\u001b[2J\u001b[0;0H");
// Print a header
console.log(
  chalk.black.bgYellow('                    MVG                     ')
);

let startStation = undefined;

if(process.argv && process.argv[2]) {
  startStation = process.argv[2];
} else {
  startStation = readlineSync.question('From what station do you want to start? : ')
}

console.log(
  chalk.yellow(`Show all trips from ${chalk.yellow.underline(startStation)}`)
);

let LiveData = [];
let LastRefresh = +new Date()

const updateData = () => {
  LoadData({
    station: startStation
  }, (err, data) => {
    if(err) throw `Error: ${err}`;
    LiveData = data;
    LastRefresh = +new Date();
  });
}
String.prototype.paddingLeft = function (paddingValue) {return String(paddingValue + this).slice(-paddingValue.length);};
コード例 #15
0
ファイル: utils.js プロジェクト: enanale/serverless
 orderedPlugins.forEach((plugin) => {
   message += `${chalk.yellow.underline(plugin.name)} - ${plugin.description}\n`;
 });
コード例 #16
0
ファイル: CLI.js プロジェクト: timporter/serverless
  generateMainHelp() {
    let platformCommands;
    let frameworkCommands;
    if (this.loadedCommands) {
      const commandKeys = Object.keys(this.loadedCommands);
      const sortedCommandKeys = _.sortBy(commandKeys);
      const partitionedCommandKeys = _.partition(sortedCommandKeys,
        (key) => this.loadedCommands[key].platform);
      platformCommands = _.fromPairs(
        _.map(partitionedCommandKeys[0], key => [key, this.loadedCommands[key]])
      );
      frameworkCommands = _.fromPairs(
        _.map(partitionedCommandKeys[1], key => [key, this.loadedCommands[key]])
      );
    }

    this.consoleLog('');

    this.consoleLog(chalk.yellow.underline('Commands'));
    this.consoleLog(chalk.dim('* You can run commands with "serverless" or the shortcut "sls"'));
    this.consoleLog(chalk.dim('* Pass "--verbose" to this command to get in-depth plugin info'));
    this.consoleLog(chalk.dim('* Pass "--no-color" to disable CLI colors'));
    this.consoleLog(chalk.dim('* Pass "--help" after any <command> for contextual help'));

    this.consoleLog('');

    this.consoleLog(chalk.yellow.underline('Framework'));
    this.consoleLog(chalk.dim('* Documentation: https://serverless.com/framework/docs/'));

    this.consoleLog('');
    if (!_.isEmpty(frameworkCommands)) {
      _.forEach(frameworkCommands, (details, command) => {
        this.displayCommandUsage(details, command);
      });
    } else {
      this.consoleLog('No commands found');
    }

    this.consoleLog('');

    this.consoleLog(chalk.yellow.underline('Platform (Beta)'));
    // eslint-disable-next-line max-len
    this.consoleLog(chalk.dim('* The Serverless Platform is currently in experimental beta. Follow the docs below to get started.'));
    this.consoleLog(chalk.dim('* Documentation: https://serverless.com/platform/docs/'));

    this.consoleLog('');

    if (!_.isEmpty(platformCommands)) {
      _.forEach(platformCommands, (details, command) => {
        this.displayCommandUsage(details, command);
      });
    } else {
      this.consoleLog('No commands found');
    }

    this.consoleLog('');

    // print all the installed plugins
    this.consoleLog(chalk.yellow.underline('Plugins'));

    if (this.loadedPlugins.length) {
      const sortedPlugins = _.sortBy(this.loadedPlugins, (plugin) => plugin.constructor.name);
      this.consoleLog(sortedPlugins.map((plugin) => plugin.constructor.name).join(', '));
    } else {
      this.consoleLog('No plugins added yet');
    }
  }
コード例 #17
0
ファイル: display.test.js プロジェクト: asprouse/serverless
  it('should display endpoints if given', () => {
    awsInfo.serverless.service.functions = {
      function1: {
        events: [
          {
            http: {
              path: '/',
              method: 'POST',
            },
          },
          {
            http: {
              path: '/both/',
              method: 'POST',
            },
          },
          {
            http: {
              path: '/both/add/',
              method: 'POST',
            },
          },
          {
            http: {
              path: 'e',
              method: 'POST',
            },
          },
        ],
      },
      function2: {
        events: [
          {
            http: 'GET function1',
          },
        ],
      },
      function3: {
        events: [
          {
            s3: 'used-to-trigger-if',
          },
        ],
      },
    };

    awsInfo.gatheredData.info.endpoint = 'ab12cd34ef.execute-api.us-east-1.amazonaws.com/dev';

    let expectedMessage = '';

    expectedMessage += `${chalk.yellow.underline('Service Information')}\n`;
    expectedMessage += `${chalk.yellow('service:')} my-first\n`;
    expectedMessage += `${chalk.yellow('stage:')} dev\n`;
    expectedMessage += `${chalk.yellow('region:')} eu-west-1`;
    expectedMessage += `\n${chalk.yellow('api keys:')}`;
    expectedMessage += '\n  None';
    expectedMessage += `\n${chalk.yellow('endpoints:')}`;
    expectedMessage += '\n  POST - ab12cd34ef.execute-api.us-east-1.amazonaws.com/dev';
    expectedMessage += '\n  POST - ab12cd34ef.execute-api.us-east-1.amazonaws.com/dev/both';
    expectedMessage += '\n  POST - ab12cd34ef.execute-api.us-east-1.amazonaws.com/dev/both/add';
    expectedMessage += '\n  POST - ab12cd34ef.execute-api.us-east-1.amazonaws.com/dev/e';
    expectedMessage += '\n  GET - ab12cd34ef.execute-api.us-east-1.amazonaws.com/dev/function1';
    expectedMessage += `\n${chalk.yellow('functions:')}`;
    expectedMessage += '\n  None';

    const message = awsInfo.display();
    expect(consoleLogStub.calledOnce).to.equal(true);
    expect(message).to.equal(expectedMessage);
  });