From c06df5bf1fe5f8c23e6810e2fe3256ba984e367e Mon Sep 17 00:00:00 2001 From: Daniel Barion Date: Tue, 26 Mar 2024 10:12:13 -0300 Subject: [PATCH] feat: add example command and update docs --- README.md | 1 + lib/index.mjs | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/README.md b/README.md index 1e68979..2c01a84 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,7 @@ Simply add these things to your **package.json**. All scripts (a.k.a., commands) | `upload` | Upload files to gh-pages branch | | `version` | Output the version of `@pixi/extension-scripts` | | `watch` | Watch the code in development mode, updates on changes | +| `example` | Copy `dist` folder with the files generated on build step into `examples` folder and start http-server | ### Chaining diff --git a/lib/index.mjs b/lib/index.mjs index 8a94856..c66272d 100755 --- a/lib/index.mjs +++ b/lib/index.mjs @@ -217,6 +217,7 @@ const Command = { Upload: 'upload', Version: 'version', Watch: 'watch', + Example: "example", }; /** Workflow tasks */ @@ -319,6 +320,27 @@ const runCommand = async (command, additionalArgs) => break; } case Command.Watch: bundle('-w'); break; + case Command.Example: + /** + * Copy the dist folder to the examples folder, so the files generated on build can be used on the examples. + * As this will be run on Plugin projects, the path reference will work as expected. + */ + await promises.cp( + "./dist", + "./examples/dist", + { recursive: true }, + (err) => { + if (err) { + console.error(err); + } + } + ); + + /** + * Start a local server to serve the examples + */ + await spawn("http-server", [extensionConfig.serve]); + break; default: { // eslint-disable-next-line no-console console.error(chalk.red(`${prefix} Error: Unknown command "${command}". `