mirror of
https://github.com/openharmony/developtools_ace-js2bundle.git
synced 2026-07-19 18:23:34 -04:00
@@ -49,7 +49,8 @@ class ResultStates {
|
||||
|
||||
apply(compiler) {
|
||||
const buildPath = this.options.build;
|
||||
const modulePaths = new Set();
|
||||
const commonPaths = new Set();
|
||||
const i18nPaths = new Set();
|
||||
|
||||
compiler.hooks.compilation.tap('toFindModule', (compilation) => {
|
||||
compilation.hooks.buildModule.tap("findModule", (module) => {
|
||||
@@ -58,18 +59,26 @@ class ResultStates {
|
||||
const afterNodeModules =
|
||||
module.context.replace(beforNodeModules, '').replace('node_modules' + path.sep, '');
|
||||
const src = afterNodeModules.substr(0, afterNodeModules.indexOf(path.sep));
|
||||
const modulePath =
|
||||
path.resolve(beforNodeModules, 'node_modules', src, 'src', 'js', 'share');
|
||||
if (fs.existsSync(modulePath)) {
|
||||
modulePaths.add(modulePath)
|
||||
const commonPath =
|
||||
path.resolve(beforNodeModules, 'node_modules', src, 'src', 'js', 'common');
|
||||
if (fs.existsSync(commonPath)) {
|
||||
commonPaths.add(commonPath)
|
||||
}
|
||||
const i18nPath =
|
||||
path.resolve(beforNodeModules, 'node_modules', src, 'src', 'js', 'i18n');
|
||||
if (fs.existsSync(i18nPath)) {
|
||||
i18nPaths.add(i18nPath)
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
compiler.hooks.afterCompile.tap('copyFindModule', () => {
|
||||
for (let modulePath of modulePaths) {
|
||||
circularFile(modulePath, path.resolve(buildPath, '../share'));
|
||||
for (let commonPath of commonPaths) {
|
||||
circularFile(commonPath, path.resolve(buildPath, '../share/common'));
|
||||
}
|
||||
for (let i18nPath of i18nPaths) {
|
||||
circularFile(i18nPath, path.resolve(buildPath, '../share/i18n'));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -67,8 +67,7 @@ function copyFile(input, output) {
|
||||
|
||||
function circularFile(inputPath, outputPath, ext) {
|
||||
const realPath = path.join(inputPath, ext);
|
||||
const localI18n = path.join(input, 'i18n');
|
||||
if (!fs.existsSync(realPath) || realPath === output || realPath === localI18n) {
|
||||
if (!fs.existsSync(realPath) || realPath === output) {
|
||||
return;
|
||||
}
|
||||
fs.readdirSync(realPath).forEach(function(file_) {
|
||||
@@ -77,18 +76,20 @@ function circularFile(inputPath, outputPath, ext) {
|
||||
if (fileStat.isFile()) {
|
||||
const baseName = path.basename(file);
|
||||
const extName = path.extname(file);
|
||||
const outputFile = path.join(outputPath, ext, path.basename(file_));
|
||||
if (outputFile === path.join(output, 'manifest.json')) {
|
||||
return;
|
||||
}
|
||||
if (FILE_EXT_NAME.indexOf(extName) < 0 && baseName !== '.DS_Store') {
|
||||
const outputFile = path.join(outputPath, ext, path.basename(file_));
|
||||
if (outputFile === path.join(output, 'manifest.json')) {
|
||||
return;
|
||||
}
|
||||
if (fs.existsSync(outputFile)) {
|
||||
const outputFileStat = fs.statSync(outputFile);
|
||||
if (outputFileStat.isFile() && fileStat.size !== outputFileStat.size) {
|
||||
copyFile(file, outputFile);
|
||||
}
|
||||
} else {
|
||||
copyFile(file, outputFile);
|
||||
toCopyFile(file, outputFile, fileStat)
|
||||
} else if (extName === '.json') {
|
||||
const parent = path.join(file, '..');
|
||||
const parent_ = path.join(parent, '..');
|
||||
if (path.parse(parent).name === 'i18n' && path.parse(parent_).name === 'share') {
|
||||
toCopyFile(file, outputFile, fileStat)
|
||||
} else if (path.parse(parent).name === 'styles' &&
|
||||
path.parse(parent_).name === 'resources') {
|
||||
toCopyFile(file, outputFile, fileStat)
|
||||
}
|
||||
}
|
||||
} else if (fileStat.isDirectory()) {
|
||||
@@ -97,6 +98,17 @@ function circularFile(inputPath, outputPath, ext) {
|
||||
});
|
||||
}
|
||||
|
||||
function toCopyFile(file, outputFile, fileStat) {
|
||||
if (fs.existsSync(outputFile)) {
|
||||
const outputFileStat = fs.statSync(outputFile);
|
||||
if (outputFileStat.isFile() && fileStat.size !== outputFileStat.size) {
|
||||
copyFile(file, outputFile);
|
||||
}
|
||||
} else {
|
||||
copyFile(file, outputFile);
|
||||
}
|
||||
}
|
||||
|
||||
class ResourcePlugin {
|
||||
constructor(input_, output_, manifestFilePath_, watchCSSFiles_) {
|
||||
input = input_;
|
||||
|
||||
Reference in New Issue
Block a user