Skip to content

Commit

Permalink
Use tsx for scripts and local env
Browse files Browse the repository at this point in the history
  • Loading branch information
rakyi committed Apr 30, 2024
1 parent b17518d commit 3b22fa6
Show file tree
Hide file tree
Showing 8 changed files with 321 additions and 127 deletions.
3 changes: 1 addition & 2 deletions .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@ tasks:
echo VITE_DEV_URL=$(gp url 8090) >> .env
echo BAKED_BASE_URL=$(gp url 3030) >> .env
echo ADMIN_BASE_URL=$(gp url 3030) >> .env
yarn startTscServer
# wait for initial-setup (above) to finish and then start vite server
- init: gp sync-await initial-setup
command: yarn startViteServer
# wait for initial-setup (above) to finish and then start admin server
- init: gp sync-await initial-setup
command: yarn startAdminServer
command: yarn startAdminDevServer

github:
prebuilds:
Expand Down
18 changes: 6 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ up: require create-if-missing.env ../owid-content tmp-downloads/owid_metadata.sq
@echo '==> Building grapher'
yarn install
yarn lerna run build
yarn run tsc -b

@echo '==> Starting dev environment'
@mkdir -p logs
Expand All @@ -64,7 +63,7 @@ up: require create-if-missing.env ../owid-content tmp-downloads/owid_metadata.sq
set remain-on-exit on \; \
set-option -g default-shell $(SCRIPT_SHELL) \; \
new-window -n admin \
'devTools/docker/wait-for-mysql.sh && yarn run tsc-watch -b --onSuccess "yarn startAdminServer"' \; \
'devTools/docker/wait-for-mysql.sh && yarn startAdminDevServer' \; \
set remain-on-exit on \; \
new-window -n vite 'yarn run startSiteFront' \; \
set remain-on-exit on \; \
Expand All @@ -83,13 +82,12 @@ up.devcontainer: create-if-missing.env.devcontainer tmp-downloads/owid_metadata.
@echo '==> Building grapher'
yarn install
yarn lerna run build
yarn run tsc -b

@echo '==> Starting dev environment'
@mkdir -p logs
tmux new-session -s grapher \
-n admin \
'devTools/docker/wait-for-mysql.sh && yarn run tsc-watch -b --onSuccess "yarn startAdminServer"' \; \
'devTools/docker/wait-for-mysql.sh && yarn startAdminDevServer' \; \
set remain-on-exit on \; \
new-window -n vite 'yarn run startSiteFront' \; \
set remain-on-exit on \; \
Expand All @@ -109,7 +107,6 @@ up.full: require create-if-missing.env.full ../owid-content wordpress/.env tmp-d
@echo '==> Building grapher'
yarn install
yarn lerna run build
yarn run tsc -b
yarn buildWordpressPlugin

@echo '==> Starting dev environment'
Expand All @@ -118,7 +115,7 @@ up.full: require create-if-missing.env.full ../owid-content wordpress/.env tmp-d
set remain-on-exit on \; \
set-option -g default-shell $(SCRIPT_SHELL) \; \
new-window -n admin \
'devTools/docker/wait-for-mysql.sh && yarn run tsc-watch -b --onSuccess "yarn startAdminServer"' \; \
'devTools/docker/wait-for-mysql.sh && yarn startAdminDevServer' \; \
set remain-on-exit on \; \
new-window -n vite 'yarn run startSiteFront' \; \
set remain-on-exit on \; \
Expand All @@ -135,7 +132,7 @@ up.full: require create-if-missing.env.full ../owid-content wordpress/.env tmp-d

migrate:
@echo '==> Running DB migrations'
rm -rf itsJustJavascript && yarn && yarn buildLerna && yarn buildTsc && yarn runDbMigrations
yarn && yarn buildLerna && yarn runDbMigrations

refresh.full: refresh refresh.wp sync-images

Expand All @@ -151,7 +148,7 @@ refresh:

refresh.pageviews:
@echo '==> Refreshing pageviews'
yarn && yarn buildTsc && yarn refreshPageviews
yarn && yarn refreshPageviews

refresh.wp:
@echo '==> Downloading wordpress data'
Expand Down Expand Up @@ -294,11 +291,8 @@ test:
yarn run jest

dbtest:
@echo '==> Building'
yarn
yarn buildTsc

@echo '==> Running db test script'
yarn
./db/tests/run-db-tests.sh

lint:
Expand Down
2 changes: 1 addition & 1 deletion db/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Run:
yarn typeorm migration:create db/migration/MigrationName
```

And then populate the file with the SQL statements to alter the tables, using [past migration files](./migration) for reference if needed. Don't forget to rebuild the JavaScript artifacts now from TypeScript view `yarn buildTsc`, then run migrations with `yarn runDbMigrations`.
And then populate the file with the SQL statements to alter the tables, using [past migration files](./migration) for reference if needed. Then run migrations with `yarn runDbMigrations`.

Make sure you write a **down** migration in case there is any chance things can go wrong we'd need to revert it.

Expand Down
2 changes: 1 addition & 1 deletion db/tests/run-db-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ docker compose -f docker-compose.dbtests.yml up -d

echo '==> Running migrations'

yarn typeorm migration:run -d itsJustJavascript/db/tests/dataSource.dbtests.js
yarn tsx node_modules/typeorm/cli.js migration:run -d db/tests/dataSource.dbtests.ts

echo '==> Running tests'
if ! yarn run jest --config=jest.db.config.js --runInBand # runInBand runs multiple test files serially - useful to avoid weird race conditions
Expand Down
4 changes: 2 additions & 2 deletions docs/grapher-admin-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ cp .env.example .env
Then run the three development processes:

```sh
yarn startTscServer
yarn startAdminServer
yarn startLernaWatcher
yarn startAdminDevServer
yarn startViteServer
```

Expand Down
28 changes: 14 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,34 @@
},
"packageManager": "[email protected]",
"scripts": {
"batchTagWithGpt": "node --enable-source-maps ./itsJustJavascript/baker/batchTagWithGpt.js",
"buildAndDeploySite": "node --enable-source-maps ./itsJustJavascript/baker/buildAndDeploySite.js",
"batchTagWithGpt": "tsx baker/batchTagWithGpt.ts",
"buildAndDeploySite": "tsx baker/buildAndDeploySite.ts",
"buildCoverage": "jest --coverage=true --coverageProvider=v8",
"buildLocalBake": "node --enable-source-maps ./itsJustJavascript/baker/buildLocalBake.js",
"buildLocalBake": "tsx baker/buildLocalBake.ts",
"buildTsc": "tsc -b -verbose",
"buildLerna": "lerna run build",
"buildViteAdmin": "vite build --config vite.config-admin.mts",
"buildViteSite": "vite build --config vite.config-site.mts",
"buildVite": "yarn buildViteSite && yarn buildViteAdmin",
"buildWordpressPlugin": "cd ./wordpress/web/app/plugins/owid && yarn && yarn build",
"bakeGdocPosts": "node --enable-source-maps ./itsJustJavascript/baker/bakeGdocPosts.js",
"bakeGdocPosts": "tsx baker/bakeGdocPosts.ts",
"cleanTsc": "rm -rf itsJustJavascript && tsc -b -clean",
"deployWordpress": "./wordpress/scripts/deploy.sh",
"deployContentPreview": "PREVIEW_BRANCH=${PREVIEW_BRANCH:-} ./ops/buildkite/deploy-content-preview",
"fetchServerStatus": "node --enable-source-maps ./itsJustJavascript/baker/liveCommit.js",
"fetchServerStatus": "tsx baker/liveCommit.ts",
"fixLint": "eslint . --fix",
"fixPrettierAll": "yarn prettier --write \"**/*.{tsx,ts,jsx,js,json,md,html,css,scss,yml}\"",
"runRegionsUpdater": "node --enable-source-maps ./itsJustJavascript/devTools/regionsUpdater/update.js",
"runDbMigrations": "yarn typeorm migration:run -d itsJustJavascript/db/dataSource.js",
"refreshPageviews": "node --enable-source-maps ./itsJustJavascript/db/refreshPageviewsFromDatasette.js",
"revertLastDbMigration": "yarn typeorm migration:revert -d itsJustJavascript/db/dataSource.js",
"runPostUpdateHook": "node --enable-source-maps ./itsJustJavascript/baker/postUpdatedHook.js",
"runRegionsUpdater": "tsx devTools/regionsUpdater/update.ts",
"runDbMigrations": "tsx node_modules/typeorm/cli.js migration:run -d db/dataSource.ts",
"refreshPageviews": "tsx db/refreshPageviewsFromDatasette.ts",
"revertLastDbMigration": "tsx node_modules/typeorm/cli.js migration:revert -d db/dataSource.ts",
"runPostUpdateHook": "tsx baker/postUpdatedHook.ts",
"startAdminServer": "node --enable-source-maps ./itsJustJavascript/adminSiteServer/app.js",
"startAdminDevServer": "tsx watch adminSiteServer/app.tsx",
"startLocalCloudflareFunctions": "wrangler pages dev localBake --compatibility-date 2023-10-09",
"startDeployQueueServer": "node --enable-source-maps ./itsJustJavascript/baker/startDeployQueueServer.js",
"startLernaWatcher": "lerna watch --scope '@ourworldindata/*' -- lerna run build --scope=\\$LERNA_PACKAGE_NAME --include-dependents",
"startTmuxServer": "node_modules/tmex/tmex dev \"yarn startTscServer\" \"yarn startLernaWatcher\" \"yarn startAdminServer\" \"yarn startViteServer\"",
"startTscServer": "tsc -b -verbose -watch",
"startTmuxServer": "node_modules/tmex/tmex dev \"yarn startLernaWatcher\" \"yarn startAdminDevServer\" \"yarn startViteServer\"",
"startViteServer": "vite dev",
"startWordpressPlugin": "cd ./wordpress/web/app/plugins/owid && yarn && yarn start",
"startSiteFront": "./devTools/vite/startVite.sh",
Expand All @@ -43,7 +43,7 @@
"testLint": "eslint .",
"testPrettierAll": "yarn prettier --check \"**/*.{tsx,ts,jsx,js,json,md,html,css,scss,yml}\"",
"testJest": "lerna run buildTests && jest",
"testSiteNavigation": "node --enable-source-maps ./itsJustJavascript/devTools/navigationTest/navigationTest.js",
"testSiteNavigation": "tsx devTools/navigationTest/navigationTest.ts",
"generateDbTypes": "npx @rmp135/sql-ts -c db/sql-ts/sql-ts-config.json"
},
"dependencies": {
Expand Down Expand Up @@ -256,7 +256,7 @@
"sql-fixtures": "^1.0.4",
"tmex": "^1.0.8",
"topojson-server": "^3.0.1",
"tsc-watch": "^6.0.4",
"tsx": "^4.7.3",
"vite": "^4.4.10",
"vite-plugin-checker": "^0.6.2",
"vite-plugin-warmup": "^0.1.0",
Expand Down
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"composite": false,
"baseUrl": "./"
},
"files": [],
"references": [
{
"path": "./gridLang"
Expand Down
Loading

0 comments on commit 3b22fa6

Please sign in to comment.