Skip to content
This repository has been archived by the owner on Nov 29, 2023. It is now read-only.

Commit

Permalink
Switch build and dev server to Vite
Browse files Browse the repository at this point in the history
  • Loading branch information
eyelidlessness committed Jan 13, 2023
1 parent 686aed7 commit 691e564
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 23 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ Thumbs.db
.nyc_output
test-coverage
coverage.shield.badge.md
dist
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

.nyc*
*/node_modules/*
dist/*
docs/*
test-coverage/*
4 changes: 1 addition & 3 deletions app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,4 @@ app.use(

api(app);

app.listen(app.get('port'), () => {
console.warn(`enketo-transformer running on port ${app.get('port')}!`);
});
export { app };
78 changes: 78 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 13 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@
"version": "2.1.7",
"description": "Library/app that transforms ODK-compliant XForms into a format that Enketo can consume",
"license": "Apache-2.0",
"main": "src/transformer.js",
"type": "module",
"main": "./dist/enketo-transformer.umd.cjs",
"module": "./dist/enketo-transformer.js",
"exports": {
".": {
"import": "./dist/enketo-transformer.js",
"require": "./dist/enketo-transformer.umd.cjs"
}
},
"bugs": {
"url": "https://github.com/enketo/enketo-transformer/issues",
"email": "martijn@enketo.org"
Expand All @@ -19,15 +27,15 @@
},
"contributors": [],
"scripts": {
"start": "node app.js",
"build": "vite build",
"start": "vite",
"eslint-check": "eslint app.ts src/**/*.ts vite.config.ts test/**/*.ts",
"eslint-fix": "eslint app.ts src/**/*.ts vite.config.ts test/**/*.ts --fix",
"prettier-fix": "prettier --write .",
"test": "vitest run --coverage && npm run prettier-fix && npm run eslint-fix && tsc && node update-readme-with-shield-badge.js",
"test:watch": "vitest",
"build-docs": "rimraf docs && ./node_modules/.bin/jsdoc -c jsdoc.config.js",
"develop": "DEBUG=api,transformer,markdown,language node app.js & http-server test/forms -p 8081",
"develop": "DEBUG=api,transformer,markdown,language node app.ts & http-server test/forms -p 8081",
"develop": "DEBUG=api,transformer,markdown,language vite & http-server test/forms -p 8081",
"tsc": "tsc --project . && tsc --project ./test"
},
"repository": {
Expand Down Expand Up @@ -82,6 +90,7 @@
"rimraf": "^3.0.2",
"typescript": "^4.9.4",
"vite": "^4.0.3",
"vite-plugin-node": "^1.0.0",
"vitest": "^0.26.2"
},
"volta": {
Expand Down
17 changes: 8 additions & 9 deletions src/transformer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import fs from 'fs';
import path from 'path';
import crypto from 'crypto';
import libxslt from 'libxslt';
import type {
Expand All @@ -13,14 +12,14 @@ import { escapeURLPath, getMediaPath } from './url';

const { libxmljs } = libxslt;

const xslForm = fs.readFileSync(
path.join(__dirname, './xsl/openrosa2html5form.xsl'),
'utf8'
);
const xslModel = fs.readFileSync(
path.join(__dirname, './xsl/openrosa2xmlmodel.xsl'),
'utf8'
);
const getXSL = (fileName: string) => {
const { pathname } = new URL(`./xsl/${fileName}`, import.meta.url);

return fs.readFileSync(pathname, 'utf8');
};

const xslForm = getXSL('openrosa2html5form.xsl');
const xslModel = getXSL('openrosa2xmlmodel.xsl');

export const NAMESPACES = {
xmlns: 'http://www.w3.org/2002/xforms',
Expand Down
6 changes: 3 additions & 3 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"allowJs": true,
"allowJs": false,
"allowSyntheticDefaultImports": true,
"allowUnreachableCode": false,
"baseUrl": ".",
Expand All @@ -12,7 +12,7 @@
"forceConsistentCasingInFileNames": true,
"inlineSourceMap": true,
"lib": ["ES2018"],
"module": "amd",
"module": "esnext",
"moduleResolution": "node",
"noEmit": true,
"noFallthroughCasesInSwitch": true,
Expand All @@ -21,7 +21,7 @@
"resolveJsonModule": true,
"skipLibCheck": true,
"strict": true,
"target": "es2018",
"target": "es2020",
"types": ["node"]
}
}
5 changes: 3 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"extends": "./tsconfig.base.json",
"exclude": ["node_modules", "./typings/test.d.ts"],
"include": ["app.ts", "src", "typings"]
"exclude": ["dist", "node_modules", "./typings/test.d.ts"],
"include": ["app.ts", "src", "typings"],
"files": ["./typings/env.d.ts"]
}
1 change: 1 addition & 0 deletions typings/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
25 changes: 23 additions & 2 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,36 @@
import { resolve } from 'path';
import { defineConfig } from 'vitest/config';
import { VitePluginNode } from 'vite-plugin-node';
import config from './config/config.json';

export default defineConfig({
assetsInclude: ['**/*.xml', '**/*.xsl'],
build: {
outDir: 'build',
minify: 'esbuild',
lib: {
entry: resolve(__dirname, './src/transformer.ts'),
name: 'enketo-transformer',
},
minify: false,
outDir: 'dist',
sourcemap: true,
},
esbuild: {
sourcemap: 'inline',
},
plugins: [
...VitePluginNode({
adapter: 'express',
appPath: './app.ts',
exportName: 'app',
tsCompiler: 'esbuild',
}),
],
server: {
port: config.port,
},
ssr: {
target: 'node',
},
test: {
// Vitest uses thread-based concurrency by defualt.
// While this would significantly improve the speed
Expand Down

0 comments on commit 691e564

Please sign in to comment.