Skip to content

Commit

Permalink
Merge pull request #80 from vivid-planet/expose-config-type
Browse files Browse the repository at this point in the history
Expose config type
  • Loading branch information
johnnyomair authored Aug 9, 2023
2 parents 827328e + 911589a commit 58cc967
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
7 changes: 7 additions & 0 deletions .changeset/weak-pants-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@comet/dev-process-manager": minor
---

Expose config type

Can be used to type check the configuration file. See [example/dev-pm.config.js](example/dev-pm.config.js) for an example.
11 changes: 10 additions & 1 deletion example/dev-pm.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
module.exports = {
// @ts-check

/**
* Normally you would use import('@comet/dev-process-manager').Config
*
* @type {import('../lib').Config}
*/
const config = {
scripts: [
{
name: "sleep-1",
Expand All @@ -13,3 +20,5 @@ module.exports = {
},
],
};

module.exports = config;
4 changes: 2 additions & 2 deletions src/commands/start-daemon.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import colors from "colors";
import { existsSync } from "fs";
import { createServer, Server } from "net";

import { Config } from "../config.type";
import { logsDaemonCommand } from "../daemon-command/logs.daemon-command";
import { restartDaemonCommand } from "../daemon-command/restart.daemon-command";
import { Script } from "../daemon-command/script";
Expand All @@ -10,7 +11,6 @@ import { shutdownDaemonCommand } from "../daemon-command/shutdown.daemon-command
import { startDaemonCommand } from "../daemon-command/start.daemon-command";
import { statusDaemonCommand } from "../daemon-command/status.daemon-command";
import { stopDaemonCommand } from "../daemon-command/stop.daemon-command";
import { ScriptDefinition } from "../script-definition.type";
import { findConfigDir } from "../utils/find-config-dir";

export interface Daemon {
Expand All @@ -21,7 +21,7 @@ export interface Daemon {
export const startDaemon = async (): Promise<void> => {
process.chdir(findConfigDir());
const pmConfigFileName = "dev-pm.config.js";
const { scripts: scriptDefinitions }: { scripts: ScriptDefinition[] } = await import(`${process.cwd()}/${pmConfigFileName}`);
const { scripts: scriptDefinitions }: Config = await import(`${process.cwd()}/${pmConfigFileName}`);
const scripts = scriptDefinitions.map((scriptDefinition, id) => {
return new Script({ ...scriptDefinition, id });
});
Expand Down
6 changes: 6 additions & 0 deletions src/config.type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { ScriptDefinition } from "./script-definition.type";

export interface Config {
// ID is set by the daemon
scripts: Omit<ScriptDefinition, "id">[];
}
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { logs, restart, shutdown, start, status } from "./commands";
import { startDaemon } from "./commands/start-daemon.command";
import { stop } from "./commands/stop.command";

export { Config } from "./config.type";

const env = dotenv.config();
dotenvExpand.expand(env);

Expand Down

0 comments on commit 58cc967

Please sign in to comment.