2021-01-16 13:27:14 +01:00
|
|
|
#!/usr/bin/env node
|
2021-01-16 13:14:17 +01:00
|
|
|
|
2021-01-16 13:27:14 +01:00
|
|
|
const { execute } = require('../shared/execute');
|
|
|
|
const { readFileSync } = require('fs');
|
|
|
|
const languages = require('../shared/languages.json');
|
|
|
|
|
|
|
|
const [languageName, sourceFile, ...args] = process.argv.slice(2);
|
|
|
|
|
|
|
|
(async () => {
|
|
|
|
if (!languageName) {
|
|
|
|
console.error('Provide a language name');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!sourceFile) {
|
|
|
|
console.error('Provide a source file');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const source = readFileSync(sourceFile).toString();
|
|
|
|
|
|
|
|
const language = languages.find(language => language.aliases.includes(languageName.toLowerCase()));
|
|
|
|
|
|
|
|
if (!language) {
|
|
|
|
console.error(`${languageName} is not supported by Piston`);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-01-16 18:41:41 +01:00
|
|
|
const { output } = await execute(language, source, '', args);
|
2021-01-16 13:27:14 +01:00
|
|
|
|
|
|
|
console.log(output);
|
|
|
|
})();
|