1.0.0 • Published 3 years ago

@wearesponge/ignite-content-combiner v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

Ignite Content Combiner

This npm script takes a module folder which contains multiple ignite modules and combines the module information into a single JSON output.

Installation

You can install this script globally and use it anywhere by running:

npm install @wearesponge/ignite-content-combiner --global

Or alternatively it can be installed as part of a project:

npm install @wearesponge/ignite-content-combiner --save-dev

Usage

Basic Example

This will output the JSON to the terminal:

# ignite-content-combiner <sourceFolder>
ignite-content-combiner ./myModule

Output To File Example

This will output the JSON to the specified file:

# ignite-content-combiner <sourceFolder> --outFile <outFile>
# ignite-content-combiner <sourceFolder> -o <outFile>
ignite-content-combiner ./myModule --outFile ./output.json

Example

If we have a module with two languages EN and DE: (JSON shortened for brevity)

// sourceFolder/en/module.json
{
  "topics": [
    {
      "pages": [
        {
          "sections": [
            {
              "items": [
                {
                  "type": "SingleChoiceItem",
                  "uuid": "abcdefgh-1234-1234-1234-abcdefghijkl",
                  "data": {
                    "question": {
                      "source": "This is the question text in English"
                    },
                    "choices": [
                      {
                        "value": {
                          "source": "This is the choice text in English"
                        }
                      }
                    ]
                  }
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}

// sourceFolder/de/module.json
{
  "topics": [
    {
      "pages": [
        {
          "sections": [
            {
              "items": [
                {
                  "type": "SingleChoiceItem",
                  "uuid": "ijklmnop-5678-5678-5678-ijklmnopqrst",
                  "data": {
                    "question": {
                      "source": "This is the question text in English",
                      "translation": "This is the question text in Deutsch"
                    },
                    "choices": [
                      {
                        "value": {
                          "source": "This is the choice text in English",
                          "translation": "This is the choice text in Deutsch"
                        }
                      }
                    ]
                  }
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}

This script will extract the relevant information and combine them together assuming the structure is the same:

{
  "1": {
    "type": "SingleChoiceItem",
    "uuids": [
      "abcdefgh-1234-1234-1234-abcdefghijkl",
      "ijklmnop-5678-5678-5678-ijklmnopqrst"
    ],
    "question": {
      "en": "This is the question text in English",
      "de": "This is the question text in Deutsch"
    },
    "choices": [
      {
        "en": "This is the choice text in English",
        "de": "This is the choice text in Deutsch"
      }
    ]
  }
}