NuxtN
Nuxt11mo ago
54 replies
Luca

GSAP Nuxt Module - Packages Installation Problem

Hello!
I recently created the GSAP module that you can find here: https://github.com/LucaArgentieri/gsap-nuxt-module

Now I would like to add the possibility of using the gsap club plugins for all users who have purchased the license and have the token.

The difficulty I’m having is to install a different package according to the user’s role, here the documentation: https://gsap.com/docs/v3/Installation/guides/Netlify


What I’ve done is this:
Created .npmrc:
always-auth=true
@gsap:registry=https://npm.greensock.com
//npm.greensock.com/:_authToken=${GSAP_TOKEN}


I have added the possibility to choose your role of gsap
role?: ('member' | 'plus' | 'premium' | 'business')


And I created a function to install a different package depending on the role :
import { fileURLToPath } from 'node:url'
import fs from 'node:fs'
import path from 'node:path'
import { execSync } from 'node:child_process'

export const installGsap = (role: undefined) => {
  const moduleRoot = fileURLToPath(new URL('../', import.meta.url))

  const packageJsonPath = path.join(moduleRoot, 'package.json')

  const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'))
  const newGsapVersion = role === undefined ? 'gsap@latest' : `gsap@npm:@gsap/${role}`

  if (packageJson.dependencies?.gsap !== newGsapVersion) {
    execSync(`npm install ${newGsapVersion}`, { cwd: moduleRoot, stdio: 'inherit' })
  }
}

Is there a better way to manage this installation?

Branch: https://github.com/LucaArgentieri/gsap-nuxt-module/tree/fe/gsap-club-plugins
GitHub
GSAP integration for Nuxt. Contribute to LucaArgentieri/gsap-nuxt-module development by creating an account on GitHub.
GitHub - LucaArgentieri/gsap-nuxt-module: GSAP integration for Nuxt.
GitHub
GSAP integration for Nuxt. Contribute to LucaArgentieri/gsap-nuxt-module development by creating an account on GitHub.
GitHub - LucaArgentieri/gsap-nuxt-module at fe/gsap-club-plugins
Was this page helpful?