1 | # 🌹 @sharyn/cli
|
2 |
|
3 | [![npm](https://img.shields.io/npm/v/@sharyn/cli.svg)](https://www.npmjs.com/package/@sharyn/cli)
|
4 |
|
5 | This package provides CLI tasks to use as your NPM scripts.
|
6 |
|
7 | ## 🌹 Install
|
8 |
|
9 | ```bash
|
10 | npx install-peerdeps -o -Y @sharyn/cli-peer-deps && npx install-peerdeps -o -Y -d @sharyn/cli-peer-devdeps && yarn add @sharyn/cli
|
11 | ```
|
12 |
|
13 | ## 🌹 Usage
|
14 |
|
15 | In your `package.json`, add the following scripts:
|
16 |
|
17 | ```json
|
18 | "scripts": {
|
19 | "start": "sharyn dev",
|
20 | "ssr-only": "sharyn dev-ssr-only",
|
21 | "no-ssr": "sharyn dev-no-ssr",
|
22 | "local-prod": "sharyn local-prod",
|
23 | "lint": "sharyn lint",
|
24 | "test": "sharyn test",
|
25 | "stats": "sharyn stats",
|
26 | "heroku-postbuild": "sharyn build-prod"
|
27 | },
|
28 | ```
|
29 |
|
30 | And if you have Husky:
|
31 |
|
32 | ```json
|
33 | "husky": {
|
34 | "hooks": {
|
35 | "pre-commit": "sharyn lint-test"
|
36 | }
|
37 | },
|
38 | ```
|
39 |
|
40 | ## 🌹 Tasks
|
41 |
|
42 | ### `dev`
|
43 |
|
44 | Runs sequencially:
|
45 |
|
46 | - If a `docker-compose.yml` file is present:
|
47 | - `docker-compose up -d`
|
48 | - If a `knex-config.js` file is present at `src/_db/knex-config.js` or provided via `@sharyn/db`:
|
49 | - `until docker run --rm --link db:pg --net sharyn-net postgres:latest pg_isready -U postgres -h pg; do sleep 1; done`
|
50 | - `knex --knexfile [path-to-knex-config.js] --cwd . migrate:latest`
|
51 | - If a `src/_db/seeds` folder is present:
|
52 | - `knex --knexfile [path-to-knex-config.js] --cwd . seed:run`
|
53 | - `rimraf dist/js/bundle.js`
|
54 |
|
55 | Then runs in parallel:
|
56 |
|
57 | - `nodemon -w src -i dist -x "babel-node src/_server/server.js"`
|
58 | - `webpack-dev-server --mode=development --progress --hot [--config node_modules/[@]sharyn/webpack-config if [@]sharyn/webpack-config installed]`
|
59 |
|
60 | ### `dev-ssr-only`
|
61 |
|
62 | Runs sequencially:
|
63 |
|
64 | - If a `docker-compose.yml` file is present:
|
65 | - `docker-compose up -d`
|
66 | - If a `knex-config.js` file is present at `src/_db/knex-config.js` or provided via `@sharyn/db`:
|
67 | - `until docker run --rm --link db:pg --net sharyn-net postgres:latest pg_isready -U postgres -h pg; do sleep 1; done`
|
68 | - `knex --knexfile [path-to-knex-config.js] --cwd . migrate:latest`
|
69 | - If a `src/_db/seeds` folder is present:
|
70 | - `knex --knexfile [path-to-knex-config.js] --cwd . seed:run`
|
71 | - `cross-env SSR_ONLY=true nodemon -w src -i dist -x "babel-node src/_server/server.js"`
|
72 |
|
73 | ### `dev-no-ssr`
|
74 |
|
75 | Runs sequencially:
|
76 |
|
77 | - If a `docker-compose.yml` file is present:
|
78 | - `docker-compose up -d`
|
79 | - If a `knex-config.js` file is present at `src/_db/knex-config.js` or provided via `@sharyn/db`:
|
80 | - `until docker run --rm --link db:pg --net sharyn-net postgres:latest pg_isready -U postgres -h pg; do sleep 1; done`
|
81 | - `knex --knexfile [path-to-knex-config.js] --cwd . migrate:latest`
|
82 | - If a `src/_db/seeds` folder is present:
|
83 | - `knex --knexfile [path-to-knex-config.js] --cwd . seed:run`
|
84 | - `rimraf dist/js/bundle.js`
|
85 |
|
86 | Then runs in parallel:
|
87 |
|
88 | - `cross-env NO_SSR=true nodemon -w src -i dist -x "babel-node src/_server/server.js"`
|
89 | - `webpack-dev-server --mode=development --progress --hot [--config node_modules/[@]sharyn/webpack-config if [@]sharyn/webpack-config installed]`
|
90 |
|
91 | ### `local-prod`
|
92 |
|
93 | Runs sequencially:
|
94 |
|
95 | - If a `docker-compose.yml` file is present:
|
96 | - `docker-compose up -d`
|
97 | - If a `knex-config.js` file is present at `src/_db/knex-config.js` or provided via `@sharyn/db`:
|
98 | - `until docker run --rm --link db:pg --net sharyn-net postgres:latest pg_isready -U postgres -h pg; do sleep 1; done`
|
99 | - `knex --knexfile [path-to-knex-config.js] --cwd . migrate:latest`
|
100 | - If a `src/_db/seeds` folder is present:
|
101 | - `knex --knexfile [path-to-knex-config.js] --cwd . seed:run`
|
102 | - `rimraf lib dist/js/bundle.js`
|
103 | - `cross-env NODE_ENV=production webpack --mode=production --progress [--config node_modules/[@]sharyn/webpack-config if [@]sharyn/webpack-config installed]`
|
104 | - `babel src -d lib`
|
105 | - If a `Procfile` file is present:
|
106 | - `cross-env NODE_ENV=production heroku local`
|
107 | - If not:
|
108 | - `node lib/_server/server.js`
|
109 |
|
110 | ### `build-prod`
|
111 |
|
112 | Runs sequencially:
|
113 |
|
114 | - `rimraf lib dist/js/bundle.js`
|
115 | - `cross-env NODE_ENV=production webpack --mode=production --progress [--config node_modules/[@]sharyn/webpack-config if [@]sharyn/webpack-config installed]`
|
116 | - `babel src -d lib`
|
117 |
|
118 | ### `migrate-db`
|
119 |
|
120 | Runs `knex --knexfile [path-to-knex-config.js] --cwd . migrate:latest`
|
121 |
|
122 | With `[path-to-knex-config.js]` being `src/_db/knex-config.js` or the one provided by `@sharyn/db`
|
123 |
|
124 | Useful for the `release` command in Heroku's `Procfile` or on its own during local development.
|
125 |
|
126 | ### `lint`
|
127 |
|
128 | Runs sequencially:
|
129 |
|
130 | - `eslint src`
|
131 | - `flow`
|
132 |
|
133 | ### `test`
|
134 |
|
135 | Runs sequencially:
|
136 |
|
137 | - If a `docker-compose.yml` file is present:
|
138 | - If a Docker process is found matching the `db-test` name:
|
139 | - `docker rm -f [db-test-id]`
|
140 | - `docker-compose up -d db-test`
|
141 | - If a `knex-config.js` file is present at `src/_db/knex-config.js` or provided via `@sharyn/db`:
|
142 | - `until docker run --rm --link db-test:pg --net sharyn-net postgres:latest pg_isready -U postgres -h pg; do sleep 1; done`
|
143 | - `cross-env NODE_ENV=test knex --knexfile [path-to-knex-config.js] --cwd . migrate:latest`
|
144 | - `jest --testMatch **/*.unit.test.js [--globalSetup ./src/_testing/global-setup.js --globalTeardown ./src/_testing/global-teardown.js if these files exist]`
|
145 | - `cross-env NODE_ENV=production webpack --mode=production --progress [--config node_modules/[@]sharyn/webpack-config if [@]sharyn/webpack-config installed]`
|
146 | - `jest --preset jest-puppeteer --testMatch **/*.e2e.test.js --runInBand [--globalSetup ./src/_testing/global-setup.js --globalTeardown ./src/_testing/global-teardown.js if these files exist]`
|
147 |
|
148 | ### `lint-test`
|
149 |
|
150 | Runs sequencially:
|
151 |
|
152 | - `eslint src`
|
153 | - `flow`
|
154 | - If a `docker-compose.yml` file is present:
|
155 | - If a Docker process is found matching the `db-test` name:
|
156 | - `docker rm -f [db-test-id]`
|
157 | - `docker-compose up -d db-test`
|
158 | - If a `knex-config.js` file is present at `src/_db/knex-config.js` or provided via `@sharyn/db`:
|
159 | - `until docker run --rm --link db-test:pg --net sharyn-net postgres:latest pg_isready -U postgres -h pg; do sleep 1; done`
|
160 | - `cross-env NODE_ENV=test knex --knexfile [path-to-knex-config.js] --cwd . migrate:latest`
|
161 | - `jest --testMatch **/*.unit.test.js [--globalSetup ./src/_testing/global-setup.js --globalTeardown ./src/_testing/global-teardown.js if these files exist]`
|
162 | - `cross-env NODE_ENV=production webpack --mode=production --progress [--config node_modules/[@]sharyn/webpack-config if [@]sharyn/webpack-config installed]`
|
163 | - `jest --preset jest-puppeteer --testMatch **/*.e2e.test.js --runInBand [--globalSetup ./src/_testing/global-setup.js --globalTeardown ./src/_testing/global-teardown.js if these files exist]`
|
164 |
|
165 | Useful as the `precommit` Git hook or on its own.
|
166 |
|
167 | ### `stats`
|
168 |
|
169 | - `cross-env NODE_ENV=production webpack --mode=production --progress --json [--config node_modules/[@]sharyn/webpack-config if [@]sharyn/webpack-config installed] > webpack-stats.json`
|