-
-
Notifications
You must be signed in to change notification settings - Fork 223
Expand file tree
/
Copy pathbuild.mjs
More file actions
60 lines (49 loc) · 1.79 KB
/
Copy pathbuild.mjs
File metadata and controls
60 lines (49 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/**
* LittleJS TypeScript Example Build System
*/
'use strict';
import { fileURLToPath } from 'node:url';
import { dirname, join } from 'node:path';
import fs from 'node:fs';
import { execSync } from 'node:child_process';
const __dirname = dirname(fileURLToPath(import.meta.url));
const PROGRAM_NAME = 'game';
const BUILD_FOLDER = join(__dirname, 'build');
// Define TypeScript source files
const tsSourceFiles = [
'game.ts',
// add your TypeScript files here
];
// Corresponding JS output files
const jsSourceFiles = tsSourceFiles.map(file => file.replace('.ts', '.js'));
console.log(`Building TypeScript for ${PROGRAM_NAME}...`);
const startTime = Date.now();
console.log(`Removing old build folder...`);
fs.rmSync(BUILD_FOLDER, { recursive: true, force: true });
console.log(`Compiling TypeScript...`);
// Use tsconfig.json for compilation settings
try
{
const result = execSync(`npx -p typescript tsc`, {cwd: __dirname, encoding: 'utf8', stdio: 'pipe'});
console.log(result);
} catch (error)
{
console.error('TypeScript compilation errors:');
if (error.stdout) console.log(error.stdout);
if (error.stderr) console.error(error.stderr);
console.error('TypeScript compilation failed!');
process.exit(1);
}
console.log(`Copying js files back to root...`);
for (const file of jsSourceFiles)
{
// TypeScript outputs to build/examples/typescript/ because of relative paths
const buildFile = join(BUILD_FOLDER, 'examples', 'typescript', file);
const targetFile = join(__dirname, file);
console.log(`Copying ${file}...`);
if (fs.existsSync(buildFile))
fs.copyFileSync(buildFile, targetFile);
else
console.error(`✗ Build file not found: ${buildFile}`);
}
console.log(`TypeScript built in ${((Date.now() - startTime)/1e3).toFixed(2)} seconds!`);