Skip to content

Commit

Permalink
Include Draco and Basis in @babylonjs/core (#14869)
Browse files Browse the repository at this point in the history
* Update build tools to allow tasks

* small fix

* Copy Draco and Basis
  • Loading branch information
RaananW authored Mar 14, 2024
1 parent b140c00 commit 485d909
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 13 deletions.
36 changes: 32 additions & 4 deletions packages/dev/buildTools/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { addJsExtensionsToCompiledFilesCommand } from "./addJSToCompiledFiles.js
import { generateDeclaration } from "./generateDeclaration.js";
import { transformLtsCommand } from "./ltsTransformer.js";
import { prepareES6Build } from "./prepareEs6Build.js";
import { checkArgs, copyFolder, populateEnvironment } from "./utils.js";
import { checkArgs, copyFolder, externalArgs, populateEnvironment } from "./utils.js";
import { devWatch } from "./devWatcher.js";
import { processAssets } from "./copyAssets.js";
import { prepareSnapshot } from "./prepareSnapshot.js";
Expand All @@ -14,15 +14,43 @@ import { declarationsEs6 } from "./declarationsEs6.js";
// public API
import transformer from "./pathTransform.js";
import * as webpackTools from "./webpackTools.js";
import * as fs from "fs";
import * as path from "path";

runCommand();
const cliCommand = checkArgs(["-c", "--command"], false, true) as string;
runCommand(cliCommand);

function runCommand() {
const command = checkArgs(["-c", "--command"], false, true);
function processConfigFile() {
const baseDir = path.resolve(".");
const configFile = (checkArgs(["-f", "--file"], false, true) as string) || "config.tasks.json";
if (configFile) {
console.log(`Processing config file: ${configFile}`);
// read the json file using fs
const config = JSON.parse(fs.readFileSync(path.resolve(baseDir, configFile), "utf8"));
if (config) {
if (config.commands) {
for (const command of config.commands as { command: string; args?: string[] }[]) {
// populate the args
externalArgs.length = 0;
if (command.args) {
externalArgs.push(...(command.args as string[]));
}
runCommand(command.command);
}
}
}
}
}

function runCommand(command: string) {
if (command) {
console.log("Babylon.js build tools");
console.log(`Command: ${command}`);
switch (command) {
case "run-tasks":
case "rt":
processConfigFile();
break;
case "add-js-to-es6":
case "ajte":
addJsExtensionsToCompiledFilesCommand();
Expand Down
24 changes: 17 additions & 7 deletions packages/dev/buildTools/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as fs from "fs";
import * as path from "path";
import * as dotenv from "dotenv";
import * as crypto from "crypto";
import { glob } from "glob";

export function populateEnvironment() {
dotenv.config({ path: path.resolve(findRootDirectory(), "./.env") });
Expand Down Expand Up @@ -46,8 +47,10 @@ const filterDashes = (str: string) => {
return str.substring(index);
};

export const externalArgs: string[] = [];

export const checkArgs = (testArgument: string | string[], checkOnly: boolean = false, requiredIfSet = false): string | boolean => {
const args = process.argv.slice(2);
const args = externalArgs.length ? externalArgs : process.argv.slice(2);
const index = typeof testArgument === "string" ? args.indexOf(testArgument) : testArgument.map((arg) => args.indexOf(arg)).find((idx) => idx !== -1);
const envValue =
typeof testArgument === "string"
Expand Down Expand Up @@ -102,16 +105,23 @@ export function copyFile(from: string, to: string, silent?: boolean, checkHash?:
*/
export function copyFolder(from: string, to: string, silent?: boolean) {
checkDirectorySync(to);
const files = fs.readdirSync(from);
// check if from is a folder
let isDirectory = false;
try {
isDirectory = fs.lstatSync(from).isDirectory();
} catch (e) {}
const files = isDirectory ? fs.readdirSync(from) : glob.sync(from);
const baseDir = isDirectory ? from : "";
for (const file of files) {
const current = fs.lstatSync(path.join(from, file));
const basename = isDirectory ? file : path.basename(file);
const current = fs.lstatSync(path.join(baseDir, file));
if (current.isDirectory()) {
copyFolder(path.join(from, file), path.join(to, file), silent);
copyFolder(path.join(baseDir, file), path.join(to, basename), silent);
} else if (current.isSymbolicLink()) {
const symlink = fs.readlinkSync(path.join(from, file));
fs.symlinkSync(symlink, path.join(to, file));
const symlink = fs.readlinkSync(path.join(baseDir, file));
fs.symlinkSync(symlink, path.join(to, basename));
}
copyFile(path.join(from, file), path.join(to, file), silent);
copyFile(path.join(baseDir, file), path.join(to, basename), silent);
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/public/@babylonjs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ node_modules
*.png
*.jpg
*.wasm
*.license
!inspector/**/*.*
!node-editor/**/*.*
!node-geometry-editor/**/*.*
Expand Down
10 changes: 10 additions & 0 deletions packages/public/@babylonjs/core/NOTICE.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
Babylon.js
Copyright 2023 The Babylon.js team

The following components are included in this package:

Draco Compression
https://github.com/google/draco
Licensed under the Apache 2.0 License

Basis transcoder
Copyright 2024 The Khronos Group (https://www.khronos.org/),
Licensed under the Apache 2.0 license.
24 changes: 24 additions & 0 deletions packages/public/@babylonjs/core/config.tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"commands": [
{
"command": "declarations-es6",
"args": ["-r", "../../../dev/core/src/LibDeclarations", "-atf", "./Engines/engine.d.ts"]
},
{
"command": "add-js-to-es6"
},
{
"command": "prepare-es6-build",
"args": ["-cf", "Engines/constants.js"]
},
{
"command": "cp",
"args": ["-f", "../../../tools/babylonServer/public/draco*.*", "--to", "./assets/Draco"]
},
{
"command": "cp",
"args": ["-f", "../../../tools/babylonServer/public/basisTranscoder/1", "--to", "./assets/Basis"]
}
]
}

5 changes: 3 additions & 2 deletions packages/public/@babylonjs/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
],
"scripts": {
"build": "npm run clean && npm run compile",
"clean": "rimraf dist && rimraf *.tsbuildinfo && rimraf \"./**/*.!(cmd|md|json|build.json|lts.json|cjs)\"",
"clean": "rimraf dist && rimraf *.tsbuildinfo && rimraf \"./**/*.!(cmd|md|json|build.json|lts.json|tasks.json|cjs)\"",
"compile": "tsc -b tsconfig.build.json && tsc -b tsconfig.lts.json",
"postcompile": "build-tools -c declarations-es6 -r ../../../dev/core/src/LibDeclarations -atf ./Engines/engine.d.ts && build-tools -c add-js-to-es6 && build-tools -c prepare-es6-build -cf Engines/constants.js",
"postcompile": "build-tools -c run-tasks",
"watch": "node ./watcher.cjs"
},
"devDependencies": {
Expand All @@ -43,3 +43,4 @@
"url": "https://github.com/BabylonJS/Babylon.js/issues"
}
}

0 comments on commit 485d909

Please sign in to comment.