Skip to content

Commit

Permalink
feat: Added an "add-dependencies" script / generator
Browse files Browse the repository at this point in the history
  • Loading branch information
codinsonn committed Jul 10, 2024
1 parent e574d32 commit de6d001
Show file tree
Hide file tree
Showing 14 changed files with 320 additions and 33 deletions.
5 changes: 4 additions & 1 deletion features/@app-core/appConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ import { DRIVER_OPTIONS, createDriverConfig } from '@app/registries/drivers.conf
// -i- Workpacke package '@green-stack/core' expects this file to be at '/features/app-core/appConfig.ts'
// -i- Please keep it here to avoid issues

/* --- Computed Fallbacks ---------------------------------------------------------------------- */
/* --- Flags ----------------------------------------------------------------------------------- */

export const isWebLocalhost = Platform.OS === 'web' && globalThis?.location?.hostname === 'localhost'
export const isExpoWebLocal = isWebLocalhost && globalThis?.location?.port === '8081'

/* --- Computed Fallbacks ---------------------------------------------------------------------- */

export const fallbackExpoWebHost = isExpoWebLocal ? 'localhost' : ''

export const expoDebuggerHost = Constants?.expoGoConfig?.debuggerHost || Constants.manifest2?.extra?.expoGo?.debuggerHost // prettier-ignore
Expand Down
17 changes: 16 additions & 1 deletion features/@app-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,26 @@
"gql.tada": "^1.4.3",
"graphql-tag": "^2.12.6",
"graphql-type-json": "^0.3.2",
"nativewind": "^2.0.11"
"nativewind": "^2.0.11",
"react-native-svg": "^15.2.0"
},
"devDependencies": {
"@0no-co/graphqlsp": "^1.9.1",
"tailwindcss": "3.3.2",
"typescript": "5.3.3"
},
"stackConfig": {
"relatedWorkspaces": [
"@green-stack/core",
"@app/registries",
"@app/core"
],
"requiredEnvVars": [
"NEXT_PUBLIC_BASE_URL",
"NEXT_PUBLIC_BACKEND_URL",
"NEXT_PUBLIC_API_URL",
"NEXT_PUBLIC_GRAPH_URL",
"APP_SECRET"
]
}
}
2 changes: 1 addition & 1 deletion features/@app-core/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { universalTheme } = require('./tailwind.theme.cjs')
const { universalTheme } = require('./tailwind.theme.js')

/** @type {import('tailwindcss').Config} */
module.exports = {
Expand Down
2 changes: 1 addition & 1 deletion features/@app-core/tailwind.theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const universalTheme = {
// -i- Reference this theme in the tailwind.config.js files in apps/expo, apps/next, features/app-core and other package or feature folders
extend: {
colors: {
primary: colors.green,
primary: colors.gray,
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion features/@app-core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"../../packages/@green-stack-core/global.d.ts",
"appConfig.ts",
"**/*.ts",
"**/*.tsx",
"**/*.tsx"
],
"exclude": [
"node_modules"
Expand Down
134 changes: 133 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@
"build": "npx turbo run build",
"build:schema": "npx turbo run @green-stack/core#build:schema",
"check:workspaces": "npx turbo run @green-stack/core#check:workspaces",
"check:workspaces:fix": "FIX_MODE=true npx turbo run @green-stack/core#check:workspaces",
"collect:generators": "npx turbo run @green-stack/core#collect:generators",
"collect:resolvers": "npx turbo run @green-stack/core#collect:resolvers",
"collect:drivers": "npx turbo run @green-stack/core#collect:drivers",
"collect:models": "npx turbo run @db/driver#collect:models",
"link:routes": "npx turbo run @green-stack/core#link:routes",
"add:dependencies": "npx turbo run @app-expo#add-dependencies",
"add:dependencies": "npx turbo gen add-dependencies",
"add:workspace": "npx turbo gen add-workspace",
"env:local": "npx turbo run env:local",
"gen": "turbo gen",
"gen": "npx turbo gen",
"turbo:login": "npx turbo login",
"turbo:link": "npx turbo link",
"turbo:unlink": "npx turbo unlink"
Expand Down
6 changes: 6 additions & 0 deletions packages/@db-driver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,11 @@
"scripts": {
"collect:models": "npm -w @green-stack/core run run:script ../../packages/@db-driver/scripts/collect-models.ts",
"collect:drivers": "npm -w @green-stack/core run run:script ../../packages/@green-stack-core/scripts/collect-drivers.ts"
},
"stackConfig": {
"relatedWorkspaces": [
"@app/registries"
],
"requiredEnvVars": []
}
}
75 changes: 75 additions & 0 deletions packages/@green-stack-core/generators/add-dependencies.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/* eslint-disable import/no-anonymous-default-export */
import { PlopTypes } from '@turbo/gen'
import { parseWorkspaces } from '../scripts/helpers/scriptUtils'
import { execSync } from 'child_process'
import fs from 'fs'

/* --- Disclaimer ------------------------------------------------------------------------------ */

// Learn more about Turborepo Generators at:
// https://turbo.build/repo/docs/core-concepts/monorepos/code-generation

/* --- Constants ------------------------------------------------------------------------------- */

const { workspacePackages } = parseWorkspaces('./')

/** --- Dependency Installer ------------------------------------------------------------------- */
/** -i- Install Expo SDK compatible dependencies in your workspace of choice */
export const registerDependencyGenerator = (plop: PlopTypes.NodePlopAPI) => {
plop.setGenerator('add-dependencies', {
description: 'Install Expo SDK compatible dependencies in your workspace of choice',
prompts: [
{
type: 'list',
name: 'workspaceTarget',
message: 'Which workspace should we install the Expo SDK compatible versions in?',
choices: workspacePackages,
},
{
type: 'input',
name: 'dependencies',
message: "Which dependencies should we install the Expo SDK compatible versions for? (separated by spaces)",
validate: (value) => !!value,
},
],
actions: (data) => {
// Args
const { workspaceTarget } = data!
const dependencies = data!.dependencies.split(' ')
const depList = dependencies.join(' ')

// Log out the dependencies
console.log('\n', `> Installing Expo SDK compatible packages ${depList} in '${workspaceTarget}' workspace`) // prettier-ignore

// Read the @app/expo package json
const originalExpoPackageJsonFile = fs.readFileSync(`apps/expo/package.json`, 'utf-8')
const originalExpoPackageJson = JSON.parse(originalExpoPackageJsonFile) // prettier-ignore
const originalDeps = originalExpoPackageJson.dependencies

// Install the new dependencies in @app/expo
const output = execSync(`npm -w @app/expo run add-dependencies ${dependencies.join(' ')}`) // prettier-ignore
const loggableOutput = output.toString().split('\n').slice(0, 9).join('\n')
console.log(loggableOutput)

// Extract the new dependencies from the package json
const newExpoPackageJson = JSON.parse(fs.readFileSync(`apps/expo/package.json`, 'utf-8')) // prettier-ignore
const newDeps = Object.entries(newExpoPackageJson.dependencies).filter(([key]) => !originalDeps[key]) // prettier-ignore

// Restore the old package json
fs.writeFileSync(`apps/expo/package.json`, originalExpoPackageJsonFile)

// Add the new dependencies to the chosen workspace
const installStatements = newDeps.map(([key, value]) => `${key}@${value}`).join(' ')
console.log(`> Moving ${installStatements} to '${workspaceTarget}' workspace`)
execSync(`npm -w ${workspaceTarget} install ${installStatements}`)
console.log(`> Install successfull`, '\n')

// Log out the dependency list
const lsOutput = execSync(`npm ls ${depList}`)
console.log(lsOutput.toString())

// Actions
return []
},
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const WORKSPACE_FOLDER_MAPPER = {
/** --- Workspace Generator -------------------------------------------------------------------- */
/** -i- Simple generator to add a new feature or package workspace */
export const registerWorkspaceGenerator = (plop: PlopTypes.NodePlopAPI) => {
plop.setGenerator('gen-workspace', {
plop.setGenerator('add-workspace', {
description: 'Create a new feature or package workspace',
prompts: [
{
Expand Down
1 change: 1 addition & 0 deletions packages/@green-stack-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"collect:generators": "npm run run:script ./scripts/collect-generators.ts",
"collect:drivers": "npm run run:script ../../packages/@green-stack-core/scripts/collect-drivers.ts",
"link:routes": "npm run run:script ./scripts/link-routes.ts",
"add:dependencies": "npm run run:script ../../packages/@green-stack-core/scripts/add-dependencies.ts",
"test": "cd ../../ && bun test --tsconfig-override ./packages/@green-stack-core/tsconfig.json --preload ./packages/@green-stack-core/preload.test.ts --verbose"
}
}
Loading

0 comments on commit de6d001

Please sign in to comment.