mirror of
https://gitee.com/openharmony/developtools_ace_js2bundle
synced 2024-11-23 07:20:22 +00:00
Signed-off-by: chengongping <chengongping@huawei.com> Change-Id: I22e687cb2dbdf09fd2914240344b49eb1e5b219f
This commit is contained in:
parent
1e780f0aa8
commit
cd2928c44c
74
BUILD.gn
74
BUILD.gn
@ -1,4 +1,15 @@
|
||||
# Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
|
||||
# Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
import("//build/ohos/ace/ace.gni")
|
||||
@ -73,19 +84,21 @@ action("build_ace_loader_library") {
|
||||
]
|
||||
}
|
||||
|
||||
ace_loader_sources = [
|
||||
"ace-loader/.npmignore",
|
||||
"ace-loader/babel.config.js",
|
||||
"ace-loader/index.js",
|
||||
"ace-loader/main.product.js",
|
||||
"ace-loader/npm-install.js",
|
||||
"ace-loader/package-lock.json",
|
||||
"ace-loader/package.json",
|
||||
"ace-loader/sample",
|
||||
"ace-loader/webpack.lite.config.js",
|
||||
"ace-loader/webpack.rich.config.js",
|
||||
]
|
||||
|
||||
ohos_copy("ace_loader") {
|
||||
sources = [
|
||||
"ace-loader/.npmignore",
|
||||
"ace-loader/babel.config.js",
|
||||
"ace-loader/index.js",
|
||||
"ace-loader/main.product.js",
|
||||
"ace-loader/npm-install.js",
|
||||
"ace-loader/package-lock.json",
|
||||
"ace-loader/package.json",
|
||||
"ace-loader/sample",
|
||||
"ace-loader/webpack.lite.config.js",
|
||||
"ace-loader/webpack.rich.config.js",
|
||||
]
|
||||
sources = ace_loader_sources
|
||||
outputs = [ target_out_dir + "/$target_name/{{source_file_part}}" ]
|
||||
module_source_dir = target_out_dir + "/$target_name/"
|
||||
module_install_name = ""
|
||||
@ -101,14 +114,29 @@ ohos_copy("ace_loader_library") {
|
||||
license_file = "//third_party/weex-loader/NOTICE"
|
||||
}
|
||||
|
||||
# copy previewer
|
||||
ohos_copy("previewer_copy") {
|
||||
if (host_os == "mac") {
|
||||
sources = [ "//prebuilts/previewer/darwin/previewer" ]
|
||||
} else {
|
||||
sources = [ "//prebuilts/previewer/windows/previewer" ]
|
||||
}
|
||||
outputs = [ target_out_dir + "/{{source_file_part}}" ]
|
||||
module_source_dir = target_out_dir + "/previewer/"
|
||||
module_install_name = ""
|
||||
ace_loader_dir =
|
||||
get_label_info(":ace_loader", "target_out_dir") + "/ace_loader_ark"
|
||||
|
||||
ohos_copy("ace_loader_ark") {
|
||||
sources = ace_loader_sources
|
||||
outputs = [ target_out_dir + "/$target_name/{{source_file_part}}" ]
|
||||
license_file = "//third_party/parse5/LICENSE"
|
||||
}
|
||||
|
||||
ohos_copy("ace_loader_ark_hap") {
|
||||
deps = [
|
||||
":ace_loader",
|
||||
":ace_loader_ark",
|
||||
":build_ace_loader_library",
|
||||
]
|
||||
sources = [ ace_loader_lib_dir ]
|
||||
outputs = [ ace_loader_dir + "/lib" ]
|
||||
license_file = "//third_party/parse5/LICENSE"
|
||||
}
|
||||
|
||||
ohos_copy("ace_loader_node_modules") {
|
||||
deps = [ ":ace_loader_ark_hap" ]
|
||||
sources = [ "//developtools/ace-js2bundle/ace-loader/node_modules" ]
|
||||
outputs = [ ace_loader_dir + "/node_modules" ]
|
||||
license_file = "//third_party/parse5/LICENSE"
|
||||
}
|
||||
|
1
LICENSE
1
LICENSE
@ -175,4 +175,3 @@
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
|
32
OAT.xml
Normal file
32
OAT.xml
Normal file
@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
This is the configuration file template for OpenHarmony OSS Audit Tool, please copy it to your project root dir and modify it refer to OpenHarmony/tools_oat/README.
|
||||
|
||||
-->
|
||||
|
||||
<configuration>
|
||||
<oatconfig>
|
||||
<licensefile></licensefile>
|
||||
<filefilterlist>
|
||||
<filefilter name="defaultFilter" desc="Files not to check">
|
||||
<filteritem type="filepath" name="ace-loader/node_modules/.*" desc="dependencies of ace-loader"/>
|
||||
<filteritem type="filepath" name="ace-loader/third_party/.*" desc="third party software"/>
|
||||
<filteritem type="filepath" name="ace-loader/lib/.*" desc="files generated by ace-loader"/>
|
||||
<filteritem type="filepath" name="ace-loader/plugin/codegen/index.js" desc="files generated by another department"/>
|
||||
</filefilter>
|
||||
</filefilterlist>
|
||||
</oatconfig>
|
||||
</configuration>
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@ -12,7 +12,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
node_modules
|
||||
src
|
||||
test
|
||||
|
@ -38,16 +38,71 @@ function deleteFolderRecursive(url) {
|
||||
function readManifest(manifestFilePath) {
|
||||
let manifest = {};
|
||||
try {
|
||||
const jsonString = fs.readFileSync(manifestFilePath).toString()
|
||||
manifest = JSON.parse(jsonString)
|
||||
if (fs.existsSync(manifestFilePath)) {
|
||||
const jsonString = fs.readFileSync(manifestFilePath).toString();
|
||||
manifest = JSON.parse(jsonString);
|
||||
} else if (process.env.aceConfigPath && fs.existsSync(process.env.aceConfigPath)) {
|
||||
buildManifest(manifest, process.env.aceConfigPath);
|
||||
} else {
|
||||
throw Error('\u001b[31m' + 'ERROR: the manifest.json or config.json is lost.' + '\u001b[39m')
|
||||
.message;
|
||||
}
|
||||
} catch (e) {
|
||||
throw Error('\u001b[31m' + 'ERROR: the manifest file is lost or format is invalid.' + '\u001b[39m').message
|
||||
throw Error('\u001b[31m' + 'ERROR: the manifest.json or config.json file format is invalid.' +
|
||||
'\u001b[39m').message;
|
||||
}
|
||||
return manifest;
|
||||
}
|
||||
|
||||
|
||||
function buildManifest(manifest, aceConfigPath) {
|
||||
try {
|
||||
const configJson = JSON.parse(fs.readFileSync(aceConfigPath).toString());
|
||||
const srcPath = process.env.srcPath;
|
||||
manifest.type = process.env.abilityType;
|
||||
manifest.pages = []
|
||||
if (manifest.type === 'form') {
|
||||
if (configJson.module && configJson.module.abilities) {
|
||||
manifest.pages = getForms(configJson, srcPath);
|
||||
} else {
|
||||
throw Error('\u001b[31m'+
|
||||
'EERROR: the config.json file miss keyword module || module[abilities].' +
|
||||
'\u001b[39m').message;
|
||||
}
|
||||
manifest.minPlatformVersion = configJson.app.apiVersion.compatible;
|
||||
}
|
||||
} catch (e) {
|
||||
throw Error('\u001b[31m' + 'ERROR: the config.json file is lost or format is invalid.' +
|
||||
'\u001b[39m').message;
|
||||
}
|
||||
}
|
||||
|
||||
function getForms(configJson, srcPath) {
|
||||
const pages = [];
|
||||
for (const ability of configJson.module.abilities){
|
||||
if (ability.srcPath === srcPath) {
|
||||
readForms(ability, pages);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return pages;
|
||||
}
|
||||
|
||||
function readForms(ability, pages) {
|
||||
if (ability.forms) {
|
||||
for (const form of ability.forms){
|
||||
if (form.src) {
|
||||
pages.push(form.src);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw Error('\u001b[31m' +`ERROR: the ${ability} in config.json file miss forms.' +
|
||||
'\u001b[39m`).message;
|
||||
}
|
||||
}
|
||||
|
||||
function loadEntryObj(projectPath, device_level, abilityType, manifestFilePath) {
|
||||
let entryObj = {}
|
||||
let entryObj = {};
|
||||
switch (abilityType) {
|
||||
case 'page':
|
||||
const appJSPath = path.resolve(projectPath, 'app.js');
|
||||
@ -60,9 +115,13 @@ function loadEntryObj(projectPath, device_level, abilityType, manifestFilePath)
|
||||
entryObj['./app'] = path.resolve(projectPath, './app.js?entry');
|
||||
}
|
||||
break;
|
||||
case 'form':
|
||||
entryObj = addPageEntryObj(readManifest(manifestFilePath), projectPath);
|
||||
entryObj[`./${abilityType}`] = path.resolve(projectPath, `./${abilityType}.js?entry`);
|
||||
break;
|
||||
default:
|
||||
entryObj[`./${abilityType}`] = path.resolve(projectPath + `./${abilityType}.js?entry`);
|
||||
break
|
||||
entryObj[`./${abilityType}`] = path.resolve(projectPath, `./${abilityType}.js?entry`);
|
||||
break;
|
||||
}
|
||||
return entryObj;
|
||||
}
|
||||
@ -85,7 +144,8 @@ function addPageEntryObj(manifest, projectPath) {
|
||||
} else if (isHml) {
|
||||
entryObj['./' + element] = path.resolve(projectPath, './' + sourcePath + '.hml?entry');
|
||||
} else if (isVisual) {
|
||||
entryObj['./' + element] = path.resolve(aceSuperVisualPath, './' + sourcePath + '.visual?entry');
|
||||
entryObj['./' + element] = path.resolve(aceSuperVisualPath, './' + sourcePath +
|
||||
'.visual?entry');
|
||||
}
|
||||
})
|
||||
return entryObj;
|
||||
|
6
ace-loader/package-lock.json
generated
6
ace-loader/package-lock.json
generated
@ -2563,9 +2563,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"deccjsunit": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.nlark.com/deccjsunit/download/deccjsunit-1.0.3.tgz",
|
||||
"integrity": "sha1-AcMxIKje4SsaoQiZGE14pszfiKI="
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.nlark.com/deccjsunit/download/deccjsunit-1.0.4.tgz",
|
||||
"integrity": "sha512-fkOzBz9uNKElrm6VGrisXLbAmLshcqBoqYAyo2+v9uceAkv75xh9dWAUmnZoWE/v4ujqYHylaudON1nj+LPuPA=="
|
||||
},
|
||||
"decode-uri-component": {
|
||||
"version": "0.2.0",
|
||||
|
@ -38,7 +38,7 @@
|
||||
"copy-webpack-plugin": "^8.1.0",
|
||||
"css": "^3.0.0",
|
||||
"css-loader": "^3.4.2",
|
||||
"deccjsunit": "1.0.3",
|
||||
"deccjsunit": "1.0.4",
|
||||
"escodegen": "^2.0.0",
|
||||
"esprima": "^4.0.1",
|
||||
"hash-sum": "^1.0.2",
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -324,6 +324,8 @@ var cardCommonTag = {
|
||||
accessibilityimportance: {
|
||||
enum: ['auto', 'yes', 'no', 'no-hide-descendants'],
|
||||
},
|
||||
for: {},
|
||||
tid: {}
|
||||
},
|
||||
'children': ['block', 'slot'],
|
||||
'parents': ['block']
|
||||
|
@ -177,7 +177,7 @@ function validateTagName(domNode, out, relativePath) {
|
||||
const depends = out.deps
|
||||
const jsonTemplate = out.jsonTemplate
|
||||
const log = out.log
|
||||
const oneChildNode = ['dialog', 'popup', 'badge']
|
||||
const oneChildNode = ['dialog', 'popup', 'badge', 'list-item']
|
||||
const logType = process.env.DEVICE_LEVEL === DEVICE_LEVEL.LITE ? 'ERROR' : 'WARNING'
|
||||
let pos = domNode.__location || {}
|
||||
const elementNamesInFile = elementNames[relativePath] || []
|
||||
@ -765,6 +765,14 @@ function validateStyle(css, out, nodeLoc, relativePath) {
|
||||
if (styleContent.length === 2) {
|
||||
const key = styleContent[0].trim().replace(/-([a-z])/g, function(s, m) { return m.toUpperCase() })
|
||||
let value = bind(styleContent[1].trim(), undefined, true, out, nodeLoc)
|
||||
const contentValue = styleContent[1].trim().toString();
|
||||
if (contentValue.match(/^linear-gradient/) && contentValue.match(/\(.*\{\{.*\}\}.*\)/)) {
|
||||
log.push({
|
||||
line: nodeLoc.line || 1,
|
||||
column: nodeLoc.col || 1,
|
||||
reason: `ERROR: can not bind data for linear-gradient in inline style at ${css}`
|
||||
})
|
||||
}
|
||||
if (key === 'flex' && typeof value === 'string') {
|
||||
expandFlex(key, value, cssStyle, nodeLoc, log)
|
||||
} else {
|
||||
@ -1074,7 +1082,7 @@ function validateEvent(eventName, val, out, pos, relativePath) {
|
||||
if (paramList) {
|
||||
paramList = transContent.parseExpression(paramList, true)
|
||||
val = eval('(function (evt) {' + bind('{{' + functionName + '(' + paramList + ',evt)}}',
|
||||
false, true, out, pos) + '})')
|
||||
false, true, out, pos) + '})')
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1102,17 +1110,17 @@ function distributeEvent(out, eventName, name, val) {
|
||||
out.jsonTemplate.onBubbleEvents[name] = val
|
||||
}
|
||||
} else if (process.env.DEVICE_LEVEL === DEVICE_LEVEL.RICH && CLICK_EVENT_REGEXP.test(name) &&
|
||||
!eventName.match(END_CAPTURE_REGEXP) && process.env.PLATFORM_VERSION === PLATFORM.VERSION6) {
|
||||
if (eventName.match(START_CATCH_REGEXP)) {
|
||||
out.jsonTemplate.catchBubbleEvents = out.jsonTemplate.catchBubbleEvents || {}
|
||||
out.jsonTemplate.catchBubbleEvents[name] = val
|
||||
} else {
|
||||
out.jsonTemplate.onBubbleEvents = out.jsonTemplate.onBubbleEvents || {}
|
||||
out.jsonTemplate.onBubbleEvents[name] = val
|
||||
}
|
||||
!eventName.match(END_CAPTURE_REGEXP) && process.env.PLATFORM_VERSION === PLATFORM.VERSION6) {
|
||||
if (eventName.match(START_CATCH_REGEXP)) {
|
||||
out.jsonTemplate.catchBubbleEvents = out.jsonTemplate.catchBubbleEvents || {}
|
||||
out.jsonTemplate.catchBubbleEvents[name] = val
|
||||
} else {
|
||||
out.jsonTemplate.events = out.jsonTemplate.events || {}
|
||||
out.jsonTemplate.events[name] = val
|
||||
out.jsonTemplate.onBubbleEvents = out.jsonTemplate.onBubbleEvents || {}
|
||||
out.jsonTemplate.onBubbleEvents[name] = val
|
||||
}
|
||||
} else {
|
||||
out.jsonTemplate.events = out.jsonTemplate.events || {}
|
||||
out.jsonTemplate.events[name] = val
|
||||
}
|
||||
}
|
||||
|
||||
@ -1244,8 +1252,8 @@ function validateAttrElse(preNode, out, nodeLoc, relativePath) {
|
||||
function parseDataAttr(name, value, out) {
|
||||
const childName = name.replace('data-', '')
|
||||
out.jsonTemplate.attr = out.jsonTemplate.attr || {}
|
||||
out.jsonTemplate.attr.data = out.jsonTemplate.attr.data || {}
|
||||
out.jsonTemplate.attr.data[childName] = bind(value, undefined, true, out)
|
||||
out.jsonTemplate.attr.$data = out.jsonTemplate.attr.$data || {}
|
||||
out.jsonTemplate.attr.$data[childName] = bind(value, undefined, true, out)
|
||||
}
|
||||
|
||||
function isSupportedSelfClosing(tagName) {
|
||||
|
@ -30,7 +30,9 @@ class AfterEmitPlugin {
|
||||
(assets, back) => {
|
||||
const keys = Object.keys(assets)
|
||||
keys.forEach(key => {
|
||||
sourceChange(key, assets, compilation);
|
||||
if ('./' + process.env.abilityType + '.js' !== key) {
|
||||
sourceChange(key, assets, compilation);
|
||||
}
|
||||
});
|
||||
back && back();
|
||||
}
|
||||
|
@ -13,12 +13,15 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const Stats = require('webpack/lib/Stats');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { DEVICE_LEVEL } = require('./lite/lite-enum');
|
||||
import Compilation from 'webpack/lib/Compilation';
|
||||
import JavascriptModulesPlugin from 'webpack/lib/javascript/JavascriptModulesPlugin';
|
||||
import CachedSource from 'webpack-sources/lib/CachedSource';
|
||||
import ConcatSource from 'webpack-sources/lib/ConcatSource';
|
||||
|
||||
import { circularFile } from './util';
|
||||
|
||||
const REG = /\([^\)]+\)/;
|
||||
let mStats;
|
||||
let mErrorCount = 0;
|
||||
let mWarningCount = 0;
|
||||
@ -29,6 +32,14 @@ let warningCount = 0;
|
||||
let noteCount = 0;
|
||||
let errorCount = 0;
|
||||
|
||||
const GLOBAL_COMMON_MODULE_CACHE = `
|
||||
globalThis["__common_module_cache__"] = globalThis["__common_module_cache__"] || {};
|
||||
globalThis["webpackChunkace_loader"].forEach((item)=> {
|
||||
Object.keys(item[1]).forEach((element) => {
|
||||
globalThis["__common_module_cache__"][element] = null;
|
||||
})
|
||||
});`;
|
||||
|
||||
class ResultStates {
|
||||
constructor(options) {
|
||||
this.options = options;
|
||||
@ -36,6 +47,30 @@ class ResultStates {
|
||||
|
||||
apply(compiler) {
|
||||
const buildPath = this.options.build;
|
||||
const modulePaths = new Set();
|
||||
|
||||
compiler.hooks.compilation.tap('toFindModule', (compilation) => {
|
||||
compilation.hooks.buildModule.tap("findModule", (module) => {
|
||||
if (/node_modules/.test(module.context)) {
|
||||
const beforNodeModules = module.context.substr(0, module.context.indexOf('node_modules'));
|
||||
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)
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
compiler.hooks.afterCompile.tap('copyFindModule', () => {
|
||||
for (let modulePath of modulePaths) {
|
||||
circularFile(modulePath, path.resolve(buildPath, '../share'));
|
||||
}
|
||||
});
|
||||
|
||||
compiler.hooks.done.tap('Result States', (stats) => {
|
||||
mStats = stats;
|
||||
warningCount = 0;
|
||||
@ -58,6 +93,38 @@ class ResultStates {
|
||||
}
|
||||
printResult(buildPath);
|
||||
});
|
||||
|
||||
compiler.hooks.compilation.tap('CommonAsset', compilation => {
|
||||
compilation.hooks.processAssets.tap(
|
||||
{
|
||||
name: 'GLOBAL_COMMON_MODULE_CACHE',
|
||||
stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,
|
||||
},
|
||||
(assets) => {
|
||||
if (assets['commons.js']) {
|
||||
assets['commons.js'] = new CachedSource(
|
||||
new ConcatSource(assets['commons.js'], GLOBAL_COMMON_MODULE_CACHE));
|
||||
} else if (assets['vendors.js']) {
|
||||
assets['vendors.js'] = new CachedSource(
|
||||
new ConcatSource(assets['vendors.js'], GLOBAL_COMMON_MODULE_CACHE));
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
compiler.hooks.compilation.tap('Require', compilation => {
|
||||
JavascriptModulesPlugin.getCompilationHooks(compilation).renderRequire.tap('renderRequire',
|
||||
(source) => {
|
||||
return `var commonCachedModule = globalThis["__common_module_cache__"] ? ` +
|
||||
`globalThis["__common_module_cache__"][moduleId]: null;\n` +
|
||||
`if (commonCachedModule) { return commonCachedModule.exports; }\n` +
|
||||
source.replace('// Execute the module function',
|
||||
`if (globalThis["__common_module_cache__"] && moduleId.indexOf("?name=") < 0 && ` +
|
||||
`Object.keys(globalThis["__common_module_cache__"]).indexOf(moduleId) >= 0) {\n` +
|
||||
` globalThis["__common_module_cache__"][moduleId] = module;\n}`);
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,20 +1,16 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import loaderUtils from 'loader-utils';
|
||||
|
@ -17,7 +17,6 @@ const fs = require('fs')
|
||||
const path = require('path')
|
||||
const process = require('child_process')
|
||||
|
||||
const arkDir = path.join(__dirname, '..', 'bin', 'ark');
|
||||
const forward = '(global.___mainEntry___ = function (globalObjects) {' + '\n' +
|
||||
' var define = globalObjects.define;' + '\n' +
|
||||
' var require = globalObjects.require;' + '\n' +
|
||||
@ -35,25 +34,25 @@ const forward = '(global.___mainEntry___ = function (globalObjects) {' + '\n' +
|
||||
const last = '\n' + '})(this.__appProto__);' + '\n' + '})'
|
||||
const firstFileEXT = '_.js'
|
||||
let output
|
||||
let webpackPath
|
||||
let isWin = false
|
||||
let isMac = false
|
||||
let isDebug = false
|
||||
let arkDir
|
||||
|
||||
class GenAbcPlugin {
|
||||
constructor(output_, webpackPath_, isDebug_) {
|
||||
constructor(output_, arkDir_, isDebug_) {
|
||||
output = output_
|
||||
webpackPath = webpackPath_
|
||||
arkDir = arkDir_
|
||||
isDebug = isDebug_
|
||||
}
|
||||
apply(compiler) {
|
||||
if (fs.existsSync(path.resolve(webpackPath, 'ark/build-win'))) {
|
||||
if (fs.existsSync(path.resolve(arkDir, 'build-win'))) {
|
||||
isWin = true
|
||||
} else {
|
||||
if (fs.existsSync(path.resolve(webpackPath, 'ark/build-mac'))) {
|
||||
if (fs.existsSync(path.resolve(arkDir, 'build-mac'))) {
|
||||
isMac = true
|
||||
} else {
|
||||
if (!fs.existsSync(path.resolve(webpackPath, 'ark/build'))) {
|
||||
if (!fs.existsSync(path.resolve(arkDir, 'build'))) {
|
||||
console.error('\u001b[31m', `find build fail`, '\u001b[39m')
|
||||
return
|
||||
}
|
||||
@ -65,11 +64,14 @@ class GenAbcPlugin {
|
||||
const keys = Object.keys(assets)
|
||||
keys.forEach(key => {
|
||||
// choice *.js
|
||||
if (output && webpackPath && path.extname(key) === '.js') {
|
||||
if (output && path.extname(key) === '.js') {
|
||||
let newContent = assets[key].source()
|
||||
if (key.search('./workers/') !== 0) {
|
||||
if (key.search('./workers/') !== 0 && key !== 'commons.js' && key !== 'vendors.js') {
|
||||
newContent = forward + newContent + last
|
||||
}
|
||||
if (key === 'commons.js' || key === 'vendors.js') {
|
||||
newContent = `\n\n\n\n\n\n\n\n\n\n\n\n\n\n` + newContent
|
||||
}
|
||||
const keyPath = key.replace(/\.js$/, firstFileEXT)
|
||||
writeFileSync(newContent, path.resolve(output, keyPath), key)
|
||||
}
|
||||
|
@ -240,8 +240,8 @@ function codegenHmlAndCss() {
|
||||
})
|
||||
`
|
||||
if (isEntry) {
|
||||
output += `$app_bootstrap$('@app-component/
|
||||
${getNameByPath(this.resourcePath)}'` + ',undefined' + ',undefined' + `)`
|
||||
output += `$app_bootstrap$('@app-component/${getNameByPath(this.resourcePath)}'`
|
||||
+ ',undefined' + ',undefined' + `)`
|
||||
}
|
||||
}
|
||||
return output
|
||||
|
@ -19,6 +19,7 @@ const SingleEntryPlugin = require('webpack/lib/SingleEntryPlugin');
|
||||
|
||||
const CUSTOM_THEME_PROP_GROUPS = require('./theme/customThemeStyles');
|
||||
const OHOS_THEME_PROP_GROUPS = require('./theme/ohosStyles');
|
||||
import { mkDir } from './util';
|
||||
|
||||
const FILE_EXT_NAME = ['.js', '.css', '.jsx', '.less', '.sass', '.scss', '.md', '.DS_Store', '.hml'];
|
||||
const red = '\u001b[31m';
|
||||
@ -63,14 +64,6 @@ function copyFile(input, output) {
|
||||
}
|
||||
}
|
||||
|
||||
function mkDir(path_) {
|
||||
const parent = path.join(path_, '..');
|
||||
if (!(fs.existsSync(parent) && !fs.statSync(parent).isFile())) {
|
||||
mkDir(parent);
|
||||
}
|
||||
fs.mkdirSync(path_);
|
||||
}
|
||||
|
||||
function circularFile(inputPath, outputPath, ext) {
|
||||
const realPath = path.join(inputPath, ext);
|
||||
const localI18n = path.join(input, 'i18n');
|
||||
@ -146,12 +139,8 @@ let entryObj = {};
|
||||
function addPageEntryObj() {
|
||||
entryObj = {};
|
||||
if (process.env.abilityType === 'page') {
|
||||
if (!fs.existsSync(manifestFilePath)) {
|
||||
throw Error('ERROR: missing manifest').message;
|
||||
}
|
||||
const jsonString = fs.readFileSync(manifestFilePath).toString();
|
||||
const obj = JSON.parse(jsonString);
|
||||
const pages = obj.pages;
|
||||
const jsonString = readManifest(manifestFilePath);
|
||||
const pages = jsonString.pages;
|
||||
if (pages === undefined) {
|
||||
throw Error('ERROR: missing pages').message;
|
||||
}
|
||||
@ -164,13 +153,12 @@ function addPageEntryObj() {
|
||||
const isVisual = fs.existsSync(visualPath);
|
||||
const projectPath = process.env.projectPath;
|
||||
if (isHml && isVisual) {
|
||||
logWarn(this, [{
|
||||
reason: 'ERROR: ' + sourcePath + ' cannot both have hml && visual',
|
||||
}]);
|
||||
console.error('ERROR: ' + sourcePath + ' cannot both have hml && visual');
|
||||
} else if (isHml) {
|
||||
entryObj['./' + element] = path.resolve(projectPath, './' + sourcePath + '.hml?entry');
|
||||
} else if (isVisual) {
|
||||
entryObj['./' + element] = path.resolve(aceSuperVisualPath, './' + sourcePath + '.visual?entry');
|
||||
entryObj['./' + element] = path.resolve(aceSuperVisualPath, './' + sourcePath +
|
||||
'.visual?entry');
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -180,6 +168,66 @@ function addPageEntryObj() {
|
||||
return entryObj;
|
||||
}
|
||||
|
||||
function readManifest(manifestFilePath) {
|
||||
let manifest = {};
|
||||
try {
|
||||
if (fs.existsSync(manifestFilePath)) {
|
||||
const jsonString = fs.readFileSync(manifestFilePath).toString();
|
||||
manifest = JSON.parse(jsonString);
|
||||
} else if (process.env.aceConfigPath && fs.existsSync(process.env.aceConfigPath)) {
|
||||
buildManifest(manifest, process.env.aceConfigPath);
|
||||
} else {
|
||||
throw Error('\u001b[31m' + 'ERROR: the manifest.json or config.json is lost.' +
|
||||
'\u001b[39m').message;
|
||||
}
|
||||
} catch (e) {
|
||||
throw Error('\u001b[31m' + 'ERROR: the manifest.json or config.json file format is invalid.' +
|
||||
'\u001b[39m').message;
|
||||
}
|
||||
return manifest;
|
||||
}
|
||||
|
||||
function buildManifest(manifest, aceConfigPath) {
|
||||
try {
|
||||
const configJson = JSON.parse(fs.readFileSync(aceConfigPath).toString());
|
||||
const srcPath = process.env.srcPath;
|
||||
manifest.type = process.env.abilityType;
|
||||
if (configJson.module && configJson.module.abilities) {
|
||||
manifest.pages = getPages(configJson, srcPath);
|
||||
} else {
|
||||
throw Error('\u001b[31m'+
|
||||
'EERROR: the config.json file miss keyword module || module[abilities].' +
|
||||
'\u001b[39m').message;
|
||||
}
|
||||
manifest.minPlatformVersion = configJson.app.apiVersion.compatible;
|
||||
} catch (e) {
|
||||
throw Error("\x1B[31m" + 'ERROR: the config.json file is lost or format is invalid.' +
|
||||
"\x1B[39m").message;
|
||||
}
|
||||
}
|
||||
|
||||
function getPages(configJson, srcPath) {
|
||||
let pages = []
|
||||
for (const ability of configJson.module.abilities){
|
||||
if (ability.srcPath === srcPath) {
|
||||
readPages(ability, pages, configJson)
|
||||
break;
|
||||
}
|
||||
}
|
||||
return pages;
|
||||
}
|
||||
|
||||
function readPages(ability, pages, configJson) {
|
||||
for (const js of configJson.module.js){
|
||||
if (ability.name === js.name) {
|
||||
js.pages.forEach(page => {
|
||||
pages.push(page)
|
||||
})
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function loadWorker(entryObj) {
|
||||
const workerPath = path.resolve(input, 'workers');
|
||||
if (fs.existsSync(workerPath)) {
|
||||
|
@ -1,20 +1,16 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const OHOS_THEME_PROP_GROUPS = require('./theme/ohosStyles')
|
||||
|
@ -1,20 +1,16 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
@ -13,6 +13,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
@colorBackground: #000000;
|
||||
.container {
|
||||
background-color: @colorBackground;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
|
@ -1,20 +1,16 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
@ -12,3 +12,4 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
@ -0,0 +1,15 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
@ -40,7 +40,7 @@ const richModule = {
|
||||
}]
|
||||
},
|
||||
{
|
||||
test: /(\.hml|app\.js|data\.js|service\.js)(\?[^?]+)?$/,
|
||||
test: /(\.hml)(\?[^?]+)?$/,
|
||||
use: [{
|
||||
loader: path.resolve(__dirname, './index.js')
|
||||
}]
|
||||
@ -137,9 +137,32 @@ let config = {
|
||||
poll: false,
|
||||
ignored: /node_modules/
|
||||
},
|
||||
optimization: {
|
||||
splitChunks: {
|
||||
chunks: "all",
|
||||
minSize: 0,
|
||||
cacheGroups: {
|
||||
vendors: {
|
||||
test: /[\\/]node_modules[\\/]/,
|
||||
priority: -10,
|
||||
name: "vendors",
|
||||
chunks: 'initial'
|
||||
},
|
||||
commons: {
|
||||
test: /\.js|css|hml$/,
|
||||
name: 'commons',
|
||||
priority: -20,
|
||||
minChunks: 2,
|
||||
chunks: 'initial',
|
||||
reuseExistingChunk: true
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
output: {
|
||||
filename: '[name].js',
|
||||
devtoolModuleFilenameTemplate: 'webpack:///[absolute-resource-path]'
|
||||
devtoolModuleFilenameTemplate: 'webpack:///[absolute-resource-path]',
|
||||
globalObject: 'globalThis'
|
||||
},
|
||||
devtool: 'nosources-source-map',
|
||||
mode: 'development',
|
||||
@ -164,7 +187,7 @@ function setConfigs(env) {
|
||||
process.env.aceManifestPath = process.env.aceManifestPath || path.resolve(process.env.projectPath, 'manifest.json');
|
||||
process.env.abilityType = process.env.abilityType || 'page'
|
||||
process.env.DEVICE_LEVEL = process.env.DEVICE_LEVEL || 'rich'
|
||||
if (process.env.abilityType === 'page') {
|
||||
if (process.env.abilityType === 'page' || process.env.abilityType === 'form') {
|
||||
const manifest = readManifest(process.env.aceManifestPath)
|
||||
process.env.DEVICE_LEVEL = manifest.type === 'form' ? 'card' : 'rich'
|
||||
process.env.PLATFORM_VERSION = PLATFORM.VERSION6;
|
||||
@ -183,13 +206,6 @@ module.exports = (env) => {
|
||||
setConfigs(env)
|
||||
deleteFolderRecursive(process.env.buildPath);
|
||||
config.cache.cacheDirectory = path.resolve(process.env.cachePath, '.rich_cache');
|
||||
config.module.rules.push({
|
||||
test: new RegExp("(" + (process.env.abilityType === 'page' ?
|
||||
'app' : process.env.abilityType) + "\.js)(\\?[^?]+)?$"),
|
||||
use: [{
|
||||
loader: path.resolve(__dirname, './index.js')
|
||||
}]
|
||||
})
|
||||
config.entry = loadEntryObj(process.env.projectPath, process.env.DEVICE_LEVEL,
|
||||
process.env.abilityType, process.env.aceManifestPath)
|
||||
config.output.path = path.resolve(__dirname, process.env.buildPath)
|
||||
@ -218,6 +234,17 @@ module.exports = (env) => {
|
||||
]
|
||||
}))
|
||||
}
|
||||
if (process.env.aceConfigPath && fs.existsSync(process.env.aceConfigPath)) {
|
||||
config.plugins.push(new CopyPlugin({
|
||||
patterns: [
|
||||
{
|
||||
from: path.resolve(process.env.aceConfigPath),
|
||||
to: path.resolve(process.env.buildPath, 'config.json'),
|
||||
noErrorOnMissing: true
|
||||
}
|
||||
]
|
||||
}))
|
||||
}
|
||||
if (process.env.DEVICE_LEVEL === 'card') {
|
||||
config.module = cardModule
|
||||
config.plugins.push(new AfterEmitPlugin())
|
||||
@ -225,7 +252,11 @@ module.exports = (env) => {
|
||||
if (env.isPreview !== "true") {
|
||||
config.plugins.push(new ModuleCollectionPlugin())
|
||||
if (env.compilerType && env.compilerType === 'ark') {
|
||||
config.plugins.push(new GenAbcPlugin(process.env.buildPath, path.join(__dirname, 'bin'),
|
||||
let arkDir = path.join(__dirname, 'bin', 'ark');
|
||||
if (env.arkFrontendDir) {
|
||||
arkDir = env.arkFrontendDir;
|
||||
}
|
||||
config.plugins.push(new GenAbcPlugin(process.env.buildPath, arkDir,
|
||||
env.buildMode === 'debug'))
|
||||
} else {
|
||||
if (env.deviceType) {
|
||||
@ -267,5 +298,12 @@ module.exports = (env) => {
|
||||
config.output.sourceMapFilename = '_releaseMap/[name].js.map'
|
||||
}
|
||||
}
|
||||
config.module.rules.push({
|
||||
test: new RegExp("(" + (process.env.abilityType === 'page' ?
|
||||
'app' : process.env.abilityType) + "\.js)(\\?[^?]+)?$"),
|
||||
use: [{
|
||||
loader: path.resolve(__dirname, './index.js')
|
||||
}]
|
||||
})
|
||||
return config
|
||||
}
|
Loading…
Reference in New Issue
Block a user