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

Make GitHub token optional - deleted #267

Closed
wants to merge 8 commits into from
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ All commands are run from the root of the project, from a terminal:

### Local Development Setup

1. Run `cp .env.example .env` to create a `.env` file for environment variables. (Don’t check this in!)
2. Create a [classic GitHub access token](https://github.com/settings/tokens) with these scopes: `repo`, `read:org`, `read:user`, and `read:project`.
3. Paste the GitHub token after `.env`’s `GITHUB_TOKEN=`.

#### DDEV setup

DDEV already has all the dependencies included.
Expand All @@ -82,6 +78,17 @@ Check out the project in your favorite Node.js environment, ideally running [`nv

To generate a static copy of the site, run `npm run build`. The contents of the `dist/` folder are exactly what get [deployed to Cloudflare Pages](#build--deployment). You can preview locally by running `npm run preview` or using a tool like [`serve`](https://www.npmjs.com/package/serve).

#### GitHub Token

This step is not required if you just want to contribute a blog post to ddev.com.

Contributors, sponsors, releases and more data about DDEV is retrieved dynamically from the GitHub API. To test this, please follow these steps:

1. Run `cp .env.example .env` to create a `.env` file for environment variables. (Don’t check this in!)
2. Create a [classic GitHub access token](https://github.com/settings/tokens) with these scopes: `repo`, `read:org`, `read:user`, and `read:project`.
3. Paste the GitHub token after `.env`’s `GITHUB_TOKEN=`.

There is a local `cache/` to reduce API calls.

#### Switching from Without DDEV to with DDEV

Expand Down
28 changes: 22 additions & 6 deletions src/content/blog/working-with-vite-in-ddev.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "Working with Vite in DDEV - an introduction"
pubDate: 2023-11-08
modifiedDate: 2024-06-10
modifiedDate: 2024-24-10
summary: Working with Vite in DDEV
author: Matthias Andrasch
featureImage:
Expand Down Expand Up @@ -449,11 +449,27 @@ Example repositories:

#### Drupal

I found this module:

- https://www.drupal.org/project/vite

But I could not find more info regarding DDEV usage. Happy to update this section with a better link / suggestion!
[Andrew Morton](https://github.com/mortona42) gave some information about the current state, thanks very much!

> Vite module: [https://www.drupal.org/project/vite](https://www.drupal.org/project/vite)
>
> This uses Vite's manifest.json to map enabled Drupal library files to the compiled versions in /dist, or to the vite server in dev mode.
>
> Here is a theme I contributed, with instructions for how to set it up with DDEV in the readme files. I'm trying to detail all the configuration possibilities we might need, with defaults that should work out of the box.
>
> [https://www.drupal.org/project/unocss_starter](https://www.drupal.org/project/unocss_starter) (uses Vite)
>
<!-- textlint-disable -->
> I'm blogging about the process here: [https://www.drupalarchitect.info/projects/unocss-starter-theme](https://www.drupalarchitect.info/projects/unocss-starter-theme)
>
> There are a handful of devs working on using Vite to bundle assets multiple modules/themes in Drupal. Looks like Vite and Foxy are becoming the leading solutions.
>
> [https://www.drupal.org/project/foxy](https://www.drupal.org/project/foxy)
>
> Working POC: [https://github.com/darvanen/drupal-js](https://github.com/darvanen/drupal-js)
>
> I think we'll be seeing a lot of new things in
this area over the next year.

#### Laravel

Expand Down
37 changes: 37 additions & 0 deletions src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ dotenv.config()
const DEVELOPMENT_CACHE_DIR = 'cache'
let octokitInstance: Octokit;

// Define variable if GITHUB_TOKEN is set and not empty
const githubTokenIsSet: boolean = (() => {
if(process.env.hasOwnProperty('GITHUB_TOKEN') === false || process.env.GITHUB_TOKEN === ''){
// add warning for production builds
if(import.meta.env.MODE === 'production'){
console.warn('GITHUB_TOKEN not set or empty. You can ignore this warning for local development.');
}
return false;
}
return true;
})();

/**
* Returns an instance of Octokit, which uses the `GITHUB_TOKEN` environment
* variable for authentication.
Expand Down Expand Up @@ -56,6 +68,11 @@ export function getCategoryUrl(name: string) {
* @returns response data
*/
export async function getSponsors() {

if(!githubTokenIsSet){
return [];
}

const cacheFilename = 'sponsors.json'
const cachedData = getCache(cacheFilename);

Expand Down Expand Up @@ -121,6 +138,11 @@ export async function getSponsors() {
* @returns response data
*/
export async function getContributors(includeAnonymous = false) {

if(!githubTokenIsSet){
return [];
}

const cacheFilename = 'contributors.json'
const cachedData = getCache(cacheFilename);

Expand Down Expand Up @@ -155,6 +177,11 @@ export async function getContributors(includeAnonymous = false) {
* @returns response data
*/
export async function getRepoDetails(name: string) {

if(!githubTokenIsSet){
return [];
}

const slug = name.replace('/', '-')
const cacheFilename = `repository-${slug}.json`;
const cachedData = getCache(cacheFilename);
Expand All @@ -178,6 +205,11 @@ export async function getRepoDetails(name: string) {
* @returns tag name
*/
export async function getLatestReleaseVersion(stable = true) {

if(!githubTokenIsSet){
return [];
}

let data = await getReleases()

if (stable) {
Expand All @@ -190,6 +222,11 @@ export async function getLatestReleaseVersion(stable = true) {
}

export async function getReleases() {

if(!githubTokenIsSet){
return [];
}

const cacheFilename = 'releases.json'
const cachedData = getCache(cacheFilename);

Expand Down