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

Is it possible to run scripts defined in a theme in an app? #13915

Closed
maecapozzi opened this issue May 7, 2019 · 4 comments
Closed

Is it possible to run scripts defined in a theme in an app? #13915

maecapozzi opened this issue May 7, 2019 · 4 comments

Comments

@maecapozzi
Copy link
Contributor

Summary

I tried making a typescript theme: https://github.com/maecapozzi/gatsby-theme-typescript

I was exploring whether I could run some of the scripts I've written in the theme in another Gatsby app. Is this possible and I'm just missing something, or is it not possible?

Relevant information

I thought that it may be possible to write scripts in my theme, and have them be executable from an application's environment.

So if I wrote a script called typecheck in gatsby-theme-typescript, and I included gatsby-theme-typescript in project-a, I though I'd be able to run yarn run typescript from project-a.

Environment (if relevant)

System:
OS: macOS 10.14.4
CPU: x64 Intel(R) Core(TM) i7-4980HQ CPU @ 2.80GHz
Shell: 5.3 - /bin/zsh
Binaries:
Node: 10.9.0 - ~/.nvm/versions/node/v10.9.0/bin/node
Yarn: 1.9.4 - ~/.nvm/versions/node/v10.9.0/bin/yarn
npm: 6.2.0 - ~/.nvm/versions/node/v10.9.0/bin/npm
Browsers:
Chrome: 74.0.3729.131
Firefox: 66.0.3
Safari: 12.1
npmGlobalPackages:
gatsby-cli: 2.4.2

File contents (if changed)

gatsby-config.js:

const path = require("path");

module.exports = {
  plugins: [
    {
      resolve: "gatsby-plugin-page-creator",
      options: {
        path: path.join(__dirname, "src", "pages")
      }
    },
    {
      resolve: "gatsby-plugin-compile-es6-packages",
      options: {
        modules: ["gatsby-theme-typescript"]
      }
    },
    {
      resolve: `gatsby-plugin-typescript`
    }
  ]
};

package.json:

{
  "name": "gatsby-theme-typescript",
  "version": "0.0.4",
  "main": "index.js",
  "author": "Mae Capozzi",
  "license": "MIT",
  "keywords": [
    "gatsby-theme"
  ],
  "scripts": {
    "develop": "gatsby develop",
    "typecheck": "tsc --noEmit",
    "typecheck:watch": "tsc --noEmit --watch"
  },
  "devDependencies": {
    "gatsby": "^2.3.31",
    "react": "^16.8.6",
    "react-dom": "^16.8.6"
  },
  "peerDependencies": {
    "gatsby": "^2.3.31",
    "react": "^16.8.6",
    "react-dom": "^16.8.6",
    "typescript": "^3.4.5"
  },
  "dependencies": {
    "gatsby-plugin-compile-es6-packages": "^1.1.0",
    "gatsby-plugin-page-creator": "^2.0.12",
    "gatsby-plugin-typescript": "^2.0.13",
    "typescript": "^3.4.5"
  }
}

gatsby-node.js: N/A
gatsby-browser.js: N/A
gatsby-ssr.js: N/A

@gatsbot gatsbot bot added the stale? Issue that may be closed soon due to the original author not responding any more. label May 28, 2019
@gatsbot
Copy link

gatsbot bot commented May 28, 2019

Hiya!

This issue has gone quiet. Spooky quiet. 👻

We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here.

If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open!

As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contributefor more information about opening PRs, triaging issues, and contributing!

Thanks for being a part of the Gatsby community! 💪💜

@maecapozzi
Copy link
Contributor Author

Not stale! I still don't think this is quite clear.

@m-allanson m-allanson added not stale and removed stale? Issue that may be closed soon due to the original author not responding any more. labels May 30, 2019
@ChristopherBiscardi
Copy link
Contributor

I don't personally know of any way to call scripts defined in npm packages as if they were scripts defined in the root package.json. I think if you declared them as bins in the theme's package.json you would be able to then run yarn my-bin, but that wouldn't show them in the root package.json and such.

@wardpeet
Copy link
Contributor

wardpeet commented Sep 4, 2019

As @ChristopherBiscardi described you'll need to do something along the lines of https://blog.npmjs.org/post/118810260230/building-a-simple-command-line-tool-with-npm. Create a custom cli and add it to bin in package.json.

We're marking this issue as answered and closing it for now but please feel free to reopen this and comment if you would like to continue this discussion. We hope we managed to help and thank you for using Gatsby! 💜

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants