This repository has been archived by the owner on Nov 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #158 from eyelidlessness/refactor/typescript-build
Convert remainder of library to TypeScript, Vite build, include type checking in CI
- Loading branch information
Showing
73 changed files
with
894 additions
and
13,626 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ Thumbs.db | |
.nyc_output | ||
test-coverage | ||
coverage.shield.badge.md | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,6 @@ | |
|
||
.nyc* | ||
*/node_modules/* | ||
dist/* | ||
docs/* | ||
test-coverage/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,63 @@ | ||
const express = require('express'); | ||
// @ts-check | ||
|
||
const app = express(); | ||
const bodyParser = require('body-parser'); | ||
const config = require('./config/config.json'); | ||
import { createServer } from 'vite'; | ||
import { VitePluginNode } from 'vite-plugin-node'; | ||
import { | ||
config, | ||
external, | ||
resolvePath, | ||
rootDir, | ||
} from './config/build.shared.js'; | ||
|
||
for (const item in config) { | ||
app.set(item, config[item]); | ||
} | ||
const appPath = resolvePath('./app.ts'); | ||
|
||
app.use(bodyParser.json()); | ||
app.use( | ||
bodyParser.urlencoded({ | ||
extended: true, | ||
}) | ||
); | ||
const init = async () => { | ||
/** @type {import('vite').UserConfig} */ | ||
const baseOptions = { | ||
mode: 'development', | ||
build: { | ||
rollupOptions: { | ||
external, | ||
}, | ||
}, | ||
optimizeDeps: { | ||
disabled: true, | ||
}, | ||
root: rootDir, | ||
ssr: { | ||
target: 'node', | ||
}, | ||
}; | ||
|
||
require('./src/api')(app); | ||
const servers = await Promise.all([ | ||
createServer({ | ||
...baseOptions, | ||
configFile: false, | ||
plugins: VitePluginNode({ | ||
adapter: 'express', | ||
appPath, | ||
exportName: 'app', | ||
tsCompiler: 'esbuild', | ||
}), | ||
server: { | ||
port: config.port, | ||
}, | ||
}), | ||
createServer({ | ||
...baseOptions, | ||
configFile: false, | ||
publicDir: resolvePath('./test/forms'), | ||
server: { | ||
port: 8081, | ||
}, | ||
}), | ||
]); | ||
|
||
app.listen(app.get('port'), () => { | ||
console.warn(`enketo-transformer running on port ${app.get('port')}!`); | ||
}); | ||
await Promise.all(servers.map((server) => server.listen())); | ||
|
||
servers.forEach((server) => { | ||
server.printUrls(); | ||
}); | ||
}; | ||
|
||
init(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import bodyParser from 'body-parser'; | ||
import express from 'express'; | ||
import { config } from './config/build.shared'; | ||
import { api } from './src/api'; | ||
|
||
const app = express(); | ||
|
||
Object.entries(config).forEach(([key, value]) => { | ||
app.set(key, value); | ||
}); | ||
|
||
app.use(bodyParser.json()); | ||
app.use( | ||
bodyParser.urlencoded({ | ||
extended: true, | ||
}) | ||
); | ||
|
||
api(app); | ||
|
||
export { app }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export { | ||
config, | ||
external, | ||
resolvePath, | ||
readFile, | ||
rootDir, | ||
} from './build.shared'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// @ts-check | ||
|
||
import fs from 'fs'; | ||
import { createRequire } from 'module'; | ||
import { dirname, resolve } from 'path'; | ||
import { fileURLToPath } from 'url'; | ||
|
||
const require = createRequire(import.meta.url); | ||
|
||
export const config = require('./config.json'); | ||
|
||
export const external = [ | ||
'body-parser', | ||
'crypto', | ||
'css.escape', | ||
'express', | ||
'fs', | ||
'language-tags', | ||
'libxslt', | ||
'node1-libxmljsmt-myh', | ||
'path', | ||
'string-direction', | ||
'undici', | ||
'url', | ||
'vite-node', | ||
'vite', | ||
]; | ||
|
||
export const rootDir = dirname(fileURLToPath(import.meta.url)).replace( | ||
/(\/enketo-transformer)(\/.*$)/, | ||
'$1' | ||
); | ||
|
||
/** | ||
* @param {string} path | ||
*/ | ||
export const resolvePath = (path) => resolve(rootDir, path); | ||
|
||
/** | ||
* @param {string} path | ||
*/ | ||
export const readFile = (path) => fs.readFileSync(resolvePath(path), 'utf-8'); |
Oops, something went wrong.