diff --git a/.gitignore b/.gitignore index 26f1442e..61c7b65c 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,4 @@ /node_modules /build /npm-debug.log -/src/backend/public .DS_Store -/pm2.config.js diff --git a/LICENSE b/LICENSE index 66e666d7..27f3bc1e 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2018 Jinseo Jason Park +Copyright (c) 2019 Jinseo Jason Park Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/app/backend.js b/app/backend.js deleted file mode 100644 index ebec15a8..00000000 --- a/app/backend.js +++ /dev/null @@ -1,42 +0,0 @@ -const { - __DEV__, - backendBuildPath, -} = require('../environment'); - -if (__DEV__) { - const webpack = require('webpack'); - const webpackConfig = require('../webpack.backend.config.js'); - const compiler = webpack(webpackConfig); - - let backend = null; - let lastHash = null; - compiler.watch({ - watchOptions: { - ignored: /public/, - }, - }, (err, stats) => { - if (err) { - lastHash = null; - compiler.purgeInputFileSystem(); - console.error(err); - } else if (stats.hash !== lastHash) { - lastHash = stats.hash; - console.info(stats.toString({ - cached: false, - colors: true, - })); - - delete require.cache[require.resolve(backendBuildPath)]; - backend = require(backendBuildPath).default; - } - }); - - const backendWrapper = (req, res, next) => backend(req, res, next); - backendWrapper.getHierarchy = () => backend.hierarchy; - module.exports = backendWrapper; -} else { - const backend = require(backendBuildPath).default; - const backendWrapper = (req, res, next) => backend(req, res, next); - backendWrapper.getHierarchy = () => backend.hierarchy; - module.exports = backendWrapper; -} diff --git a/app/frontend.js b/app/frontend.js deleted file mode 100644 index d54c3fb5..00000000 --- a/app/frontend.js +++ /dev/null @@ -1,78 +0,0 @@ -const express = require('express'); -const path = require('path'); -const fs = require('fs'); -const url = require('url'); -const packageJson = require('../package'); - -const { - __DEV__, - frontendSrcPath, - frontendBuildPath, -} = require('../environment'); - -const app = express(); - -if (__DEV__) { - const webpack = require('webpack'); - const webpackDev = require('webpack-dev-middleware'); - const webpackHot = require('webpack-hot-middleware'); - const webpackConfig = require('../webpack.frontend.config.js'); - const compiler = webpack(webpackConfig); - app.use(express.static(path.resolve(frontendSrcPath, 'static'))); - app.use(webpackDev(compiler, { - stats: { - cached: false, - colors: true, - }, - serverSideRender: true, - index: false, - })); - app.use(webpackHot(compiler)); - app.use((req, res, next) => { - const { fs } = res.locals; - const outputPath = res.locals.webpackStats.toJson().outputPath; - const filePath = path.resolve(outputPath, 'index.html'); - fs.readFile(filePath, 'utf8', (err, data) => { - if (err) return next(err); - res.indexFile = data; - next(); - }); - }); -} else { - app.use(express.static(frontendBuildPath, { index: false })); - app.use((req, res, next) => { - const filePath = path.resolve(frontendBuildPath, 'index.html'); - fs.readFile(filePath, 'utf8', (err, data) => { - if (err) return next(err); - res.indexFile = data; - next(); - }); - }); -} - -app.use((req, res) => { - const backend = require('./backend'); - const hierarchy = backend.getHierarchy(); - - const [, categoryKey, algorithmKey] = url.parse(req.originalUrl).pathname.split('/'); - let { title, description } = packageJson; - let algorithm = undefined; - if (categoryKey && categoryKey !== 'scratch-paper') { - algorithm = hierarchy.find(categoryKey, algorithmKey) || null; - if (algorithm) { - title = [algorithm.categoryName, algorithm.algorithmName].join(' - '); - description = algorithm.description; - } else { - res.status(404); - } - } - - const indexFile = res.indexFile - .replace(/\$TITLE/g, title) - .replace(/\$DESCRIPTION/g, description) - .replace(/\$ALGORITHM/g, algorithm === undefined ? 'undefined' : - JSON.stringify(algorithm).replace(/ { - if (req.hostname === 'algo-visualizer.jasonpark.me') { - res.redirect(301, 'https://algorithm-visualizer.org/'); - } else if (credentials && !req.secure) { - res.redirect(301, `https://${req.hostname}${req.url}`); - } else { - next(); - } -}); -app.get('/robots.txt', (req, res) => { - res.sendFile(path.resolve(__dirname, '..', 'robots.txt')); -}); -app.use(apiEndpoint, backend); -app.use(frontend); - -module.exports = app; diff --git a/bin/pull b/bin/pull deleted file mode 100755 index e0acb4d3..00000000 --- a/bin/pull +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash - -git fetch && -! git diff-index --quiet origin/master -- ':!package-lock.json' && -git reset --hard origin/master && -npm install && -npm run build diff --git a/bin/www b/bin/www deleted file mode 100755 index 19bd7639..00000000 --- a/bin/www +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env node - -const http = require('http'); -const https = require('https'); - -const app = require('../app'); -const { - httpPort, - httpsPort, - credentials, -} = require('../environment'); - -const httpServer = http.createServer(app); -httpServer.listen(httpPort); -console.info(`http: listening on port ${httpPort}`); - -if (credentials) { - const httpsServer = https.createServer(credentials, app); - httpsServer.listen(httpsPort); - console.info(`https: listening on port ${httpsPort}`); -} diff --git a/package.json b/package.json index 1ff89109..775ce6bb 100644 --- a/package.json +++ b/package.json @@ -23,11 +23,6 @@ "visualization", "animation" ], - "author": { - "name": "Jinseo Jason Park", - "email": "parkjs814@gmail.com", - "url": "https://jasonpark.me/" - }, "license": "MIT", "dependencies": { "axios": "latest", diff --git a/src/frontend/apis/index.js b/src/apis/index.js similarity index 100% rename from src/frontend/apis/index.js rename to src/apis/index.js diff --git a/src/backend/apis/index.js b/src/backend/apis/index.js deleted file mode 100644 index 5aedb723..00000000 --- a/src/backend/apis/index.js +++ /dev/null @@ -1,82 +0,0 @@ -import Promise from 'bluebird'; -import axios from 'axios'; -import fs from 'fs'; -import { githubClientId, githubClientSecret } from '/environment'; - -const instance = axios.create(); - -instance.interceptors.request.use(request => { - request.params = { client_id: githubClientId, client_secret: githubClientSecret, ...request.params }; - return request; -}); - -instance.interceptors.response.use(response => { - return response.data; -}, error => { - return Promise.reject(error.response.data); -}); - -const request = (url, process) => { - const tokens = url.split('/'); - const baseURL = /^https?:\/\//i.test(url) ? '' : 'https://api.github.com'; - return (...args) => { - return new Promise((resolve, reject) => { - const mappedURL = baseURL + tokens.map((token, i) => token.startsWith(':') ? args.shift() : token).join('/'); - return resolve(process(mappedURL, args)); - }); - }; -}; - -const GET = URL => { - return request(URL, (mappedURL, args) => { - const [params] = args; - return instance.get(mappedURL, { params }); - }); -}; - -const DELETE = URL => { - return request(URL, (mappedURL, args) => { - const [params] = args; - return instance.delete(mappedURL, { params }); - }); -}; - -const POST = URL => { - return request(URL, (mappedURL, args) => { - const [body, params] = args; - return instance.post(mappedURL, body, { params }); - }); -}; - -const PUT = URL => { - return request(URL, (mappedURL, args) => { - const [body, params] = args; - return instance.put(mappedURL, body, { params }); - }); -}; - -const PATCH = URL => { - return request(URL, (mappedURL, args) => { - const [body, params] = args; - return instance.patch(mappedURL, body, { params }); - }); -}; - -const GitHubApi = { - listCommits: GET('/repos/:owner/:repo/commits'), - getAccessToken: code => instance.post('https://github.com/login/oauth/access_token', { code }, { headers: { Accept: 'application/json' } }), - getLatestRelease: GET('/repos/:owner/:repo/releases/latest'), - download: (url, path) => instance({ - method: 'get', - url, - responseType: 'stream', - }).then(data => new Promise((resolve, reject) => { - data.pipe(fs.createWriteStream(path)); - data.on('end', resolve); - data.on('error', reject); - })), -}; - -export { - GitHubApi, -}; \ No newline at end of file diff --git a/src/backend/common/config.js b/src/backend/common/config.js deleted file mode 100644 index 6e06a994..00000000 --- a/src/backend/common/config.js +++ /dev/null @@ -1,7 +0,0 @@ -const memoryLimit = 256; // in megabytes -const timeLimit = 5000; // in milliseconds - -export { - memoryLimit, - timeLimit, -}; diff --git a/src/backend/common/error.js b/src/backend/common/error.js deleted file mode 100644 index c0894706..00000000 --- a/src/backend/common/error.js +++ /dev/null @@ -1,18 +0,0 @@ -class ClientError extends Error { -} - -class NotFoundError extends ClientError { -} - -class ForbiddenError extends ClientError { -} - -class UnauthorizedError extends ClientError { -} - -export { - ClientError, - NotFoundError, - ForbiddenError, - UnauthorizedError, -}; diff --git a/src/backend/common/hierarchy.js b/src/backend/common/hierarchy.js deleted file mode 100644 index 61635f1e..00000000 --- a/src/backend/common/hierarchy.js +++ /dev/null @@ -1,7 +0,0 @@ -import { Hierarchy } from '/models'; -import path from 'path'; - -const repoPath = path.resolve(__dirname, '..', 'public', 'algorithms'); -const hierarchy = new Hierarchy(repoPath); - -export default hierarchy; diff --git a/src/backend/common/util.js b/src/backend/common/util.js deleted file mode 100644 index 8c9ddfa0..00000000 --- a/src/backend/common/util.js +++ /dev/null @@ -1,52 +0,0 @@ -import Promise from 'bluebird'; -import axios from 'axios'; -import child_process from 'child_process'; -import path from 'path'; -import fs from 'fs-extra'; -import removeMarkdown from 'remove-markdown'; - -const execute = (command, { stdout = process.stdout, stderr = process.stderr, ...options } = {}) => new Promise((resolve, reject) => { - const child = child_process.exec(command, options, (error, stdout, stderr) => { - if (error) return reject(error.code ? new Error(stderr) : error); - resolve(stdout); - }); - if (stdout) child.stdout.pipe(stdout); - if (stderr) child.stderr.pipe(stderr); -}); - -const createKey = name => name.toLowerCase().trim().replace(/[^\w \-]/g, '').replace(/ /g, '-'); - -const isDirectory = dirPath => fs.lstatSync(dirPath).isDirectory(); - -const listFiles = dirPath => fs.readdirSync(dirPath).filter(fileName => !fileName.startsWith('.')); - -const listDirectories = dirPath => listFiles(dirPath).filter(fileName => isDirectory(path.resolve(dirPath, fileName))); - -const getDescription = files => { - const readmeFile = files.find(file => file.name === 'README.md'); - if (!readmeFile) return ''; - const lines = readmeFile.content.split('\n'); - lines.shift(); - while (lines.length && !lines[0].trim()) lines.shift(); - let descriptionLines = []; - while (lines.length && lines[0].trim()) descriptionLines.push(lines.shift()); - return removeMarkdown(descriptionLines.join(' ')); -}; - -const download = (url, localPath) => axios({ url, method: 'GET', responseType: 'stream' }) - .then(response => new Promise((resolve, reject) => { - const writer = fs.createWriteStream(localPath); - writer.on('finish', resolve); - writer.on('error', reject); - response.data.pipe(writer); - })); - -export { - execute, - createKey, - isDirectory, - listFiles, - listDirectories, - getDescription, - download, -}; diff --git a/src/backend/common/webhook.js b/src/backend/common/webhook.js deleted file mode 100644 index 5f7599ad..00000000 --- a/src/backend/common/webhook.js +++ /dev/null @@ -1,6 +0,0 @@ -import GithubWebHook from 'express-github-webhook'; -import { githubWebhookSecret } from '/environment'; - -const webhook = GithubWebHook({ path: '/', secret: githubWebhookSecret }); - -export default webhook; diff --git a/src/backend/controllers/algorithms.js b/src/backend/controllers/algorithms.js deleted file mode 100644 index 6bac3746..00000000 --- a/src/backend/controllers/algorithms.js +++ /dev/null @@ -1,49 +0,0 @@ -import express from 'express'; -import fs from 'fs-extra'; -import { execute } from '/common/util'; -import webhook from '/common/webhook'; -import hierarchy from '/common/hierarchy'; -import { NotFoundError } from '/common/error'; - -const router = express.Router(); - -const downloadCategories = () => ( - fs.pathExistsSync(hierarchy.path) ? - execute(`git fetch && git reset --hard origin/master`, { cwd: hierarchy.path }) : - execute(`git clone https://github.com/algorithm-visualizer/algorithms.git ${hierarchy.path}`) -).then(() => hierarchy.refresh()); - -downloadCategories().catch(console.error); - -webhook.on('algorithms', event => { - switch (event) { - case 'push': - downloadCategories().catch(console.error); - break; - } -}); - -router.route('/') - .get((req, res, next) => { - res.json(hierarchy); - }); - -router.route('/:categoryKey/:algorithmKey') - .get((req, res, next) => { - const { categoryKey, algorithmKey } = req.params; - const algorithm = hierarchy.find(categoryKey, algorithmKey); - if (!algorithm) return next(new NotFoundError()); - res.json({ algorithm }); - }); - -router.route('/sitemap.txt') - .get((req, res, next) => { - const urls = []; - hierarchy.iterate((category, algorithm) => { - urls.push(`https://algorithm-visualizer.org/${category.key}/${algorithm.key}`); - }); - res.set('Content-Type', 'text/plain'); - res.send(urls.join('\n')); - }); - -export default router; diff --git a/src/backend/controllers/auth.js b/src/backend/controllers/auth.js deleted file mode 100644 index 45e156e7..00000000 --- a/src/backend/controllers/auth.js +++ /dev/null @@ -1,32 +0,0 @@ -import express from 'express'; -import { githubClientId } from '/environment'; -import { GitHubApi } from '/apis'; - -const router = express.Router(); - -const request = (req, res, next) => { - res.redirect(`https://github.com/login/oauth/authorize?client_id=${githubClientId}&scope=user,gist`); -}; - -const response = (req, res, next) => { - const { code } = req.query; - - GitHubApi.getAccessToken(code).then(({ access_token }) => { - res.send(``); - }).catch(next); -}; - -const destroy = (req, res, next) => { - res.send(``); -}; - -router.route('/request') - .get(request); - -router.route('/response') - .get(response); - -router.route('/destroy') - .get(destroy); - -export default router; diff --git a/src/backend/controllers/index.js b/src/backend/controllers/index.js deleted file mode 100644 index a971818b..00000000 --- a/src/backend/controllers/index.js +++ /dev/null @@ -1,4 +0,0 @@ -export { default as auth } from './auth'; -export { default as algorithms } from './algorithms'; -export { default as tracers } from './tracers'; -export { default as visualizations } from './visualizations'; diff --git a/src/backend/controllers/tracers.js b/src/backend/controllers/tracers.js deleted file mode 100644 index 04806e49..00000000 --- a/src/backend/controllers/tracers.js +++ /dev/null @@ -1,81 +0,0 @@ -import express from 'express'; -import fs from 'fs-extra'; -import Promise from 'bluebird'; -import uuid from 'uuid'; -import path from 'path'; -import { GitHubApi } from '/apis'; -import { execute } from '/common/util'; -import webhook from '/common/webhook'; -import { ImageBuilder, WorkerBuilder } from '/tracers'; -import { memoryLimit, timeLimit } from '/common/config'; - -const router = express.Router(); - -const trace = lang => (req, res, next) => { - const { code } = req.body; - const tempPath = path.resolve(__dirname, '..', 'public', 'codes', uuid.v4()); - fs.outputFile(path.resolve(tempPath, `Main.${lang}`), code) - .then(() => { - const builder = builderMap[lang]; - const containerName = uuid.v4(); - let killed = false; - const timer = setTimeout(() => { - execute(`docker kill ${containerName}`).then(() => { - killed = true; - }); - }, timeLimit); - return execute([ - 'docker run --rm', - `--name=${containerName}`, - '-w=/usr/visualization', - `-v=${tempPath}:/usr/visualization:rw`, - `-m=${memoryLimit}m`, - '-e ALGORITHM_VISUALIZER=1', - builder.imageName, - ].join(' '), { stdout: null, stderr: null }).catch(error => { - if (killed) throw new Error('Time Limit Exceeded'); - throw error; - }).finally(() => clearTimeout(timer)); - }) - .then(() => new Promise((resolve, reject) => { - const visualizationPath = path.resolve(tempPath, 'visualization.json'); - res.sendFile(visualizationPath, err => { - if (err) return reject(new Error('Visualization Not Found')); - resolve(); - }); - })) - .catch(next) - .finally(() => fs.remove(tempPath)); -}; - -const builderMap = { - js: new WorkerBuilder(), - cpp: new ImageBuilder('cpp'), - java: new ImageBuilder('java'), -}; - -Promise.map(Object.keys(builderMap), lang => { - const builder = builderMap[lang]; - return GitHubApi.getLatestRelease('algorithm-visualizer', `tracers.${lang}`).then(builder.build); -}).catch(console.error); - -webhook.on('release', (repo, data) => { - const result = /^tracers\.(\w+)$/.exec(repo); - if (result) { - const [, lang] = result; - const builder = builderMap[lang]; - builder.build(data.release).catch(console.error); - } -}); - -Object.keys(builderMap).forEach(lang => { - const builder = builderMap[lang]; - if (builder instanceof ImageBuilder) { - router.post(`/${lang}`, trace(lang)); - } else if (builder instanceof WorkerBuilder) { - router.get(`/${lang}`, (req, res) => res.sendFile(builder.tracerPath)); - router.get(`/${lang}/worker`, (req, res) => res.sendFile(builder.workerPath)); - } -}); - -export default router; diff --git a/src/backend/controllers/visualizations.js b/src/backend/controllers/visualizations.js deleted file mode 100644 index 968f78a4..00000000 --- a/src/backend/controllers/visualizations.js +++ /dev/null @@ -1,42 +0,0 @@ -import express from 'express'; -import path from 'path'; -import uuid from 'uuid'; -import fs from 'fs-extra'; -import Promise from 'bluebird'; - -const router = express.Router(); - -const uploadPath = path.resolve(__dirname, '..', 'public', 'visualizations'); -const getVisualizationPath = visualizationId => path.resolve(uploadPath, `${visualizationId}.json`); - -fs.remove(uploadPath).catch(console.error); - -const uploadVisualization = (req, res, next) => { - const { content } = req.body; - const visualizationId = uuid.v4(); - const tracesPath = getVisualizationPath(visualizationId); - const url = `https://algorithm-visualizer.org/scratch-paper/new?visualizationId=${visualizationId}`; - fs.outputFile(tracesPath, content) - .then(() => res.send(url)) - .catch(next); -}; - -const getVisualization = (req, res, next) => { - const { visualizationId } = req.params; - const visualizationPath = getVisualizationPath(visualizationId); - new Promise((resolve, reject) => { - res.sendFile(visualizationPath, err => { - if (err) return reject(new Error('Visualization Expired')); - resolve(); - }); - }).catch(next) - .finally(() => fs.remove(visualizationPath)); -}; - -router.route('/') - .post(uploadVisualization); - -router.route('/:visualizationId') - .get(getVisualization); - -export default router; diff --git a/src/backend/index.js b/src/backend/index.js deleted file mode 100644 index 3f9df620..00000000 --- a/src/backend/index.js +++ /dev/null @@ -1,41 +0,0 @@ -import express from 'express'; -import morgan from 'morgan'; -import cookieParser from 'cookie-parser'; -import bodyParser from 'body-parser'; -import * as controllers from '/controllers'; -import { ClientError, ForbiddenError, NotFoundError, UnauthorizedError } from '/common/error'; -import webhook from '/common/webhook'; -import hierarchy from '/common/hierarchy'; - -const app = express(); -app.use(morgan('tiny')); -app.use(cookieParser()); -app.use(bodyParser.json()); -app.use(bodyParser.urlencoded({ extended: true })); -Object.keys(controllers).forEach(key => app.use(`/${key}`, controllers[key])); -app.use('/webhook', webhook); -app.use((req, res, next) => next(new NotFoundError())); -app.use((err, req, res, next) => { - const statusMap = [ - [UnauthorizedError, 401], - [ForbiddenError, 403], - [NotFoundError, 404], - [ClientError, 400], - [Error, 500], - ]; - const [, status] = statusMap.find(([Error]) => err instanceof Error); - res.status(status); - res.send(err.message); - console.error(err); -}); -app.hierarchy = hierarchy; - -webhook.on('algorithm-visualizer', event => { - switch (event) { - case 'push': - process.exit(0); - break; - } -}); - -export default app; diff --git a/src/backend/models/Algorithm.js b/src/backend/models/Algorithm.js deleted file mode 100644 index 45dfde29..00000000 --- a/src/backend/models/Algorithm.js +++ /dev/null @@ -1,25 +0,0 @@ -import path from 'path'; -import { createKey, getDescription, listFiles } from '/common/util'; -import { File } from '/models'; - -class Algorithm { - constructor(path, name) { - this.path = path; - this.key = createKey(name); - this.name = name; - this.refresh(); - } - - refresh() { - this.files = listFiles(this.path) - .map(fileName => new File(path.resolve(this.path, fileName), fileName)); - this.description = getDescription(this.files); - } - - toJSON() { - const { key, name } = this; - return { key, name }; - } -} - -export default Algorithm; diff --git a/src/backend/models/Category.js b/src/backend/models/Category.js deleted file mode 100644 index 03ea980b..00000000 --- a/src/backend/models/Category.js +++ /dev/null @@ -1,24 +0,0 @@ -import path from 'path'; -import { createKey, listDirectories } from '/common/util'; -import { Algorithm } from '/models'; - -class Category { - constructor(path, name) { - this.path = path; - this.key = createKey(name); - this.name = name; - this.refresh(); - } - - refresh() { - this.algorithms = listDirectories(this.path) - .map(algorithmName => new Algorithm(path.resolve(this.path, algorithmName), algorithmName)); - } - - toJSON() { - const { key, name, algorithms } = this; - return { key, name, algorithms }; - } -} - -export default Category; diff --git a/src/backend/models/File.js b/src/backend/models/File.js deleted file mode 100644 index 3bb69da7..00000000 --- a/src/backend/models/File.js +++ /dev/null @@ -1,21 +0,0 @@ -import fs from 'fs-extra'; - -class File { - constructor(path, name) { - this.path = path; - this.name = name; - this.refresh(); - } - - refresh() { - this.content = fs.readFileSync(this.path, 'utf-8'); - this.contributors = []; - } - - toJSON() { - const { name, content, contributors } = this; - return { name, content, contributors }; - } -} - -export default File; diff --git a/src/backend/models/Hierarchy.js b/src/backend/models/Hierarchy.js deleted file mode 100644 index 589910e0..00000000 --- a/src/backend/models/Hierarchy.js +++ /dev/null @@ -1,84 +0,0 @@ -import Promise from 'bluebird'; -import path from 'path'; -import { execute, listDirectories } from '/common/util'; -import { GitHubApi } from '/apis'; -import { Category } from '/models'; - -class Hierarchy { - constructor(path) { - this.path = path; - this.refresh(); - } - - refresh() { - this.categories = listDirectories(this.path) - .map(categoryName => new Category(path.resolve(this.path, categoryName), categoryName)); - - const files = []; - this.categories.forEach(category => category.algorithms.forEach(algorithm => files.push(...algorithm.files))); - this.cacheCommitAuthors().then(commitAuthors => this.cacheContributors(files, commitAuthors)); - } - - cacheCommitAuthors(page = 1, commitAuthors = {}) { - const per_page = 100; - return GitHubApi.listCommits('algorithm-visualizer', 'algorithms', { - per_page, - page, - }).then(commits => { - commits.forEach(({ sha, commit, author }) => { - if (!author) return; - const { login, avatar_url } = author; - commitAuthors[sha] = { login, avatar_url }; - }); - if (commits.length < per_page) { - return commitAuthors; - } else { - return this.cacheCommitAuthors(page + 1, commitAuthors); - } - }); - } - - cacheContributors(files, commitAuthors) { - return Promise.each(files, file => { - return execute(`git --no-pager log --follow --no-merges --format="%H" "${file.path}"`, { - cwd: this.path, stdout: null, - }).then(stdout => { - const output = stdout.toString().replace(/\n$/, ''); - const shas = output.split('\n').reverse(); - const contributors = []; - for (const sha of shas) { - const author = commitAuthors[sha]; - if (author && !contributors.find(contributor => contributor.login === author.login)) { - contributors.push(author); - } - } - file.contributors = contributors; - }); - }); - } - - find(categoryKey, algorithmKey) { - const category = this.categories.find(category => category.key === categoryKey); - if (!category) return; - const algorithm = category.algorithms.find(algorithm => algorithm.key === algorithmKey); - if (!algorithm) return; - - const categoryName = category.name; - const algorithmName = algorithm.name; - const files = algorithm.files; - const description = algorithm.description; - - return { categoryKey, categoryName, algorithmKey, algorithmName, files, description }; - } - - iterate(callback) { - this.categories.forEach(category => category.algorithms.forEach(algorithm => callback(category, algorithm))); - } - - toJSON() { - const { categories } = this; - return { categories }; - } -} - -export default Hierarchy; diff --git a/src/backend/models/index.js b/src/backend/models/index.js deleted file mode 100644 index 64dea130..00000000 --- a/src/backend/models/index.js +++ /dev/null @@ -1,4 +0,0 @@ -export { default as Algorithm } from './Algorithm'; -export { default as Category } from './Category'; -export { default as File } from './File'; -export { default as Hierarchy } from './Hierarchy'; diff --git a/src/backend/tracers/ImageBuilder.js b/src/backend/tracers/ImageBuilder.js deleted file mode 100644 index e25d7c19..00000000 --- a/src/backend/tracers/ImageBuilder.js +++ /dev/null @@ -1,19 +0,0 @@ -import path from 'path'; -import { execute } from '/common/util'; - -class ImageBuilder { - constructor(lang) { - this.lang = lang; - this.directory = path.resolve(__dirname, lang); - this.imageName = `tracer-${this.lang}`; - - this.build = this.build.bind(this); - } - - build(release) { - const { tag_name } = release; - return execute(`docker build -t ${this.imageName} . --build-arg tag_name=${tag_name}`, { cwd: this.directory }); - } -} - -export default ImageBuilder; diff --git a/src/backend/tracers/WorkerBuilder.js b/src/backend/tracers/WorkerBuilder.js deleted file mode 100644 index 07369cd0..00000000 --- a/src/backend/tracers/WorkerBuilder.js +++ /dev/null @@ -1,18 +0,0 @@ -import path from 'path'; -import { download } from '/common/util'; - -class WorkerBuilder { - constructor() { - this.tracerPath = path.resolve(__dirname, '..', 'public', 'algorithm-visualizer.js'); - this.workerPath = path.resolve(__dirname, 'js', 'worker.js'); - - this.build = this.build.bind(this); - } - - build(release) { - const { tag_name } = release; - return download(`https://github.com/algorithm-visualizer/tracers.js/releases/download/${tag_name}/algorithm-visualizer.js`, this.tracerPath); - } -} - -export default WorkerBuilder; diff --git a/src/backend/tracers/cpp/Dockerfile b/src/backend/tracers/cpp/Dockerfile deleted file mode 100644 index 03b3d944..00000000 --- a/src/backend/tracers/cpp/Dockerfile +++ /dev/null @@ -1,17 +0,0 @@ -FROM rikorose/gcc-cmake - -ARG tag_name - -RUN curl --create-dirs -o /usr/local/include/nlohmann/json.hpp -L "https://github.com/nlohmann/json/releases/download/v3.1.2/json.hpp" \ - && curl --create-dirs -o /usr/tmp/algorithm-visualizer.tar.gz -L "https://github.com/algorithm-visualizer/tracers.cpp/archive/${tag_name}.tar.gz" \ - && cd /usr/tmp \ - && mkdir algorithm-visualizer \ - && tar xvzf algorithm-visualizer.tar.gz -C algorithm-visualizer --strip-components=1 \ - && cd /usr/tmp/algorithm-visualizer \ - && mkdir build \ - && cd build \ - && cmake .. \ - && make install - -CMD g++ Main.cpp -o Main -O2 -std=c++11 -lcurl \ - && ./Main diff --git a/src/backend/tracers/index.js b/src/backend/tracers/index.js deleted file mode 100644 index d41b0493..00000000 --- a/src/backend/tracers/index.js +++ /dev/null @@ -1,2 +0,0 @@ -export { default as ImageBuilder } from './ImageBuilder'; -export { default as WorkerBuilder } from './WorkerBuilder'; diff --git a/src/backend/tracers/java/Dockerfile b/src/backend/tracers/java/Dockerfile deleted file mode 100644 index 8aabc076..00000000 --- a/src/backend/tracers/java/Dockerfile +++ /dev/null @@ -1,8 +0,0 @@ -FROM openjdk:8 - -ARG tag_name - -RUN curl --create-dirs -o /usr/local/lib/algorithm-visualizer.jar -L "https://github.com/algorithm-visualizer/tracers.java/releases/download/${tag_name}/algorithm-visualizer.jar" - -CMD javac -cp /usr/local/lib/algorithm-visualizer.jar Main.java \ - && java -cp /usr/local/lib/algorithm-visualizer.jar:. Main diff --git a/src/backend/tracers/js/worker.js b/src/backend/tracers/js/worker.js deleted file mode 100644 index 7d5ac5b8..00000000 --- a/src/backend/tracers/js/worker.js +++ /dev/null @@ -1,14 +0,0 @@ -const process = { env: { ALGORITHM_VISUALIZER: '1' } }; -importScripts('/api/tracers/js'); - -const sandbox = code => { - const require = name => ({ 'algorithm-visualizer': AlgorithmVisualizer }[name]); // fake require - eval(code); -}; - -onmessage = e => { - const lines = e.data.split('\n').map((line, i) => line.replace(/(\.\s*delay\s*)\(\s*\)/g, `$1(${i})`)); - const code = lines.join('\n'); - sandbox(code); - postMessage(AlgorithmVisualizer.Commander.commands); -}; diff --git a/src/frontend/common/config.js b/src/common/config.js similarity index 100% rename from src/frontend/common/config.js rename to src/common/config.js diff --git a/src/frontend/common/stylesheet/colors.scss b/src/common/stylesheet/colors.scss similarity index 100% rename from src/frontend/common/stylesheet/colors.scss rename to src/common/stylesheet/colors.scss diff --git a/src/frontend/common/stylesheet/dimensions.scss b/src/common/stylesheet/dimensions.scss similarity index 100% rename from src/frontend/common/stylesheet/dimensions.scss rename to src/common/stylesheet/dimensions.scss diff --git a/src/frontend/common/stylesheet/fonts.scss b/src/common/stylesheet/fonts.scss similarity index 100% rename from src/frontend/common/stylesheet/fonts.scss rename to src/common/stylesheet/fonts.scss diff --git a/src/frontend/common/stylesheet/index.scss b/src/common/stylesheet/index.scss similarity index 100% rename from src/frontend/common/stylesheet/index.scss rename to src/common/stylesheet/index.scss diff --git a/src/frontend/common/util.js b/src/common/util.js similarity index 100% rename from src/frontend/common/util.js rename to src/common/util.js diff --git a/src/frontend/components/App/index.jsx b/src/components/App/index.jsx similarity index 100% rename from src/frontend/components/App/index.jsx rename to src/components/App/index.jsx diff --git a/src/frontend/components/App/stylesheet.scss b/src/components/App/stylesheet.scss similarity index 100% rename from src/frontend/components/App/stylesheet.scss rename to src/components/App/stylesheet.scss diff --git a/src/frontend/components/BaseComponent/index.jsx b/src/components/BaseComponent/index.jsx similarity index 100% rename from src/frontend/components/BaseComponent/index.jsx rename to src/components/BaseComponent/index.jsx diff --git a/src/frontend/components/Button/index.jsx b/src/components/Button/index.jsx similarity index 100% rename from src/frontend/components/Button/index.jsx rename to src/components/Button/index.jsx diff --git a/src/frontend/components/Button/stylesheet.scss b/src/components/Button/stylesheet.scss similarity index 100% rename from src/frontend/components/Button/stylesheet.scss rename to src/components/Button/stylesheet.scss diff --git a/src/frontend/components/CodeEditor/index.jsx b/src/components/CodeEditor/index.jsx similarity index 100% rename from src/frontend/components/CodeEditor/index.jsx rename to src/components/CodeEditor/index.jsx diff --git a/src/frontend/components/CodeEditor/stylesheet.scss b/src/components/CodeEditor/stylesheet.scss similarity index 100% rename from src/frontend/components/CodeEditor/stylesheet.scss rename to src/components/CodeEditor/stylesheet.scss diff --git a/src/frontend/components/Divider/index.jsx b/src/components/Divider/index.jsx similarity index 100% rename from src/frontend/components/Divider/index.jsx rename to src/components/Divider/index.jsx diff --git a/src/frontend/components/Divider/stylesheet.scss b/src/components/Divider/stylesheet.scss similarity index 100% rename from src/frontend/components/Divider/stylesheet.scss rename to src/components/Divider/stylesheet.scss diff --git a/src/frontend/components/Ellipsis/index.jsx b/src/components/Ellipsis/index.jsx similarity index 100% rename from src/frontend/components/Ellipsis/index.jsx rename to src/components/Ellipsis/index.jsx diff --git a/src/frontend/components/Ellipsis/stylesheet.scss b/src/components/Ellipsis/stylesheet.scss similarity index 100% rename from src/frontend/components/Ellipsis/stylesheet.scss rename to src/components/Ellipsis/stylesheet.scss diff --git a/src/frontend/components/ExpandableListItem/index.jsx b/src/components/ExpandableListItem/index.jsx similarity index 100% rename from src/frontend/components/ExpandableListItem/index.jsx rename to src/components/ExpandableListItem/index.jsx diff --git a/src/frontend/components/ExpandableListItem/stylesheet.scss b/src/components/ExpandableListItem/stylesheet.scss similarity index 100% rename from src/frontend/components/ExpandableListItem/stylesheet.scss rename to src/components/ExpandableListItem/stylesheet.scss diff --git a/src/frontend/components/FoldableAceEditor/index.jsx b/src/components/FoldableAceEditor/index.jsx similarity index 100% rename from src/frontend/components/FoldableAceEditor/index.jsx rename to src/components/FoldableAceEditor/index.jsx diff --git a/src/frontend/components/Header/index.jsx b/src/components/Header/index.jsx similarity index 100% rename from src/frontend/components/Header/index.jsx rename to src/components/Header/index.jsx diff --git a/src/frontend/components/Header/stylesheet.scss b/src/components/Header/stylesheet.scss similarity index 100% rename from src/frontend/components/Header/stylesheet.scss rename to src/components/Header/stylesheet.scss diff --git a/src/frontend/components/ListItem/index.jsx b/src/components/ListItem/index.jsx similarity index 100% rename from src/frontend/components/ListItem/index.jsx rename to src/components/ListItem/index.jsx diff --git a/src/frontend/components/ListItem/stylesheet.scss b/src/components/ListItem/stylesheet.scss similarity index 100% rename from src/frontend/components/ListItem/stylesheet.scss rename to src/components/ListItem/stylesheet.scss diff --git a/src/frontend/components/Navigator/index.jsx b/src/components/Navigator/index.jsx similarity index 100% rename from src/frontend/components/Navigator/index.jsx rename to src/components/Navigator/index.jsx diff --git a/src/frontend/components/Navigator/stylesheet.scss b/src/components/Navigator/stylesheet.scss similarity index 100% rename from src/frontend/components/Navigator/stylesheet.scss rename to src/components/Navigator/stylesheet.scss diff --git a/src/frontend/components/Player/index.jsx b/src/components/Player/index.jsx similarity index 100% rename from src/frontend/components/Player/index.jsx rename to src/components/Player/index.jsx diff --git a/src/frontend/components/Player/stylesheet.scss b/src/components/Player/stylesheet.scss similarity index 100% rename from src/frontend/components/Player/stylesheet.scss rename to src/components/Player/stylesheet.scss diff --git a/src/frontend/components/ProgressBar/index.jsx b/src/components/ProgressBar/index.jsx similarity index 100% rename from src/frontend/components/ProgressBar/index.jsx rename to src/components/ProgressBar/index.jsx diff --git a/src/frontend/components/ProgressBar/stylesheet.scss b/src/components/ProgressBar/stylesheet.scss similarity index 100% rename from src/frontend/components/ProgressBar/stylesheet.scss rename to src/components/ProgressBar/stylesheet.scss diff --git a/src/frontend/components/ResizableContainer/index.jsx b/src/components/ResizableContainer/index.jsx similarity index 100% rename from src/frontend/components/ResizableContainer/index.jsx rename to src/components/ResizableContainer/index.jsx diff --git a/src/frontend/components/ResizableContainer/stylesheet.scss b/src/components/ResizableContainer/stylesheet.scss similarity index 100% rename from src/frontend/components/ResizableContainer/stylesheet.scss rename to src/components/ResizableContainer/stylesheet.scss diff --git a/src/frontend/components/TabContainer/index.jsx b/src/components/TabContainer/index.jsx similarity index 100% rename from src/frontend/components/TabContainer/index.jsx rename to src/components/TabContainer/index.jsx diff --git a/src/frontend/components/TabContainer/stylesheet.scss b/src/components/TabContainer/stylesheet.scss similarity index 100% rename from src/frontend/components/TabContainer/stylesheet.scss rename to src/components/TabContainer/stylesheet.scss diff --git a/src/frontend/components/ToastContainer/index.jsx b/src/components/ToastContainer/index.jsx similarity index 100% rename from src/frontend/components/ToastContainer/index.jsx rename to src/components/ToastContainer/index.jsx diff --git a/src/frontend/components/ToastContainer/stylesheet.scss b/src/components/ToastContainer/stylesheet.scss similarity index 100% rename from src/frontend/components/ToastContainer/stylesheet.scss rename to src/components/ToastContainer/stylesheet.scss diff --git a/src/frontend/components/VisualizationViewer/index.jsx b/src/components/VisualizationViewer/index.jsx similarity index 100% rename from src/frontend/components/VisualizationViewer/index.jsx rename to src/components/VisualizationViewer/index.jsx diff --git a/src/frontend/components/VisualizationViewer/stylesheet.scss b/src/components/VisualizationViewer/stylesheet.scss similarity index 100% rename from src/frontend/components/VisualizationViewer/stylesheet.scss rename to src/components/VisualizationViewer/stylesheet.scss diff --git a/src/frontend/components/index.js b/src/components/index.js similarity index 100% rename from src/frontend/components/index.js rename to src/components/index.js diff --git a/src/frontend/core/layouts/HorizontalLayout.js b/src/core/layouts/HorizontalLayout.js similarity index 100% rename from src/frontend/core/layouts/HorizontalLayout.js rename to src/core/layouts/HorizontalLayout.js diff --git a/src/frontend/core/layouts/Layout.jsx b/src/core/layouts/Layout.jsx similarity index 100% rename from src/frontend/core/layouts/Layout.jsx rename to src/core/layouts/Layout.jsx diff --git a/src/frontend/core/layouts/VerticalLayout.js b/src/core/layouts/VerticalLayout.js similarity index 100% rename from src/frontend/core/layouts/VerticalLayout.js rename to src/core/layouts/VerticalLayout.js diff --git a/src/frontend/core/layouts/index.js b/src/core/layouts/index.js similarity index 100% rename from src/frontend/core/layouts/index.js rename to src/core/layouts/index.js diff --git a/src/frontend/core/renderers/Array1DRenderer/index.jsx b/src/core/renderers/Array1DRenderer/index.jsx similarity index 100% rename from src/frontend/core/renderers/Array1DRenderer/index.jsx rename to src/core/renderers/Array1DRenderer/index.jsx diff --git a/src/frontend/core/renderers/Array1DRenderer/stylesheet.scss b/src/core/renderers/Array1DRenderer/stylesheet.scss similarity index 100% rename from src/frontend/core/renderers/Array1DRenderer/stylesheet.scss rename to src/core/renderers/Array1DRenderer/stylesheet.scss diff --git a/src/frontend/core/renderers/Array2DRenderer/index.jsx b/src/core/renderers/Array2DRenderer/index.jsx similarity index 100% rename from src/frontend/core/renderers/Array2DRenderer/index.jsx rename to src/core/renderers/Array2DRenderer/index.jsx diff --git a/src/frontend/core/renderers/Array2DRenderer/stylesheet.scss b/src/core/renderers/Array2DRenderer/stylesheet.scss similarity index 100% rename from src/frontend/core/renderers/Array2DRenderer/stylesheet.scss rename to src/core/renderers/Array2DRenderer/stylesheet.scss diff --git a/src/frontend/core/renderers/ChartRenderer/index.jsx b/src/core/renderers/ChartRenderer/index.jsx similarity index 100% rename from src/frontend/core/renderers/ChartRenderer/index.jsx rename to src/core/renderers/ChartRenderer/index.jsx diff --git a/src/frontend/core/renderers/ChartRenderer/stylesheet.scss b/src/core/renderers/ChartRenderer/stylesheet.scss similarity index 100% rename from src/frontend/core/renderers/ChartRenderer/stylesheet.scss rename to src/core/renderers/ChartRenderer/stylesheet.scss diff --git a/src/frontend/core/renderers/GraphRenderer/index.jsx b/src/core/renderers/GraphRenderer/index.jsx similarity index 100% rename from src/frontend/core/renderers/GraphRenderer/index.jsx rename to src/core/renderers/GraphRenderer/index.jsx diff --git a/src/frontend/core/renderers/GraphRenderer/stylesheet.scss b/src/core/renderers/GraphRenderer/stylesheet.scss similarity index 100% rename from src/frontend/core/renderers/GraphRenderer/stylesheet.scss rename to src/core/renderers/GraphRenderer/stylesheet.scss diff --git a/src/frontend/core/renderers/LogRenderer/index.jsx b/src/core/renderers/LogRenderer/index.jsx similarity index 100% rename from src/frontend/core/renderers/LogRenderer/index.jsx rename to src/core/renderers/LogRenderer/index.jsx diff --git a/src/frontend/core/renderers/LogRenderer/stylesheet.scss b/src/core/renderers/LogRenderer/stylesheet.scss similarity index 100% rename from src/frontend/core/renderers/LogRenderer/stylesheet.scss rename to src/core/renderers/LogRenderer/stylesheet.scss diff --git a/src/frontend/core/renderers/MarkdownRenderer/index.jsx b/src/core/renderers/MarkdownRenderer/index.jsx similarity index 100% rename from src/frontend/core/renderers/MarkdownRenderer/index.jsx rename to src/core/renderers/MarkdownRenderer/index.jsx diff --git a/src/frontend/core/renderers/MarkdownRenderer/stylesheet.scss b/src/core/renderers/MarkdownRenderer/stylesheet.scss similarity index 100% rename from src/frontend/core/renderers/MarkdownRenderer/stylesheet.scss rename to src/core/renderers/MarkdownRenderer/stylesheet.scss diff --git a/src/frontend/core/renderers/Renderer/index.jsx b/src/core/renderers/Renderer/index.jsx similarity index 100% rename from src/frontend/core/renderers/Renderer/index.jsx rename to src/core/renderers/Renderer/index.jsx diff --git a/src/frontend/core/renderers/Renderer/stylesheet.scss b/src/core/renderers/Renderer/stylesheet.scss similarity index 100% rename from src/frontend/core/renderers/Renderer/stylesheet.scss rename to src/core/renderers/Renderer/stylesheet.scss diff --git a/src/frontend/core/renderers/index.js b/src/core/renderers/index.js similarity index 100% rename from src/frontend/core/renderers/index.js rename to src/core/renderers/index.js diff --git a/src/frontend/core/tracers/Array1DTracer.js b/src/core/tracers/Array1DTracer.js similarity index 100% rename from src/frontend/core/tracers/Array1DTracer.js rename to src/core/tracers/Array1DTracer.js diff --git a/src/frontend/core/tracers/Array2DTracer.js b/src/core/tracers/Array2DTracer.js similarity index 100% rename from src/frontend/core/tracers/Array2DTracer.js rename to src/core/tracers/Array2DTracer.js diff --git a/src/frontend/core/tracers/ChartTracer.js b/src/core/tracers/ChartTracer.js similarity index 100% rename from src/frontend/core/tracers/ChartTracer.js rename to src/core/tracers/ChartTracer.js diff --git a/src/frontend/core/tracers/GraphTracer.js b/src/core/tracers/GraphTracer.js similarity index 100% rename from src/frontend/core/tracers/GraphTracer.js rename to src/core/tracers/GraphTracer.js diff --git a/src/frontend/core/tracers/LogTracer.js b/src/core/tracers/LogTracer.js similarity index 100% rename from src/frontend/core/tracers/LogTracer.js rename to src/core/tracers/LogTracer.js diff --git a/src/frontend/core/tracers/MarkdownTracer.js b/src/core/tracers/MarkdownTracer.js similarity index 100% rename from src/frontend/core/tracers/MarkdownTracer.js rename to src/core/tracers/MarkdownTracer.js diff --git a/src/frontend/core/tracers/Tracer.jsx b/src/core/tracers/Tracer.jsx similarity index 100% rename from src/frontend/core/tracers/Tracer.jsx rename to src/core/tracers/Tracer.jsx diff --git a/src/frontend/core/tracers/index.js b/src/core/tracers/index.js similarity index 100% rename from src/frontend/core/tracers/index.js rename to src/core/tracers/index.js diff --git a/src/frontend/files/algorithm-visualizer/README.md b/src/files/algorithm-visualizer/README.md similarity index 100% rename from src/frontend/files/algorithm-visualizer/README.md rename to src/files/algorithm-visualizer/README.md diff --git a/src/frontend/files/index.js b/src/files/index.js similarity index 100% rename from src/frontend/files/index.js rename to src/files/index.js diff --git a/src/frontend/files/scratch-paper/CONTRIBUTING.md b/src/files/scratch-paper/CONTRIBUTING.md similarity index 100% rename from src/frontend/files/scratch-paper/CONTRIBUTING.md rename to src/files/scratch-paper/CONTRIBUTING.md diff --git a/src/frontend/files/skeletons/code.cpp b/src/files/skeletons/code.cpp similarity index 100% rename from src/frontend/files/skeletons/code.cpp rename to src/files/skeletons/code.cpp diff --git a/src/frontend/files/skeletons/code.java b/src/files/skeletons/code.java similarity index 100% rename from src/frontend/files/skeletons/code.java rename to src/files/skeletons/code.java diff --git a/src/frontend/files/skeletons/code.js b/src/files/skeletons/code.js similarity index 100% rename from src/frontend/files/skeletons/code.js rename to src/files/skeletons/code.js diff --git a/src/frontend/index.jsx b/src/index.jsx similarity index 100% rename from src/frontend/index.jsx rename to src/index.jsx diff --git a/src/frontend/reducers/current.js b/src/reducers/current.js similarity index 100% rename from src/frontend/reducers/current.js rename to src/reducers/current.js diff --git a/src/frontend/reducers/directory.js b/src/reducers/directory.js similarity index 100% rename from src/frontend/reducers/directory.js rename to src/reducers/directory.js diff --git a/src/frontend/reducers/env.js b/src/reducers/env.js similarity index 100% rename from src/frontend/reducers/env.js rename to src/reducers/env.js diff --git a/src/frontend/reducers/index.js b/src/reducers/index.js similarity index 100% rename from src/frontend/reducers/index.js rename to src/reducers/index.js diff --git a/src/frontend/reducers/player.js b/src/reducers/player.js similarity index 100% rename from src/frontend/reducers/player.js rename to src/reducers/player.js diff --git a/src/frontend/reducers/toast.js b/src/reducers/toast.js similarity index 100% rename from src/frontend/reducers/toast.js rename to src/reducers/toast.js diff --git a/src/frontend/static/favicon.png b/src/static/favicon.png similarity index 100% rename from src/frontend/static/favicon.png rename to src/static/favicon.png diff --git a/src/frontend/static/icon.png b/src/static/icon.png similarity index 100% rename from src/frontend/static/icon.png rename to src/static/icon.png diff --git a/src/frontend/static/manifest.json b/src/static/manifest.json similarity index 100% rename from src/frontend/static/manifest.json rename to src/static/manifest.json diff --git a/robots.txt b/src/static/robots.txt similarity index 100% rename from robots.txt rename to src/static/robots.txt diff --git a/src/frontend/template.html b/src/template.html similarity index 100% rename from src/frontend/template.html rename to src/template.html diff --git a/webpack.backend.config.js b/webpack.backend.config.js deleted file mode 100644 index 5185c701..00000000 --- a/webpack.backend.config.js +++ /dev/null @@ -1,45 +0,0 @@ -const CleanWebpackPlugin = require('clean-webpack-plugin'); -const nodeExternals = require('webpack-node-externals'); -const path = require('path'); -const fs = require('fs'); - -const { - __DEV__, - backendBuildPath: buildPath, - backendSrcPath: srcPath, -} = require('./environment'); - -const alias = { - '/environment': path.resolve(__dirname, 'environment.js'), -}; -fs.readdirSync(srcPath).forEach(name => { - alias['/' + name] = path.resolve(srcPath, name); -}); - -module.exports = { - target: 'node', - node: { - __dirname: true, - }, - entry: srcPath, - externals: [nodeExternals()], - resolve: { - modules: [srcPath], - extensions: ['.js'], - alias, - }, - output: { - path: buildPath, - filename: 'index.js', - libraryTarget: 'umd', - }, - module: { - rules: [ - { test: /\.js$/, use: 'babel-loader', include: srcPath }, - ], - }, - plugins: [ - new CleanWebpackPlugin([buildPath]), - ], - mode: __DEV__ ? 'development' : 'production', -}; \ No newline at end of file