Skip to content
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
10 changes: 10 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
node_modules
dist
.git
.gitignore
.gitmodules
.gitattributes
.vscode
test
*.md
LICENSE
19 changes: 0 additions & 19 deletions .travis.yml

This file was deleted.

11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM emscripten/emsdk:latest AS build

WORKDIR /src
COPY build-config.mjs build.mjs ./
COPY src/ src/
COPY include/ include/

RUN mkdir -p dist && node build.mjs

FROM alpine
COPY --from=build /src/dist/ /out/
53 changes: 53 additions & 0 deletions build-config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import path from 'node:path'
import { fileURLToPath } from 'node:url'

const __dirname = path.dirname(fileURLToPath(import.meta.url))
const inc = path.resolve(__dirname, 'include')
const src = path.resolve(__dirname, 'src')

export const includeDirs = [inc]

export const sources = [
path.resolve(inc, 'anitomy/anitomy.cpp'),
path.resolve(inc, 'anitomy/element.cpp'),
path.resolve(inc, 'anitomy/keyword.cpp'),
path.resolve(inc, 'anitomy/parser.cpp'),
path.resolve(inc, 'anitomy/parser_helper.cpp'),
path.resolve(inc, 'anitomy/parser_number.cpp'),
path.resolve(inc, 'anitomy/string.cpp'),
path.resolve(inc, 'anitomy/token.cpp'),
path.resolve(inc, 'anitomy/tokenizer.cpp'),
path.resolve(src, 'anitomyscript.cpp'),
]

export const outputFile = path.resolve(__dirname, 'dist', 'anitomyscript.js')

export const baseFlags = [
'-std=c++17',
'-fno-exceptions',
'-Wall',
'-Wpedantic',
'-s', 'EXPORT_NAME="anitomyscript"',
'-s', 'WASM=1',
'-s', 'ENVIRONMENT=web,node',
'-s', 'FILESYSTEM=0',
'-s', 'MODULARIZE=1',
'-s', 'EXPORT_ES6=1',
'-s', 'DYNAMIC_EXECUTION=0',
'-s', 'TEXTDECODER=2',
'-s', 'SUPPORT_LONGJMP=0',
'-s', 'EMBIND_AOT=1',
'-s', 'INITIAL_MEMORY=524288',
'-s', 'ALLOW_MEMORY_GROWTH=1',
'-lembind',
]

export const releaseFlags = [
'-O3',
]

export const debugFlags = [
'-O0',
'-g',
'-v',
]
26 changes: 26 additions & 0 deletions build.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { spawn } from 'node:child_process'
import { baseFlags, releaseFlags, includeDirs, sources, outputFile } from './build-config.mjs'

const includeArgs = includeDirs.flatMap(d => ['-I', d])

const spawnArgs = [
...baseFlags,
...releaseFlags,
...includeArgs,
...sources,
'-o', outputFile,
]

const emcc = process.platform === 'win32' ? 'emcc.bat' : 'emcc'

console.log('Starting Docker build with:', spawnArgs.join(' '))
const s = spawn(emcc, spawnArgs, { stdio: 'inherit' })

s.on('error', (e) => {
console.error('Failed to start emcc:', e)
process.exit(1)
})

s.on('close', (code) => {
process.exit(code ?? 0)
})
93 changes: 0 additions & 93 deletions build/anitomyscript.js

This file was deleted.

Binary file removed build/anitomyscript.wasm
Binary file not shown.
1,460 changes: 0 additions & 1,460 deletions dist/anitomyscript.bundle.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/anitomyscript.bundle.min.js

This file was deleted.

2 changes: 2 additions & 0 deletions dist/anitomyscript.js

Large diffs are not rendered by default.

Binary file modified dist/anitomyscript.wasm
Binary file not shown.
131 changes: 31 additions & 100 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,112 +1,43 @@
'use strict';

const gulp = require('gulp');
const spawn = require('child_process').spawn;
const path = require('path');
const fs = require('fs');
const fse = require('fs-extra');
const browserify = require('browserify');

function build(cb) {
const emscriptenPath = process.env.EMSCRIPTEN || process.env.EMSCRIPTEN_ROOT;
console.log(process.env)

if (!emscriptenPath || !fs.existsSync(path.resolve(emscriptenPath))) {
return cb('Unable to find emscripten root. Use the env variable EMSCRIPTEN or EMSCRIPTEN_ROOT to set it manually.');
import gulp from 'gulp'
import { spawn } from 'child_process'
import path from 'path'
import { baseFlags, releaseFlags, debugFlags, includeDirs, sources, outputFile } from './build-config.mjs'

function getEmcc () {
const emscriptenPath = process.env.EMSCRIPTEN || process.env.EMSCRIPTEN_ROOT
const emcc = process.platform === 'win32' ? 'emcc.bat' : 'emcc'
if (emscriptenPath) {
return path.join(emscriptenPath, emcc)
}
return emcc
}

const out = path.resolve('./', 'build', 'anitomyscript.js');
const isRelease = process.env.NODE_ENV === 'prod';

let spawnArgs = [
'--memory-init-file', '0',
'-std=c++14',
'-fPIC', '-fno-exceptions', '-Wall', '-Wextra', '-Wpedantic', '-Werror',
'--bind',
'-v',
'-I', path.resolve('./include'),
'-s', 'EXPORT_NAME="anitomyscript"',
'-s', 'WASM=1',
'-s', 'FILESYSTEM=0',
'-s', 'MODULARIZE=1',
path.resolve('./include/anitomy/anitomy.cpp'),
path.resolve('./include/anitomy/element.cpp'),
path.resolve('./include/anitomy/keyword.cpp'),
path.resolve('./include/anitomy/parser.cpp'),
path.resolve('./include/anitomy/parser_helper.cpp'),
path.resolve('./include/anitomy/parser_number.cpp'),
path.resolve('./include/anitomy/string.cpp'),
path.resolve('./include/anitomy/token.cpp'),
path.resolve('./include/anitomy/tokenizer.cpp'),
path.resolve('./src/anitomyscript.cpp'),
'-o', out,
];

if (isRelease) {
spawnArgs = spawnArgs.concat([
'-O3',
'--closure', '1',
'--llvm-lto', '3',
])
}
function build (cb) {
const isRelease = process.env.NODE_ENV === 'prod'
const includeArgs = includeDirs.flatMap(d => ['-I', d])

console.log(`Starting ${isRelease ? 'release' : 'debug'} build with emcc args`, spawnArgs);
const spawnArgs = [
...baseFlags,
...(isRelease ? releaseFlags : debugFlags),
...includeArgs,
...sources,
'-o', outputFile,
]

const emccExec = process.platform === 'win32' ? 'emcc.bat' : 'emcc';
const s = spawn(path.join(emscriptenPath, emccExec), spawnArgs, {
cwd: './build',
});
console.log(`Starting ${isRelease ? 'release' : 'debug'} build`)
const emcc = getEmcc()
const s = spawn(emcc, spawnArgs)

s.stdout.on('data', (data) => {
console.log(data.toString());
});
console.log(data.toString())
})

s.stderr.on('data', (data) => {
console.log(data.toString());
});
console.log(data.toString())
})

s.on('error', (e) => cb(e))
s.on('close', () => cb());
}

function copyWasm() {
return gulp.src('./build/anitomyscript.wasm').pipe(gulp.dest('./dist'));
}

function clearBuild(cb) {
const buildPath = path.resolve('./build');
fs.readdirSync(buildPath).forEach((file) => {
const fileWithPath = path.resolve(buildPath, file);
if (file !== '.gitkeep') fse.removeSync(fileWithPath);
});
cb();
}

function _babel() {
return {
presets: ['@babel/preset-env'],
plugins: [
['@babel/plugin-transform-runtime', { helpers: false }]
],
only: ['index.js'],
};
}

function browser() {
return browserify('./index.js', { standalone: 'anitomyscript' })
.transform('babelify', _babel())
.bundle()
.pipe(fs.createWriteStream('./dist/anitomyscript.bundle.js'));
}

function browserMin() {
return browserify('./index.js', { standalone: 'anitomyscript' })
.transform('babelify', _babel())
.plugin('tinyify')
.bundle()
.pipe(fs.createWriteStream('./dist/anitomyscript.bundle.min.js'));
s.on('close', () => cb())
}

gulp.task('build', build);
gulp.task('browser', gulp.series(gulp.parallel(browser, browserMin), copyWasm));
gulp.task('default', gulp.series(clearBuild, 'build', 'browser'));
gulp.task('default', build)
60 changes: 30 additions & 30 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
declare module "anitomyscript" {
declare module 'anitomyscript' {
export interface AnitomyResult {
file_name: string;
anime_season?: string;
season_prefix?: string;
anime_title?: string;
anime_type?: string;
anime_year?: string;
audio_term?: string;
device_compatibility?: string;
episode_number?: string;
episode_number_alt?: string;
episode_prefix?: string;
episode_title?: string;
file_checksum?: string;
file_extension?: string;
language?: string;
other?: string;
release_group?: string;
release_information?: string;
release_version?: string;
source?: string;
subtitles?: string;
video_resolution?: string;
video_term?: string;
volume_number?: string;
volume_prefix?: string;
unknown?: string;
file_name: string[];
anime_season: string[];
season_prefix: string[];
anime_title: string[];
anime_type: string[];
anime_year: string[];
audio_term: string[];
device_compatibility: string[];
episode_number: string[];
episode_number_alt: string[];
episode_prefix: string[];
episode_title: string[];
file_checksum: string[];
file_extension: string[];
language: string[];
other: string[];
release_group: string[];
release_information: string[];
release_version: string[];
source: string[];
subtitles: string[];
video_resolution: string[];
video_term: string[];
volume_number: string[];
volume_prefix: string[];
unknown: string[];
}

function parse(
input: string | string[]
): Promise<AnitomyResult[] | AnitomyResult>;
input: string[]
): Promise<AnitomyResult[]>;

export default parse;
export default parse
}
Loading