From 294e8d40a00dbdfe4e8d4d3ec6a49f7a3dc27631 Mon Sep 17 00:00:00 2001 From: Marc Cataford Date: Tue, 27 Jun 2023 13:54:34 -0400 Subject: [PATCH] feat: api reorg (#118) * feat: reorg into workspaces * build: commands update * ci: update build steps * ci: publish from dist * feat: api scaffold * chore: clean up dist --- .github/workflows/main.yml | 51 ++++- .gitignore | 1 + netlify.toml | 2 +- package.json | 25 ++- packages/api/package.json | 19 ++ packages/api/src/index.ts | 14 ++ packages/api/tsconfig.json | 10 + packages/app/package.json | 29 +++ {src => packages/app/src}/App.tsx | 0 {src => packages/app/src}/FeedsPanel.tsx | 0 {src => packages/app/src}/NavigationBar.tsx | 0 {src => packages/app/src}/SettingsPanel.tsx | 0 {src => packages/app/src}/constants.ts | 0 .../app/src}/hooks/useLocalStorage.ts | 0 .../app/src}/hooks/useNavigation.tsx | 0 .../app/src}/hooks/useRSSFeeds.ts | 0 .../app/src}/hooks/useSettings.ts | 0 {src => packages/app/src}/index.html | 0 {src => packages/app/src}/index.tsx | 0 {src => packages/app/src}/types.ts | 0 {src => packages/app/src}/utils.ts | 0 yarn.lock | 177 +++++++++++++++--- 22 files changed, 274 insertions(+), 54 deletions(-) create mode 100644 packages/api/package.json create mode 100644 packages/api/src/index.ts create mode 100644 packages/api/tsconfig.json create mode 100644 packages/app/package.json rename {src => packages/app/src}/App.tsx (100%) rename {src => packages/app/src}/FeedsPanel.tsx (100%) rename {src => packages/app/src}/NavigationBar.tsx (100%) rename {src => packages/app/src}/SettingsPanel.tsx (100%) rename {src => packages/app/src}/constants.ts (100%) rename {src => packages/app/src}/hooks/useLocalStorage.ts (100%) rename {src => packages/app/src}/hooks/useNavigation.tsx (100%) rename {src => packages/app/src}/hooks/useRSSFeeds.ts (100%) rename {src => packages/app/src}/hooks/useSettings.ts (100%) rename {src => packages/app/src}/index.html (100%) rename {src => packages/app/src}/index.tsx (100%) rename {src => packages/app/src}/types.ts (100%) rename {src => packages/app/src}/utils.ts (100%) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 227869e..3cc558b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -48,9 +48,9 @@ jobs: run: | . script/bootstrap yarn lint - build: + build-app: runs-on: ubuntu-latest - name: Build + name: Build App needs: setup steps: - uses: actions/checkout@v3 @@ -74,17 +74,50 @@ jobs: key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}-${{ env.NODE_VERSION }}-parcel - run: | . script/bootstrap - yarn build + yarn build:app - name: Build Artifacts uses: actions/upload-artifact@v3 with: name: build-artifacts - path: dist + path: packages/app/dist + build-api: + runs-on: ubuntu-latest + name: Build API + needs: setup + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + id: node-setup + with: + node-version: ${{ env.NODE_VERSION }} + - name: Yarn cache + uses: actions/cache@v3 + id: yarn-cache-restore + with: + path: | + .yarn + key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}-${{ env.NODE_VERSION }} + - name: Parcel cache + uses: actions/cache@v3 + id: parcel-cache-restore + with: + path: | + .parcel-cache + key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}-${{ env.NODE_VERSION }}-parcel + - run: | + . script/bootstrap + yarn build:api + - name: Build Artifacts + uses: actions/upload-artifact@v3 + with: + name: build-artifacts-api + path: packages/api/dist + preview: runs-on: ubuntu-latest name: Deploy preview if: ${{ github.ref != 'refs/heads/main' }} - needs: build + needs: build-app steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 @@ -103,14 +136,14 @@ jobs: uses: actions/download-artifact@v3 with: name: build-artifacts - path: dist + path: packages/app/dist - name: Deploy id: preview-deploy env: NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_TOKEN }} NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} run: | - yarn netlify deploy --dir=dist --json | jq .deploy_url > output.log + yarn netlify deploy --dir=packages/app/dist --json | jq .deploy_url > output.log echo "::set-output name=draft-url::$(cat output.log)" - name: Report uses: actions/github-script@v6 @@ -128,7 +161,7 @@ jobs: deploy: runs-on: ubuntu-latest name: Deploy - needs: build + needs: build-app if: ${{ github.ref == 'refs/heads/main' }} steps: - uses: actions/checkout@v3 @@ -157,4 +190,4 @@ jobs: NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_TOKEN }} NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} run: | - yarn netlify deploy --dir=dist --prod + yarn netlify deploy --dir=packages/app/dist --prod diff --git a/.gitignore b/.gitignore index 781b7c1..8a15c7b 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ .parcel-cache parcel-bundle-reports dist +packages/**/dist # Logs logs diff --git a/netlify.toml b/netlify.toml index 5699831..24ba50b 100644 --- a/netlify.toml +++ b/netlify.toml @@ -3,7 +3,7 @@ [dev] command = "yarn start:parcel" - publish = "dist" + publish = "packages/app/dist" targetPort = 1234 port = 8080 framework = "parcel" diff --git a/package.json b/package.json index 5a62fab..60651f7 100644 --- a/package.json +++ b/package.json @@ -4,16 +4,20 @@ "version": "1.0.0", "packageManager": "yarn@3.3.1", "license": "GPL-3.0", + "workspaces": [ + "packages/*" + ], "scripts": { - "start": "netlify dev", - "start:parcel": "parcel serve src/index.html", - "lint": "eslint src", - "lint:fix": "eslint src netlify --fix", + "start:app": "yarn workspace app start", + "start:api": "yarn workspace api start", + "lint": "eslint packages/**/*.ts", + "lint:fix": "eslint packages/**/*.ts netlify --fix", "types": "tsc --noEmit", "clean": "rm -rf dist/*", - "build": "parcel build src/index.html", - "build:watch": "parcel watch src/index.html", - "build:bundlesize": "parcel build src/index.html --reporter @parcel/reporter-bundle-analyzer" + "build:app": "yarn workspace app build", + "build:app:watch": "yarn workspace app watch", + "build:app:bundlesize": "yarn workspace app build:bundlesize", + "build:api": "yarn workspace api build" }, "devDependencies": { "@parcel/reporter-bundle-analyzer": "^2.9.3", @@ -39,13 +43,6 @@ "prettier": "2.7.1", "typescript": "^4.9.4" }, - "dependencies": { - "@material-ui/core": "4.12.4", - "@material-ui/icons": "4.11.3", - "htmlparser2": "8.0.1", - "preact": "10.11.3", - "react-query": "3.39.2" - }, "resolutions": { "minimist": "^1.2.6" }, diff --git a/packages/api/package.json b/packages/api/package.json new file mode 100644 index 0000000..0d3c22e --- /dev/null +++ b/packages/api/package.json @@ -0,0 +1,19 @@ +{ + "name": "api", + "private": true, + "version": "1.0.0", + "type": "module", + "license": "GPL-3.0", + "scripts": { + "start": "test -f dist/index.js && yarn node dist/index.js", + "build": "yarn tsc" + }, + "dependencies": { + "express": "^4.18.2" + }, + "devDependencies": { + "@types/express": "^4.17.17", + "@types/node": "^20.3.2", + "typescript": "*" + } +} diff --git a/packages/api/src/index.ts b/packages/api/src/index.ts new file mode 100644 index 0000000..909092a --- /dev/null +++ b/packages/api/src/index.ts @@ -0,0 +1,14 @@ +import { + type Express, + type Request, + type Response, + default as express, +} from 'express' + +const app: Express = express() + +app.get('/', (req: Request, res: Response) => { + res.send('ok') +}) + +app.listen(8081, () => {}) diff --git a/packages/api/tsconfig.json b/packages/api/tsconfig.json new file mode 100644 index 0000000..0105f3f --- /dev/null +++ b/packages/api/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "target": "es2022", + "moduleResolution": "node", + "esModuleInterop": true, + "outDir": "dist" + }, + "include": ["src/**/*"] +} diff --git a/packages/app/package.json b/packages/app/package.json new file mode 100644 index 0000000..3c53a45 --- /dev/null +++ b/packages/app/package.json @@ -0,0 +1,29 @@ +{ + "name": "app", + "private": true, + "version": "1.0.0", + "packageManager": "yarn@3.3.1", + "license": "GPL-3.0", + "scripts": { + "start": "netlify dev", + "start:parcel": "parcel serve src/index.html", + "build": "parcel build src/index.html", + "build:watch": "parcel watch src/index.html", + "build:bundlesize": "parcel build src/index.html --reporter @parcel/reporter-bundle-analyzer" + }, + "dependencies": { + "@material-ui/core": "4.12.4", + "@material-ui/icons": "4.11.3", + "htmlparser2": "8.0.1", + "preact": "10.11.3", + "react-query": "3.39.2" + }, + "resolutions": { + "minimist": "^1.2.6" + }, + "alias": { + "react": "preact/compat", + "react-dom": "preact/compat", + "preact/jsx-dev-runtime": "preact/jsx-runtime" + } +} diff --git a/src/App.tsx b/packages/app/src/App.tsx similarity index 100% rename from src/App.tsx rename to packages/app/src/App.tsx diff --git a/src/FeedsPanel.tsx b/packages/app/src/FeedsPanel.tsx similarity index 100% rename from src/FeedsPanel.tsx rename to packages/app/src/FeedsPanel.tsx diff --git a/src/NavigationBar.tsx b/packages/app/src/NavigationBar.tsx similarity index 100% rename from src/NavigationBar.tsx rename to packages/app/src/NavigationBar.tsx diff --git a/src/SettingsPanel.tsx b/packages/app/src/SettingsPanel.tsx similarity index 100% rename from src/SettingsPanel.tsx rename to packages/app/src/SettingsPanel.tsx diff --git a/src/constants.ts b/packages/app/src/constants.ts similarity index 100% rename from src/constants.ts rename to packages/app/src/constants.ts diff --git a/src/hooks/useLocalStorage.ts b/packages/app/src/hooks/useLocalStorage.ts similarity index 100% rename from src/hooks/useLocalStorage.ts rename to packages/app/src/hooks/useLocalStorage.ts diff --git a/src/hooks/useNavigation.tsx b/packages/app/src/hooks/useNavigation.tsx similarity index 100% rename from src/hooks/useNavigation.tsx rename to packages/app/src/hooks/useNavigation.tsx diff --git a/src/hooks/useRSSFeeds.ts b/packages/app/src/hooks/useRSSFeeds.ts similarity index 100% rename from src/hooks/useRSSFeeds.ts rename to packages/app/src/hooks/useRSSFeeds.ts diff --git a/src/hooks/useSettings.ts b/packages/app/src/hooks/useSettings.ts similarity index 100% rename from src/hooks/useSettings.ts rename to packages/app/src/hooks/useSettings.ts diff --git a/src/index.html b/packages/app/src/index.html similarity index 100% rename from src/index.html rename to packages/app/src/index.html diff --git a/src/index.tsx b/packages/app/src/index.tsx similarity index 100% rename from src/index.tsx rename to packages/app/src/index.tsx diff --git a/src/types.ts b/packages/app/src/types.ts similarity index 100% rename from src/types.ts rename to packages/app/src/types.ts diff --git a/src/utils.ts b/packages/app/src/utils.ts similarity index 100% rename from src/utils.ts rename to packages/app/src/utils.ts diff --git a/yarn.lock b/yarn.lock index b64bce7..6e1301a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3647,6 +3647,49 @@ __metadata: languageName: node linkType: hard +"@types/body-parser@npm:*": + version: 1.19.2 + resolution: "@types/body-parser@npm:1.19.2" + dependencies: + "@types/connect": "*" + "@types/node": "*" + checksum: e17840c7d747a549f00aebe72c89313d09fbc4b632b949b2470c5cb3b1cb73863901ae84d9335b567a79ec5efcfb8a28ff8e3f36bc8748a9686756b6d5681f40 + languageName: node + linkType: hard + +"@types/connect@npm:*": + version: 3.4.35 + resolution: "@types/connect@npm:3.4.35" + dependencies: + "@types/node": "*" + checksum: fe81351470f2d3165e8b12ce33542eef89ea893e36dd62e8f7d72566dfb7e448376ae962f9f3ea888547ce8b55a40020ca0e01d637fab5d99567673084542641 + languageName: node + linkType: hard + +"@types/express-serve-static-core@npm:^4.17.33": + version: 4.17.35 + resolution: "@types/express-serve-static-core@npm:4.17.35" + dependencies: + "@types/node": "*" + "@types/qs": "*" + "@types/range-parser": "*" + "@types/send": "*" + checksum: cc8995d10c6feda475ec1b3a0e69eb0f35f21ab6b49129ad5c6f279e0bc5de8175bc04ec51304cb79a43eec3ed2f5a1e01472eb6d5f827b8c35c6ca8ad24eb6e + languageName: node + linkType: hard + +"@types/express@npm:^4.17.17": + version: 4.17.17 + resolution: "@types/express@npm:4.17.17" + dependencies: + "@types/body-parser": "*" + "@types/express-serve-static-core": ^4.17.33 + "@types/qs": "*" + "@types/serve-static": "*" + checksum: 0196dacc275ac3ce89d7364885cb08e7fb61f53ca101f65886dbf1daf9b7eb05c0943e2e4bbd01b0cc5e50f37e0eea7e4cbe97d0304094411ac73e1b7998f4da + languageName: node + linkType: hard + "@types/graceful-fs@npm:^4.1.3": version: 4.1.5 resolution: "@types/graceful-fs@npm:4.1.5" @@ -3663,6 +3706,13 @@ __metadata: languageName: node linkType: hard +"@types/http-errors@npm:*": + version: 2.0.1 + resolution: "@types/http-errors@npm:2.0.1" + checksum: 3bb0c50b0a652e679a84c30cd0340d696c32ef6558518268c238840346c077f899315daaf1c26c09c57ddd5dc80510f2a7f46acd52bf949e339e35ed3ee9654f + languageName: node + linkType: hard + "@types/http-proxy@npm:^1.17.8": version: 1.17.9 resolution: "@types/http-proxy@npm:1.17.9" @@ -3711,6 +3761,20 @@ __metadata: languageName: node linkType: hard +"@types/mime@npm:*": + version: 3.0.1 + resolution: "@types/mime@npm:3.0.1" + checksum: 4040fac73fd0cea2460e29b348c1a6173da747f3a87da0dbce80dd7a9355a3d0e51d6d9a401654f3e5550620e3718b5a899b2ec1debf18424e298a2c605346e7 + languageName: node + linkType: hard + +"@types/mime@npm:^1": + version: 1.3.2 + resolution: "@types/mime@npm:1.3.2" + checksum: 0493368244cced1a69cb791b485a260a422e6fcc857782e1178d1e6f219f1b161793e9f87f5fae1b219af0f50bee24fcbe733a18b4be8fdd07a38a8fb91146fd + languageName: node + linkType: hard + "@types/node@npm:*": version: 16.3.1 resolution: "@types/node@npm:16.3.1" @@ -3718,6 +3782,13 @@ __metadata: languageName: node linkType: hard +"@types/node@npm:^20.3.2": + version: 20.3.2 + resolution: "@types/node@npm:20.3.2" + checksum: 5929ce2b9b12b1e2a2304a0921a953c72a81f5753ad39ac43b99ce6312fbb2b4fb5bc6b60d64a2550704e3223cd5de1299467d36085ac69888899db978f2653a + languageName: node + linkType: hard + "@types/normalize-package-data@npm:^2.4.1": version: 2.4.1 resolution: "@types/normalize-package-data@npm:2.4.1" @@ -3746,6 +3817,20 @@ __metadata: languageName: node linkType: hard +"@types/qs@npm:*": + version: 6.9.7 + resolution: "@types/qs@npm:6.9.7" + checksum: 7fd6f9c25053e9b5bb6bc9f9f76c1d89e6c04f7707a7ba0e44cc01f17ef5284adb82f230f542c2d5557d69407c9a40f0f3515e8319afd14e1e16b5543ac6cdba + languageName: node + linkType: hard + +"@types/range-parser@npm:*": + version: 1.2.4 + resolution: "@types/range-parser@npm:1.2.4" + checksum: b7c0dfd5080a989d6c8bb0b6750fc0933d9acabeb476da6fe71d8bdf1ab65e37c136169d84148034802f48378ab94e3c37bb4ef7656b2bec2cb9c0f8d4146a95 + languageName: node + linkType: hard + "@types/react-transition-group@npm:^4.2.0": version: 4.4.2 resolution: "@types/react-transition-group@npm:4.4.2" @@ -3787,6 +3872,27 @@ __metadata: languageName: node linkType: hard +"@types/send@npm:*": + version: 0.17.1 + resolution: "@types/send@npm:0.17.1" + dependencies: + "@types/mime": ^1 + "@types/node": "*" + checksum: 10b620a5960058ef009afbc17686f680d6486277c62f640845381ec4baa0ea683fdd77c3afea4803daf5fcddd3fb2972c8aa32e078939f1d4e96f83195c89793 + languageName: node + linkType: hard + +"@types/serve-static@npm:*": + version: 1.15.2 + resolution: "@types/serve-static@npm:1.15.2" + dependencies: + "@types/http-errors": "*" + "@types/mime": "*" + "@types/node": "*" + checksum: 15c261dbfc57890f7cc17c04d5b22b418dfa0330c912b46c5d8ae2064da5d6f844ef7f41b63c7f4bbf07675e97ebe6ac804b032635ec742ae45d6f1274259b3e + languageName: node + linkType: hard + "@types/stack-utils@npm:^2.0.0": version: 2.0.1 resolution: "@types/stack-utils@npm:2.0.1" @@ -4494,6 +4600,29 @@ __metadata: languageName: node linkType: hard +"api@workspace:packages/api": + version: 0.0.0-use.local + resolution: "api@workspace:packages/api" + dependencies: + "@types/express": ^4.17.17 + "@types/node": ^20.3.2 + express: ^4.18.2 + typescript: "*" + languageName: unknown + linkType: soft + +"app@workspace:packages/app": + version: 0.0.0-use.local + resolution: "app@workspace:packages/app" + dependencies: + "@material-ui/core": 4.12.4 + "@material-ui/icons": 4.11.3 + htmlparser2: 8.0.1 + preact: 10.11.3 + react-query: 3.39.2 + languageName: unknown + linkType: soft + "aproba@npm:^1.0.3": version: 1.2.0 resolution: "aproba@npm:1.2.0" @@ -5371,17 +5500,10 @@ __metadata: languageName: node linkType: hard -"caniuse-lite@npm:^1.0.30001219": - version: 1.0.30001243 - resolution: "caniuse-lite@npm:1.0.30001243" - checksum: 912cf885036847a8b6972cd65170d9f355a08b08cfd6b06bcaa8de965755ee5b35a4bbe4eb73844aac313a42e2038ae0971a5b4c9b94d631db2f073c906ce1d6 - languageName: node - linkType: hard - -"caniuse-lite@npm:^1.0.30001370": - version: 1.0.30001373 - resolution: "caniuse-lite@npm:1.0.30001373" - checksum: cd2f027e2fcf66ed3b0e3eccec89df871f951f2e7600944fae2c3f6f1c37ac82392e573c279e15bf851b75f9696472e38d33fd52d964819ffb8af7af4078ceba +"caniuse-lite@npm:^1.0.30001219, caniuse-lite@npm:^1.0.30001370": + version: 1.0.30001508 + resolution: "caniuse-lite@npm:1.0.30001508" + checksum: 0a083ed92194d87e608fc35cac65830a27900249729eb8a68e270f866f2c4f83396c2e54eb47b0ef71360682174dd74e2e68eac0b8d407d125611c7bc12488eb languageName: node linkType: hard @@ -7587,7 +7709,7 @@ __metadata: languageName: node linkType: hard -"express@npm:4.18.2": +"express@npm:4.18.2, express@npm:^4.18.2": version: 4.18.2 resolution: "express@npm:4.18.2" dependencies: @@ -14164,8 +14286,6 @@ resolve@^1.20.0: version: 0.0.0-use.local resolution: "rss-reader@workspace:." dependencies: - "@material-ui/core": 4.12.4 - "@material-ui/icons": 4.11.3 "@parcel/reporter-bundle-analyzer": ^2.9.3 "@parcel/validator-typescript": ^2.9.3 "@tophat/eslint-config": 3.3.0 @@ -14183,13 +14303,10 @@ resolve@^1.20.0: eslint-plugin-prettier: 4.2.1 eslint-plugin-react: 7.31.10 eslint-plugin-react-hooks: 4.6.0 - htmlparser2: 8.0.1 jest: 29.3.1 netlify-cli: ^15.7.0 parcel: ^2.9.3 - preact: 10.11.3 prettier: 2.7.1 - react-query: 3.39.2 typescript: ^4.9.4 languageName: unknown linkType: soft @@ -15711,6 +15828,16 @@ resolve@^1.20.0: languageName: node linkType: hard +"typescript@npm:*, typescript@npm:^5.0.0, typescript@npm:^5.0.4": + version: 5.1.3 + resolution: "typescript@npm:5.1.3" + bin: + tsc: bin/tsc + tsserver: bin/tsserver + checksum: d9d51862d98efa46534f2800a1071a613751b1585dc78884807d0c179bcd93d6e9d4012a508e276742f5f33c480adefc52ffcafaf9e0e00ab641a14cde9a31c7 + languageName: node + linkType: hard + "typescript@npm:^4.9.4": version: 4.9.4 resolution: "typescript@npm:4.9.4" @@ -15721,13 +15848,13 @@ resolve@^1.20.0: languageName: node linkType: hard -"typescript@npm:^5.0.0, typescript@npm:^5.0.4": +"typescript@patch:typescript@*#~builtin, typescript@patch:typescript@^5.0.0#~builtin, typescript@patch:typescript@^5.0.4#~builtin": version: 5.1.3 - resolution: "typescript@npm:5.1.3" + resolution: "typescript@patch:typescript@npm%3A5.1.3#~builtin::version=5.1.3&hash=ad5954" bin: tsc: bin/tsc tsserver: bin/tsserver - checksum: d9d51862d98efa46534f2800a1071a613751b1585dc78884807d0c179bcd93d6e9d4012a508e276742f5f33c480adefc52ffcafaf9e0e00ab641a14cde9a31c7 + checksum: 32a25b2e128a4616f999d4ee502aabb1525d5647bc8955e6edf05d7fbc53af8aa98252e2f6ba80bcedfc0260c982b885f3c09cfac8bb65d2924f3133ad1e1e62 languageName: node linkType: hard @@ -15741,16 +15868,6 @@ resolve@^1.20.0: languageName: node linkType: hard -"typescript@patch:typescript@^5.0.0#~builtin, typescript@patch:typescript@^5.0.4#~builtin": - version: 5.1.3 - resolution: "typescript@patch:typescript@npm%3A5.1.3#~builtin::version=5.1.3&hash=ad5954" - bin: - tsc: bin/tsc - tsserver: bin/tsserver - checksum: 32a25b2e128a4616f999d4ee502aabb1525d5647bc8955e6edf05d7fbc53af8aa98252e2f6ba80bcedfc0260c982b885f3c09cfac8bb65d2924f3133ad1e1e62 - languageName: node - linkType: hard - "uid-safe@npm:2.1.5": version: 2.1.5 resolution: "uid-safe@npm:2.1.5"