Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ability to run any bison dev app script #234

Merged
merged 1 commit into from
Nov 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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