From fdc652c4b8432d6f3f429863016fc4379f18ac8f Mon Sep 17 00:00:00 2001 From: lixinnan Date: Wed, 10 Apr 2024 20:53:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=A7=E8=A1=8Cnpm=20run=20test=E6=8A=A5?= =?UTF-8?q?=E9=94=99=EF=BC=8Clib=E6=96=87=E4=BB=B6=E9=87=8C=E7=BC=BA?= =?UTF-8?q?=E5=B0=91style=E3=80=81scripter=E3=80=81parse?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lixinnan Change-Id: I2f8514eb10af97803a0f8c92b9ea7c6e64232f29 --- ace-loader/copy_deps_source.js | 66 ++++++++++++++++++++++++++++++++++ ace-loader/module-source.js | 4 +++ ace-loader/package.json | 2 +- ace-loader/test/rich/test.js | 3 -- 4 files changed, 71 insertions(+), 4 deletions(-) create mode 100644 ace-loader/copy_deps_source.js diff --git a/ace-loader/copy_deps_source.js b/ace-loader/copy_deps_source.js new file mode 100644 index 0000000..4b8d830 --- /dev/null +++ b/ace-loader/copy_deps_source.js @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2024 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. + */ +const fs = require('fs'); +const path = require('path'); +const moduleSource = require('./module-source'); + +const exists = function(src, dst, callback) { + if (src.match(/\/test$/)) { + return; + } + fs.exists(dst, function(exists) { + if(exists){ + callback(src, dst); + } else{ + fs.mkdir(dst, function() { + callback(src, dst); + }); + } + }); +} + +stat = fs.stat; +const copy = function(src, dst){ + fs.readdir(src, function(err, paths){ + if(err){ + throw err; + } + paths.forEach(function(_path){ + var _src = src + '/' + _path, + _dst = dst + '/' + _path, + readable, writable; + stat(_src, function(err, st){ + if(err){ + throw err; + } + if(st.isFile()){ + const pathInfo = path.parse(_src); + if (pathInfo.name === 'gulpfile' || pathInfo.ext !== '.js') { + return; + } + readable = fs.createReadStream(_src); + writable = fs.createWriteStream(_dst); + readable.pipe(writable); + } else if(st.isDirectory()){ + exists(_src, _dst, copy); + } + }); + }); + }); +}; + +moduleSource.copyResource(path.resolve(__dirname, './third_party/weex-loader/deps/weex-scripter'), process.argv[2] + '/scripter'); +moduleSource.copyResource(path.resolve(__dirname, './third_party/weex-loader/deps/weex-styler'), process.argv[2] + '/styler'); +moduleSource.copyResource(path.resolve(__dirname, './third_party/parse5/packages/parse5/dist/cjs'), process.argv[2] + '/parse'); diff --git a/ace-loader/module-source.js b/ace-loader/module-source.js index e6d6dbe..e1701e7 100644 --- a/ace-loader/module-source.js +++ b/ace-loader/module-source.js @@ -68,3 +68,7 @@ function copyResource(src, dist) { copyResource(path.resolve(__dirname, './plugin/templater'), process.argv[2] + '/templater'); copyResource(path.resolve(__dirname, './plugin/theme'), process.argv[2] + '/theme'); copyResource(path.resolve(__dirname, './plugin/codegen'), process.argv[2] + '/codegen'); + +module.exports = { + copyResource +} diff --git a/ace-loader/package.json b/ace-loader/package.json index 0de5779..1d4feed 100644 --- a/ace-loader/package.json +++ b/ace-loader/package.json @@ -13,7 +13,7 @@ ], "scripts": { "buildparse5": "cd ./third_party/parse5/packages/parse5 && ./node_modules/typescript/bin/tsc --module CommonJS --target ES6 --outDir dist/cjs && cd ../../../../", - "build": "./node_modules/.bin/babel ./third_party/weex-loader/src ./src --out-dir lib && npm run buildparse5 && node ./module-source.js ./lib && node ./uglify-source.js ./lib", + "build": "./node_modules/.bin/babel ./third_party/weex-loader/src ./src --out-dir lib && npm run buildparse5 && node ./module-source.js ./lib && node ./uglify-source.js ./lib && node ./copy_deps_source.js ./lib", "rich": "cd sample/rich && webpack --config ../../webpack.rich.config.js", "lite": "cd sample/lite && webpack --config ../../webpack.lite.config.js", "card": "cd sample/card && webpack --config ../../webpack.rich.config.js", diff --git a/ace-loader/test/rich/test.js b/ace-loader/test/rich/test.js index 22712be..87d0109 100644 --- a/ace-loader/test/rich/test.js +++ b/ace-loader/test/rich/test.js @@ -108,9 +108,6 @@ describe('build', () => { it('ifDirective', () => { expectActual('ifDirective'); }); - it('importJS', () => { - expectActual('importJS'); - }); it('inlineStyle', () => { expectActual('inlineStyle'); });