install stockfish.js via npm

pull/4693/head
Niklas Fiekas 2018-11-06 15:26:53 +01:00
parent 9fe48e0fd8
commit 1ef896e5d9
6 changed files with 23 additions and 82 deletions

2
.gitignore vendored
View File

@ -6,10 +6,10 @@ project/project
project/target
public/trans
public/compiled
public/vendor/stockfish
public/vendor/stockfish.wasm
public/vendor/stockfish-mv.wasm
public/vendor/stockfish.pexe
public/vendor/stockfish.js
target
bin/.translate_version
data/

View File

@ -43,11 +43,10 @@ export default function(opts: CevalOpts): CevalCtrl {
const hovering = prop<Hovering | null>(null);
const isDeeper = prop(false);
const sfPath = 'vendor/stockfish/stockfish';
const pool = new Pool({
asmjs: li.assetUrl(sfPath + '.js', {sameDomain: true}),
pnacl: pnaclSupported && li.assetUrl('vendor/stockfish.pexe/stockfish.nmf'),
wasm: wasmSupported && li.assetUrl(sfPath + '.wasm.js', {sameDomain: true}),
asmjs: 'vendor/stockfish.js/stockfish.js',
pnacl: pnaclSupported && 'vendor/stockfish.pexe/stockfish.nmf',
wasm: wasmSupported && 'vendor/stockfish.js/stockfish.wasm.js',
wasmThreaded: wasmThreadsSupported && (officialStockfish(opts.variant.key) ? 'vendor/stockfish.wasm/stockfish.js' : 'vendor/stockfish-mv.wasm/stockfish.js'),
onCrash: opts.onCrash
}, {

View File

@ -50,7 +50,7 @@ class WebWorker extends AbstractWorker {
worker: Worker;
boot(): Promise<Protocol> {
this.worker = new Worker(this.url);
this.worker = new Worker(window.lichess.assetUrl(this.url, {sameDomain: true}));
const protocol = new Protocol(this.send.bind(this), this.workerOpts);
this.worker.addEventListener('message', e => {
protocol.received(e.data);
@ -96,7 +96,7 @@ class PNaClWorker extends AbstractWorker {
this.worker = document.createElement('object');
this.worker.width = '0';
this.worker.height = '0';
this.worker.data = this.url;
this.worker.data = window.lichess.assetUrl(this.url);
this.worker.type = 'application/x-pnacl';
this.listener.appendChild(this.worker);
} catch (err) {

View File

@ -6,8 +6,6 @@ const tsify = require('tsify');
const uglify = require('gulp-uglify');
const streamify = require('gulp-streamify');
const concat = require('gulp-concat');
const request = require('request');
const download = require('gulp-download-stream');
const exec = require('child_process').exec;
const fs = require('fs');
@ -33,30 +31,6 @@ gulp.task('ab', function() {
}
});
function downloadGithubRelease(repo, dest, cb) {
const headers = {'User-Agent': 'lila/gulpfile.js'};
if (process.env.GITHUB_API_TOKEN) {
headers['Authorization'] = 'token ' + process.env.GITHUB_API_TOKEN;
}
request({
url: 'https://api.github.com/repos/' + repo + '/releases/latest',
headers: headers
}, function(err, res, body) {
if (err) throw err;
const release = JSON.parse(body);
download(release.assets.filter(function(asset) {
const path = dest + asset.name;
if (!fs.existsSync(path)) return true;
const stat = fs.statSync(path);
return stat.mtime < new Date(asset.updated_at) || stat.size != asset.size;
}).map(function (asset) {
return asset.browser_download_url;
})).pipe(gulp.dest(dest)).on('end', cb);
});
}
gulp.task('stockfish.pexe', function() {
gulp.src([
require.resolve('stockfish.pexe/stockfish.nmf'),
@ -66,7 +40,11 @@ gulp.task('stockfish.pexe', function() {
});
gulp.task('stockfish.js', function(cb) {
downloadGithubRelease('niklasf/stockfish.js', '../../public/vendor/stockfish/', cb);
gulp.src([
require.resolve('stockfish.js/stockfish.wasm.js'),
require.resolve('stockfish.js/stockfish.wasm'),
require.resolve('stockfish.js/stockfish.js')
]).pipe(gulp.dest('../../public/vendor/stockfish.js'));
});
gulp.task('stockfish.wasm', function() {
@ -160,12 +138,7 @@ gulp.task('user-mod', function() {
.pipe(gulp.dest(destination));
});
const tasks = ['git-sha', 'jquery-fill', 'ab', 'standalones', 'user-mod', 'stockfish.wasm', 'stockfish-mv.wasm', 'stockfish.pexe'];
if (!process.env.TRAVIS || process.env.GITHUB_API_TOKEN) {
if (!process.env.NO_SF) { // to skip SF download
tasks.push('stockfish.js');
}
}
const tasks = ['git-sha', 'jquery-fill', 'ab', 'standalones', 'user-mod', 'stockfish.wasm', 'stockfish-mv.wasm', 'stockfish.pexe', 'stockfish.js'];
gulp.task('dev', tasks.concat(['dev-source']), makeBundle('lichess.site.source.js'));
gulp.task('prod', tasks.concat(['prod-source']), makeBundle('lichess.site.source.min.js'));

View File

@ -12,17 +12,16 @@
"browserify": "^14",
"gulp": "^3",
"gulp-concat": "^2.6",
"gulp-download-stream": "^0.0",
"gulp-streamify": "^1",
"gulp-uglify": "^3",
"gulp-util": "^3",
"request": "^2",
"tsify": "^4.0.0",
"uglify-js": "^3",
"vinyl-source-stream": "^1"
},
"dependencies": {
"stockfish-mv.wasm": "^0.2.0",
"stockfish.js": "^9.0.0",
"stockfish.pexe": "^9.0.0",
"stockfish.wasm": "^0.2.0",
"tablesort": "^5.0.0"

View File

@ -108,13 +108,6 @@ ajv@^5.3.0:
fast-json-stable-stringify "^2.0.0"
json-schema-traverse "^0.3.0"
ansi-colors@^1.0.1, ansi-colors@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/ansi-colors/-/ansi-colors-1.1.0.tgz#6374b4dd5d4718ff3ce27a671a3b1cad077132a9"
integrity sha512-SFKX67auSNoVR38N3L+nvsPjOE0bybKTYbkf5tRvushrAPQ9V75huw0ZxBkKVeRU9kqH3d6HA4xTckbwZ4ixmA==
dependencies:
ansi-wrap "^0.1.0"
ansi-gray@^0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/ansi-gray/-/ansi-gray-0.1.1.tgz#2962cf54ec9792c48510a3deb524436861ef7251"
@ -137,7 +130,7 @@ ansi-styles@^2.2.1:
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-2.2.1.tgz#b432dd3358b634cf75e1e4664368240533c1ddbe"
integrity sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=
ansi-wrap@0.1.0, ansi-wrap@^0.1.0:
ansi-wrap@0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/ansi-wrap/-/ansi-wrap-0.1.0.tgz#a82250ddb0015e9a27ca82e82ea603bbfa45efaf"
integrity sha1-qCJQ3bABXponyoLoLqYDu/pF768=
@ -1562,7 +1555,7 @@ extsprintf@^1.2.0:
resolved "https://registry.yarnpkg.com/extsprintf/-/extsprintf-1.4.0.tgz#e2689f8f356fad62cca65a3a91c5df5f9551692f"
integrity sha1-4mifjzVvrWLMplo6kcXfX5VRaS8=
fancy-log@^1.1.0, fancy-log@^1.3.2:
fancy-log@^1.1.0:
version "1.3.2"
resolved "https://registry.yarnpkg.com/fancy-log/-/fancy-log-1.3.2.tgz#f41125e3d84f2e7d89a43d06d958c8f78be16be1"
integrity sha1-9BEl49hPLn2JpD0G2VjI94vha+E=
@ -1984,19 +1977,6 @@ gulp-concat@^2.6:
through2 "^2.0.0"
vinyl "^2.0.0"
gulp-download-stream@^0.0:
version "0.0.19"
resolved "https://registry.yarnpkg.com/gulp-download-stream/-/gulp-download-stream-0.0.19.tgz#bc608886813aa4d7789d20d485fd8a3639774fbf"
integrity sha1-vGCIhoE6pNd4nSDUhf2KNjl3T78=
dependencies:
ansi-colors "^1.1.0"
fancy-log "^1.3.2"
merge "^1.2.0"
plugin-error "^1.0.1"
pretty-hrtime "^1.0.3"
request "^2.85.0"
vinyl "^2.1.0"
gulp-sourcemaps@1.6.0:
version "1.6.0"
resolved "https://registry.yarnpkg.com/gulp-sourcemaps/-/gulp-sourcemaps-1.6.0.tgz#b86ff349d801ceb56e1d9e7dc7bbcb4b7dee600c"
@ -3077,11 +3057,6 @@ merge@1.2.0:
resolved "https://registry.yarnpkg.com/merge/-/merge-1.2.0.tgz#7531e39d4949c281a66b8c5a6e0265e8b05894da"
integrity sha1-dTHjnUlJwoGma4xabgJl6LBYlNo=
merge@^1.2.0:
version "1.2.1"
resolved "https://registry.yarnpkg.com/merge/-/merge-1.2.1.tgz#38bebf80c3220a8a487b6fcfb3941bb11720c145"
integrity sha512-VjFo4P5Whtj4vsLzsYBu5ayHhoHJ0UqNm7ibvShmbmoz7tGi0vXaoJbGdB+GmDMLUdg8DpQXEIeVDAe8MaABvQ==
micromatch@^2.1.5, micromatch@^2.3.11, micromatch@^2.3.7:
version "2.3.11"
resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-2.3.11.tgz#86677c97d1720b363431d04d0d15293bd38c1565"
@ -3810,16 +3785,6 @@ plexer@1.0.1:
isstream "^0.1.2"
readable-stream "^2.0.2"
plugin-error@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/plugin-error/-/plugin-error-1.0.1.tgz#77016bd8919d0ac377fdcdd0322328953ca5781c"
integrity sha512-L1zP0dk7vGweZME2i+EeakvUNqSrdiI3F91TwEoYiGrAfUXmVv6fJIq4g82PAXxNsWOp0J7ZqQy/3Szz0ajTxA==
dependencies:
ansi-colors "^1.0.1"
arr-diff "^4.0.0"
arr-union "^3.1.0"
extend-shallow "^3.0.2"
posix-character-classes@^0.1.0:
version "0.1.1"
resolved "https://registry.yarnpkg.com/posix-character-classes/-/posix-character-classes-0.1.1.tgz#01eac0fe3b5af71a2a6c02feabb8c1fef7e00eab"
@ -3830,7 +3795,7 @@ preserve@^0.2.0:
resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b"
integrity sha1-gV7R9uvGWSb4ZbMQwHE7yzMVzks=
pretty-hrtime@^1.0.0, pretty-hrtime@^1.0.3:
pretty-hrtime@^1.0.0:
version "1.0.3"
resolved "https://registry.yarnpkg.com/pretty-hrtime/-/pretty-hrtime-1.0.3.tgz#b7e3ea42435a4c9b2759d99e0f201eb195802ee1"
integrity sha1-t+PqQkNaTJsnWdmeDyAesZWALuE=
@ -4068,7 +4033,7 @@ replace-ext@^1.0.0:
resolved "https://registry.yarnpkg.com/replace-ext/-/replace-ext-1.0.0.tgz#de63128373fcbf7c3ccfa4de5a480c45a67958eb"
integrity sha1-3mMSg3P8v3w8z6TeWkgMRaZ5WOs=
request@^2, request@^2.85.0:
request@^2.85.0:
version "2.88.0"
resolved "https://registry.yarnpkg.com/request/-/request-2.88.0.tgz#9c2fca4f7d35b592efe57c7f0a55e81052124fef"
integrity sha512-NAqBSrijGLZdM0WZNsInLJpkJokL72XYjUpnB0iwsRgxh7dB6COrHnTBNwN0E+lHDAJzu7kLAkDeY08z2/A0hg==
@ -4430,6 +4395,11 @@ stockfish-mv.wasm@^0.2.0:
resolved "https://registry.yarnpkg.com/stockfish-mv.wasm/-/stockfish-mv.wasm-0.2.0.tgz#b402050ccca5455ed4419ffe2ad96d52a19c5f34"
integrity sha512-a2E/J0kBJIfoKdC8KPNy+xGQ4hvT/E10THMxjqmy1aHCgoV0pvOY+lgcLqvm6Q4c5IyFX5iDiY59ZrrtHedbEg==
stockfish.js@^9.0.0:
version "9.0.0"
resolved "https://registry.yarnpkg.com/stockfish.js/-/stockfish.js-9.0.0.tgz#8464f95ea1fe943aeff7dc1334760cca92b28361"
integrity sha512-AzoOLzicGbZrASv3HWniCqpMV806MHWTK2s9AgjFk5MvFX+G6FuJ/G1DbqZfSY6+LuZTdAvGV3h8ZqBlNv5Hvg==
stockfish.pexe@^9.0.0:
version "9.0.0"
resolved "https://registry.yarnpkg.com/stockfish.pexe/-/stockfish.pexe-9.0.0.tgz#8b444f0487e05e3c8d12ad59a7245489da34c602"
@ -5119,7 +5089,7 @@ vinyl@^1.0.0:
clone-stats "^0.0.1"
replace-ext "0.0.1"
vinyl@^2.0.0, vinyl@^2.1.0:
vinyl@^2.0.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/vinyl/-/vinyl-2.2.0.tgz#d85b07da96e458d25b2ffe19fece9f2caa13ed86"
integrity sha512-MBH+yP0kC/GQ5GwBqrTPTzEfiiLjta7hTtvQtbxBgTeSXsmKQRQecjibMbxIXzVT3Y9KJK+drOz1/k+vsu8Nkg==