mirror of
https://github.com/openharmony/developtools_ace-js2bundle.git
synced 2026-07-25 06:06:09 -04:00
@@ -177,6 +177,36 @@ function filterWorker(workerPath) {
|
|||||||
return /\.(ts|js)$/.test(workerPath);
|
return /\.(ts|js)$/.test(workerPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function compareCache(cachePath) {
|
||||||
|
const entryFile = path.join(cachePath, 'entry.json');
|
||||||
|
const cssFile = process.env.watchCSSFiles;
|
||||||
|
|
||||||
|
let files = [];
|
||||||
|
if (fs.existsSync(cssFile)) {
|
||||||
|
const cssObject = JSON.parse(fs.readFileSync(cssFile));
|
||||||
|
if (cssObject['clear'] === true) {
|
||||||
|
deleteFolderRecursive(cachePath);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Object.keys(cssObject).forEach(key => {
|
||||||
|
if (key !== 'entry') {
|
||||||
|
files.push(key);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fs.existsSync(entryFile)) {
|
||||||
|
files = files.concat(JSON.parse(fs.readFileSync(entryFile)));
|
||||||
|
}
|
||||||
|
|
||||||
|
for(let file of files) {
|
||||||
|
if (!fs.existsSync(file)) {
|
||||||
|
deleteFolderRecursive(cachePath);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
deleteFolderRecursive: deleteFolderRecursive,
|
deleteFolderRecursive: deleteFolderRecursive,
|
||||||
readManifest: readManifest,
|
readManifest: readManifest,
|
||||||
@@ -186,4 +216,5 @@ module.exports = {
|
|||||||
checkMultiResourceBuild: checkMultiResourceBuild,
|
checkMultiResourceBuild: checkMultiResourceBuild,
|
||||||
multiResourceBuild: multiResourceBuild,
|
multiResourceBuild: multiResourceBuild,
|
||||||
readWorkerFile: readWorkerFile,
|
readWorkerFile: readWorkerFile,
|
||||||
|
compareCache: compareCache
|
||||||
};
|
};
|
||||||
@@ -55,9 +55,15 @@ class ResultStates {
|
|||||||
const buildPath = this.options.build;
|
const buildPath = this.options.build;
|
||||||
const commonPaths = new Set();
|
const commonPaths = new Set();
|
||||||
const i18nPaths = new Set();
|
const i18nPaths = new Set();
|
||||||
|
const cachePath = path.resolve(process.env.cachePath, '.rich_cache');
|
||||||
|
const entryFile = path.join(cachePath, 'entry.json');
|
||||||
|
const entryPaths = new Set();
|
||||||
|
|
||||||
compiler.hooks.compilation.tap('toFindModule', (compilation) => {
|
compiler.hooks.compilation.tap('toFindModule', (compilation) => {
|
||||||
compilation.hooks.buildModule.tap("findModule", (module) => {
|
compilation.hooks.buildModule.tap("findModule", (module) => {
|
||||||
|
if (module.resource && fs.existsSync(module.resource)) {
|
||||||
|
entryPaths.add(module.resource);
|
||||||
|
}
|
||||||
if (module.context.indexOf(process.env.projectPath) >= 0) {
|
if (module.context.indexOf(process.env.projectPath) >= 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -86,6 +92,7 @@ class ResultStates {
|
|||||||
for (let i18nPath of i18nPaths) {
|
for (let i18nPath of i18nPaths) {
|
||||||
circularFile(i18nPath, path.resolve(buildPath, '../share/i18n'));
|
circularFile(i18nPath, path.resolve(buildPath, '../share/i18n'));
|
||||||
}
|
}
|
||||||
|
addCacheFiles(entryFile, cachePath, entryPaths);
|
||||||
});
|
});
|
||||||
|
|
||||||
compiler.hooks.done.tap('Result States', (stats) => {
|
compiler.hooks.done.tap('Result States', (stats) => {
|
||||||
@@ -154,6 +161,20 @@ class ResultStates {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function addCacheFiles(entryFile, cachePath, entryPaths) {
|
||||||
|
const entryArray = [];
|
||||||
|
if (fs.existsSync(entryFile)) {
|
||||||
|
const oldArray = JSON.parse(fs.readFileSync(entryFile));
|
||||||
|
oldArray.forEach(element => {
|
||||||
|
entryPaths.add(element);
|
||||||
|
})
|
||||||
|
} else if (!fs.existsSync(cachePath)) {
|
||||||
|
mkDir(cachePath);
|
||||||
|
}
|
||||||
|
entryArray.push(...entryPaths);
|
||||||
|
fs.writeFileSync(entryFile, JSON.stringify(entryArray));
|
||||||
|
}
|
||||||
|
|
||||||
const red = '\u001b[31m';
|
const red = '\u001b[31m';
|
||||||
const yellow = '\u001b[33m';
|
const yellow = '\u001b[33m';
|
||||||
const blue = '\u001b[34m';
|
const blue = '\u001b[34m';
|
||||||
|
|||||||
@@ -36,7 +36,8 @@ const {
|
|||||||
compileCardModule,
|
compileCardModule,
|
||||||
hashProjectPath,
|
hashProjectPath,
|
||||||
checkMultiResourceBuild,
|
checkMultiResourceBuild,
|
||||||
readWorkerFile
|
readWorkerFile,
|
||||||
|
compareCache
|
||||||
} = require('./main.product')
|
} = require('./main.product')
|
||||||
|
|
||||||
const richModule = {
|
const richModule = {
|
||||||
@@ -180,7 +181,7 @@ function setConfigs(env) {
|
|||||||
process.env.DEVICE_LEVEL = env.DEVICE_LEVEL || process.env.DEVICE_LEVEL || 'rich';
|
process.env.DEVICE_LEVEL = env.DEVICE_LEVEL || process.env.DEVICE_LEVEL || 'rich';
|
||||||
process.env.aceModuleJsonPath = env.aceModuleJsonPath || process.env.aceModuleJsonPath;
|
process.env.aceModuleJsonPath = env.aceModuleJsonPath || process.env.aceModuleJsonPath;
|
||||||
process.env.aceProfilePath = env.aceProfilePath || process.env.aceProfilePath;
|
process.env.aceProfilePath = env.aceProfilePath || process.env.aceProfilePath;
|
||||||
process.env.watchCSSFiles = process.env.watchCSSFiles || path.resolve(process.env.buildPath, 'preview_css.json');
|
process.env.watchCSSFiles = process.env.watchCSSFiles || path.resolve(process.env.cachePath, '.rich_cache', 'preview_css.json');
|
||||||
watchMode = (process.env.watchMode && process.env.watchMode === 'true') ||
|
watchMode = (process.env.watchMode && process.env.watchMode === 'true') ||
|
||||||
(env.watchMode && env.watchMode === 'true') || false;
|
(env.watchMode && env.watchMode === 'true') || false;
|
||||||
if (process.env.abilityType === 'page' || process.env.abilityType === 'form') {
|
if (process.env.abilityType === 'page' || process.env.abilityType === 'form') {
|
||||||
@@ -252,6 +253,7 @@ function excludeWorker(workerFile, name) {
|
|||||||
|
|
||||||
module.exports = (env) => {
|
module.exports = (env) => {
|
||||||
setConfigs(env);
|
setConfigs(env);
|
||||||
|
compareCache(path.resolve(process.env.cachePath, '.rich_cache'));
|
||||||
const workerFile = readWorkerFile();
|
const workerFile = readWorkerFile();
|
||||||
if (process.env.compileMode === 'moduleJson') {
|
if (process.env.compileMode === 'moduleJson') {
|
||||||
compileCardModule(env);
|
compileCardModule(env);
|
||||||
|
|||||||
Reference in New Issue
Block a user