1.5.11 ā€¢ Published 5 years ago

create-prisma-app v1.5.11

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

Create Prisma App

āœØ Setup environments sophisticated Prisma back end in just one command!

Important

āš ļø Breaking change in Prisma v1.28 and this template v1.5.0 + is intended to accommodate the change

Installation

npm i -g create-prisma-app
create-prisma-app MyPrismaApp

OR

npx create-prisma-app MyPrismaApp

šŸ If your docker unable to run this package then you may need Docker v18.06 +.

Quick Start

Dev Environment Quick Start

start:

npm run dev-setup

ā˜€ļø It is ok to always use dev-setup to start dev

shut down:

npm run dev-down

then Ctrl + C to terminate Node in terminal

Test Environment Quick Start

start:

npm run test-setup # for 1st time only (run this again for different docker file setting)
npm run test-up #āš” for 2nd time and above(do not run test-up soon after test-setup, it is unnecessary)

shut down:

npm run test-down

šŸš© test-start, test-deploy and test-schema automatically run in container and doesn't work outside the of the container(remember unlike dev environment, test and prod Node is running in container)

Prod Environment Quick Start

Prod is very similar to test, so the instructions also similar:

start:

npm run prod-setup # 1st time only (run this again for different docker file setting)
npm run prod-up # āš”ļø for 2nd time and above(do not run prod-up soon after prod-setup, it is unnecessary)

shut down:

npm run prod-down

šŸš© prod start, prod-deploy and prod-schema automatically run in container and doesn't work outside the of the container(remember unlike dev environment, test and prod Node is running in container)

Jest Environment Quick Start

  1. in ./.config/jest.env, change the value of PRISMA_ENDPOINT to match dev or test.

šŸ  Jest run on Prisma endpoint not Node endpoint

āš ļø important: do not run jest on production because jest delete database in the beginning of run, that is why there is no jest-prod config file!

Configuration

Most configurations are exposed already exposed in ./.config folder, read comments in dev.env to have better understanding what each variable does.

Scripts

The scripts may look overwhelming, but it is actually repetitive in pattern, what the scripts do are also very straight forward, they are like the scripts that you frequently use, just more organized and accessible.

Troubleshooting

Unexpected End of JSON Input During Installation

šŸ‘æ npm cache corrupted
šŸ˜‡ run npm cache clean --force to fix it

"Project default\$default Not Found"

šŸ‘æ mostly when running test or prod, this is due to Node server is ready before Prisma server and fail to deploy schema, this happen if your server is sleeping and prisma need time to establish connection.
šŸ˜‡ the solution is easy, increase delay of wait-prisma scripts in package.json.
šŸ‘· will add checking mechanism in future.

"Internal Server Error"

šŸ‘æ mostly when running test or prod, could be many reason, most possible reason is Node unable to connect with Prima due to .env variables misconfiguration.
šŸ˜‡ if your config is correct but has this error, wait a while and keep trying; if not check your .env variables configuration.

Graphql Playground Shows Blank Page After dev or test Setup

šŸ‘æ Node fail or haven't establish the connection with Prisma server
šŸ˜‡ the solution is easy, just wait and refresh the page or increase delay of wait-prisma npm scripts in package.json.

Port is Already Allocated Error

šŸ‘æ it is most likely you have another program like postgres installed and running with 5433 port.
šŸ˜‡ change PSQL_PORT variable in ./.config/xxx.env, xxx is dev or test or prod.

Architecture

This package is aim to get you up and running in different environments, in general there are 4 types of environments:

  1. dev(dev.env) Ideally dev is an environment that allow us to code and experimenting our thing even without internet. It is an environment that we can carry on planning and creating without relying third party service such as server on AWS, instead we should have a server that we can toy with anytime in our computer.

  2. prod(prod.env) Prod is the environment where we want to treat our data, data model and configuration delicately. Imagine if we accidentally deploy our dev data and configuration into prod, that would be hell unleashed.For some cases we can mix up test and dev environments and that is tolerable, but production environment must has it own space.

  3. test(test.env) Ideally the test environment should be as similar as prod environment as possible so that we can expect the same behavior when we deploy it, do not confuse this with jest.

  4. jest(jest.env) Do not confuse this with test, jest has its own environment variables that points to test environment from outside world, in short jest are interaction from real world upon this dev, test and ci environment.

To summarize it:

EnvironmentPrismaNodePostgresJustification
devdockerized locallylocaldockerized locallyfor fast development
proddockerized in prod server 1dockerized in prod server 1prod server 2for easy deployment in production
testdockerized locally or in test server 1dockerized locally or in test server 1test server 2to mimic production environment with free to torture database
jestnonenonenoneto interact with dev/test/ci environment

āœˆļø You can always change the architecure, simply modify the docker(compose) files and change the variables in ./.config accordingly

Docker refuses to add a key that allows user chooses to run a service or not even though it is a highly requested feature.

The implication is we are unable to share the same docker-compose file for all modes, especially dev mode because dev mode run Node outside docker.

I have no choice but to create a separated docker yml file for dev. Yes we can use --scale service=0 command, but that doesn't stop docker wasting time building the service and building Node every time user run dev mode.

Prerequisite

Knowledge:

  1. Graphql
  2. Prisma

Tools:

  1. Docker
  2. Kitematic(optional): Docker GUI šŸš²
  3. DBeaver(optional): SQL database GUI šŸš²

šŸš² With or without Kitematic and DBeaver, we still able to get the app running, but I recommend them because they are very useful especially DBeaver.

Extra Benefits

  1. commit hooked prettier styling
  2. Babel env preset, write ES6ļøāƒ£ right away!
  3. basic data model
  4. basic schema
  5. basic api call
  6. basic Jest test
  7. basic CircleCI configuration file
  8. basic JWT authentication
  9. modularity, replace any dependency you want.

Documentation

The scripts is extended to 5 parts:

  • basic
  • jest
  • prod
  • test
  • dev
  1. prod, test and dev are derived from basic script.
  2. The scripts are mostly structured in the same way: prod and test scripts have 99% of similarity.
  3. The 1% is test-setup will open server endpoint in browser when it is ready.
  4. test will fails to open the browser in Ubuntu but it does no harm while prod-setup will not.
  5. dev has slightly more scripts and much loosely structured so that you can develope with more flexible scripts.
  6. jest only has 2 scripts.

Please study ./config/dev.env for better understanding on how each environment variable works.

Here is doc for scripts:

scriptcommanddescription
šŸ“‹ basicbasic
startnpm run build && Node dist/index.jsbuild the code and start Node
buildbabel src --out-dir dist --copy-filesbuild the code with babel
dbuilddocker-compose buildbuild the containers
rebuilddocker-compose build --no-cachebuild the containers with no cache
updocker-compose up -dorchestrate containers
taildocker-compose uporchestrate containers with tail logs
deployPrisma deploydeploy Prisma data model to database
schemaPrisma generategenerate schema from Prisma for Node
tokenPrisma tokengenerate Prisma authentication token
volumecross-env-shell \"docker volume create \$DOCKER_VOLUME\"create docker volume
downdocker-compose down --remove-orphansshut down containers
playgroundcross-env-shell \"./Node_modules/.bin/opn \$Node_ENDPOINT\"open Node endpoint in browser (will fails in Ubuntu but do no harm)
wait-Prismacross-env-shell \"sleep 20\"delay for 20 seconds
jestjest
jest-devenv-cmd ./.config/jest_dev.env jest --watch --runInBandbuild, watch for the change and run the jest in sequence with dev config
jest-testenv-cmd ./.config/jest_test.env jest --runInBandbuild and run the jest in sequence with test config
jest-cienv-cmd ./.config/jest_ci.env jest --runInBandbuild and run the jest in sequence
šŸ“‹ prodprod
prod-setupnpm run prod-schema && npm run prod-volume && npm run prod-build && npm run prod-up && Node ./terminalString/mprod.jsgenerate schema, create docker volume, build and orchestrate containers
prod-start šŸš©npm run wait-Prisma && npm run prod-deploy && env-cmd ./.config/prod.env npm run startdeploy and generate schema, start Node
prod-deploy šŸš©env-cmd ./.config/prod.env npm run deploy && npm run prod-schemadeploy and generate schema
prod-schema šŸš©env-cmd ./.config/prod.env npm run schemagenerate Prisma schema
prod-tokenenv-cmd ./.config/prod.env npm run tokengenerate Prisma token
prod-volumeenv-cmd ./.config/prod.env npm run volumecreate docker volume
prod-buildenv-cmd ./.config/prod.env npm run dbuildbuild containers
prod-rebuildenv-cmd ./.config/prod.env npm run rebuildbuild containers with no cache
prod-upenv-cmd ./.config/prod.env npm run uporchestrate containers
prod-tailenv-cmd ./.config/prod.env npm run tailorchestrate containers with tail logs
prod-downenv-cmd ./.config/prod.env npm run downshut down containers
šŸ“‹ testtest
test-setupnpm run test-schema && npm run test-volume && npm run test-build && npm run test-up && Node ./terminalString/mtest.js && npm run wait-Prisma && env-cmd ./.config/test.env npm rungenerate schema, create docker volume, build, orchestrate containers and open Node endpoint in browser(if possible)
test-start šŸš©npm run wait-Prisma && npm run test-deploy && env-cmd ./.config/test.env npm run startdeploy and generate schema, start Node
test-deploy šŸš©env-cmd ./.config/test.env npm run deploy && npm run test-schemadeploy and generate schema
test-schema šŸš©env-cmd ./.config/test.env npm run schemagenerate Prisma schema
test-tokenenv-cmd ./.config/test.env npm run tokengenerate Prisma token
test-volumeenv-cmd ./.config/test.env npm run volumecreate docker volume
test-buildenv-cmd ./.config/test.env npm run dbuildbuild containers
test-rebuildenv-cmd ./.config/test.env npm run rebuildbuild containers with no cache
test-upenv-cmd ./.config/test.env npm run uporchestrate containers
test-tailenv-cmd ./.config/test.env npm run tailorchestrate containers with tail logs
test-downenv-cmd ./.config/test.env npm run downshut down containers
šŸ“‹ devdevdev
dev-setupnpm run dev-volume && npm run dev-build && npm run dev-up && cross-env-shell \"sleep 3\" && npm run dev-deploy && concurrently \"npm run dev-start\" \"npm run dev-browse\"create volume, build container, orchestrate containers and open Node endpoint in browser
dev-readyconcurrently \"npm run dev-up\" \"npm run dev-start\" \"npm run dev-browse\"orchestrate containers, start Node and open browser in parallel
dev-startenv-cmd ./.config/dev.env npm startstart Node
dev-browsecross-env-shell \"sleep 3\" && Node ./terminalString/mdev.js && cross-env-shell \"sleep 5\" && env-cmd ./.config/dev.env npm run playgroundopen Node endpoint in browser
dev-Nodemonenv-cmd ./.config/dev.env Nodemon src/index.js --ext js,graphql --exec babel-Nodestart Node in Nodemon with babel, watch js and graphql file change
dev-deployenv-cmd ./.config/dev.env npm run deploy && npm run dev-schemadeploy and generate schema
dev-schemaenv-cmd ./.config/dev.env npm run schemagenerate Prisma schema
dev-tokenenv-cmd ./.config/dev.env npm run tokengenerate Prisma token
dev-volumeenv-cmd ./.config/dev.env npm run volumecreate docker volume
dev-buildenv-cmd ./.config/dev.env docker-compose -f ./docker-compose-dev.yml buildbuild containers
dev-rebuildenv-cmd ./.config/dev.env docker-compose -f ./docker-compose-dev.yml build --no-cachebuild containers with no cache
dev-upenv-cmd ./.config/dev.env docker-compose -f ./docker-compose-dev.yml up -dorchestrate containers
dev-tailenv-cmd ./.config/dev.env docker-compose -f ./docker-compose-dev.yml uporchestrate containers with tail logs
dev-downenv-cmd ./.config/dev.env npm run downshut down containers

šŸš© Automatically run in container and doesn't work outside the of the container(remember unlike dev environment, Test and Prod Node are running in container)

Tip & Star

šŸ˜„ Consider star or tipping me if you found this template helpful, and wish to see more rapid development.

BTC: 1KbpCqzZ6FSfoi1R9obGEVXRHpbJMQQCda
ETH: 0x4DfD790D98F8f3E013E70da51E70B60b953c7e61
LTC: LXVYLpe9zQ48aGCuBqjLW8xxaBfVBauXST
XRP: rnftUYRq91TBL6ceK5y3UnFiYBLQMFkZn6
ADA: Ae2tdPwUPEYxapgJjg9qpg1RhyfBq5vx6ZdWXafNqZihg4rCD7baXhMf7CH
BNB: 0x4DfD790D98F8f3E013E70da51E70B60b953c7e61
PayPal

Acknowledgement

This project is inspired by the authors of existing related project

MISC

šŸŒŸ this project generator was bootstrapped with create-npm-create packageception

1.5.11

5 years ago

1.5.9

5 years ago

1.5.8

5 years ago

1.5.7

5 years ago

1.5.6

5 years ago

1.5.5

5 years ago

1.5.4

5 years ago

1.5.3

5 years ago

1.5.2

5 years ago

1.5.1

5 years ago

1.5.0

5 years ago

1.4.2

5 years ago

1.4.1

5 years ago

1.4.0

5 years ago

1.3.9

5 years ago

1.3.8

5 years ago

1.3.7

5 years ago

1.3.6

5 years ago

1.3.5

5 years ago

1.3.4

5 years ago

1.3.3

5 years ago

1.3.2

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.4

5 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.15

5 years ago

1.1.13

5 years ago

1.1.12

5 years ago

1.1.11

5 years ago

1.1.10

5 years ago

1.1.9

5 years ago

1.1.8

5 years ago

1.1.7

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.2

5 years ago

1.0.0

5 years ago