1 | #!/usr/bin/env node
|
2 |
|
3 |
|
4 |
|
5 | 'use strict';
|
6 |
|
7 | const program = require('commander');
|
8 |
|
9 | const getVisitor = require('../lib/visitor').getVisitor;
|
10 | const notifier = require('../lib/update-notifier');
|
11 | const { collectOptions } = require('../lib/options');
|
12 |
|
13 | program
|
14 | .name('fun local start')
|
15 | .description(`
|
16 | Allows you to run the Function Compute applicatoin locally for quick development & testing.
|
17 | It will start a http server locally to receive requests for http triggers and apis.
|
18 | It scans all functions in template.yml. If the resource type is HTTP, it will be registered to this http server, which can be triggered by the browser or any http tools.
|
19 | For other types of functions, they will be registered as apis, which can be called by sdk in each language or directly via api.
|
20 |
|
21 | Function Compute will look up the code by CodeUri in template.yml.
|
22 | For interpreted languages, such as node, python, php, the modified code will take effect immediately without restarting the http server.
|
23 | For compiled languages such as java, we recommend you set CodeUri to the compiled or packaged location.
|
24 | Once compiled or packaged result changed, the modified code will take effect immediately without restarting the http server.`
|
25 | )
|
26 | .usage('[options] <[service/]function>')
|
27 | .option('-t, --template [template]', 'The path of fun template file.', collectOptions)
|
28 | .option('-d, --debug-port <port>', 'Specify the sandbox container starting in debug' +
|
29 | ' mode, and exposing this port on localhost')
|
30 | .option('-c, --config <ide/debugger>',
|
31 | 'Select which IDE to use when debugging and output related debug config tips for the IDE. Options:\'vscode\', \'pycharm\'')
|
32 | .option('--debugger-path <debuggerPath>', 'The path of the debugger on the host')
|
33 | .option('--debug-args <debugArgs>', 'Additional parameters that will be passed to the debugger')
|
34 | .parse(process.argv);
|
35 |
|
36 | if (program.args.length > 1) {
|
37 | console.error();
|
38 | console.error(" error: unexpected argument `%s'", program.args[1]);
|
39 | program.help();
|
40 | }
|
41 |
|
42 | notifier.notify();
|
43 |
|
44 | getVisitor().then(visitor => {
|
45 | visitor.pageview('/fun/local/start').send();
|
46 |
|
47 | require('../lib/commands/local/start')(program, program.args[0])
|
48 | .then(() => {
|
49 | visitor.event({
|
50 | ec: 'local start',
|
51 | ea: 'start',
|
52 | el: 'success',
|
53 | dp: '/fun/local/start'
|
54 | }).send();
|
55 | })
|
56 | .catch(error => {
|
57 | visitor.event({
|
58 | ec: 'local start',
|
59 | ea: 'start',
|
60 | el: 'error',
|
61 | dp: '/fun/local/start'
|
62 | }).send();
|
63 |
|
64 | require('../lib/exception-handler')(error);
|
65 | });
|
66 | });
|
67 |
|