npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@taqueria/toolkit

v0.65.0

Published

A TypeScript library for NodeJS to work with Taqueria projects

Downloads

747

Readme

Taqueria Toolkit

A client-side package to load Taqueria config and state into a (d)App.

Quickstart

  1. Initialize a taqueria project: taq init
  2. Create an app in ./app.
  3. In app, install the toolkit: npm i -S @taqueria/toolkit.
  4. In your app, use the toolkit to get an address of an originated contract:
import {loadFromEnv, getAliasAddress} from "@taqueria/toolkit"
const config = await loadFromEnv(process.env)
const address = getAliasAddress(config, "hello-tacos")
  1. Build the app with the needed environment variables: withTaq --projectdir ./ npm run app:build.

This will populate environment variables needed by the toolkit

Using with create-react-app

  1. Initialize a taqueria project: taq init
  2. Create a react app: npx create-react-app ./app --template typescript
  3. In ./app/.env, add SKIP_PREFLIGHT_CHECK=true.
  4. In ./app, run: npm install
  5. In ./app, run: npm i -S @taqueria/toolkit.
  6. In ./app, edit index.tsx to pass environment variables to the App component:
<App env={process.env}/>
  1. In ./app, edit App.tsx to include the toolkit:
import {loadFromEnv, getAliasAddress} from "@taqueria/toolkit"

type AppProps = {
  env: Record<string, string|undefined>
}

function App(props: AppProps) {
    const [contractAddress, setContractAddress] = useState<string|undefined>(undefined)

    useEffect(async ()=>{
        const config = await loadFromEnv(props.env)
        // "hello-tacos" is the name of the contract
        setContractAddress(getAliasAddress(config, "hello-tacos"))
    })
}
  1. Adjust the build and start scripts in package.json to use the toolkit to populate the necessary environment variables:
"scripts": {
    "start": "withTaq --projectDir ../ --prefix REACT_APP_ react-scripts start",
    "build": "withTaq --projectDir ../ --prefix REACT_APP_ react-scripts build",
}

How it works

The withTaq command populates the environment with variables needed by the toolkit. These variables will include your Taqueria & environment configuration:

TAQ_CONFIG=[base64 encoded data]
TAQ_CONFIG_LOCAL_DEVELOPMENT=[base64 encoded data]
TAQ_CONFIG_LOCAL_TESTING=[base64 encoded data]

An environment variable will exist for each environment configuration file that exists in your Taqueria project.

These environment variables are then consumed in your app using loadFromEnv:

import loadFromEnv from `@taqueria/toolkit`
const config = await loadFromEnv(process.env)

Rather than having to set these environment variables manually, you can wrap a command using withTaq:

withTaq --projectDir ../ npm run build

The above command is an example of how you would populate the environment variables needed when running npm run build.

Advanced Usage:

In some cases and app frameworks, environment variables need special prefixes to be included in your app's environment context. For instance, apps created using create-react-app will only have access to environment variables with the REACT_APP_ prefix. To handle this, two modifications are required:

Adjust withTaq to use the prefix

withTaq --projectDir ../ --prefix "REACT_APP_" npm run build

Adjust the loadFromEnv call to use the prefix

import loadFromEnv from `@taqueria/toolkit`
const config = await loadFromEnv(process.env, "REACT_APP_")