1 |
|
2 | 'use strict'
|
3 |
|
4 | const FJS = require('fast-json-stringify')
|
5 | const path = require('node:path')
|
6 | const fs = require('node:fs')
|
7 |
|
8 | const code = FJS({
|
9 | type: 'object',
|
10 | properties: {
|
11 | statusCode: { type: 'number' },
|
12 | code: { type: 'string' },
|
13 | error: { type: 'string' },
|
14 | message: { type: 'string' }
|
15 | }
|
16 | }, { mode: 'standalone' })
|
17 |
|
18 | const file = path.join(__dirname, '..', 'lib', 'error-serializer.js')
|
19 |
|
20 | const moduleCode = `// This file is autogenerated by build/build-error-serializer.js, do not edit
|
21 | /* istanbul ignore file */
|
22 | ${code}
|
23 | `
|
24 |
|
25 | if (require.main === module) {
|
26 | fs.writeFileSync(file, moduleCode)
|
27 | console.log(`Saved ${file} file successfully`)
|
28 | } else {
|
29 | module.exports = {
|
30 | code: moduleCode
|
31 | }
|
32 | }
|