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 lifecycle hooks for nitric. #237

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

tjholm
Copy link
Member

@tjholm tjholm commented Mar 6, 2025

A proposal for lifecycle hooks in the nitric runtime sdks.

Happy to update the naming to whatever we like. Implementing in the node-sdk first as this will represent the reference implementation for the other SDKs.

import { Environment, EnvironmentStage } from "@nitric/sdk";

// Check if a local run
Environment.isLocalRun();

// Execute code during a local run
Environment.whenLocalRun(() => {
   // run code here
});
// Check if a build/collection (during nitric up, wording here could be updated to reflect this better
Environment.isBuild();

// Execute code during a build
Environment.whenBuild(() => {
   // run code here
});

// Check if the app is running in a deployment environment
Environment.isCloud();

// execute code only in a deployed environment
Environment.whenCloud(() => {

});

// Check if current environment is oneof
Environment.is([EnvironmentStage.Build, EnvironmentStage.LocalRun]);

// Execute code if current environment is oneof the provided stages.
Environment.when([EnvironmentStage.Build, EnvironmentStage.LocalRun], () => {

});

@tjholm
Copy link
Member Author

tjholm commented Mar 6, 2025

Will rebase on: #238 when merged

@tjholm tjholm force-pushed the feat/life-cycle-hooks branch from 8efccb1 to 6705621 Compare March 6, 2025 00:59
tjholm and others added 2 commits March 6, 2025 14:04
@tjholm tjholm requested a review from HomelessDinosaur March 6, 2025 03:05
@tjholm
Copy link
Member Author

tjholm commented Mar 6, 2025

Current usage now:

import { Lifecycle } from "@nitric/sdk"

Lifecycle.whenCollecting(() => {

});

Lifecycle.whenRunning(() => {

});

Lifecycle.isRunning();

Lifecycle.isCollecting();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants