-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
prebuild.js
24 lines (22 loc) · 1.08 KB
/
prebuild.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
const { readFileSync, writeFileSync } = require('fs-extra')
const base = readFileSync('./src/index.js', { encoding: 'utf-8' })
const minifiedBase = base
.replace(/\bhandlers\b/g, 'hs') // Handler(S)
.replace(/\bhandler\b/g, 'h') // Handler
.replace(/([^\.])obj\b/g, '$1t') // Target
.replace(/([^\.])options\b/g, '$1o') // Options
.replace(/([^\.])receiver\b/g, '$1c') // Options
.replace(/([^\.])route\b/g, '$1p') // Path
.replace(/([^\.])\.routes\b/g, '$1\.r') // routes Queue
.replace(/args/g, 'a') // Args
.replace(/([^\.])request\b/g, '$1r') // Request
.replace(/([^\.])response\b/g, '$1s') // reSponse
.replace(/([^\.])match\b/g, '$1m') // Match
.replace(/([^\.])prop\b/g, '$1k') // Key
.replace(/([^\.])url\b/g, '$1u') // Url
writeFileSync('./dist/index.js', minifiedBase)
console.log('minifying variables --> dist/index.js')
const test = readFileSync('./src/index.spec.js', { encoding: 'utf-8' })
const minifiedTest = test.replace('index.js', 'index.min.js')
writeFileSync('./dist/index.spec.js', minifiedTest)
console.log('creating dist tests --> dist/index.spec.js')