Skip to content

Commit

Permalink
feat: Spawn offline process with sls offline command (#214)
Browse files Browse the repository at this point in the history
sls offline builds Azure Functions files and spawns func host start in the same shell
  sls offline start spawns func host start in the same shell
  BaseService has spawn function that spawns and waits for child process in shell (routes stdout and stderr to internal logger)
  Using mock-spawn library to mock spawned child processes
  Add invocation commands to config constants
  • Loading branch information
tbarlow12 authored and wbreza committed Jul 25, 2019
1 parent 844ffb5 commit 77553ae
Show file tree
Hide file tree
Showing 13 changed files with 182 additions and 80 deletions.
20 changes: 15 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,27 @@ $ npm i azure-functions-core-tools -g
Then, at the root of your project directory, run:

```bash
# Builds necessary function bindings files
# Builds necessary function bindings files and starts the function app
$ sls offline
# Starts the function app
$ npm start
```

The `offline` process will generate a directory for each of your functions, which will contain a file titled `function.json`. This will contain a relative reference to your handler file & exported function from that file as long as they are referenced correctly in `serverless.yml`.

The `npm start` script just runs `func host start`, but we included the `npm` script for ease of use.
After the necessary files are generated, it will start the function app from within the same shell. For HTTP functions, the local URLs will be displayed in the console when the function app is initialized.

To clean up files generated from the build, you can simply run:
To simply start the function app *without* building the files, run:

```bash
$ sls offline start
```

To build the files *without* spawning the process to start the function app, run:

```bash
$ sls offline build
```

To clean up files generated from the build, run:

```bash
sls offline cleanup
Expand Down
64 changes: 20 additions & 44 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"jest": "^24.8.0",
"jest-cli": "^24.8.0",
"mock-fs": "^4.10.0",
"mock-spawn": "^0.2.6",
"serverless": "^1.44.1",
"shx": "^0.3.2",
"typescript": "^3.4.5"
Expand Down
5 changes: 4 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ export const configConstants = {
functionAppDomain: ".azurewebsites.net",
functionsAdminApiPath: "/admin/functions/",
functionsApiPath: "/api/functions",
funcCoreTools: "func",
funcCoreToolsArgs: ["host", "start"],
funcConsoleColor: "blue",
jsonContentType: "application/json",
logInvocationsApiPath: "/azurejobs/api/functions/definitions/",
logOutputApiPath: "/azurejobs/api/log/output/",
Expand All @@ -21,4 +24,4 @@ export const configConstants = {
scmZipDeployApiPath: "/api/zipdeploy"
};

export default configConstants;
export default configConstants;
6 changes: 6 additions & 0 deletions src/models/serverless.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,9 @@ export interface ServerlessCommandMap {
export interface ServerlessAzureOptions extends Serverless.Options {
resourceGroup?: string;
}

export interface ServerlessLogOptions {
underline?: boolean;
bold?: boolean;
color?: string;
}
Loading

0 comments on commit 77553ae

Please sign in to comment.