Sakwe Sakwe
Goal
- You have a list of Question Answer pairs and
- You have to create a system that consumes the list then answer asked questions using the list
Step by Step
-
Decide on what technology stack to use
- The system is a
nodejs package
- We use
Typescript
as the coding language - We use
Gulp
as the build system (along with Typescript and Babel plugins) - We use
jest
for testing
- The system is a
-
Initialize the project
# in your terminal mkdir sakwesakwecd sakwesakwenpm init -y
- Create the project structure
/- | - __tests__ | - index.js # we test javascript usage | - index.ts # Make sure our package can be used in other typescript projects | - src | - index.ts | - dist | - index.js
- Install development related packages
npm install --save-dev typescriptnpm install --save-dev @types/nodenpm install --save-dev gulp-clinpm install --save-dev gulpnpm install --save-dev gulp-sourcemapsnpm install --save-dev gulp-typescriptnpm install --save-dev gulp-babel babel-plugin-transform-runtime babel-preset-es2015npm install --save-dev jestnpm install --save-dev ts-jest @types/jest
- Create Typescript configuration file
tsconfig.json
// inside package.json... "scripts": ... "tsc:init": "node ./node_modules/typescript/lib/tsc --init" "tsc:compile": "node ./node_modules/typescript/lib/tsc"... ...
npm run tsc:init
- Modify the Typescript config file
tsconfig.json
so that it compiles to es6
... "compilerOptions": "target": "es6" ...
- Add Jest configuration info to
package.json
// inside package.json... "scripts": ... "test": "jest"... ... "jest": "transform": ".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js" "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$" "moduleFileExtensions": "ts" "tsx" "js" ...
- Create a
gulpfile.js
touch gulpfile.js
- Add script content to the Gulp file
var gulp = ; var sourcemaps = ; var ts = ; var babel = ; var tsProject = ts; gulp;
- Create a test for Javascript usage
touch __tests__/index.js
// inside __tests__/index.js;
- Create a test for Typescript usage
touch __tests__/index.ts
// inside __tests__/index.tsdescribe'matching cities to foods',;
- Run the tests They should fail
npm test
- Write the required logic