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,73 +1,69 @@
#!/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'
)
console.log('Generating constants...') ;(async () => {
console.log('Generating constants...')
fs.createReadStream(header) const header_data = await fs.readFile(header, 'utf-8')
.pipe(split()) for (const line of header_data.split(/\r?\n/g)) {
.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', () => {
const constants = data
.filter(
({ key }) => key.toUpperCase()[0] === key[0] // check if define name is uppercase
)
.sort((lhs, rhs) => {
if (lhs.key < rhs.key) return -1
else if (lhs.key > rhs.key) return 1
return 0
})
.map((row) => {
return ` ${row.key}: ${row.value}`
})
.join(',\n')
const events = data delete header_data
.sort((lhs, rhs) => {
if (lhs.value < rhs.value) return -1
else if (lhs.value > rhs.value) return 1
return 0
})
.filter((i) => {
return i.key.startsWith('DC_EVENT_')
})
.map((i) => {
return ` ${i.value}: '${i.key}'`
})
.join(',\n')
// backwards compat const constants = data
fs.writeFileSync( .filter(
path.resolve(__dirname, '../constants.js'), ({ key }) => key.toUpperCase()[0] === key[0] // check if define name is uppercase
`// Generated!\n\nmodule.exports = {\n${constants}\n}\n`
)
// backwards compat
fs.writeFileSync(
path.resolve(__dirname, '../events.js'),
`/* eslint-disable quotes */\n// Generated!\n\nmodule.exports = {\n${events}\n}\n`
) )
.sort((lhs, rhs) => {
if (lhs.key < rhs.key) return -1
else if (lhs.key > rhs.key) return 1
return 0
})
.map((row) => {
return ` ${row.key}: ${row.value}`
})
.join(',\n')
fs.writeFileSync( const events = data
path.resolve(__dirname, '../lib/constants.ts'), .sort((lhs, rhs) => {
`// Generated!\n\nexport enum C {\n${constants.replace(/:/g, ' =')},\n}\n if (lhs.value < rhs.value) return -1
else if (lhs.value > rhs.value) return 1
return 0
})
.filter((i) => {
return i.key.startsWith('DC_EVENT_')
})
.map((i) => {
return ` ${i.value}: '${i.key}'`
})
.join(',\n')
// backwards compat
await fs.writeFile(
path.resolve(__dirname, '../constants.js'),
`// Generated!\n\nmodule.exports = {\n${constants}\n}\n`
)
// backwards compat
await fs.writeFile(
path.resolve(__dirname, '../events.js'),
`/* eslint-disable quotes */\n// Generated!\n\nmodule.exports = {\n${events}\n}\n`
)
await fs.writeFile(
path.resolve(__dirname, '../lib/constants.ts'),
`// 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"
}, },