-
Notifications
You must be signed in to change notification settings - Fork 1
/
python.js
31 lines (24 loc) · 2.19 KB
/
python.js
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
var pythonjs = Npm.require('python-js');
var handler = function (compileStep) {
var source = compileStep.read().toString('utf8');
var outputFile = compileStep.inputPath + ".js";
try {
var output = pythonjs.translator.to_javascript( source );
} catch (e) {
throw new Error(
compileStep.inputPath + ':' +
e.message
);
}
output = output.replace(" require(", "Npm.require(");
output = pythonjs.runtime.javascript + output;
compileStep.addJavaScript({
path: outputFile,
sourcePath: compileStep.inputPath,
data: output,
// sourceMap: ... ?
bare: compileStep.fileOptions.bare
});
};
Plugin.registerSourceHandler("py", handler);
Plugin.registerSourceHandler("python", handler);