Bingo for meetings–typescript making exe console–part 14
Bingo
Bingo is a small project, written in TypeScript , and developed with Alexandru Badita in launch break (one hour - more or less). You can find sources at https://github.com/alexandru360/PresentationBingoCards/ . Those are my blog posts for Bingo : ( scroll below for the post)Now it is the moment to have our first executable release– console application. First, we want to see if the js obtain by compilation of ts run under node ( it runs under ts-node index.ts , but it runs under node.js ? ). And we see that , when I run node index.js it gives error “ could not find bingo-meeting-object/MeetingFactory”.
It is clear that, even if yean workspaces works well with node and typescript, the final result, index.js , is not prepared to run under node. Solving the problem is about compiling typescript with project references . The documentation is at https://www.typescriptlang.org/docs/handbook/project-references.html#composite , and a sample project can be found at https://github.com/RyanCavanaugh/learn-a
It is composed by
1. having a tsconfig.json with
{
“compilerOptions”: {
“target”: “es5”,
“module”: “commonjs”,
“declaration”: true,
“declarationMap”: true,
“sourceMap”: true,
“strict”: false,
“composite”: true,
“esModuleInterop”: true
}
}
and extending in tsconfig.json
“extends”: “../tsconfig.settings.json”,
2. Compiling the projects with
tsc -b .
3. Creating index.ts with all classes exports
export * from “./MeetingsFactory”;
export * from “./Meeting”;
export * from “./Cards”;
export * from “./Participant”;
And now we can execute index.js with node index.jsinto
That means also the referenced projects are compiled into node_modules. That means that will not run without it.
We want now to create a console executable for the console project. That means something that compiles everything into an exe – no matter windows , linux , or macos
We use for that https://www.npmjs.com/package/pkg
In the package.json of the console project we put
“build” : “pkg dist/index.js -c package.json”
“scripts”: {“test”: “cd bingo-meeting-objects-test && yarn test”,“runConsole”: “cd bingo-meeting-console && yarn start”,“buildConsole”:”yarn build && cd bingo-meeting-console && yarn build”,“build”:”tsc -b .”}
FROM node:8
WORKDIR /app
COPY . ./
RUN yarn
RUN yarn buildConsole
CMD tail -f /dev/null
docker build .. -f docker_build_console.txt -t bingo_build_console
docker run -d –rm –name bingo_build_console_container bingo_build_console
docker cp bingo_build_console_container:/app/bingo-meeting-console/bingo-meeting-console-win.exe .
docker cp bingo_build_console_container:/app/bingo-meeting-console/bingo-meeting-console-linux .
docker cp bingo_build_console_container:/app/bingo-meeting-console/bingo-meeting-console-macos .
docker container kill bingo_build_console_container
Leave a Reply