1 | var colors = require('colors')
|
2 | var version = require('../package.json').version
|
3 | var txain = require('txain')
|
4 | var util = require('util')
|
5 | var fs = require('fs')
|
6 | var path = require('path')
|
7 |
|
8 | exports.notImplemented = function() {
|
9 | console.log('Not implemented'.red)
|
10 | process.exit(1)
|
11 | }
|
12 |
|
13 | exports.end = function(err) {
|
14 | if (err) {
|
15 | if (err.stack) {
|
16 | console.error(err.stack.red)
|
17 | } else {
|
18 | console.error(err.message || err)
|
19 | }
|
20 | }
|
21 | }
|
22 |
|
23 | exports.requiresRegion = function() {
|
24 | var config = exports.readConfig()
|
25 | if (!config.region) {
|
26 | console.log('Please configure your AWS region with `backbeam-lambda region select`')
|
27 | process.exit(1)
|
28 | } else {
|
29 | var AWS = require('aws-sdk')
|
30 | AWS.config.update({region: config.region})
|
31 | return config.region
|
32 | }
|
33 | }
|
34 |
|
35 | exports.requiresAPI = function() {
|
36 | var config = exports.readConfig()
|
37 | if (!config.api) {
|
38 | console.log('Please configure your AWS API with `backbeam-lambda api select')
|
39 | process.exit(1)
|
40 | } else {
|
41 | return config.api
|
42 | }
|
43 | }
|
44 |
|
45 | exports.requiresStage = function() {
|
46 | var config = exports.readConfig()
|
47 | if (!config.stage) {
|
48 | console.log('Please configure your AWS stage with `backbeam-lambda stage select`')
|
49 | process.exit(1)
|
50 | } else {
|
51 | return config.stage
|
52 | }
|
53 | }
|
54 |
|
55 | exports.configFile = function() {
|
56 | return path.join(process.cwd(), 'config.json')
|
57 | }
|
58 |
|
59 | exports.readConfig = function() {
|
60 | return JSON.parse(fs.readFileSync(exports.configFile()))
|
61 | }
|
62 |
|
63 | exports.writeConfig = function(config) {
|
64 | fs.writeFileSync(exports.configFile(), JSON.stringify(config, null, 2))
|
65 | }
|
66 |
|
67 | exports.routesFile = function() {
|
68 | return path.join(process.cwd(), 'web/controllers/routes.json')
|
69 | }
|
70 |
|
71 | exports.readRoutes = function() {
|
72 | return JSON.parse(fs.readFileSync(exports.routesFile()))
|
73 | }
|
74 |
|
75 | exports.writeRoutes = function(routes) {
|
76 | fs.writeFileSync(exports.routesFile(), JSON.stringify(routes, null, 2))
|
77 | }
|