UNPKG

1.79 kBJavaScriptView Raw
1'use strict';
2
3var merge = require('lodash.merge');
4var chalk = require('chalk');
5module.exports = {
6 addAsPrivateProps: function(target, source) {
7 Object.keys(source).forEach(function(key) {
8 target['_' + key] = source[key];
9 });
10 },
11 promptAndSaveResponse: function(generator, prompts, cb) {
12 if (generator.options['skip-prompts']) {
13 prompts.forEach(function(prompt) {
14 generator['_' + prompt.name] = (typeof prompt.default === 'function') ? prompt.default() : prompt.default;
15 });
16 cb();
17 } else {
18 generator.prompt(prompts, function(answers) {
19 Object.keys(answers).forEach(function(key) {
20 generator['_' + key] = answers[key];
21 });
22 cb();
23 });
24 }
25 },
26 makeSDKContext: function(self) {
27 return {
28 appKey: self['_' + self.developerInfoKeys.AppKey],
29 sharedSecret: self['_' + self.developerInfoKeys.SharedSecret],
30 baseUrl: self._homePod,
31 developerAccountId: self._developerAccountId,
32 developerAccount: {
33 emailAddress: self['_' + self.developerInfoKeys.AccountLogin]
34 },
35 workingApplicationKey: self._applicationKey
36 };
37 },
38 trimString: function(str) {
39 return str.trim();
40 },
41 trimAll: function(obj) {
42 return Object.keys(obj).reduce(function(result, k) {
43 result[k] = (typeof obj[k] === 'string') ? obj[k].trim() : obj[k];
44 return result;
45 }, {});
46 },
47 merge: merge,
48 remark: function(ctx, str) {
49 ctx.log(chalk.green('>> ') + str + '\n');
50 },
51 lament: function(ctx, str, e) {
52 ctx.log(chalk.bold.red(str + '\n'));
53 if (process.env.NODE_DEBUG && process.env.NODE_DEBUG.indexOf('mozu-app') !== -1) {
54 ctx.log(e && chalk.bold.red('Details: \n' + require('util').inspect(e, { depth: 4 })));
55 }
56 }
57};
\No newline at end of file