node: remove split2 dependency

This commit is contained in:
Simon Laux
2022-06-10 22:55:07 +02:00
committed by Simon Laux
parent 548335082b
commit 008e78a022
3 changed files with 52 additions and 56 deletions

View File

@@ -7,6 +7,7 @@
- ignore ratelimits for bots #3439 - ignore ratelimits for bots #3439
- remove `msgs_mdns` references to deleted messages during housekeeping #3387 - remove `msgs_mdns` references to deleted messages during housekeeping #3387
- format message lines starting with `>` as quotes #3434 - format message lines starting with `>` as quotes #3434
- node: remove `split2` dependency
### Fixes ### Fixes
- set a default error if NDN does not provide an error - set a default error if NDN does not provide an error

View File

@@ -1,31 +1,27 @@
#!/usr/bin/env node #!/usr/bin/env node
const fs = require('fs/promises')
const fs = require('fs')
const path = require('path') const path = require('path')
const split = require('split2')
const data = [] const data = []
const regex = /^#define\s+(\w+)\s+(\w+)/i const regex = /^#define\s+(\w+)\s+(\w+)/i
const header = path.resolve( const header = path.resolve(__dirname, '../../deltachat-ffi/deltachat.h')
__dirname,
'../../deltachat-ffi/deltachat.h'
)
;(async () => {
console.log('Generating constants...') console.log('Generating constants...')
const header_data = await fs.readFile(header, 'utf-8')
fs.createReadStream(header) for (const line of header_data.split(/\r?\n/g)) {
.pipe(split())
.on('data', (line) => {
const match = regex.exec(line) const match = regex.exec(line)
if (match) { if (match) {
const key = match[1] const key = match[1]
const value = parseInt(match[2]) const value = parseInt(match[2])
if (isNaN(value)) return if (isNaN(value)) continue
data.push({ key, value }) data.push({ key, value })
} }
}) }
.on('end', () => {
delete header_data
const constants = data const constants = data
.filter( .filter(
({ key }) => key.toUpperCase()[0] === key[0] // check if define name is uppercase ({ key }) => key.toUpperCase()[0] === key[0] // check if define name is uppercase
@@ -55,19 +51,19 @@ fs.createReadStream(header)
.join(',\n') .join(',\n')
// backwards compat // backwards compat
fs.writeFileSync( await fs.writeFile(
path.resolve(__dirname, '../constants.js'), path.resolve(__dirname, '../constants.js'),
`// Generated!\n\nmodule.exports = {\n${constants}\n}\n` `// Generated!\n\nmodule.exports = {\n${constants}\n}\n`
) )
// backwards compat // backwards compat
fs.writeFileSync( await fs.writeFile(
path.resolve(__dirname, '../events.js'), path.resolve(__dirname, '../events.js'),
`/* eslint-disable quotes */\n// Generated!\n\nmodule.exports = {\n${events}\n}\n` `/* eslint-disable quotes */\n// Generated!\n\nmodule.exports = {\n${events}\n}\n`
) )
fs.writeFileSync( await fs.writeFile(
path.resolve(__dirname, '../lib/constants.ts'), path.resolve(__dirname, '../lib/constants.ts'),
`// Generated!\n\nexport enum C {\n${constants.replace(/:/g, ' =')},\n}\n `// Generated!\n\nexport enum C {\n${constants.replace(/:/g, ' =')},\n}\n
// Generated!\n\nexport const EventId2EventName: { [key: number]: string } = {\n${events},\n}\n` // Generated!\n\nexport const EventId2EventName: { [key: number]: string } = {\n${events},\n}\n`
) )
}) })()

View File

@@ -19,7 +19,6 @@
"prebuildify": "^3.0.0", "prebuildify": "^3.0.0",
"prebuildify-ci": "^1.0.4", "prebuildify-ci": "^1.0.4",
"prettier": "^2.0.5", "prettier": "^2.0.5",
"split2": "^4.1.0",
"typedoc": "^0.17.0", "typedoc": "^0.17.0",
"typescript": "^3.9.10" "typescript": "^3.9.10"
}, },