Skip to content

Commit

Permalink
MAN-256 fix esbuild config issues
Browse files Browse the repository at this point in the history
  • Loading branch information
neil-mills committed Jan 15, 2025
1 parent ee7f8e5 commit ecebe1c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 64 deletions.
49 changes: 0 additions & 49 deletions assets/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,55 +7,6 @@ import './predictors'
govukFrontend.initAll()
mojFrontend.initAll()

MOJFrontend.BackendSortableTable = params => {
this.table = $(params.table)

if (this.table.data('moj-search-toggle-initialised')) {
return
}

this.table.data('moj-search-toggle-initialised', true)

this.setupOptions(params)
this.body = this.table.find('tbody')
this.createHeadingButtons()
this.setNaturalOrder()
this.createStatusBox()
this.table.on('click', 'th button', $.proxy(this, 'onSortButtonClick'))
}

MOJFrontend.BackendSortableTable.prototype.sortNatural = (rowA, rowB) => {
const tdA = $(rowA).find('td').eq(this.naturalSortColumn)
const tdB = $(rowB).find('td').eq(this.naturalSortColumn)
const valueA = this.getCellValue(tdA)
const valueB = this.getCellValue(tdB)
if (this.naturalSortDirection === 'ascending') {
if (valueA < valueB) {
return -1
}
if (valueA > valueB) {
return 1
}
return 0
}
if (valueB < valueA) {
return -1
}
if (valueB > valueA) {
return 1
}
return 0
}

MOJFrontend.BackendSortableTable.prototype.getCellValue = cell => {
let val = cell.attr('data-sort-value')
val = val || cell.html()
if ($.isNumeric(val)) {
val = parseInt(val, 10)
}
return val
}

/* eslint-disable no-restricted-globals */
const lastAppointment = () => {
const repeatingFrequency = document.querySelector('div[data-repeating-frequency]')
Expand Down
23 changes: 20 additions & 3 deletions esbuild/esbuild.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,30 @@ function main() {
Promise.all([buildApp(buildConfig), buildAssets(buildConfig)]).catch(() => process.exit(1))
}

if (args.includes('--feature-dev-server')) {
let serverProcess = null
chokidar.watch(['dist']).on('all', () => {
if (serverProcess) serverProcess.kill()
serverProcess = spawn(
'node',
['--inspect=0.0.0.0', '--enable-source-maps', 'dist/server.js', ' | bunyan -o short'],
{
stdio: 'inherit',
},
)
})
}
if (args.includes('--dev-server')) {
let serverProcess = null
chokidar.watch(['dist']).on('all', () => {
if (serverProcess) serverProcess.kill()
serverProcess = spawn('node', ['--inspect=0.0.0.0', '--enable-source-maps', 'dist/server.js'], {
stdio: 'inherit',
})
serverProcess = spawn(
'node',
['--inspect=0.0.0.0', '--enable-source-maps', '-r', 'dotenv/config', 'dist/server.js', ' | bunyan -o short'],
{
stdio: 'inherit',
},
)
})
}

Expand Down
12 changes: 2 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,9 @@
"license": "MIT",
"scripts": {
"prepare": "husky",
"copy-views": "cp -R server/views dist/server/",
"compile-sass": "sass --quiet-deps --no-source-map --load-path=node_modules/govuk-frontend/dist --load-path=node_modules/@ministryofjustice/frontend --load-path=. assets/scss/application.scss:./assets/stylesheets/application.css --style compressed",
"watch-ts": "tsc -w",
"watch-views": "nodemon --watch server/views -e html,njk -x npm run copy-views",
"watch-node": "DEBUG=gov-starter-server* nodemon -r dotenv/config --watch dist/ dist/server.js | bunyan -o short",
"watch-sass": "npm run compile-sass -- --watch",
"build": "npm run compile-sass && tsc && npm run copy-views && npm run sentry:sourcemaps",
"start": "node $NODE_OPTIONS dist/server.js | bunyan -o short",
"start:dev": "concurrently -k -p \"[{name}]\" -n \"Views,TypeScript,Node,Sass\" -c \"yellow.bold,cyan.bold,green.bold,blue.bold\" \"npm run watch-views\" \"npm run watch-ts\" \"npm run watch-node\" \"npm run watch-sass\"",
"start:dev": "concurrently -k -p \"[{name}]\" -n \"Views,TypeScript,ESBuild,Node,Sass\" -c \"yellow.bold,cyan.bold,green.bold,blue.bold\" \"node esbuild/esbuild.config.js --build --watch\" \"node esbuild/esbuild.config.js --dev-server\"",
"start-feature": "concurrently -k -p \"[{name}]\" -n \"WireMock,Node\" -c \"magenta.bold,green.bold\" \"npm run wiremock\" \"npm run start-node-feature\"",
"start-feature:dev": "export $(cat feature.env) && concurrently -k -p \"[{name}]\" -n \"WireMock,Views,TypeScript,ESBuild,Node,Sass\" -c \"yellow.bold,cyan.bold\" \"npm run wiremock\" \"node esbuild/esbuild.config.js --build --watch\" \"node esbuild/esbuild.config.js --dev-server\"",
"start-feature:dev": "export $(cat feature.env) && concurrently -k -p \"[{name}]\" -n \"WireMock,Views,TypeScript,ESBuild,Node,Sass\" -c \"yellow.bold,cyan.bold\" \"npm run wiremock\" \"node esbuild/esbuild.config.js --build --watch\" \"node esbuild/esbuild.config.js --feature-dev-server\"",
"start-node-feature": "export $(cat feature.env) && node $NODE_DEBUG_OPTION dist/server.js | bunyan -o short",
"watch-node-feature": "export $(cat feature.env) && nodemon --watch dist/ $NODE_DEBUG_OPTION dist/server.js | bunyan -o short",
"wiremock": "npx wiremock --port 9091 --root-dir wiremock --local-response-templating",
Expand Down
2 changes: 1 addition & 1 deletion server/applicationInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export type ApplicationInfo = {
}

export default (): ApplicationInfo => {
const packageJson = path.join(__dirname, './package.json')
const packageJson = path.join(__dirname, '../package.json')
const { name: applicationName, version } = JSON.parse(fs.readFileSync(packageJson).toString())
return { applicationName, version, buildNumber, gitRef, gitShortHash: gitRef.substring(0, 7), productId, branchName }
}
1 change: 0 additions & 1 deletion server/views/partials/layout.njk
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
{% block pageTitle %}{{pageTitle | default(applicationName)}}{% endblock %}

{% block header %}
{{applicationInsightsConnectionString }}
{% include "./header.njk" %}
{% block banner %}{% endblock %}

Expand Down

0 comments on commit ecebe1c

Please sign in to comment.