Skip to content

Commit e9011ba

Browse files
authored
Merge pull request #20 from J4Numbers/feat/typescript
feat(typescript): move website logic over to typescript
2 parents 6771388 + 44f7e20 commit e9011ba

File tree

213 files changed

+6079
-5028
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

213 files changed

+6079
-5028
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ config/local*
33
data/
44
public/
55
src/gql
6+
src/javascript/
67
src/js/
78
src/images/
89
src/stylesheets/
10+
src/tsconfig.json

.github/workflows/aws.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
on:
2+
workflow_call:
3+
inputs:
4+
env:
5+
required: true
6+
type: string
7+
secrets:
8+
AWS_ACCESS_KEY_ID:
9+
required: true
10+
AWS_SECRET_ACCESS_KEY:
11+
required: true
12+
13+
name: Deploy to Amazon ECS
14+
15+
jobs:
16+
deploy:
17+
name: Deploy
18+
runs-on: ubuntu-latest
19+
environment: production
20+
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v2
24+
25+
- name: Configure AWS credentials
26+
uses: aws-actions/configure-aws-credentials@v1
27+
with:
28+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
29+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
30+
aws-region: eu-west-2
31+
32+
- name: Login to Amazon ECR
33+
id: login-ecr
34+
uses: aws-actions/amazon-ecr-login@v1
35+
36+
- name: Build, tag, and push image to Amazon ECR
37+
id: build-image
38+
env:
39+
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
40+
ECR_REPOSITORY: j4numbers/personal-website
41+
IMAGE_TAG: ${{ github.sha }}
42+
run: |
43+
# Build a docker container and
44+
# push it to ECR so that it can
45+
# be deployed to ECS.
46+
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
47+
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
48+
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
49+
50+
- name: HashiCorp - Setup Terraform
51+
uses: hashicorp/[email protected]
52+
with:
53+
# The version of Terraform CLI to install. Defaults to `latest`.
54+
terraform_version: "> 0.15.5"
55+
56+
- name: Validate and plan deployment Terraform
57+
id: terraform-plan-validate
58+
env:
59+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
60+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
61+
62+
TF_VAR_deploy_version: ${{ github.sha }}
63+
TF_VAR_vpc_id: ${{ secrets.DEPLOY_VPC_ID }}
64+
TF_VAR_application_debug_mode: "false"
65+
66+
TF_VAR_logger_level: "info"
67+
run: |
68+
cd tf/site/
69+
terraform init -backend-config backend_config/dev.conf
70+
terraform validate
71+
terraform plan -no-color -out plan.tfplan
72+
73+
- name: Deploy Terraform
74+
id: terraform-apply
75+
env:
76+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
77+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
78+
run: cd tf/site/ && terraform apply plan.tfplan
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
name: NodeJS build and test
2+
3+
on: push
4+
5+
env:
6+
default_node_version: 14.x
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v2
14+
15+
- name: Use Node.js ${{ matrix.node-version }}
16+
uses: actions/setup-node@v1
17+
with:
18+
node-version: ${{ env.default_node_version }}
19+
20+
- name: Build
21+
run: |
22+
npm install
23+
npm run build
24+
25+
- name: Upload public build artefacts
26+
uses: actions/[email protected]
27+
with:
28+
# Artifact name
29+
name: npm-gulp-build-files-public
30+
# A file, directory or wildcard pattern that describes what to upload
31+
path: public
32+
# The desired behavior if no files are found using the provided path.
33+
if-no-files-found: error
34+
retention-days: 1
35+
- name: Upload TS build artefacts
36+
uses: actions/[email protected]
37+
with:
38+
# Artifact name
39+
name: npm-gulp-build-files-ts
40+
# A file, directory or wildcard pattern that describes what to upload
41+
path: src/js
42+
# The desired behavior if no files are found using the provided path.
43+
if-no-files-found: error
44+
retention-days: 1
45+
46+
lint:
47+
runs-on: ubuntu-latest
48+
49+
needs: build
50+
continue-on-error: true
51+
52+
steps:
53+
- uses: actions/checkout@v2
54+
55+
- name: Download public build artefacts
56+
uses: actions/[email protected]
57+
with:
58+
# Artifact name
59+
name: npm-gulp-build-files-public
60+
# Destination path
61+
path: public
62+
- name: Download TS build artefacts
63+
uses: actions/[email protected]
64+
with:
65+
# Artifact name
66+
name: npm-gulp-build-files-ts
67+
# Destination path
68+
path: src/js
69+
70+
- name: Use Node.js ${{ matrix.node-version }}
71+
uses: actions/setup-node@v1
72+
with:
73+
node-version: ${{ env.default_node_version }}
74+
75+
- name: Perform lint checks
76+
run: |
77+
npm i
78+
npm run quality:eslint
79+
80+
test:
81+
runs-on: ubuntu-latest
82+
83+
needs: build
84+
85+
strategy:
86+
matrix:
87+
node-version: [12.x, 14.x, 16.x]
88+
89+
steps:
90+
- uses: actions/checkout@v2
91+
92+
- name: Download public build artefacts
93+
uses: actions/[email protected]
94+
with:
95+
# Artifact name
96+
name: npm-gulp-build-files-public
97+
# Destination path
98+
path: public
99+
- name: Download TS build artefacts
100+
uses: actions/[email protected]
101+
with:
102+
# Artifact name
103+
name: npm-gulp-build-files-ts
104+
# Destination path
105+
path: src/js
106+
107+
- name: Use Node.js ${{ matrix.node-version }}
108+
uses: actions/setup-node@v1
109+
with:
110+
node-version: ${{ matrix.node-version }}
111+
112+
- name: Perform tests
113+
run: |
114+
npm i
115+
npm run generate-certs
116+
npm run test:unit
117+
118+
deploy:
119+
if: github.ref_name == 'main'
120+
needs:
121+
- test
122+
uses: j4numbers/common-workflows/.github/workflows/build-ecr-aws.yml@main
123+
with:
124+
env: production
125+
repo_name: j4numbers/personal-website
126+
secrets:
127+
AWS_ACCESS_KEY_ID: ${{ secrets.aws_access_key_id }}
128+
AWS_SECRET_ACCESS_KEY: ${{ secrets.aws_secret_access_key }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
.idea/
55
*.iml
66

7+
src/js/
8+
79
### Terraform
810
tf/site/.terraform
911

gulpfile.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const gulp = require('gulp');
22
const npath = require('path');
33
const sassCompiler = require('sass');
44
const sass = require('gulp-sass')(sassCompiler);
5+
const ts = require('gulp-typescript');
56
const babel = require('gulp-babel');
67
const clean = require('gulp-clean');
78

@@ -11,10 +12,12 @@ const clean = require('gulp-clean');
1112
const srcDir = './';
1213
const destDir = './public/';
1314

15+
const tsProject = ts.createProject('./src/tsconfig.json');
16+
1417
/* -------------------------------------------------------------------- CLEAN */
1518

1619
gulp.task('clean', () => gulp.src(
17-
[ npath.resolve(destDir) ],
20+
[ npath.resolve(destDir), './src/js' ],
1821
{
1922
read: false,
2023
allowEmpty: true,
@@ -48,12 +51,18 @@ gulp.task('sass', () => gulp
4851
.pipe(gulp.dest('./public/stylesheets')));
4952

5053
gulp.task('babel', () => gulp
51-
.src([ npath.resolve(srcDir, 'src/js/**/*.js') ])
54+
.src([ npath.resolve(srcDir, 'src/javascript/**/*.js') ])
5255
.pipe(babel({
5356
presets: [ '@babel/env' ],
5457
}))
5558
.pipe(gulp.dest('./public/javascript')));
5659

60+
gulp.task('typescript', () => gulp
61+
.src([ npath.resolve(srcDir, 'src/ts/**/*.ts') ])
62+
.pipe(tsProject())
63+
.js
64+
.pipe(gulp.dest('./src/js')));
65+
5766
// Copies javascript files to public folder
5867
gulp.task('copy-scripts', () => gulp
5968
.src([
@@ -82,7 +91,11 @@ gulp.task('copy-fonts', () => gulp
8291
/* -------------------------------------------------------------------- Tasks */
8392
gulp.task(
8493
'build',
85-
gulp.series('clean', 'sass', 'babel', 'copy-scripts', 'copy-images', 'copy-fonts'),
94+
gulp.series(
95+
'clean',
96+
gulp.parallel('sass', 'babel', 'typescript'),
97+
gulp.parallel('copy-scripts', 'copy-images', 'copy-fonts'),
98+
),
8699
);
87100

88101
gulp.task('default', gulp.series('build'));

0 commit comments

Comments
 (0)