-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #166 from lmn8/scribunto-examples
Add Scribunto console/remoting examples
- Loading branch information
Showing
4 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# `nodemw` examples | ||
The `examples` directory contains `nodemw` script examples that communicate with the MediaWiki API. | ||
|
||
To run each example, use the following in your console: | ||
```console | ||
cd examples | ||
node pagesInCategory.js | ||
``` | ||
|
||
## Scribunto examples | ||
There are two scripts - `scribuntoConsole.js` and `scribuntoRemoteDebug.js` - that provide Scribunto debugging in your IDE using Node.js. | ||
|
||
The `scribuntoConsole.js` script will query the Scribunto console for a wiki module. | ||
|
||
The `scribuntoRemoteDebug.js` script will query the console for staging or debugging of a local file. A simple Scribunto module is provided at `'helloworld.lua'` for convenience and configuration testing. | ||
|
||
Script usage: | ||
1. Set the `title` value in the API query parameters (the `params` variable) to the module's current or future page name. | ||
2. When using `scribuntoRemoteDebug.js`, the local module is placed in the same folder. The script would be edited to replace the `'helloworld.lua'` file (the first `fs.readFile` argument) with your staged module's filename. | ||
3. When the script is run, the Scribunto console introduction is shown and a console session begins. | ||
4. Write a single line of Lua code into the console (for example, `p "help"`), and press <kbd>ENTER</kbd> to see the output. | ||
|
||
Note that for both scripts, the module content remains the same throughout the session. You will need to close the current session (<kbd>CTRL-C</kbd>) and rerun the script if there are changes to the module you wish to test. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--- Hello world module for Scribunto remote debugging on Node.js. | ||
local title = mw.title | ||
local currentTitle = title.getCurrentTitle() | ||
|
||
local CommandLine = require('Dev:CLI') | ||
local commands = {} | ||
|
||
function commands.hello(args) | ||
mw.log('Hello, world! Max didn\'t make me put this here.') | ||
end | ||
|
||
return CommandLine:new{ | ||
description = '"Hello world" command line script for Scribunto.', | ||
commands = commands, | ||
words = { | ||
hello = { | ||
description = 'Outputs a "hello world" string to the console.' | ||
} | ||
}, | ||
options = {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
'use strict'; | ||
const Bot = require( '..' ), | ||
readline = require( 'readline' ), | ||
c = require( 'ansicolors' ), | ||
rl = readline.createInterface( { | ||
input: process.stdin, | ||
output: process.stdout | ||
} ), | ||
client = new Bot( { | ||
protocol: 'https', | ||
server: 'dev.fandom.com', | ||
path: '' | ||
} ), | ||
params = { | ||
action: 'scribunto-console', | ||
title: 'Module:CLI/testcases/title', | ||
clear: true | ||
}; | ||
|
||
function call( err, info, next, data ) { | ||
if ( err ) { | ||
console.error( err ); | ||
} else if ( data.type === 'error' ) { | ||
console.error( data.message ); | ||
} else { | ||
console.log( data.print ); | ||
} | ||
} | ||
|
||
function cli( input ) { | ||
params.question = input; | ||
client.api.call( params, call ); | ||
} | ||
|
||
function session( err, content ) { | ||
params.content = content; | ||
console.log( c.green( '* The module exports are available as the variable "p", including unsaved modifications.' ) ); | ||
console.log( c.green( '* Precede a line with "=" to evaluate it as an expression, or use print().' ) ); | ||
console.log( c.green( '* Use mw.log() in module code to send messages to this console.' ) ); | ||
rl.on( 'line', cli ); | ||
} | ||
|
||
client.getArticle( params.title, session ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
'use strict'; | ||
const Bot = require( '..' ), | ||
readline = require( 'readline' ), | ||
fs = require( 'fs' ), | ||
c = require( 'ansicolors' ), | ||
rl = readline.createInterface( { | ||
input: process.stdin, | ||
output: process.stdout | ||
} ), | ||
client = new Bot( { | ||
protocol: 'https', | ||
server: 'dev.fandom.com', | ||
path: '' | ||
} ), | ||
params = { | ||
action: 'scribunto-console', | ||
title: 'Module:Sandbox/CLI', | ||
clear: true | ||
}; | ||
|
||
function call( err, info, next, data ) { | ||
if ( err ) { | ||
console.error( err ); | ||
} else if ( data.type === 'error' ) { | ||
console.error( data.message ); | ||
} else { | ||
console.log( data.print ); | ||
} | ||
} | ||
|
||
function cli( input ) { | ||
params.question = input; | ||
client.api.call( params, call ); | ||
} | ||
|
||
function session( err, data ) { | ||
params.content = data; | ||
console.log( c.green( '* The module exports are available as the variable "p", including unsaved modifications.' ) ); | ||
console.log( c.green( '* Precede a line with "=" to evaluate it as an expression, or use print().' ) ); | ||
console.log( c.green( '* Use mw.log() in module code to send messages to this console.' ) ); | ||
rl.on( 'line', cli ); | ||
} | ||
|
||
fs.readFile( 'helloworld.lua', 'utf8', session ); |