The code imports various modules and functions, including a utility function to parse version numbers, and defines a nodeKernel
function that uses the imported modules to create a Node.js kernel. The nodeKernel
function is then exported as a module, making it available for use in other parts of the application.
npm run import -- "node wire kernel"
var importer = require('../Core');
var {nodeJson, notebookJson} = importer.import("get kernel json");
var {wireKernel} = importer.import("jupyter wire kernel");
var {nativeKernelInfo} = importer.import("get kernel info");
var {processMetaKernel} = importer.import("process meta kernel");
var {languageInterface} = importer.import("get kernel language");
function getVersion(str) {
return str.split('.').map(v => parseInt(v, 10)).join('.')
}
function nodeKernel(config, options) {
return wireKernel({
kernel_config: config,
start_config: options,
install_config: notebookJson,
kernel_info: {
banner: 'Node JS',
// TODO: automatically create this from installation intructions
help_links: ['https://nodejs.org']
},
language_info: {
name: 'node',
file_extension: '.js',
mimetype: 'application/javascript',
version: getVersion(process.versions.node),
codemirror_mode: 'javascript'
},
child_process: [],
});
}
module.exports = nodeKernel;
const { importModules } = require('../Core');
const { nodeJson, notebookJson } = importModules('get kernel json');
const { wireKernel } = importModules('jupyter wire kernel');
const { nativeKernelInfo } = importModules('get kernel info');
const { processMetaKernel } = importModules('process meta kernel');
const { languageInterface } = importModules('get kernel language');
/**
* Extracts the version from a string in the format'major.minor.patch'
* @param {string} str - The version string
* @returns {string} The version in the format'major.minor.patch'
*/
function getVersion(str) {
const versionParts = str.split('.');
const version = versionParts.map((part) => parseInt(part, 10));
return version.join('.');
}
/**
* Creates a Node.js kernel configuration
* @param {object} config - The kernel configuration
* @param {object} options - The start configuration
* @returns {object} The Node.js kernel configuration
*/
function nodeKernel(config, options) {
const languageInfo = {
name: 'node',
fileExtension: '.js',
mimetype: 'application/javascript',
version: getVersion(process.versions.node),
codemirrorMode: 'javascript',
};
const kernelInfo = {
banner: 'Node JS',
helpLinks: ['https://nodejs.org'], // TODO: automatically create this from installation instructions
};
return wireKernel({
kernelConfig: config,
startConfig: options,
installConfig: notebookJson,
kernelInfo,
languageInfo,
childProcess: [],
});
}
module.exports = nodeKernel;
var importer = require('../Core');
var {nodeJson, notebookJson} = importer.import('get kernel json');
var {wireKernel} = importer.import('jupyter wire kernel');
var {nativeKernelInfo} = importer.import('get kernel info');
var {processMetaKernel} = importer.import('process meta kernel');
var {languageInterface} = importer.import('get kernel language');
Core
module using the require
function.import
method.function getVersion(str) {
return str.split('.').map(v => parseInt(v, 10)).join('.');
}
function nodeKernel(config, options) {
return wireKernel({
kernel_config: config,
start_config: options,
install_config: notebookJson,
kernel_info: {
banner: 'Node JS',
help_links: ['https://nodejs.org']
},
language_info: {
name: 'node',
file_extension: '.js',
mimetype: 'application/javascript',
version: getVersion(process.versions.node),
codemirror_mode: 'javascript'
},
child_process: [],
});
}
config
and options
.wireKernel
function with an object containing several properties.kernel_config
: the config
argument.start_config
: the options
argument.install_config
: an imported notebookJson
object.kernel_info
: an object containing information about the kernel, including a banner and help links.language_info
: an object containing information about the language, including its name, file extension, mimetype, and version (which is determined by calling the getVersion
function).child_process
: an empty array.module.exports = nodeKernel;
nodeKernel
function is exported as a module, making it available for use in other parts of the application.