From 938702c23f75a57605afe9c0e2c061241fbe21e8 Mon Sep 17 00:00:00 2001 From: Divlo Date: Mon, 6 Dec 2021 19:04:16 +0100 Subject: [PATCH] refactor: no duplicate of package.json in solutions --- .../solutions/javascript/function/package.json | 3 --- .../solutions/javascript/function/package.json | 3 --- .../solutions/javascript/function/package.json | 3 --- .../solutions/javascript/function/package.json | 3 --- .../javascript/bubble-sort/package.json | 3 --- .../solutions/javascript/function/package.json | 3 --- .../javascript/insertion-sort/package.json | 3 --- .../solutions/javascript/merge-sort/package.json | 3 --- cli/services/Docker.ts | 16 ++++++++++++---- .../docker/javascript}/package.json | 0 templates/docker/typescript/Dockerfile | 10 +++++++--- templates/docker/typescript/package.json | 10 ++++++++++ templates/docker/typescript/tsconfig.json | 13 +++++++++++++ 13 files changed, 42 insertions(+), 31 deletions(-) delete mode 100644 challenges/first-non-repeating-character/solutions/javascript/function/package.json delete mode 100644 challenges/hello-world/solutions/javascript/function/package.json delete mode 100644 challenges/is-palindrome/solutions/javascript/function/package.json delete mode 100644 challenges/reverse-polish-notation/solutions/javascript/function/package.json delete mode 100644 challenges/sorting-algorithms/solutions/javascript/bubble-sort/package.json delete mode 100644 challenges/sorting-algorithms/solutions/javascript/function/package.json delete mode 100644 challenges/sorting-algorithms/solutions/javascript/insertion-sort/package.json delete mode 100644 challenges/sorting-algorithms/solutions/javascript/merge-sort/package.json rename {challenges/camel-case/solutions/javascript/function => templates/docker/javascript}/package.json (100%) create mode 100644 templates/docker/typescript/package.json create mode 100644 templates/docker/typescript/tsconfig.json diff --git a/challenges/first-non-repeating-character/solutions/javascript/function/package.json b/challenges/first-non-repeating-character/solutions/javascript/function/package.json deleted file mode 100644 index 3dbc1ca..0000000 --- a/challenges/first-non-repeating-character/solutions/javascript/function/package.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "type": "module" -} diff --git a/challenges/hello-world/solutions/javascript/function/package.json b/challenges/hello-world/solutions/javascript/function/package.json deleted file mode 100644 index 3dbc1ca..0000000 --- a/challenges/hello-world/solutions/javascript/function/package.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "type": "module" -} diff --git a/challenges/is-palindrome/solutions/javascript/function/package.json b/challenges/is-palindrome/solutions/javascript/function/package.json deleted file mode 100644 index 3dbc1ca..0000000 --- a/challenges/is-palindrome/solutions/javascript/function/package.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "type": "module" -} diff --git a/challenges/reverse-polish-notation/solutions/javascript/function/package.json b/challenges/reverse-polish-notation/solutions/javascript/function/package.json deleted file mode 100644 index 3dbc1ca..0000000 --- a/challenges/reverse-polish-notation/solutions/javascript/function/package.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "type": "module" -} diff --git a/challenges/sorting-algorithms/solutions/javascript/bubble-sort/package.json b/challenges/sorting-algorithms/solutions/javascript/bubble-sort/package.json deleted file mode 100644 index 3dbc1ca..0000000 --- a/challenges/sorting-algorithms/solutions/javascript/bubble-sort/package.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "type": "module" -} diff --git a/challenges/sorting-algorithms/solutions/javascript/function/package.json b/challenges/sorting-algorithms/solutions/javascript/function/package.json deleted file mode 100644 index 3dbc1ca..0000000 --- a/challenges/sorting-algorithms/solutions/javascript/function/package.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "type": "module" -} diff --git a/challenges/sorting-algorithms/solutions/javascript/insertion-sort/package.json b/challenges/sorting-algorithms/solutions/javascript/insertion-sort/package.json deleted file mode 100644 index 3dbc1ca..0000000 --- a/challenges/sorting-algorithms/solutions/javascript/insertion-sort/package.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "type": "module" -} diff --git a/challenges/sorting-algorithms/solutions/javascript/merge-sort/package.json b/challenges/sorting-algorithms/solutions/javascript/merge-sort/package.json deleted file mode 100644 index 3dbc1ca..0000000 --- a/challenges/sorting-algorithms/solutions/javascript/merge-sort/package.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "type": "module" -} diff --git a/cli/services/Docker.ts b/cli/services/Docker.ts index 6355cb8..9e265a0 100644 --- a/cli/services/Docker.ts +++ b/cli/services/Docker.ts @@ -3,6 +3,7 @@ import ora from 'ora' class Docker { static CONTAINER_TAG = 'programming-challenges' + static SIGSEGV_EXIT_CODE = 139 public async build (): Promise { const loader = ora('Building the Docker image').start() @@ -22,11 +23,18 @@ class Docker { input } ) - const { stdout, stderr } = await subprocess - if (stderr.length !== 0) { - throw new Error(stderr) + try { + const { stdout, stderr } = await subprocess + if (stderr.length !== 0) { + throw new Error(stderr) + } + return stdout + } catch (error: any) { + if (error.exitCode === Docker.SIGSEGV_EXIT_CODE) { + throw new Error('Docker run failed: SIGSEGV indicates a segmentation fault (attempts to access a memory location that it\'s not allowed to access).') + } + throw new Error(`Docker run failed: ${error.message as string}`) } - return stdout } } diff --git a/challenges/camel-case/solutions/javascript/function/package.json b/templates/docker/javascript/package.json similarity index 100% rename from challenges/camel-case/solutions/javascript/function/package.json rename to templates/docker/javascript/package.json diff --git a/templates/docker/typescript/Dockerfile b/templates/docker/typescript/Dockerfile index 7f76dbd..6bf7aa6 100644 --- a/templates/docker/typescript/Dockerfile +++ b/templates/docker/typescript/Dockerfile @@ -1,4 +1,8 @@ FROM node:16.13.1 -RUN npm install --global ts-node typescript @types/node -COPY ./ ./ -CMD ["ts-node", "solution.ts"] + +WORKDIR /usr/app +COPY ./ /usr/app +RUN npm install +RUN npm run build + +CMD ["node", "build/solution.js"] diff --git a/templates/docker/typescript/package.json b/templates/docker/typescript/package.json new file mode 100644 index 0000000..d9ac8d8 --- /dev/null +++ b/templates/docker/typescript/package.json @@ -0,0 +1,10 @@ +{ + "type": "module", + "scripts": { + "build": "tsc" + }, + "devDependencies": { + "@types/node": "latest", + "typescript": "latest" + } +} diff --git a/templates/docker/typescript/tsconfig.json b/templates/docker/typescript/tsconfig.json new file mode 100644 index 0000000..7a4423c --- /dev/null +++ b/templates/docker/typescript/tsconfig.json @@ -0,0 +1,13 @@ +{ + "compilerOptions": { + "target": "ESNext", + "module": "ESNext", + "lib": ["ESNext"], + "moduleResolution": "node", + "outDir": "./build", + "rootDir": "./", + "strict": true, + "skipLibCheck": true, + "esModuleInterop": true + } +}