1

I'm creating a rails application from scratch using the following blog which needs me to run rails s and then yarn start in the /client folder of the application (where all the JS and React components will live).

The /client/package.json file has some scripts configured to run a server that detects changes in my react components and reloads the components automatically:

client/package.json:

{
  "name": "client",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^16.8.6",
    "react-dom": "^16.8.6",
    "react-scripts": "3.0.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "proxy": "http://localhost:3001"
}

I use a program called hivemind which is a Procfile manager and I would like both the rails server process and the yarn process to run together in the same terminal.

I'd like to do something like this in my Profile:

server: bin/rails server
react:  yarn start

The problem is that Profile lives in the root of my application and I have to change directory into client and then run yarn start.

TL;DR:

Is there an option with yarn run that you can tell it to run from another folder or read a package.json file in another folder and have it run the script in that file?

tk421
  • 5,775
  • 6
  • 23
  • 34
aarona
  • 35,986
  • 41
  • 138
  • 186

2 Answers2

1

You can write cmd arguments in Procfile

try changing react command to

react: cd client && yarn start

It will change the current directory and runs your script

Sumanth Madishetty
  • 3,425
  • 2
  • 12
  • 24
1

When you run yarn [command] yarn looks for a file locally called package.json. You can add yarn commands inside the "scripts" section of this file. In my own rails app root directory I added a "start" command that did what Sumanth's answer does but now I can just have

react: yarn start

in my Procfile.

Below is the edited version of my package.json file in my app's root path:

{
  "name": "create-repack-app",
  "version": "1.0.0",
  "scripts": {
    "build": "cd client && npm install --only=dev && npm install && npm run build && cd ..",
    "deploy": "cp -a client/build/. public/",
    "heroku-postbuild": "npm run build && npm run deploy && echo 'Client Built'",
    "start": "cd client && yarn start"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}
Joshua Pinter
  • 45,245
  • 23
  • 243
  • 245
aarona
  • 35,986
  • 41
  • 138
  • 186