mirror of
https://github.com/openharmony/developtools_ace-js2bundle.git
synced 2026-07-19 10:15:08 -04:00
@@ -293,19 +293,43 @@ 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.aceWorkPath).toString());
|
||||
workerConfig.forEach(worker => {
|
||||
const relativePath = path.ralative(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.aceWorkPath && fs.existsSync(process.env.aceWorkPath)) {
|
||||
const workerConfig = JSON.parse(fs.readFileSync(process.env.aceWorkPath).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