Skip to content

Commit

Permalink
Merge pull request #2 from oat-sa/release_0.1.0
Browse files Browse the repository at this point in the history
Release 0.1.0
  • Loading branch information
krampstudio authored May 21, 2019
2 parents aa984f2 + b72d2c4 commit 9f21e28
Show file tree
Hide file tree
Showing 250 changed files with 42,711 additions and 0 deletions.
71 changes: 71 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"env" : {
"browser" : true,
"es6" : true,
"qunit" : true,
"node" : true
},
"globals" : {
"ENVIRONMENT" : true
},
"plugins" : ["es", "jsdoc"],
"parserOptions" : {
"sourceType" : "module",
"ecmaVersion" : 2015
},
"extends" : "eslint:recommended",
"rules" : {
"array-bracket-newline" : ["warn", "consistent"],
"arrow-body-style" : ["error", "as-needed"],
"arrow-spacing" : ["warn", { "before" : true, "after" : true }],
"brace-style" : ["warn", "1tbs"],
"consistent-this" : ["error", "self"],
"eqeqeq" : ["error", "smart"],
"es/no-classes" : ["error"],
"es/no-generators" : ["error"],
"func-call-spacing" : ["error"],
"implicit-arrow-linebreak" : ["error"],
"indent" : ["warn", 4, { "SwitchCase" : 1, "MemberExpression" : "off" }],
"jsdoc/check-alignment" : ["warn"],
"jsdoc/check-param-names" : ["warn"],
"jsdoc/require-param" : ["warn"],
"jsdoc/require-param-name" : ["warn"],
"jsdoc/require-param-type" : ["warn"],
"jsdoc/require-returns" : ["warn"],
"jsdoc/require-returns-check" : ["warn"],
"jsdoc/require-returns-type" : ["warn"],
"linebreak-style" : ["error", "unix"],
"new-parens" : ["error"],
"no-alert" : ["error"],
"no-caller" : ["error"],
"no-confusing-arrow" : ["error", { "allowParens" : false }],
"no-console" : ["error"],
"no-debugger" : ["error"],
"no-duplicate-imports" : ["error"],
"no-eval" : ["error"],
"no-extend-native" : ["error"],
"no-extra-bind" : ["error"],
"no-implicit-globals" : ["error"],
"no-implied-eval" : ["error"],
"no-lone-blocks" : ["error"],
"no-multi-assign" : ["error"],
"no-new-func" : ["error"],
"no-script-url" : ["error"],
"no-self-compare" : ["error"],
"no-sequences" : ["error"],
"no-shadow" : ["error", { "hoist" : "functions" }],
"no-template-curly-in-string" : ["error"],
"no-throw-literal" : ["error"],
"no-trailing-spaces" : ["error"],
"no-undefined" : ["error"],
"no-use-before-define" : ["error", { "functions" : false }],
"no-useless-call" : ["error"],
"no-useless-computed-key" : ["error"],
"no-useless-rename" : ["error"],
"prefer-rest-params" : ["error"],
"prefer-spread" : ["error"],
"prefer-template" : ["error"],
"semi" : ["error", "always"],
"vars-on-top" : ["error"]
}
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,5 @@ typings/

# next.js build output
.next

dist
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@
# tao-core-sdk-fe
TAO Frontend Core SDK

Core libraries of TAO.

Available scripts in the project:

- `HOST=<host> PORT=<port> npm run test <testname>`: run test suite
- `HOST` (optional environment variable, default: 127.0.0.1): Test server listen host
- `PORT` (optional environment variable, default: 8082): Test server listen port
- `testname` (optional): Specific test to run. If it is not provided, all will be ran.
- `HOST=<host> PORT=<port> npm run test:keepAlive`: start test server
- `HOST` (optional environment variable, default: 127.0.0.1): Test server listen host
- `PORT` (optional environment variable, default: 8082): Test server listen port
- `npm run build`: build for production into `dist` directory
- `npm run lint`: check syntax of code
31 changes: 31 additions & 0 deletions build/path.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; under version 2
* of the License (non-upgradable).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2019 (original work) Open Assessment Technologies SA ;
*/

/**
* This file contains path definitions for build scripts.
*/
const path = require("path");
const rootPath = path.resolve(__dirname, "..");

module.exports = {
srcDir: path.resolve(rootPath, "src"),
testDir: path.resolve(rootPath, "test"),
outputDir: path.resolve(rootPath, "dist"),
testOutputDir: path.resolve(rootPath, "test")
};

98 changes: 98 additions & 0 deletions build/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; under version 2
* of the License (non-upgradable).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2019 (original work) Open Assessment Technologies SA ;
*/

import path from 'path';
import glob from 'glob';
import alias from 'rollup-plugin-alias';
import json from 'rollup-plugin-json';
import copy from 'rollup-plugin-copy';

const { srcDir, outputDir } = require('./path');

const inputs = glob.sync(path.join(srcDir, '!(lib)', '**', '*.js'));
const inputGlobalNames = inputs.reduce((memo, input) => {
const moduleName = path.relative(srcDir, input).replace(/\.js$/, '');
return { ...memo, [moduleName]: moduleName };
}, {});

const localExternals = inputs.map(input => path.relative(srcDir, input).replace(/\.js$/, ''));

const libs = glob.sync(path.join(srcDir, 'lib', '**', '*.js'));
const libExternals = libs.map(input => path.relative(srcDir, input).replace(/\.js$/, ''));

export default inputs.map(input => {
const name = path.relative(srcDir, input).replace(/\.js$/, '');
const dir = path.dirname(path.relative(srcDir, input));

return {
input,
output: {
dir: path.join(outputDir, dir),
format: 'umd',
name,
globals: {
jquery: '$',
lodash: '_',
context: 'context',
module: 'module',
moment: 'moment',
i18n: '__',
async: 'async',
handlebars: 'handlebars',
'lib/uuid': 'lib/uuid',
'lib/store/idbstore': 'lib/store/idbstore',
'lib/decimal/decimal': 'lib/decimal/decimal',
'lib/expr-eval/expr-eval': 'lib/expr-eval/expr-eval',
'lib/polyfill/es6-promise': 'lib/polyfill/es6-promise',
...inputGlobalNames
}
},
external: [
...localExternals,
...libExternals,
'jquery',
'lodash',
'handlebars',
'moment',
'i18n',
'async',
'jquery.fileDownload',
'module',
'context',
'lib/uuid',
'lib/store/idbstore',
'lib/decimal/decimal',
'lib/expr-eval/expr-eval'
],
plugins: [
alias({
resolve: ['.js', '.json'],
core: path.resolve(srcDir, 'core'),
util: path.resolve(srcDir, 'util'),
lib: path.resolve(srcDir, 'lib')
}),
json({
preferConst: false
}),
copy({
targets: [path.resolve(srcDir, 'lib')],
outputFolder: outputDir
})
]
};
});
73 changes: 73 additions & 0 deletions build/testrunner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; under version 2
* of the License (non-upgradable).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2019 (original work) Open Assessment Technologies SA ;
*/

const glob = require('glob');
const path = require('path');
const { runQunitPuppeteer, printResultSummary, printFailedTests } = require('node-qunit-puppeteer');
const promiseLimit = require('promise-limit');

const webServer = require('./webserver');

const { testDir } = require('./path');

const TESTNAME = process.argv[2] || '*';

let hasFailed = false;
const limit = promiseLimit(5);

webServer.then(({ host, port }) =>
Promise.all(
glob.sync(path.join(testDir, '**', TESTNAME, '**', '*.html')).map(testFile => {
const test = path.relative(testDir, testFile);
const qunitArgs = {
// Path to qunit tests suite
targetUrl: `http://${host}:${port}/test/${test}`,
// (optional, 30000 by default) global timeout for the tests suite
timeout: 30000,
// (optional, false by default) should the browser console be redirected or not
redirectConsole: false
};

return limit(() =>
runQunitPuppeteer(qunitArgs)
.then(result => {
if (TESTNAME === '*') {
process.stdout.write('.');
} else {
process.stdout.write(`${testFile} `);
printResultSummary(result, console);
console.log();
}

if (result.stats.failed > 0) {
console.log(`\n${testFile}`);
printFailedTests(result, console);
hasFailed = true;
}
})
.catch(ex => {
console.error(testFile);
console.error(ex);
})
);
})
).then(() => {
console.log();
process.exit(hasFailed ? -1 : 0);
})
);
54 changes: 54 additions & 0 deletions build/webserver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; under version 2
* of the License (non-upgradable).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2019 (original work) Open Assessment Technologies SA ;
*/

const HttpServer = require('http-server');
const fs = require('fs');
const path = require('path');

const HOST = process.env.HOST || '127.0.0.1';
const PORT = process.env.PORT || '8082';
const ROOT = path.resolve(__dirname, '..');

module.exports = new Promise(resolve =>
new HttpServer.createServer({
root: ROOT,
cache: -1,
before: [
(req, res) => {
if (req.method === 'POST') {
res.writeHead(200, { 'Content-Type': 'application/json' });
fs.readFile(path.join(__dirname, '..', req.url), (err, data) => {
if (err) throw err;
res.end(data.toString());
});
} else {
res.emit('next');
}
}
]
}).listen(PORT, HOST, err => {
if (err) {
console.log(err);
process.exit(-1);
}

console.log(`Server is listening on http://${HOST}:${PORT}/ and serving ${ROOT}`);

resolve({ host: HOST, port: PORT });
})
);
Loading

0 comments on commit 9f21e28

Please sign in to comment.