Skip to content

Commit

Permalink
refactor: build scripts instead of running them directly (#822)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlj95 authored Nov 17, 2024
1 parent d175e8e commit 8d5ca90
Show file tree
Hide file tree
Showing 72 changed files with 381 additions and 420 deletions.
3 changes: 0 additions & 3 deletions .ci/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,5 @@ install:
pnpm install --frozen-lockfile

unit-test:
pnpm run prebuild:font-subsets
pnpm run prebuild:simple-icons

pnpm run test:unit --browsers=ChromeHeadless \
--no-watch --no-progress --reporters progress --code-coverage
10 changes: 8 additions & 2 deletions .github/workflows/reusable-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Setup
uses: ./.github/actions/setup
- name: Render templates
run: 'pnpm run prebuild:render-templates'
run: cd scripts && pnpm run build && pnpm run generate:templated-files
- name: Ensure no pending changes
run: cd .ci && make ensure-no-pending-changes

Expand All @@ -33,6 +33,12 @@ jobs:
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Setup
uses: ./.github/actions/setup
- name: Generate files
run: |
cd scripts
pnpm run build
pnpm run generate:simple-icons
pnpm run generate:font-subsets
- name: Run tests
run: cd .ci && make unit-test
- name: Upload coverage results
Expand Down Expand Up @@ -76,7 +82,7 @@ jobs:
- name: Cypress install
run: pnpm cypress install
- name: Generate font subsets
run: pnpm run prebuild:font-subsets
run: cd scripts && pnpm run build && pnpm run generate:font-subsets
- name: Cypress run
uses: cypress-io/github-action@v6
with:
Expand Down
2 changes: 1 addition & 1 deletion .idea/runConfigurations/Dev_Serve__Pull_Request_.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions .idea/runConfigurations/Prebuild__simple_icons.xml

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/runConfigurations/__scripts__release_info.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/runConfigurations/__scripts__simple_icons.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions .idea/runConfigurations/security_txt.xml

This file was deleted.

2 changes: 1 addition & 1 deletion .release-it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const createReleaseItConfig = ({
commit: false,
push: true, // default, but for explicitness
},
// @ts-expect-error Invalid type definition. TODO: PR for this
// @ts-expect-error TODO: Invalid type definition, PR for this
npm: false,
github: {
release: true,
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ For every push to `main` branch, [Release It!][release-it] will run and check if
In order to embed release information in the app, a script runs to export that kind of information using
[Release It!'s programmatic API](https://github.com/release-it/release-it/blob/main/docs/recipes/programmatic.md).

To generate the release info, run
To generate the release info, go to `scripts` directory and run

```shell
pnpm run prebuild:release-info
pnpm run generate:release-info
```

It will generate a `release.json` file in the source directory of the app containing the:
Expand All @@ -110,7 +110,7 @@ It will generate a `release.json` file in the source directory of the app contai
- Current release version & CHANGELOG
- Unreleased changes CHANGELOG

Checkout the [script](./scripts/src/generate-release-info.mts) for more information.
Checkout the [script](scripts/src/generate-release-info.ts) for more information.

## Git hooks

Expand Down Expand Up @@ -160,10 +160,10 @@ See https://github.com/davidlj95/website/pull/289 for more info.

## Rendering font subsets

Some fonts included are a subset of a big font file. Before doing anything, please run
Some fonts included are a subset of a big font file. Before doing anything, please go to `scripts` directory and run

```shell
pnpm run prebuild:font-subsets
pnpm run generate:font-subsets
```

To generate them. Otherwise, those fonts won't be found and you may get some errors. Also, remember to run it if
Expand Down
1 change: 1 addition & 0 deletions data/.release-it.ts
File renamed without changes.
6 changes: 4 additions & 2 deletions src/app/metadata.ts → data/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ import {
const NICKNAME = 'davidlj95'
const REAL_NAME = 'David LJ'
const TITLE = 'Senior software engineer'
// PoliceTranslator the earliest code found at 2023. But I started the project / did more things earlier!
// PoliceTranslator's was the earliest code I found at 2023.
// Though I started the project / did more things earlier!
const FIRST_JOB_START_DATE = new Date('2014-06-19')
const TIMESTAMP_DIFF = Date.now() - FIRST_JOB_START_DATE.getTime()
const YEARS_OF_EXPERIENCE = Math.abs(
// Oh dear JavaScript, why you make things so difficult? https://stackoverflow.com/a/24181701/3263250
// Oh dear JavaScript, why you make things so difficult?
// https://stackoverflow.com/a/24181701/3263250
new Date(TIMESTAMP_DIFF).getUTCFullYear() - 1970,
)

Expand Down
9 changes: 9 additions & 0 deletions data/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "@/data",
"version": "0.0.0-PLACEHOLDER",
"description": "Data files needed by both app and scripts",
"type": "module",
"exports": {
"./*": "./*"
}
}
File renamed without changes.
11 changes: 2 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
"url": "https://github.com/davidlj95/website.git"
},
"scripts": {
"prebuild": "pnpm run '/prebuild:.*/'",
"prebuild": "cd scripts && pnpm run build && pnpm run generate",
"build": "ng build",
"build:pack": "DIST_DIR=dist/@davidlj95/website/browser; [ -d \"$DIST_DIR\" ] && cd $DIST_DIR && zip -r ../../../build.zip . || true",
"build:pull-request": "pnpm run build --configuration pullRequest,production",
"build:scripts": "cd scripts && tsc",
"bundle:analyze": "pnpm run bundle:analyze:files '*.js'",
"bundle:analyze:files": "cd dist/@davidlj95/website/browser && pnpm dlx source-map-explorer --no-border-checks",
"bundle:analyze:files//": "☝️ Something weird in source maps after switching to ESBuild. So `--no-border-checks` was added",
Expand Down Expand Up @@ -39,14 +38,9 @@
"lint:code:files//": "☝️ lint-staged can't/shouldn't use 'ng lint'",
"lint:commit-message": "pnpm run commitlint:edit-msg",
"lint:gh-actions": "actionlint || true",
"prebuild:font-subsets": "tsm scripts/src/generate-font-subsets.ts",
"prebuild:release-info": "tsx scripts/src/generate-release-info.mts",
"prebuild:render-templates": "tsm scripts/src/generate-templated-files.ts",
"prebuild:simple-icons": "tsm scripts/src/generate-simple-icons.ts",
"release": "release-it",
"release:dry-run": "release-it --dry-run --no-git.requireBranch",
"release:dry-run:local": "pnpm run release:dry-run --no-git.requireCleanWorkingDir --no-git.requireUpstream",
"security-txt": "tsm scripts/src/generate-security-txt.ts",
"serve:ssr:@davidlj95/website": "node dist/@davidlj95/website/server/server.mjs",
"start": "ng serve",
"start:prod": "pnpm dlx http-server dist/@davidlj95/website/browser -a localhost",
Expand Down Expand Up @@ -119,6 +113,7 @@
"eslint-plugin-json": "4.0.1",
"eslint-plugin-json-files": "4.4.1",
"execa": "9.5.1",
"extensionless": "1.9.9",
"glob": "11.0.0",
"husky": "9.1.6",
"jasmine-core": "5.4.0",
Expand All @@ -134,8 +129,6 @@
"prettier": "3.3.3",
"release-it": "17.10.0",
"subset-font": "2.3.0",
"tsm": "2.3.0",
"tsx": "4.19.2",
"typescript": "5.4.5"
},
"packageManager": "[email protected]",
Expand Down
Loading

0 comments on commit 8d5ca90

Please sign in to comment.