Skip to content

Collection of useful utilities for JavaScript and Node.js.

License

Notifications You must be signed in to change notification settings

firefoxic/utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

author
GitHub Actions
Oct 30, 2024
12bcf1d · Oct 30, 2024

History

19 Commits
Aug 19, 2024
Oct 30, 2024
May 11, 2024
Apr 26, 2024
Apr 26, 2024
Apr 26, 2024
Oct 30, 2024
Oct 30, 2024
Apr 26, 2024
Aug 19, 2024
Aug 19, 2024
Oct 30, 2024
Oct 30, 2024

Repository files navigation

@firefoxic/utils

License: MIT Changelog NPM version Test Status

Collection of useful utilities for JavaScript and Node.js.

Installation

pnpm add -D @firefoxic/utils

Usage

getProjectRoot

Your action should set the REPO_NAME environment variable to the step you want. If your action works with pull requests, you should also add two lines (which are marked below with a special comment) to use the PR_NUMBER variable. For example:

jobs:
  job_name:
    runs-on: ubuntu-latest
    steps:

      # Any steps before building a project

      - name: Build project
        run: pnpm build
        env:
          REPO_NAME: ${{ github.event.repository.name }}
          PR_NUMBER: ${{ github.event.pull_request.number }}     # For PR action

      - name: Deploy
        uses: JamesIves/github-pages-deploy-action@v4
        with:
          folder: ./dist
          branch: gh-pages
          target-folder: ${{ github.event.pull_request.number }} # For PR action

Than you can get the path to the project root when deploying to GitHub Pages, for example in vite.config.js:

import { defineConfig } from "vite"
import { getProjectRoot } from "@firefoxic/utils"

export default defineConfig({
	base: `${getProjectRoot()}/`,
})

setGitHubEnvVar

Your action must accept the environment variable you pass into it from the JS. For example, you can pass the path to the distribution directory from the vite.config.js:

import { defineConfig } from "vite"

import { setGitHubEnvVar } from "@firefoxic/utils"

const PATH_TO_SRC = `./a_very_strange_path_to_source`
const PATH_TO_DIST = `./a_very_strange_path_to_dist`

setGitHubEnvVar(`PATH_TO_DIST`, PATH_TO_DIST)

export default defineConfig({
	root: PATH_TO_SRC,
	build: {
		outDir: `.${PATH_TO_DIST}`,
	},
})

Then you can use this variable in the deploy step of your action:

jobs:
  job_name:
    runs-on: ubuntu-latest
    steps:

      # Any steps before deploying a project

      - name: Deploy
        uses: JamesIves/github-pages-deploy-action@v4
        with:
          folder: ${{ env.PATH_TO_DIST }}
          branch: gh-pages

About

Collection of useful utilities for JavaScript and Node.js.

Resources

License

Stars

Watchers

Forks

Packages

No packages published