Skip to content

Commit

Permalink
feat: add ability to run any bison dev app script
Browse files Browse the repository at this point in the history
  • Loading branch information
kgajera committed Oct 8, 2021
1 parent eb8a8cb commit bc26543
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
19 changes: 14 additions & 5 deletions packages/create-bison-app/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,25 @@
Run the following commands in the `packages/create-bison-app` directory to start the development server:

1. Run `yarn install` to install dependencies
1. Run `yarn dev` to create a Bison app and start the server. Optionally, you may pass the following arguments:
1. Run `yarn dev` to create a Bison app and start the server. Optionally, you may pass the following arguments and options:
- `[script]` Any script in the template's [package.json](/packages/create-bison-app/template/package.json.ejs). By default, the `dev` script is run.
- `--acceptDefaults` Skip interactive prompts and use default options to create a new Bison app
- `--clean` When running `yarn dev` subsequent times, use this to reconfigure and create a new Bison app
- `--port` Specify the port to listen on. Defaults to 3001.

Example:
### Example Usages

Start the development server:

```
yarn dev --acceptDefaults --clean
```

Run the `test` script in the template's [package.json](/packages/create-bison-app/template/package.json.ejs):

```
yarn dev --acceptDefaults --clean --port=5000
yarn dev test
```

## Making Changes to the Bison Template

After you have the development server running, you can make your changes in the `packages/create-bison-app/template/` directory which will trigger the server to recompile.
After you have the development server running, you can make your changes in the `packages/create-bison-app/template/` directory which will trigger the server to recompile.
28 changes: 18 additions & 10 deletions packages/create-bison-app/scripts/createDevAppAndStartServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const fs = require("fs");
const path = require("path");
const yargs = require("yargs/yargs");
const { createApp } = require("../scripts/createApp");
const { startServer } = require("../scripts/startServer");
const { templateFolder } = require("../tasks/copyFiles");
const { cleanTemplateDestPath } = require("../utils/copyDirectoryWithTemplate");
const { copyWithTemplate } = require("../utils/copyWithTemplate");
Expand All @@ -16,7 +15,10 @@ async function init() {
const distPath = path.join(__dirname, "..", "dist");
const devAppPath = path.join(distPath, BISON_DEV_APP_NAME);
const args = process.argv.slice(2);
const { clean, port } = yargs(args).argv;
const { _, clean } = yargs(args).argv;

// Script in the template's package.json to run
const templateCommand = _.length ? _[0] : 'dev';

if (clean) {
await removeTemplateSymlinks();
Expand Down Expand Up @@ -56,15 +58,21 @@ async function init() {
}
};

// Watch template files and copy to dev app
chokidar
.watch(templateFolder, {
ignored: (path) => path.includes("node_modules"),
})
.on("add", copyFile)
.on("change", copyFile);
if (templateCommand === 'dev') {
// Watch template files and copy to dev app
chokidar
.watch(templateFolder, {
ignored: (path) => path.includes("node_modules"),
})
.on("add", copyFile)
.on("change", copyFile);
}

return startServer(devAppPath, port);
return await execa(`yarn ${templateCommand}`, {
cwd: devAppPath,
shell: true,
stdio: "inherit",
});
}

/**
Expand Down

0 comments on commit bc26543

Please sign in to comment.