Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2b754bf

Browse files
committedMay 18, 2022
feat: Make jest-preview accepts argument (use commander)
1 parent ec099c9 commit 2b754bf

12 files changed

+48
-18
lines changed
 

‎.vscode/launch.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"request": "launch",
1010
"name": "Debug Preview Server",
1111
"skipFiles": ["<node_internals>/**"],
12-
"program": "${workspaceFolder}/server/previewServer.js",
12+
"program": "${workspaceFolder}/cli/index.js",
1313
"outFiles": ["${workspaceFolder}/**/*.js"]
1414
}
1515
]

‎CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Whenever `preview.debug()` is triggered, or whenever a test fails, you will see
7777
Following are brief descriptions of the repository architecture:
7878

7979
- [src](https://github.com/nvh95/jest-preview/tree/main/src/): contains most of the code of Jest Preview such as `debug` function, `jestPreviewConfigure`, all Jest Transformations, pre-configured presets, adapters, etc.
80-
- [server](https://github.com/nvh95/jest-preview/tree/main/server/): contains Jest Preview server code, which is a web server that serves the preview page (Jest Preview Dashboard).
80+
- [cli/server](https://github.com/nvh95/jest-preview/tree/main/cli/server): contains Jest Preview server code, which is a web server that serves the preview page (Jest Preview Dashboard).
8181
- [demo](https://github.com/nvh95/jest-preview/tree/main/demo/): contains the demo app. You will work with this app most of the time when developing Jest Preview.
8282
- [config/jest](https://github.com/nvh95/jest-preview/tree/main/config/jest/): jest configuration files for the demo app.
8383
- [dist](https://github.com/nvh95/jest-preview/tree/main/dist/): Distribution code, which is bundled and processed by Rollup (previously: Vite Library Mode).

‎cli/index.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env node
2+
const { program } = require('commander');
3+
4+
program
5+
.command('config-cra')
6+
.description('Integrate Jest Preview with CRA.')
7+
.action(() => {
8+
// TODO: Execute function instead of require-ing
9+
require('./configCra');
10+
});
11+
12+
program.action(() => {
13+
// TODO: Execute function instead of require-ing
14+
require('./server/previewServer');
15+
});
16+
17+
program.parse(process.argv);
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

‎examples/create-react-app/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"eject": "react-scripts eject",
2525
"jest-preview": "jest-preview",
2626
"test:debug": "npm-run-all -p test jest-preview",
27-
"config-cra": "config-cra"
27+
"config-cra": "jest-preview config-cra"
2828
},
2929
"eslintConfig": {
3030
"extends": [

‎package-lock.json

+23-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+4-5
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@
1919
"author": "nvh95",
2020
"main": "dist/index.js",
2121
"bin": {
22-
"jest-preview": "./server/previewServer.js",
23-
"config-cra": "./cli/configCra.js"
22+
"jest-preview": "./cli/index.js"
2423
},
2524
"files": [
2625
"dist",
27-
"server",
2826
"transforms",
2927
"cli"
3028
],
@@ -42,8 +40,8 @@
4240
"publish:alpha": "npm publish --tag alpha",
4341
"publish:latest": "npm publish",
4442
"preview": "vite preview",
45-
"server": "node server/previewServer.js",
46-
"server:watch": "nodemon server/previewServer.js",
43+
"server": "node cli/index.js",
44+
"server:watch": "nodemon cli/index.js",
4745
"test:dev": "NODE_ENV=test jest --watch --no-cache App",
4846
"test:ci": "NODE_ENV=test jest",
4947
"clearCache": "rimraf node_modules/.cache/jest-preview && jest --clearCache",
@@ -57,6 +55,7 @@
5755
"dependencies": {
5856
"camelcase": "^6.3.0",
5957
"chokidar": "^3.5.3",
58+
"commander": "^9.2.0",
6059
"connect": "^3.7.0",
6160
"open": "^8.4.0",
6261
"postcss": "^8.4.12",

‎tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
"noEmit": true,
1717
"jsx": "react-jsx"
1818
},
19-
"include": ["demo", "src", "server"],
19+
"include": ["demo", "src", "cli"],
2020
"references": [{ "path": "./tsconfig.node.json" }]
2121
}

0 commit comments

Comments
 (0)
Please sign in to comment.