|
1 | 1 | import { execSync } from "child_process"; |
2 | 2 |
|
| 3 | +/** |
| 4 | + * This is a custom Serverless Framework Plugin that allows you to |
| 5 | + * define and run custom scripts in your serverless.yml file, similar to npm scripts. |
| 6 | + * For more information on creating custom plugins, see the documentation: |
| 7 | + * https://www.serverless.com/framework/docs/guides/plugins/creating-plugins |
| 8 | + * |
| 9 | + * In this AI example, we need to run vite build script before deploying the website service. |
| 10 | + * So we built this quick plugin, and loaded it in the serverless.yml file. |
| 11 | + */ |
| 12 | + |
3 | 13 | class Scripts { |
4 | 14 | constructor(serverless, options, utils) { |
5 | 15 | this.serverless = serverless; |
6 | | - this.options = options; |
7 | | - this.utils = utils; |
| 16 | + this.options = options; // CLI options are passed to the plugin |
| 17 | + this.utils = utils; // Helper logging functions are passed to the plugin |
8 | 18 |
|
9 | 19 | this.commands = {}; |
10 | 20 | this.hooks = {}; |
@@ -56,12 +66,16 @@ class Scripts { |
56 | 66 | } |
57 | 67 |
|
58 | 68 | execute(command) { |
| 69 | + // By default, only show stderr in the terminal |
| 70 | + // So that you can see any build errors that may occur |
59 | 71 | let stdio = ["ignore", "ignore", "inherit"]; |
60 | 72 |
|
| 73 | + // But in verbose or debug mode, we show all output |
61 | 74 | if (this.options.verbose || this.options.debug) { |
62 | 75 | stdio = "inherit"; |
63 | 76 | } |
64 | 77 |
|
| 78 | + // Execute the command/script in a child service |
65 | 79 | execSync(command, { stdio }); |
66 | 80 | } |
67 | 81 | } |
|
0 commit comments