Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…to csg
  • Loading branch information
joeng03 committed Apr 12, 2023
2 parents 130729b + 9ca1e99 commit dc81e48
Show file tree
Hide file tree
Showing 60 changed files with 5,049 additions and 2,446 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pages-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

jobs:
deploy:
runs-on: ubuntu-18.04
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
jobs:
test:
name: Verify all tests pass and build success
runs-on: ubuntu-18.04
runs-on: ubuntu-latest
steps:
- name: Check out source code
uses: actions/checkout@v2
Expand Down
18 changes: 18 additions & 0 deletions modules.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
{
"painter": {
"tabs": [
"Painter"
]
},
"unity_academy": {
"tabs": [
"UnityAcademy"
]
},
"plotly": {
"tabs": [
"Plotly"
]
},
"repeat": {
"tabs": [
"Repeat"
Expand Down Expand Up @@ -67,5 +82,8 @@
"tabs": [
"Repl"
]
},
"remote_execution": {
"tabs": []
}
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"@types/jest": "^27.4.1",
"@types/lodash": "^4.14.191",
"@types/node": "^17.0.23",
"@types/plotly.js-dist": "npm:@types/plotly.js",
"@types/react": "^17.0.43",
"@typescript-eslint/eslint-plugin": "^5.47.1",
"@typescript-eslint/parser": "^5.47.1",
Expand Down Expand Up @@ -91,10 +92,11 @@
"classnames": "^2.3.1",
"dayjs": "^1.10.4",
"gl-matrix": "^3.3.0",
"js-slang": "^0.5.38",
"js-slang": "^1.0.20",
"lodash": "^4.17.21",
"patch-package": "^6.5.1",
"phaser": "^3.54.0",
"plotly.js-dist": "^2.17.1",
"postinstall-postinstall": "^2.1.0",
"react": "^17.0.2",
"react-ace": "^10.1.0",
Expand Down
12 changes: 5 additions & 7 deletions scripts/bin/build/dev.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import chalk from 'chalk';
import { context as esbuild } from 'esbuild';
import { buildHtml, buildJsons, initTypedoc, logHtmlResult } from './docs/index.js';
import { reduceBundleOutputFiles } from './modules/bundle.js';
import { esbuildOptions } from './modules/moduleUtils.js';
import { reduceTabOutputFiles } from './modules/tab.js';
import { bundleOptions, reduceBundleOutputFiles } from './modules/bundle.js';
import { reduceTabOutputFiles, tabOptions } from './modules/tab.js';
import { bundleNameExpander, copyManifest, createBuildCommand, createBuildDirs, divideAndRound, logResult, retrieveBundlesAndTabs, tabNameExpander, } from './buildUtils.js';
/**
* Wait until the user presses 'ctrl+c' on the keyboard
Expand All @@ -21,11 +20,10 @@ const waitForQuit = () => new Promise((resolve, reject) => {
process.stdin.on('error', reject);
});
const getBundleContext = ({ srcDir, outDir }, bundles, app) => esbuild({
...esbuildOptions,
...bundleOptions,
outbase: outDir,
outdir: outDir,
entryPoints: bundles.map(bundleNameExpander(srcDir)),
external: ['js-slang/moduleHelpers'],
plugins: [{
name: 'Bundle Compiler',
async setup(pluginBuild) {
Expand Down Expand Up @@ -56,11 +54,11 @@ const getBundleContext = ({ srcDir, outDir }, bundles, app) => esbuild({
}],
});
const getTabContext = ({ srcDir, outDir }, tabs) => esbuild({
...esbuildOptions,
...tabOptions,
outbase: outDir,
outdir: outDir,
entryPoints: tabs.map(tabNameExpander(srcDir)),
external: ['react', 'react-dom'],
external: ['react*', 'react-dom'],
plugins: [{
name: 'Tab Compiler',
setup(pluginBuild) {
Expand Down
2 changes: 1 addition & 1 deletion scripts/bin/build/docs/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const getBuildHtmlCommand = () => new Command('html')
bundles,
tabs: [],
});
logTscResults(tscResult, opts.srcDir);
logTscResults(tscResult);
if (tscResult.result.severity === 'error')
process.exit(1);
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/bin/build/docs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const getBuildDocsCommand = () => createBuildCommand('docs', true)
bundles,
tabs: [],
});
logTscResults(tscResult, srcDir);
logTscResults(tscResult);
if (tscResult.result.severity === 'error')
process.exit(1);
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/bin/build/docs/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ const getJsonCommand = () => createBuildCommand('jsons', false)
bundles,
tabs: [],
});
logTscResults(tscResult, srcDir);
logTscResults(tscResult);
if (tscResult.result.severity === 'error')
process.exit(1);
}
Expand Down
36 changes: 17 additions & 19 deletions scripts/bin/build/modules/bundle.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { parse } from 'acorn';
import { generate } from 'astring';
import { build as esbuild } from 'esbuild';
import { build as esbuild, } from 'esbuild';
import fs from 'fs/promises';
import pathlib from 'path';
import { bundleNameExpander } from '../buildUtils.js';
import { esbuildOptions, requireCreator } from './moduleUtils.js';
const HELPER_NAME = 'moduleHelpers';
import { esbuildOptions } from './moduleUtils.js';
export const outputBundle = async (name, bundleText, outDir) => {
try {
const parsed = parse(bundleText, { ecmaVersion: 6 });
Expand All @@ -21,25 +20,20 @@ export const outputBundle = async (name, bundleText, outDir) => {
const callExpression = varDeclarator.init;
const moduleCode = callExpression.callee;
const output = {
type: 'FunctionExpression',
type: 'ArrowFunctionExpression',
body: {
type: 'BlockStatement',
body: [
requireCreator({
'js-slang/moduleHelpers': HELPER_NAME,
}),
...(moduleCode.body.type === 'BlockStatement'
? moduleCode.body.body
: [{
type: 'ExpressionStatement',
expression: moduleCode.body,
}]),
],
body: moduleCode.body.type === 'BlockStatement'
? moduleCode.body.body
: [{
type: 'ExpressionStatement',
expression: moduleCode.body,
}],
},
params: [
{
type: 'Identifier',
name: HELPER_NAME,
name: 'require',
},
],
};
Expand All @@ -62,13 +56,17 @@ export const outputBundle = async (name, bundleText, outDir) => {
};
}
};
export const bundleOptions = {
...esbuildOptions,
external: ['js-slang*'],
};
export const buildBundles = async (bundles, { srcDir, outDir }) => {
const nameExpander = bundleNameExpander(srcDir);
const { outputFiles } = await esbuild({
...esbuildOptions,
entryPoints: bundles.map(bundleNameExpander(srcDir)),
...bundleOptions,
entryPoints: bundles.map(nameExpander),
outbase: outDir,
outdir: outDir,
external: ['js-slang/moduleHelpers'],
});
return outputFiles;
};
Expand Down
61 changes: 22 additions & 39 deletions scripts/bin/build/modules/tab.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,32 @@
import { parse } from 'acorn';
import { generate } from 'astring';
import chalk from 'chalk';
import { build as esbuild } from 'esbuild';
import { build as esbuild, } from 'esbuild';
import fs from 'fs/promises';
import uniq from 'lodash/uniq.js';
import pathlib from 'path';
import { printList } from '../../scriptUtils.js';
import { copyManifest, createBuildCommand, exitOnError, logResult, retrieveTabs, tabNameExpander, } from '../buildUtils.js';
import { prebuild } from '../prebuild/index.js';
import { esbuildOptions, requireCreator } from './moduleUtils.js';
/**
* Imports that are provided at runtime
*/
const externals = {
'react': '_react',
'react-dom': 'ReactDOM',
};
import { esbuildOptions } from './moduleUtils.js';
const outputTab = async (tabName, text, outDir) => {
try {
const parsed = parse(text, { ecmaVersion: 6 });
const declStatement = parsed.body[1];
const newTab = {
type: 'ExpressionStatement',
expression: {
type: 'FunctionExpression',
params: uniq(Object.values(externals))
.map((name) => ({
type: 'Identifier',
name,
})),
body: {
type: 'BlockStatement',
body: [
requireCreator(externals),
{
type: 'ReturnStatement',
argument: {
type: 'MemberExpression',
object: declStatement.declarations[0].init,
property: {
type: 'Literal',
value: 'default',
},
computed: true,
},
},
],
type: 'ArrowFunctionExpression',
body: {
type: 'MemberExpression',
object: declStatement.declarations[0].init,
property: {
type: 'Literal',
value: 'default',
},
computed: true,
},
params: [{
type: 'Identifier',
name: 'require',
}],
};
let newCode = generate(newTab);
if (newCode.endsWith(';'))
Expand All @@ -67,14 +46,18 @@ const outputTab = async (tabName, text, outDir) => {
};
}
};
export const tabOptions = {
...esbuildOptions,
jsx: 'automatic',
external: ['react', 'react-dom', 'react/jsx-runtime'],
};
export const buildTabs = async (tabs, { srcDir, outDir }) => {
const nameExpander = tabNameExpander(srcDir);
const { outputFiles } = await esbuild({
...esbuildOptions,
entryPoints: tabs.map(tabNameExpander(srcDir)),
...tabOptions,
entryPoints: tabs.map(nameExpander),
outbase: outDir,
outdir: outDir,
external: Object.keys(externals),
jsx: 'transform',
});
return outputFiles;
};
Expand Down
2 changes: 1 addition & 1 deletion scripts/bin/build/prebuild/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const prebuildInternal = async (opts, assets) => {
export const prebuild = async (opts, assets) => {
const { lintResult, tscResult } = await prebuildInternal(opts, assets);
logLintResult(lintResult);
logTscResults(tscResult, opts.srcDir);
logTscResults(tscResult);
exitOnError([], lintResult?.result, tscResult?.result);
if (lintResult?.result.severity === 'error' || tscResult?.result.severity === 'error') {
throw new Error('Exiting for jest');
Expand Down
6 changes: 3 additions & 3 deletions scripts/bin/build/prebuild/tsc.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const runTsc = wrapWithTimer((async (srcDir, { bundles, tabs }) => {
results: diagnostics,
};
}));
export const logTscResults = (input, srcDir) => {
export const logTscResults = (input) => {
if (!input)
return;
const { elapsed, result: { severity, results, error } } = input;
Expand All @@ -76,7 +76,7 @@ export const logTscResults = (input, srcDir) => {
}
const diagStr = ts.formatDiagnosticsWithColorAndContext(results, {
getNewLine: () => '\n',
getCurrentDirectory: () => srcDir,
getCurrentDirectory: () => pathlib.resolve('.'),
getCanonicalFileName: (name) => pathlib.basename(name),
});
if (severity === 'error') {
Expand All @@ -96,7 +96,7 @@ const getTscCommand = () => new Command('typecheck')
.action(async ({ modules, tabs, manifest, srcDir }) => {
const assets = await retrieveBundlesAndTabs(manifest, modules, tabs);
const tscResults = await runTsc(srcDir, assets);
logTscResults(tscResults, srcDir);
logTscResults(tscResults);
exitOnError([], tscResults.result);
});
export default getTscCommand;
12 changes: 5 additions & 7 deletions scripts/src/build/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ import { context as esbuild } from 'esbuild';
import type { Application } from 'typedoc';

import { buildHtml, buildJsons, initTypedoc, logHtmlResult } from './docs/index.js';
import { reduceBundleOutputFiles } from './modules/bundle.js';
import { esbuildOptions } from './modules/moduleUtils.js';
import { reduceTabOutputFiles } from './modules/tab.js';
import { bundleOptions, reduceBundleOutputFiles } from './modules/bundle.js';
import { reduceTabOutputFiles, tabOptions } from './modules/tab.js';
import {
bundleNameExpander,
copyManifest,
Expand Down Expand Up @@ -36,11 +35,10 @@ const waitForQuit = () => new Promise<void>((resolve, reject) => {

type ContextOptions = Record<'srcDir' | 'outDir', string>;
const getBundleContext = ({ srcDir, outDir }: ContextOptions, bundles: string[], app?: Application) => esbuild({
...esbuildOptions,
...bundleOptions,
outbase: outDir,
outdir: outDir,
entryPoints: bundles.map(bundleNameExpander(srcDir)),
external: ['js-slang/moduleHelpers'],
plugins: [{
name: 'Bundle Compiler',
async setup(pluginBuild) {
Expand Down Expand Up @@ -75,11 +73,11 @@ const getBundleContext = ({ srcDir, outDir }: ContextOptions, bundles: string[],
});

const getTabContext = ({ srcDir, outDir }: ContextOptions, tabs: string[]) => esbuild({
...esbuildOptions,
...tabOptions,
outbase: outDir,
outdir: outDir,
entryPoints: tabs.map(tabNameExpander(srcDir)),
external: ['react', 'react-dom'],
external: ['react*', 'react-dom'],
plugins: [{
name: 'Tab Compiler',
setup(pluginBuild) {
Expand Down
2 changes: 1 addition & 1 deletion scripts/src/build/docs/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const getBuildHtmlCommand = () => new Command('html')
bundles,
tabs: [],
});
logTscResults(tscResult, opts.srcDir);
logTscResults(tscResult);
if (tscResult.result.severity === 'error') process.exit(1);
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/src/build/docs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const getBuildDocsCommand = () => createBuildCommand('docs', true)
bundles,
tabs: [],
});
logTscResults(tscResult, srcDir);
logTscResults(tscResult);
if (tscResult.result.severity === 'error') process.exit(1);
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/src/build/docs/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ const getJsonCommand = () => createBuildCommand('jsons', false)
bundles,
tabs: [],
});
logTscResults(tscResult, srcDir);
logTscResults(tscResult);
if (tscResult.result.severity === 'error') process.exit(1);
}

Expand Down
Loading

0 comments on commit dc81e48

Please sign in to comment.