Skip to content

Commit

Permalink
add getDevTaskRunner for loading custom dev tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
jchip committed Oct 28, 2020
1 parent 509017e commit d5ac7af
Show file tree
Hide file tree
Showing 4 changed files with 221 additions and 54 deletions.
1 change: 0 additions & 1 deletion packages/xarc-app-dev/src/config/opt2/xarc-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { BabelOptions } from "./babel-options";

export type XarcOptions = {
// configurations from env-app.ts

/**
* hostname to listen on for serving your application
*
Expand Down
33 changes: 31 additions & 2 deletions packages/xarc-app-dev/src/lib/dev-tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,40 @@ function setWebpackDev() {

export { XarcOptions } from "../config/opt2/xarc-options";

/**
* Get the dev task runner (xclap) from Electrode module's perspective.
*
* @returns the instance of xclap that's required
*/
export function getDevTaskRunner(): any {
return requireAt(process.cwd())("xclap") || require("xclap");
}

/**
* Load xarc development tasks that can be invoked using @xarc/run
*
* You can override any of the tasks here by loading your own using the same
* name with a different namespace (ie: "user").
*
* **For example:**
*
* ```js
* import { getDevTaskRunner, loadXarcDevTasks } from "@xarc/app-dev/lib/dev-tasks"
*
* const xclap = getDevTaskRunner();
*
* xclap.load("user", {
* check: xclap.exec("echo my custom check task")
* });
*
* loadXarcDevTasks();
* ```
*
* @param xrun - `@xarc/run` (or xclap) task runner. pass `null` and an
* internal version will be used.
* @param xarcOptions user provided options to configure features etc
* @returns void
*
* @returns The xclap task runner instance that was used.
*/
export function loadXarcDevTasks(xrun, xarcOptions: XarcOptions = {}) {
// lazy require modules that have effects so as to permit customization
Expand Down Expand Up @@ -1234,11 +1261,13 @@ You only need to run this if you are doing something not through the xarc tasks.
// require.resolve(`${archetype.devArchetypeName}/package.json`);
// }

xrun = xrun || requireAt(process.cwd())("xclap") || require("xclap");
xrun = xrun || getDevTaskRunner();
process.env._ELECTRODE_DEV_ = "1";
if (!process.env.hasOwnProperty("FORCE_COLOR")) {
process.env.FORCE_COLOR = "1"; // force color for chalk
}
xrun.load("electrode", makeTasks(xrun), -10);
generateBrowsersListRc();

return xrun;
}
Loading

0 comments on commit d5ac7af

Please sign in to comment.