aboutsummaryrefslogtreecommitdiff
path: root/course/chapters/05-modules.json
blob: 4b68f42b85aa7aefaf0d357fd8ad4edaad9c2efe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
{
  "id": "05-modules",
  "title": "Modules & packages",
  "icon": "🧩",
  "level": "intermediate",
  "lessons": [
    {
      "id": "5.1",
      "title": "Browse and install modules",
      "objective": "See what is loaded and install from the WebX11 package index.",
      "minutes": 8,
      "commands": [
        "modules",
        "wpm",
        "load-local"
      ],
      "blocks": [
        {
          "type": "text",
          "text": "`wpm` is the package manager for terminal modules: list the index, install a module from `packages.json` or a URL."
        },
        {
          "type": "cmd",
          "text": "wpm list"
        },
        {
          "type": "cmd",
          "text": "modules"
        },
        {
          "type": "text",
          "text": "Every ext module in the default build auto-loads. There is no separate “needs loadmod” tier."
        },
        {
          "type": "cmd",
          "text": "load-local modules/ext/calc.js"
        }
      ],
      "exercise": {
        "instruction": "List available packages.",
        "accept": [
          "wpm list"
        ],
        "check": {
          "type": "command"
        },
        "hint": "Type: wpm list"
      },
      "quiz": {
        "q": "What does wpm install?",
        "options": [
          "terminal modules",
          "system packages",
          "browser extensions"
        ],
        "answer": 0
      },
      "sources": [
        "modules/ext/wpm.js",
        "packages.json",
        "modules/core/module-loader.js"
      ]
    },
    {
      "id": "5.2",
      "title": "Module anatomy (a complete mini module)",
      "objective": "Read the contract every module follows: class, commands map, help info, registration.",
      "minutes": 12,
      "commands": [
        "load-local"
      ],
      "blocks": [
        {
          "type": "text",
          "text": "A module is a class with `commands`, `registerCommands()`, `getHelpInfo()` and optionally `init(terminal)`. The module manager injects `terminal` before calling `registerCommands()`."
        },
        {
          "type": "code",
          "text": "class HelloModule {\n  constructor(){ this.commands = {}; }\n  getHelpInfo(){ return { hello: 'hello — print a greeting' }; }\n  registerCommands(){ this.commands['hello'] = () => this.terminal.print('hello newOS4'); }\n}"
        },
        {
          "type": "tip",
          "text": "Tier-3 modules register at the end with `webx11.moduleManager.registerModule(new HelloModule(), url)`."
        },
        {
          "type": "cmd",
          "text": "modules"
        }
      ],
      "exercise": {
        "instruction": "Open the module list and find a module you have not used.",
        "accept": [
          "modules"
        ],
        "check": {
          "type": "command"
        },
        "hint": "Type: modules"
      },
      "quiz": {
        "q": "What does the module manager inject before registerCommands()?",
        "options": [
          "the terminal",
          "the database",
          "nothing"
        ],
        "answer": 0
      },
      "sources": [
        "modules/core/module-manager.js",
        "modules/ext/kanban.js"
      ]
    }
  ]
}