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