Start typing to search...

Port existing code to Koji

In this tutorial, you will port an existing web app to Koji. You will then build and deploy the app to the Koji platform.

Prerequisites

  • Familiarity with basic Git commands.

  • Familiarity with the Koji editor and customization process. For an overview, go through the Koji starter tutorial.

Starting from a scaffold

Because every new Koji app is a fork of an existing one, you will want to find a good place to start from. There are scaffolds for many existing application frameworks, including Phaser, P5, and React.

In this case, you will be working with a React app.

  1. Open the Frontend-Only React Starter scaffold.

  2. Click Fork. After a short loading time, the app opens in Project Details.

  3. Click Open in Code Editor. After a short loading time, the app opens in the Koji editor.

Bringing in existing code

There are many ways to bring existing code into your Koji project. If you have private files to import, you could share them using a service and bring them in with something like wget.

For this example, you will import files from a public git repository. This repository contains the code for Paul Houghton’s Mortgage Overpayment Calculator.

  1. In the Koji editor, open the frontend terminal, and cancel the running process (for example, press Ctrl+C).

  2. Clone the Mortgage Overpayment Calculator repository into a temporary folder.

    git clone https://github.com/paulhoughton/mortgage.git temp
  3. Go to the temp/src folder, and move all the files from frontend/temp/src into frontend/src. They will replace some of the files already in that folder.

    cd temp/src
    mv *.* ../../src
  4. In the navigation panel, find the package.json file in the temp folder, and open it in the Koji editor.

    Mortgage Overpayment Calculator uses some functions from the D3.js JavaScript library to draw graphs. These functions must be listed as dependencies in the package.json file.

  5. Copy the following lines to the clipboard.

    "d3-axis": "^1.0.12",
    "d3-scale": "^2.2.2",
    "d3-selection": "^1.4.0",
    "d3-shape": "^1.3.4",
    "d3-transition": "^1.2.0",
  6. In the navigation panel, find the package.json file in the frontend folder and open it in the Koji editor.

  7. Paste the lines into the dependencies section. The new contents should look something like this.

    {
      "name": "frontend",
      "version": "0.1.0",
      "private": true,
      "dependencies": {
        "d3-axis": "^1.0.12",
        "d3-scale": "^2.2.2",
        "d3-selection": "^1.4.0",
        "d3-shape": "^1.3.4",
        "d3-transition": "^1.2.0",
        "@testing-library/jest-dom": "^5.11.4",
        "@testing-library/react": "^11.1.0",
        "@testing-library/user-event": "^12.1.10",
        "@withkoji/core": "^1.3.0",
        "react": "^17.0.1",
        "react-dom": "^17.0.1",
        "react-scripts": "4.0.1",
        ...
  8. Be sure to save the file.

  9. In the navigation panel, find index.html in the temp/public folder and open it in the editor.

  10. Copy the following lines to the clipboard.

    <link
      rel="stylesheet"
      href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
    />
  11. In the navigation panel, find the index.html in the frontend/public folder and open it in the editor.

  12. Paste the lines into the header section of the file. It should look something like this.

    <!DOCTYPE html>
    <html lang="en">
      <head>
        <meta charset="utf-8" />
        <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <meta name="theme-color" content="#000000" />
        <meta
          name="description"
          content="Web site created using create-react-app"
        />
        <link
          rel="stylesheet"
          href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
        />
        <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
        ...
  13. Be sure to save the file.

  14. In the terminal, go back to the frontend folder, and remove the temporary folder.

    cd ../..
    rm -rf temp
  15. Run the npm install command to install the new packages, then run the start command.

    npm install
    npm start
  16. Refresh the preview to see the Mortgage Overpayment Calculator.

Publishing your app

You are now ready to test a live build of your project.

  1. Click Publish Now on the left side of the editor.

    You will be prompted to enter additional information about your app, such as the name and description.

  2. Click Publish New Version.

    Publishing runs the build commands specified for the project, and then displays a live link to your production app.

Wrapping up

Hopefully, this tutorial has given you a better understanding of how to bring existing code onto the Koji platform. As a next step, you could make your app customizable by allowing creators to change the title or the color scheme, for example. And don’t forget to add your app to the App Store so that creators can add it to their profiles!