Skip to content

Commit

Permalink
setup for npmjs library
Browse files Browse the repository at this point in the history
  • Loading branch information
petersalomonsen committed Jun 24, 2019
1 parent ef5b080 commit 2c89a6d
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
build
node_modules
xapianasm.*
.vscode
.vscode
dist
7 changes: 6 additions & 1 deletion compilermmxapianapi.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const execSync = require('child_process').execSync;
const { mkdirSync, existsSync } = require('fs');

const xapianDirArgName = '--xapiandir=';
const xapianDirArg = process.argv.find(arg => arg.indexOf(xapianDirArgName)===0);

if (xapianDirArg) {

process.env.XAPIAN = xapianDirArg.substr(xapianDirArgName.length);
Expand All @@ -13,11 +15,14 @@ if(!process.env.XAPIAN) {
} else {
try {
console.log('Building Runbox Xapian webassembly library');
if(!existsSync('dist')) {
mkdirSync('dist');
}
execSync(`em++ -Oz -s DISABLE_EXCEPTION_CATCHING=0 -s USE_ZLIB=1 ` +
`-s "EXTRA_EXPORTED_RUNTIME_METHODS=['FS','cwrap','stringToUTF8','UTF8ToString','getValue']" ` +
`-std=c++11 -s DEMANGLE_SUPPORT=1 -s ALLOW_MEMORY_GROWTH=1 ` +
`-I$XAPIAN/include -I$XAPIAN -I$XAPIAN/common rmmxapianapi.cc $XAPIAN/.libs/libxapian-1.5.a ` +
`-o xapianasm.js`, { stdio: 'inherit' });
`-o dist/xapianasm.js`, { stdio: 'inherit' });
console.log('Successful build of xapianasm.wasm and xapianasm.js');
} catch(e) {
console.error('Compile failed');
Expand Down
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
"scripts": {
"build": "node compilermmxapianapi.js",
"test": "mocha-typescript-watch -p tsconfig.json build/test/test.js",
"test-no-watch": "tsc -p tsconfig.json && mocha build/test/test.js"
},
"dependencies": {
"runbox7lib": "^0.2.0",
"rxjs": "^6.3.3"
"test-no-watch": "tsc -p tsconfig.json && mocha build/test/test.js",
"preparelib": "node preparelibrary.js"
},
"devDependencies": {
"runbox7lib": "^0.2.0",
"rxjs": "^6.3.3",
"@types/node": "^10.12.18",
"mocha": "^5.2.0",
"mocha-typescript": "^1.1.17",
Expand Down
8 changes: 8 additions & 0 deletions preparelibrary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const { readFileSync, writeFileSync } = require('fs');

const packageJSON = JSON.parse(readFileSync('package.json').toString());

delete packageJSON['scripts'];
delete packageJSON['devDependencies'];

writeFileSync('dist/package.json', JSON.stringify(packageJSON, null, 1));
2 changes: 1 addition & 1 deletion ts/xapian/xapian.loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function loadXapian(): AsyncSubject<boolean> {
if(!xapianLoadedSubject) {
xapianLoadedSubject = new AsyncSubject();

const xapian = require(`${process.cwd()}/xapianasm.js`);
const xapian = require(`${process.cwd()}/dist/xapianasm.js`);

global.termlistresult = [];
global.Module = xapian;
Expand Down

0 comments on commit 2c89a6d

Please sign in to comment.