Giter Club home page Giter Club logo

materia-widget-dev-kit's Introduction

Materia Widget Development Kit (MWDK)

The Materia Widget Development Kit (MWDK) is designed to facilitate the rapid development of widgets for use in Materia. It is a required dependency of all widgets, and in addition to providing in-situ player and creator interfaces, the MWDK enables quick installation to a local Materia instance and compiling the widget for production use.

For more information about developing Materia widgets, visit our docs site

Features

  • Supports rapid development of player, creator, and score screen* interfaces
  • Live reloading
  • Helpful utilies including icon generators and screenshot annotation
  • Uses the same javascript as the production Materia Server
  • Quick installation to a local Materia instance and utilities for widget package compiling
  • Materia API mocking

*experimental feature

Setup

Visit the MWDK wiki for instructions related to installation, use, upgrading from prior versions, and more.

Contributing

For more information on contributing, visit the MWDK wiki.

materia-widget-dev-kit's People

Contributors

cayb0rg avatar clpetersonucf avatar dependabot[bot] avatar frenjaminbanklin avatar iturgeon avatar nathaned avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

materia-widget-dev-kit's Issues

Creator saves qsets for later use, but strips them of 'nonstandard' properties.

The MWDK is highly opinionated about what properties any given item in a qset should have, and omits properties it thinks should not belong.

This behavior ends up producing qset json files that are missing data necessary for the widget to function, which makes it difficult or impossible to test editing a currently existing widget properly.

Add ability to use a different demo.json for development

This is being done in several widgets, let's move support into the MWDK.

const devDemo = 'demo_dev.json'
if (process.env.npm_lifecycle_script == 'webpack-dev-server') {
	options.demoPath = devDemo
}
  • Add an option to getLegacyWidgetBuildConfig() named devDemoPath
  • If devDemoPath set and webpack dev server in use, load the file from devDemoPath
  • add a print output saying which demo.json is being loaded

Add a qset editor

It's technically possible to save and load a qset in the creator, but loading a custom qset in the player is severely limited - either demo.json would have to be changed, or an alternate demo_dev.json would have to be provided.

In addition to enabling the player to load instance qsets like the creator does, there should also be an interface (either built into the player/creator or as a separate page) to view/adjust those qsets.

Make it easier to override default module rules in webpack-widget config

Right now there's no easy way to override the rulesets for a given pattern, ex:

rules = [
    {
        test: /\.js$/,
        loader: 'some-loader'
    }
]

Overriding the default rules for the pattern matching JS files would require copying over significant chunks of the default webpack-widget config into the webpack config for an individual widget. Instead, we can create default definitions for individual rules, allowing them to be more easily overridden by widgets based on their needs, like so:

module: {
    rules: [
		rules.loaderDoNothingToJs,
		rules.loaderCompileCoffee,
	]
},

Add preflight checks to help new widget authors

Idea: add some checks to help deal with common problems when creating a new widget. These would check for all the required parts of a widget and make sure nothing is malformed - giving advice when possible.

1 minute mockup:

Screen Shot 2019-03-22 at 11 21 17 AM

Docker install option is broken with 2.5.0.0

docker inspect <image> is now prepending host_mnt to the Source path of the mounts. This breaks the host directory path MWDK uses to install widgets.

/path/to/materia/fuel/app/tmp/widget_packages

is now

/host_mnt/path/to/materia/fuel/app/tmp/widget_packages

DevMateria util to create a qset yaml from a CSV

This needs a bit more work, but I basically needed a way to create a qset file from an instructor's document. I decided to create a task to convert a CSV into a qset yaml file, however this will only work for short answer questions, and currently is somewhat hardcoded for Flash Cards

    // Accepts a csv file and turns it into a qset yaml file.
    // Only works for Question-Answer qsets (not multiple choice)
    // Requires CSV in the following format:
    // -------------------------------------
    //  "Q","A"
    //  "Your first question","Your first answer"
    //  "Your second question","Your second answer"
    //  ...
    // -------------------------------------
    // Additionally the file should have UNIX line endings
    // (If using Sublime Text, go to View->Line Endings->Unix)
    // Reading of the CSV file can be touchy, so you may
    // want to strip out non-printable characters in the CSV
    // Sed can do this:
    //      sed 's/[^[:print:]]|[^[\n]]//g' in.csv > out.csv
    public static function convert_csv_to_qset_yaml($csv_file)
    {
        // read in CSV
        $file_area = \File::forge(['basedir' => null]);
        $csv_data = \Format::forge($file_area->read($csv_file, true), 'csv')->to_array();
        // \Cli::write(print_r($csv_data, true));

        // go through each question and convert to a qset structure
        $items = [];
        foreach($csv_data as $q)
        {
            $item = [
                'materiaType' => 'question',
                'type' => 'QA',
                'id' => 0,
                'questions' => [ ['text' => $q['Q']] ],
                'assets' => [],
                'answers' => [[
                    'value' => '100',
                    'text' => $q['A'],
                    'id' => 0
                ]]
            ];

            $item['assets'][] = false;
            $item['assets'][] = false;

            $items[] = $item;

        }

        // create yaml
        // $qset = ['items' => $items ];
        $qset = [
            'rand' => false,
            'items' => [],
            'assets' => [],
            'options' => [],
            'name' => ''
        ];
        $qset['items'][] = ['items' => $items ];
        $yaml = \Format::forge($qset)->to_yaml();

        // write yaml
        $output_file = $csv_file.'_qset.yaml';
        if (file_exists($output_file))
        {
            $output_file = $csv_file.'_'.mt_rand().'_qset.yaml';
        }
        $file_area = \File::forge(['basedir' => null]);
        if ($file_area->create(DOCROOT, $output_file, $yaml))
        {
            \Cli::write($output_file.' created', 'green');
            self::quit();
        }

        \Cli::write(print_r($yaml, true));
    }

Target Materia docker container needs to be changed (again)

The docker command to grab the container name of the webserver will be incorrect with the new docker deployment changes coming to Materia:

docker ps -a --format "{{.Image}} {{.Names}}" | grep -e ".*materia-phpfpm:.* materia-phpfpm" | head -n 1 | cut -d" " -f2

The correct search string should be the following:

docker ps -a --format "{{.Image}} {{.Names}}" | grep -e ".*materia:.* docker_app_1" | head -n 1 | cut -d" " -f2

The MWDK needs to provide default values where appropriate.

Currently Materia will provide empty arrays for the 'features' and 'supported data' properties of a widget object if none exist for that widget - since the front end code is expecting those to be arrays, and the back end code is responsible for grabbing the relevant data from the database and formatting it properly.

The MWDK doesn't.

git config user.name and user.email aren't populated in build info yaml when run by github actions

Currently, building the widget with github actions results in a non-fatal error:

Error: Command failed: git config user.email

In the generateWidgetHash plugin:

email = execSync('git config user.email').toString()

Looking at older builds, those fields were never populated in the build info yaml, even if the builds are marked as successful. Either the way we grab user.name and user.email needs to change, or the github actions need to be updated to accommodate the issue.

Have the MWDK generate ids for question like object

The server creates ids for questions and answers if an object looks like a question, but the MWDK doesn't.

This will cause issues when testing scoring and playing if the player relies on those IDs.

The workaround right now is to add this to the individual widget's webpack config and create a second demo.json

//override the demo with a copy that assigns ids to each question for dev purposes
let configOptions = {}
if (process.env.npm_lifecycle_script == 'webpack-dev-server') {
	configOptions.demoPath = 'devmateria_demo.json'
}
module.exports = require('materia-widget-development-kit/webpack-widget').getLegacyWidgetBuildConfig(configOptions)

Add support for building markdown guide files

Convert .md files to .html guides given a template

Example in Crossword:

  1. Create markdown file in widget's src/_helper-docs/player.md
  2. Create HTML template in widget's src/_helper-docs/playerTemplate.html
  3. Add rules.loadGuideTemplate to webpack rules
  4. Add 'guides/player.html': [__dirname + '/src/_helper-docs/playerTemplate.html'] to webpack entries (same for creator)

running yarn build will then compile the markdown into html, and insert that into the given template, then export it to build/guides/player.html

Self-compiling widget server doesn't yet support custom qsets

It shouldn't be super tedious to implement, namely some updates to the bundled express.js in the widget-development-kit repo to handle custom question sets. Currently, the player always loads with the demo, regardless of whether or not you're previewing a custom Qset from the creator.

Add an install.yaml validator

The install.yaml file has a few strict requirements and is easy to mess up. It would be nice if the MDK had a yaml editor / builder, or at least a validator.

I can imagine a number of ways to go about this, perhaps it's best to split up into multiple issues. I'm open to ideas.

Windows Testing for new DevMateria

This is a deferred issue since we currently have no developers working in Windows.

This is in reference to the completed issue #715, specifically branch: "the-big-gulp" that has been merged into master most likely before this issue is looked at.

At the time of this issue's creation, the changes were QAed on Mac already.

Check for player and helper guides individually.

Currently the MWDK will check to see if src/_guides exists and, if so, run the creator and player guide files through a plugin to be fully generated.

This is fine most of the time, but if a widget is using the default creator it doesn't really need a creator guide - but if there isn't a creator guide, the build errors.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.