forked from maptalks/maptalks.three
-
Notifications
You must be signed in to change notification settings - Fork 0
/
workerinit.js
19 lines (16 loc) · 859 Bytes
/
workerinit.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
const fs = require('fs');
const path = require('path');
const chalk = require('chalk');
const bundlePath = path.join(__dirname, './dist/worker.amd.js');
let code = fs.readFileSync(bundlePath).toString();
console.log(chalk.greenBright(`read ${bundlePath} worker bundle success`));
code = code.replace(`define(['exports'],`, '');
code = code.replace(`define(["exports"],`, '');
code = code.substring(0, code.length - 3);
const workerTempPath = path.join(__dirname, './src/worker/worker.ts');
let worker = fs.readFileSync(workerTempPath).toString();
worker = worker.replace('{code}', code);
console.log(chalk.greenBright(`read ${workerTempPath} workte template success`));
const getWorkerPath = path.join(__dirname, './src/worker/getworker.ts');
fs.writeFileSync(getWorkerPath, worker);
console.log(chalk.greenBright(`write ${getWorkerPath} worker success`));