0

I would like to have repository with default NPM modules and its configs for all future NPM projects. For now the configs consists of tsconfig.json, tslint.json, .prettierrc. The goal is to have a simple way for creating new project with custom defaults and also have possibility of changing configs for all of these projects from one place.

I tried to create my own NPM module with package.json containing dependencies I want to have in all my new projects and its configs in root. The problem is obvious - if I install this package into new project, modules (and configs) are scoped to my custom module and not to my newly created project.

Does anyone has any idea how to deal with this?

cJayy
  • 11
  • 4

1 Answers1

0

You are basically making a boilerplate. Do develop it, I see two possible approcches:

  1. Publish the boilerplate as NPM module.
  2. Build and publish the boilerplate on your repository provider (Github, Bitbucket etc) and use it as starting project to be forked for every new project you build.

I will suggest you to follow the second approach, that's easier to achieve.

You are instead tryng to follow the first approch that's more tricky. To generate a starting project you should build a CLI (Command line interface). So you will build an NPM module that should be globally installed and that you will use with a set of commands like:

myawesomecli generate my-new-starting-project

And the myawesomecli module will generate a my-new-starting-project folder containing your boilerplate. You could optionally ask to the user for settings to be selected in an interactive session. That's what famous framework like React, Vue.js, Angular etc. are doing. You can follow this tutorial to build a CLI that generates boilerplates. Keep in mind that the inquier module is the key module for such scopes.

radar155
  • 1,796
  • 2
  • 11
  • 28
  • Thanks for an explanation. I see why is the second approach easier but since the coding standards base is about to be variable upon used frameworks in different use cases it really seems nice to create our own interactive generator. Another option came to my mind though; We are building all our apps in Docker - this means that we could create our own Docker images which could be used as a base for every project. i.e. we could extend Node docker image with NextJS (+React) and all the tools and configurations specific to this type of project. Does this seem as a good option to you? – cJayy Mar 25 '19 at 20:11
  • no it doesn't. I mean, with a Docker image, you will be up and running everytime you will use docker. But, even if you are using Docker a lot now (and you should, it is awesome), it's possible that you will stop using it in the future. In my opinion, a customized CLI would survive to deploy/hosting techonologies changes – radar155 Mar 26 '19 at 12:20
  • That's actually pretty good point. I didn't think of that. Thanks! :) – cJayy Mar 27 '19 at 12:59