mirror of
https://github.com/chatmail/core.git
synced 2026-04-18 22:16:30 +03:00
build(node): migrate from CommonJS to ESM modules
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
const spawnSync = require('child_process').spawnSync
|
||||
import { spawnSync } from 'child_process'
|
||||
|
||||
const verbose = isVerbose()
|
||||
|
||||
@@ -23,4 +23,4 @@ function isVerbose () {
|
||||
return loglevel === 'verbose' || process.env.CI === 'true'
|
||||
}
|
||||
|
||||
module.exports = { spawn, log, isVerbose, verbose }
|
||||
export { spawn, log, isVerbose, verbose }
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
#!/usr/bin/env node
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import * as url from 'url'
|
||||
|
||||
const data = []
|
||||
const header = path.resolve(__dirname, '../../deltachat-ffi/deltachat.h')
|
||||
const header = path.resolve(url.fileURLToPath(new URL('.', import.meta.url)), '../../deltachat-ffi/deltachat.h')
|
||||
|
||||
console.log('Generating constants...')
|
||||
|
||||
const header_data = fs.readFileSync(header, 'UTF-8')
|
||||
const regex = /^#define\s+(\w+)\s+(\w+)/gm
|
||||
var match
|
||||
while (null != (match = regex.exec(header_data))) {
|
||||
const key = match[1]
|
||||
const value = parseInt(match[2])
|
||||
@@ -17,8 +19,6 @@ while (null != (match = regex.exec(header_data))) {
|
||||
}
|
||||
}
|
||||
|
||||
delete header_data
|
||||
|
||||
const constants = data
|
||||
.filter(
|
||||
({ key }) => key.toUpperCase()[0] === key[0] // check if define name is uppercase
|
||||
@@ -49,17 +49,17 @@ const events = data
|
||||
|
||||
// backwards compat
|
||||
fs.writeFileSync(
|
||||
path.resolve(__dirname, '../constants.js'),
|
||||
path.resolve(url.fileURLToPath(new URL('.', import.meta.url)), '../constants.js'),
|
||||
`// Generated!\n\nmodule.exports = {\n${constants}\n}\n`
|
||||
)
|
||||
// backwards compat
|
||||
fs.writeFileSync(
|
||||
path.resolve(__dirname, '../events.js'),
|
||||
path.resolve(url.fileURLToPath(new URL('.', import.meta.url)), '../events.js'),
|
||||
`/* eslint-disable quotes */\n// Generated!\n\nmodule.exports = {\n${events}\n}\n`
|
||||
)
|
||||
|
||||
fs.writeFileSync(
|
||||
path.resolve(__dirname, '../lib/constants.ts'),
|
||||
path.resolve(url.fileURLToPath(new URL('.', import.meta.url)), '../lib/constants.js'),
|
||||
`// Generated!\n\nexport enum C {\n${constants.replace(/:/g, ' =')},\n}\n
|
||||
// Generated!\n\nexport const EventId2EventName: { [key: number]: string } = {\n${events},\n}\n`
|
||||
)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
const {execSync} = require('child_process')
|
||||
const {existsSync} = require('fs')
|
||||
const {join} = require('path')
|
||||
import {execSync} from 'child_process'
|
||||
import {existsSync} from 'fs'
|
||||
import {join} from 'path'
|
||||
import * as url from 'url'
|
||||
|
||||
const run = (cmd) => {
|
||||
console.log('[i] running `' + cmd + '`')
|
||||
@@ -16,7 +17,7 @@ if (process.env.USE_SYSTEM_LIBDELTACHAT === 'true') {
|
||||
run('npm run install:prebuilds')
|
||||
}
|
||||
|
||||
if (!existsSync(join(__dirname, '..', 'dist'))) {
|
||||
if (!existsSync(join(url.fileURLToPath(new URL('.', import.meta.url)), '..', 'dist'))) {
|
||||
console.log('[i] Didn\'t find already built typescript bindings. Trying to transpile them. If this fail, make sure typescript is installed ;)')
|
||||
run('npm run build:bindings:ts')
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
const { readFileSync } = require('fs')
|
||||
import { readFileSync } from 'fs'
|
||||
import { request } from 'https'
|
||||
|
||||
const sha = JSON.parse(
|
||||
readFileSync(process.env['GITHUB_EVENT_PATH'], 'utf8')
|
||||
@@ -21,8 +22,6 @@ const STATUS_DATA = {
|
||||
target_url: base_url + file_url,
|
||||
}
|
||||
|
||||
const http = require('https')
|
||||
|
||||
const options = {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
@@ -32,7 +31,7 @@ const options = {
|
||||
},
|
||||
}
|
||||
|
||||
const req = http.request(GITHUB_API_URL, options, function(res) {
|
||||
const req = request(GITHUB_API_URL, options, function (res) {
|
||||
var chunks = []
|
||||
res.on('data', function(chunk) {
|
||||
chunks.push(chunk)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import * as url from 'url'
|
||||
|
||||
if (process.platform !== 'win32') {
|
||||
console.log('postinstall: not windows, so skipping!')
|
||||
@@ -7,7 +8,7 @@ if (process.platform !== 'win32') {
|
||||
}
|
||||
|
||||
const from = path.resolve(
|
||||
__dirname,
|
||||
url.fileURLToPath(new URL('.', import.meta.url)),
|
||||
'..',
|
||||
'..',
|
||||
'target',
|
||||
@@ -19,7 +20,7 @@ const getDestination = () => {
|
||||
const argv = process.argv
|
||||
if (argv.length === 3 && argv[2] === '--prebuild') {
|
||||
return path.resolve(
|
||||
__dirname,
|
||||
url.fileURLToPath(new URL('.', import.meta.url)),
|
||||
'..',
|
||||
'prebuilds',
|
||||
'win32-x64',
|
||||
@@ -27,7 +28,7 @@ const getDestination = () => {
|
||||
)
|
||||
} else {
|
||||
return path.resolve(
|
||||
__dirname,
|
||||
url.fileURLToPath(new URL('.', import.meta.url)),
|
||||
'..',
|
||||
'build',
|
||||
'Release',
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
const path = require('path')
|
||||
const { spawn } = require('./common')
|
||||
import path from 'path'
|
||||
import { spawn } from './common.js'
|
||||
import * as url from 'url'
|
||||
const opts = {
|
||||
cwd: path.resolve(__dirname, '../..'),
|
||||
cwd: path.resolve(url.fileURLToPath(new URL('.', import.meta.url)), '../..'),
|
||||
stdio: 'inherit'
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user