Skip to content

Commit

Permalink
Add rename script (#10)
Browse files Browse the repository at this point in the history
* Add rename script

* PR reviews

* Removing unused vars
  • Loading branch information
andrewrlee authored Dec 18, 2020
1 parent ac0dfa6 commit c8a5587
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 12 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
# hmpps-template-typescript
Template github repo used for new Typescript based projects.

## Getting started
## Manually branding from template app
Run the `rename-project.bash` and create a PR.

The rename-project.bash script takes a single argument - the name of the project and calculates from it the project description
It then performs a search and replace and directory renames so the project is ready to be used.

## Running the app
The easiest way to run the app is to use docker compose to create the service and all dependencies.

`docker-compose pull`
Expand All @@ -19,8 +25,7 @@ To start the main services excluding the example typescript template app:

`docker-compose up`

Install dependencies using `npm install`, ensuring you are using >= `Node v12.16.x`
(Circle build/test using node:12.18.2-buster-browsers, Dockerfile using node:12-buster-slim)
Install dependencies using `npm install`, ensuring you are using >= `Node v14.x`

And then, to build the assets and start the app with nodemon:

Expand Down
2 changes: 1 addition & 1 deletion helm_deploy/values-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ ingress:
env:
HMPPS_AUTH_URL: https://sign-in-dev.hmpps.service.justice.gov.uk/auth
TOKEN_VERIFICATION_API_URL: https://token-verification-api-dev.prison.service.justice.gov.uk
TOKEN_VERIFICATION_ENABLED: true
TOKEN_VERIFICATION_ENABLED: true
2 changes: 1 addition & 1 deletion log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import bunyanFormat from 'bunyan-format'

const formatOut = bunyanFormat({ outputMode: 'short', color: true })

const log = bunyan.createLogger({ name: 'Example Typescript Template', stream: formatOut, level: 'debug' })
const log = bunyan.createLogger({ name: 'HMPPS Typescript Template', stream: formatOut, level: 'debug' })

export default log
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "hmpps-template-typescript",
"version": "0.0.1",
"description": "HMPPS Template Typescript",
"description": "HMPPS Typescript Template",
"repository": "[email protected]:ministryofjustice/hmpps-template-typescript.git",
"license": "MIT",
"scripts": {
Expand Down
46 changes: 46 additions & 0 deletions rename-project.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env bash

set -e

if ! echo "$BASH_VERSION" | grep -E "^[45]" &>/dev/null; then
echo "Found bash version: $BASH_VERSION"
echo "Ensure you are using bash version 4 or 5"
exit 1
fi

if [[ $# -ge 1 ]]; then
PROJECT_INPUT=$1
else
read -rp "New project name e.g. prison-visits >" PROJECT_INPUT
fi

PROJECT_NAME_LOWER=${PROJECT_INPUT,,} # lowercase
PROJECT_NAME_HYPHENS=${PROJECT_NAME_LOWER// /-} # spaces to hyphens

PROJECT_NAME=${PROJECT_NAME_HYPHENS//[^a-z0-9-]/} # remove all other characters

read -ra PROJECT_NAME_ARRAY <<<"${PROJECT_NAME//-/ }" # convert to array
PROJECT_DESCRIPTION=${PROJECT_NAME_ARRAY[*]^} # convert array back to string thus capitalising first character

echo "Found: Project of $PROJECT_DESCRIPTION"
echo " Project name of $PROJECT_NAME"

echo "Performing search and replace"

# exclude files that get in the way and don't make any difference
EXCLUDES="( -path ./dist -o -path ./node_modules -o -path ./assets -o -path ./.git -o -path ./rename-project.bash -o -path ./README.md )"
# shellcheck disable=SC2086
find . $EXCLUDES -prune -o -type f -exec /usr/bin/sed -i.bak \
-e "s/hmpps-template-typescript/$PROJECT_NAME/g" \
-e "s/HMPPS Typescript Template/$PROJECT_DESCRIPTION/g" {} \; -exec rm '{}.bak' \;

echo "Performing directory renames"

# move helm stuff to new name
mv "helm_deploy/hmpps-template-typescript" "helm_deploy/$PROJECT_NAME"

# lastly remove ourselves
rm rename-project.bash

echo "Completed."
echo "Please now review changes"
1 change: 1 addition & 0 deletions server/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export default function createApp(userService: UserService): express.Application

// GovUK Template Configuration
app.locals.asset_path = '/assets/'
app.locals.applicationName = 'HMPPS Typescript Template'

app.use((req, res, next) => {
res.locals.user = req.user
Expand Down
3 changes: 1 addition & 2 deletions server/views/pages/error.njk
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{% extends "../partials/layout.njk" %}

{% set pageTitle = "Example Typescript Template - Error" %}
{% block pageTitle %}{{ pageTitle }} - GOV.UK{% endblock %}
{% set pageTitle = applicationName + " - Error" %}

{% block content %}

Expand Down
3 changes: 1 addition & 2 deletions server/views/pages/index.njk
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{% extends "../partials/layout.njk" %}

{% set pageTitle = "Example Typescript Template" %}
{% block pageTitle %}{{ pageTitle }} - GOV.UK{% endblock %}
{% set pageTitle = applicationName + " - Home" %}

{% block content %}

Expand Down
2 changes: 1 addition & 1 deletion server/views/partials/header.njk
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<span id="hmpps-title">
HMPPS
</span>
<span id="main-title">Example Typescript Template</span>
<span id="main-title">{{applicationName}}</span>
</div>
</a>

Expand Down
2 changes: 1 addition & 1 deletion server/views/partials/layout.njk
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

{% endblock %}

{% block pageTitle %}Example Typescript Template{% endblock %}
{% block pageTitle %}{{pageTitle | default(applicationName)}}{% endblock %}

{% block header %}
{% include "./header.njk" %}
Expand Down

0 comments on commit c8a5587

Please sign in to comment.