UNPKG

4.44 kBJavaScriptView Raw
1#!/usr/bin/env node
2
3/* eslint-disable no-console */ // this is a CLI entrypoint
4
5'use strict'
6
7const path = require('path')
8
9const meow = require('meow')
10const updateNotifier = require('update-notifier')
11const chalk = require('chalk')
12
13const BlinkMobileIdentity = require('@blinkmobile/bm-identity')
14
15const pkg = require('../package.json')
16
17const blinkMobileIdentity = new BlinkMobileIdentity(pkg.name)
18
19updateNotifier({ pkg }).notify()
20
21const help = `
22Usage: blinkm server <command>
23
24Where command is one of:
25
26 info, serve, scope, deploy, logs, serverless
27
28Local development:
29
30 info => displays project information
31 --env <environment> => optionally sets the environment to display information for, defaults to 'dev'
32 --cwd <path> => optionally set the path to project, defaults to current working directory
33 serve => start a local development server using local API files
34 --port <port> => sets the port to use for server, defaults to 3000
35 --cwd <path> => optionally set the path to project, defaults to current working directory
36
37Initial settings:
38
39 scope => displays the current scope
40 <project> => sets the project id
41 --region <region> => optionally sets the region
42 --cwd <path> => optionally set the path to project, defaults to current working directory
43
44Deploying server side code:
45
46 The deploy command requires a login to BlinkMobile before use.
47 For help on the login and logout commands please see:
48 https://github.com/blinkmobile/identity-cli#usage
49
50 deploy => deploy the project
51 --force => deploy without confirmation
52 --env <environment> => optionally sets the environment to deploy to, defaults to 'dev'
53 --cwd <path> => optionally set the path to project, defaults to current working directory
54
55Viewing server logs:
56
57 logs => view logs for project
58 --tail => keep listening for new logs in your terminal session
59 --filter <filterPattern> => optionally set a search filter, defaults to all logs
60 --start-time <startTime> => a unit in time to start fetching logs from (ie: 2010-10-20 or 1469705761), defaults to all logs
61 --env <environment> => optionally set the environment to view logs for, defaults to 'dev'
62 --cwd <path> => optionally set the path to project, defaults to current working directory
63
64Create serverless project:
65
66 serverless => create serverless project
67 --deployment-bucket <bucket> => set the deployment S3 bucket
68 --execution-role <role> => set the execution IAM Role ARN
69 --vpc-security-groups <groups> => comma separated list of VPC Security Group identifiers
70 --vpc-subnets <subnets> => comma separated list of VPC Subnet identifiers
71 --bm-server-version <version> => server version of @blinkmobile/sever-cli that the project was created with
72 --env <environment> => optionally set the environment, defaults to 'dev'
73 --cwd <path> => optionally set the path to project, defaults to current working directory
74`
75
76const cli = meow({
77 help,
78 version: true
79}, {
80 boolean: [
81 'force',
82 'tail'
83 ],
84 default: {
85 'bmServerVersion': pkg.version,
86 'cwd': process.cwd(),
87 'force': false,
88 'env': 'dev',
89 'region': 'ap-southeast-2',
90 'tail': false
91 },
92 string: [
93 'bmServerVersion',
94 'cwd',
95 'deploymentBucket',
96 'env',
97 'executionRole',
98 'filter',
99 'out',
100 'port',
101 'region',
102 'startTime',
103 'vpcSecurityGroups',
104 'vpcSubnets'
105 ]
106})
107
108const command = cli.input[0]
109
110if (!command) {
111 cli.showHelp(0)
112}
113
114let main
115try {
116 main = require(path.join(__dirname, '..', 'commands', `${command}.js`))
117} catch (err) {
118 console.error(chalk.red(`
119Unknown command: ${command}`))
120 cli.showHelp(1)
121}
122
123if (typeof main !== 'function') {
124 console.error(chalk.red(`
125Command not implemented: ${command}`))
126 cli.showHelp(1)
127}
128
129const input = cli.input.slice(1)
130const options = {
131 blinkMobileIdentity
132}
133
134Promise.resolve()
135 .then(() => main(input, cli.flags, console, options))
136 .catch((err) => {
137 console.error(`
138There was a problem executing '${command}':
139
140${chalk.red(err)}
141
142Please fix the error and try again.
143`)
144 process.exitCode = 1
145 })