mirror of
https://github.com/openharmony/developtools_ace-js2bundle.git
synced 2026-07-19 18:23:34 -04:00
@@ -294,19 +294,46 @@ function buildManifest(manifest) {
|
||||
}
|
||||
|
||||
function loadWorker(entryObj) {
|
||||
const workerPath = path.resolve(input, 'workers');
|
||||
if (fs.existsSync(workerPath)) {
|
||||
const workerFiles = [];
|
||||
readFile(workerPath, workerFiles);
|
||||
workerFiles.forEach((item) => {
|
||||
if (/\.js$/.test(item)) {
|
||||
const relativePath = path.relative(workerPath, item).replace(/\.js$/, '');
|
||||
entryObj[`./workers/` + relativePath] = item;
|
||||
if(validateWorkOption()) {
|
||||
const workerConfig = JSON.parse(fs.readFileSync(process.env.aceBuildJson).toString());
|
||||
workerConfig.workers.forEach(worker => {
|
||||
if (!/\.(js)$/.test(worker)) {
|
||||
worker += '.js';
|
||||
}
|
||||
});
|
||||
const relativePath = path.relative(process.env.projectPath, worker);
|
||||
if (filterWorker(relativePath)) {
|
||||
entryObj[relativePath.replace(/\.(ts|js)$/,'')] = worker;
|
||||
}
|
||||
})
|
||||
} else {
|
||||
const workerPath = path.resolve(input, 'workers');
|
||||
if (fs.existsSync(workerPath)) {
|
||||
const workerFiles = [];
|
||||
readFile(workerPath, workerFiles);
|
||||
workerFiles.forEach((item) => {
|
||||
if (/\.js$/.test(item)) {
|
||||
const relativePath = path.relative(workerPath, item).replace(/\.js$/, '');
|
||||
entryObj[`./workers/` + relativePath] = item;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function validateWorkOption() {
|
||||
if (process.env.aceBuildJson && fs.existsSync(process.env.aceBuildJson)) {
|
||||
const workerConfig = JSON.parse(fs.readFileSync(process.env.aceBuildJson).toString());
|
||||
if(workerConfig.workers) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function filterWorker(workerPath) {
|
||||
return /\.(ts|js)$/.test(workerPath) && !/^\.\./.test(workerPath);
|
||||
}
|
||||
|
||||
function readFile(dir, utFiles) {
|
||||
try {
|
||||
const files = fs.readdirSync(dir);
|
||||
|
||||
Reference in New Issue
Block a user