Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert to ES6 module system #62

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions exercises/arrow_function/exercise.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
"use strict";

var exercise = require('workshopper-exercise')();
var filecheck = require('workshopper-exercise/filecheck');
var execute = require('workshopper-exercise/execute');
var comparestdout = require('workshopper-exercise/comparestdout');
var babelProcessor = require('../babel-processor');
import exercise from 'workshopper-exercise';
import filecheck from 'workshopper-exercise/filecheck';
import execute from 'workshopper-exercise/execute';
import comparestdout from 'workshopper-exercise/comparestdout';
import babelProcessor from '../babel-processor';

var obj = comparestdout(execute(babelProcessor(filecheck(exercise()))));

module.exports = comparestdout(execute(babelProcessor(filecheck(exercise))));
var names = [
"Hello", "Babel", "Arrow", "Function", "Sebastian", "Mckenzie", "Yosuke"
];

module.exports.addSetup(function(mode, cb) {
obj.addSetup(function(mode, cb) {
// Fisher-Yates
var i = names.length;
while(i) {
Expand All @@ -25,3 +26,4 @@ module.exports.addSetup(function(mode, cb) {
process.nextTick(cb);
});

export default obj;
21 changes: 10 additions & 11 deletions exercises/babel-processor.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
"use strict";
var babel = require("babel-core");
var fs = require("fs");
var q = require("q");
var path = require("path");
var os = require("os");
var rimraf = require("rimraf");
import {transform} from "babel-core";
import fs from "fs";
import q from "q";
import path from "path";
import os from "os";
import rimraf from "rimraf";

var tmpDir = path.resolve(os.tmpDir(), "_babel_" + process.pid);

module.exports = function (exercise) {
export default function (exercise) {
exercise.addProcessor(processor);
exercise.addCleanup(cleanup);

Expand All @@ -20,8 +19,8 @@ function processor(mode, callback) {

q.nfcall(fs.mkdir, tmpDir).then(function () {
return q.nfcall(
fs.symlink,
path.resolve(__dirname + '/../node_modules'),
fs.symlink,
path.resolve(__dirname + '/../node_modules'),
tmpDir + '/node_modules');
})
.then(function(){
Expand Down Expand Up @@ -89,7 +88,7 @@ function writeFile(filename, contents) {
}

var transpile = q.fbind(function (contents, filename) {
var transpiled = babel.transform(contents, {
var transpiled = transform(contents, {
filename: filename,
modules: "common",
optional: ["runtime"]
Expand Down
16 changes: 9 additions & 7 deletions exercises/babel_setup/exercise.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
"use strict";

var exercise = require('workshopper-exercise')();
var filecheck = require('workshopper-exercise/filecheck');
var execute = require('workshopper-exercise/execute');
var comparestdout = require('workshopper-exercise/comparestdout');
var babelProcessor = require('../babel-processor');
import exercise from 'workshopper-exercise';
import filecheck from 'workshopper-exercise/filecheck';
import execute from 'workshopper-exercise/execute';
import comparestdout from 'workshopper-exercise/comparestdout';
import babelProcessor from '../babel-processor';

module.exports = comparestdout(execute(babelProcessor(filecheck(exercise))));
var obj = comparestdout(execute(babelProcessor(filecheck(exercise()))));

var names = ['ES6', 'Babel', '6to5', 'transpiler', 'ES2015'];
module.exports.addSetup(function(mode, cb) {
obj.addSetup(function(mode, cb) {
var name = names[Math.floor(Math.random() * names.length)];
this.requiredString = ['`', '$'];
this.submissionArgs = this.solutionArgs = [name];
process.nextTick(cb);
});

export default obj;
20 changes: 11 additions & 9 deletions exercises/block_scope/exercise.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
"use strict";

var exercise = require('workshopper-exercise')();
var filecheck = require('workshopper-exercise/filecheck');
var execute = require('workshopper-exercise/execute');
var comparestdout = require('workshopper-exercise/comparestdout');
var babelProcessor = require('../babel-processor');
import exercise from 'workshopper-exercise';
import filecheck from 'workshopper-exercise/filecheck';
import execute from 'workshopper-exercise/execute';
import comparestdout from 'workshopper-exercise/comparestdout';
import babelProcessor from '../babel-processor';

module.exports = comparestdout(execute(babelProcessor(filecheck(exercise))));
var obj = comparestdout(execute(babelProcessor(filecheck(exercise()))));

module.exports.addSetup(function(mode, cb) {
var x = Math.floor(Math.random() * 100);
var y = Math.floor(Math.random() * 100);
obj.addSetup(function(mode, cb) {
var x = Math.floor(Math.random() * 100);
var y = Math.floor(Math.random() * 100);
this.requiredString = ['let', 'const'];
this.submissionArgs = this.solutionArgs = [x, y];
process.nextTick(cb);
});

export default obj;
20 changes: 11 additions & 9 deletions exercises/class/exercise.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
"use strict";

var exercise = require('workshopper-exercise')();
var filecheck = require('workshopper-exercise/filecheck');
var execute = require('workshopper-exercise/execute');
var comparestdout = require('workshopper-exercise/comparestdout');
var babelProcessor = require('../babel-processor');
import exercise from 'workshopper-exercise';
import filecheck from 'workshopper-exercise/filecheck';
import execute from 'workshopper-exercise/execute';
import comparestdout from 'workshopper-exercise/comparestdout';
import babelProcessor from '../babel-processor';

module.exports = comparestdout(execute(babelProcessor(filecheck(exercise))));
var obj = comparestdout(execute(babelProcessor(filecheck(exercise()))));

module.exports.addSetup(function(mode, cb) {
var x = Math.floor(Math.random() * 100);
var y = Math.floor(Math.random() * 100);
obj.addSetup(function(mode, cb) {
var x = Math.floor(Math.random() * 100);
var y = Math.floor(Math.random() * 100);
this.requiredString = ['class'];
this.submissionArgs = this.solutionArgs = [x, y];
process.nextTick(cb);
});

export default obj;
21 changes: 12 additions & 9 deletions exercises/class_extend/exercise.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
"use strict";

var exercise = require('workshopper-exercise')();
var filecheck = require('workshopper-exercise/filecheck');
var execute = require('workshopper-exercise/execute');
var comparestdout = require('workshopper-exercise/comparestdout');
var babelProcessor = require('../babel-processor');
import exercise from 'workshopper-exercise';
import filecheck from 'workshopper-exercise/filecheck';
import execute from 'workshopper-exercise/execute';
import comparestdout from 'workshopper-exercise/comparestdout';
import babelProcessor from '../babel-processor';

var obj = comparestdout(execute(babelProcessor(filecheck(exercise()))));

module.exports = comparestdout(execute(babelProcessor(filecheck(exercise))));
var names = ['alice', 'bob', 'charlie', 'dave', 'eva'];

module.exports.addSetup(function(mode, cb) {
var x = Math.floor(Math.random() * 100);
var y = Math.floor(Math.random() * 100);
obj.addSetup(function(mode, cb) {
var x = Math.floor(Math.random() * 100);
var y = Math.floor(Math.random() * 100);
var name = names[Math.floor(Math.random() * names.length)];
this.requiredString = ['class', 'extends'];
this.submissionArgs = this.solutionArgs = [x, y, name];
process.nextTick(cb);
});

export default obj;
20 changes: 11 additions & 9 deletions exercises/computed_property/exercise.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
"use strict";

var exercise = require('workshopper-exercise')();
var filecheck = require('workshopper-exercise/filecheck');
var execute = require('workshopper-exercise/execute');
var comparestdout = require('workshopper-exercise/comparestdout');
var babelProcessor = require('../babel-processor');
import exercise from 'workshopper-exercise';
import filecheck from 'workshopper-exercise/filecheck';
import execute from 'workshopper-exercise/execute';
import comparestdout from 'workshopper-exercise/comparestdout';
import babelProcessor from '../babel-processor';

module.exports = comparestdout(execute(babelProcessor(filecheck(exercise))));
var obj = comparestdout(execute(babelProcessor(filecheck(exercise()))));

module.exports.addSetup(function(mode, cb) {
var x = Math.floor(Math.random() * 100);
var y = Math.floor(Math.random() * 100);
obj.addSetup(function(mode, cb) {
var x = Math.floor(Math.random() * 100);
var y = Math.floor(Math.random() * 100);
this.submissionArgs = this.solutionArgs = [x, y];
process.nextTick(cb);
});

export default obj;
17 changes: 10 additions & 7 deletions exercises/destructure/exercise.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
"use strict";

var exercise = require('workshopper-exercise')();
var filecheck = require('workshopper-exercise/filecheck');
var execute = require('workshopper-exercise/execute');
var comparestdout = require('workshopper-exercise/comparestdout');
var babelProcessor = require('../babel-processor');
import exercise from 'workshopper-exercise';
import filecheck from 'workshopper-exercise/filecheck';
import execute from 'workshopper-exercise/execute';
import comparestdout from 'workshopper-exercise/comparestdout';
import babelProcessor from '../babel-processor';

module.exports = comparestdout(execute(babelProcessor(filecheck(exercise))));
var obj = comparestdout(execute(babelProcessor(filecheck(exercise()))));

var names = ['Furukawa', 'Nakajima', 'Kuwahara', 'Sora', 'Ishikawa'];
module.exports.addSetup(function(mode, cb) {

obj.addSetup(function(mode, cb) {
var name = names[Math.floor(Math.random() * names.length)];
var day = Math.floor(Math.random() * 31);
this.submissionArgs = this.solutionArgs = [name, day];
process.nextTick(cb);
});

export default obj;
24 changes: 13 additions & 11 deletions exercises/generator/exercise.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
"use strict";

var fs = require('fs');
var path = require('path');
var os = require("os");
import fs from 'fs';
import path from 'path';
import os from 'os';

var exercise = require('workshopper-exercise')();
var filecheck = require('workshopper-exercise/filecheck');
var execute = require('workshopper-exercise/execute');
var comparestdout = require('workshopper-exercise/comparestdout');
var babelProcessor = require('../babel-processor');
import exercise from 'workshopper-exercise';
import filecheck from 'workshopper-exercise/filecheck';
import execute from 'workshopper-exercise/execute';
import comparestdout from 'workshopper-exercise/comparestdout';
import babelProcessor from '../babel-processor';

module.exports = comparestdout(execute(babelProcessor(filecheck(exercise))));
var obj = comparestdout(execute(babelProcessor(filecheck(exercise()))));

module.exports.addSetup(function(mode, cb) {
var x = Math.floor(Math.random() * 100);
obj.addSetup(function(mode, cb) {
var x = Math.floor(Math.random() * 100);
this.requiredString = ['yield'];
this.submissionArgs = this.solutionArgs = [x];
process.nextTick(cb);
});

export default obj;
24 changes: 13 additions & 11 deletions exercises/iterator_for_of/exercise.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
"use strict";

var fs = require('fs');
var path = require('path');
var os = require("os");
import fs from 'fs';
import path from 'path';
import os from 'os';

var exercise = require('workshopper-exercise')();
var filecheck = require('workshopper-exercise/filecheck');
var execute = require('workshopper-exercise/execute');
var comparestdout = require('workshopper-exercise/comparestdout');
var babelProcessor = require('../babel-processor');
import exercise from 'workshopper-exercise';
import filecheck from 'workshopper-exercise/filecheck';
import execute from 'workshopper-exercise/execute';
import comparestdout from 'workshopper-exercise/comparestdout';
import babelProcessor from '../babel-processor';

module.exports = comparestdout(execute(babelProcessor(filecheck(exercise))));
var obj = comparestdout(execute(babelProcessor(filecheck(exercise()))));

module.exports.addSetup(function(mode, cb) {
var x = Math.floor(Math.random() * 100);
obj.addSetup(function(mode, cb) {
var x = Math.floor(Math.random() * 100);
this.requiredString = ['Symbol.iterator'];
this.submissionArgs = this.solutionArgs = [x];
process.nextTick(cb);
});

export default obj;
20 changes: 11 additions & 9 deletions exercises/modules_default_export/exercise.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
"use strict";

var exercise = require('workshopper-exercise')();
var filecheck = require('workshopper-exercise/filecheck');
var execute = require('workshopper-exercise/execute');
var comparestdout = require('workshopper-exercise/comparestdout');
var babelProcessor = require('../babel-processor');
import exercise from 'workshopper-exercise';
import filecheck from 'workshopper-exercise/filecheck';
import execute from 'workshopper-exercise/execute';
import comparestdout from 'workshopper-exercise/comparestdout';
import babelProcessor from '../babel-processor';

module.exports = comparestdout(execute(babelProcessor(filecheck(exercise))));
var obj = comparestdout(execute(babelProcessor(filecheck(exercise()))));

module.exports.addSetup(function(mode, cb) {
obj.addSetup(function(mode, cb) {
if (process.argv.length !== 5) {
console.error("USAGE: tower-of-babel run|verify <executeFile> <importFile>");
throw new Error("invalid arguments");
}
this.submissionImportFile = process.argv[4];
this.requireImportString = ['export', 'default'];
var x = Math.floor(Math.random() * 100);
var y = Math.floor(Math.random() * 100);
var x = Math.floor(Math.random() * 100);
var y = Math.floor(Math.random() * 100);
this.submissionArgs = this.solutionArgs = [x, y];
this.requiredString = ['import'];
process.nextTick(cb);
});

export default obj;
20 changes: 11 additions & 9 deletions exercises/modules_with_name/exercise.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
"use strict";

var exercise = require('workshopper-exercise')();
var filecheck = require('workshopper-exercise/filecheck');
var execute = require('workshopper-exercise/execute');
var comparestdout = require('workshopper-exercise/comparestdout');
var babelProcessor = require('../babel-processor');
import exercise from 'workshopper-exercise';
import filecheck from 'workshopper-exercise/filecheck';
import execute from 'workshopper-exercise/execute';
import comparestdout from 'workshopper-exercise/comparestdout';
import babelProcessor from '../babel-processor';

module.exports = comparestdout(execute(babelProcessor(filecheck(exercise))));
var obj = comparestdout(execute(babelProcessor(filecheck(exercise()))));

module.exports.addSetup(function(mode, cb) {
obj.addSetup(function(mode, cb) {
if (process.argv.length !== 5) {
console.error("USAGE: tower-of-babel run|verify <executeFile> <importFile>");
throw new Error("invalid arguments");
}
this.submissionImportFile = process.argv[4];
this.requireImportString = ['export'];
var x = Math.floor(Math.random() * 100);
var y = Math.floor(Math.random() * 100);
var x = Math.floor(Math.random() * 100);
var y = Math.floor(Math.random() * 100);
this.requiredString = ['import'];
this.submissionArgs = this.solutionArgs = [x, y];
process.nextTick(cb);
});

export default obj;
Loading