提交 a0e55c8a 编写于 作者: B buzhifeng

mock napi index 文件导入重名适配

Signed-off-by: Nbuzhifeng <buzhifeng2@huawei.com>
上级 943efce6
const fs = require('fs'); const fs = require('fs');
const { spawn } = require('child_process'); const { spawnSync } = require('child_process');
const path = require('path'); const path = require('path');
const os = require('os'); const os = require('os');
function compileMock() { function compileMock() {
...@@ -11,37 +11,12 @@ function compileMock() { ...@@ -11,37 +11,12 @@ function compileMock() {
nodeDir = './node-v12.18.4-darwin-x64/bin/node'; nodeDir = './node-v12.18.4-darwin-x64/bin/node';
} }
const bat = spawn(`${path.join(__dirname, '..', nodeDir)} ${path.join(__dirname, '..','./node_modules/typescript/bin/tsc')} && const bat = spawnSync(`${path.join(__dirname, '..', nodeDir)} ${path.join(__dirname, '..','./node_modules/typescript/bin/tsc')} &&
${path.join(__dirname, '..', nodeDir)} ${path.join(__dirname, 'dist')}/main.js && ${path.join(__dirname, '..', nodeDir)} ${path.join(__dirname, 'dist')}/main.js &&
${path.join(__dirname, '..', nodeDir)} ${path.join(__dirname, '..', './node_modules/eslint/bin/eslint.js')} -c .eslintrc --fix ${mockJsPath}/**/*.js`, { ${path.join(__dirname, '..', nodeDir)} ${path.join(__dirname, '..', './node_modules/eslint/bin/eslint.js')} -c .eslintrc --fix ${mockJsPath}/**/*.js`, {
cwd: __dirname, cwd: __dirname,
shell: true shell: true
}); });
shellOutput(bat);
}
function shellOutput(bat) {
bat.stdout.on('data', (data) => {
const lines = `${data}`.split(/\r{0,1}\n/);
if (lines) {
lines.forEach(line => {
if (line.length > 0) {
console.log(line.toString());
}
});
}
});
bat.stderr.on('data', (data) => {
const lines = `${data}`.split(/\r{0,1}\n/);
if (lines) {
lines.forEach(line => {
if (line.length > 0) {
console.log(line.toString());
}
});
}
});
} }
compileMock(); compileMock();
...@@ -64,7 +64,7 @@ export function generateCommonMethodSignature(rootName: string, methodSignatureA ...@@ -64,7 +64,7 @@ export function generateCommonMethodSignature(rootName: string, methodSignatureA
isReturnPromise = true; isReturnPromise = true;
} }
}); });
if (isReturnPromise) { if (isReturnPromise && isCallBack) {
methodSignatureBody += `else { methodSignatureBody += `else {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
resolve('[PC Preview] unknow boolean'); resolve('[PC Preview] unknow boolean');
......
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
* limitations under the License. * limitations under the License.
*/ */
import { firstCharacterToUppercase } from "../common/commonUtils";
/** /**
* save all mock function * save all mock function
*/ */
...@@ -40,7 +42,12 @@ export function generateIndex(): string { ...@@ -40,7 +42,12 @@ export function generateIndex(): string {
let isHasSameValue = false; let isHasSameValue = false;
if (filterSet.has(value.mockFunctionName)) { if (filterSet.has(value.mockFunctionName)) {
isHasSameValue = true; isHasSameValue = true;
functionName = `_${value.mockFunctionName}`; const tmpArr = value.fileName.split('_');
let tmpName = tmpArr[0];
for (let i = 1; i < tmpArr.length; i++) {
tmpName += firstCharacterToUppercase(tmpArr[i]);
}
functionName = `${tmpName}`;
} }
filterSet.add(functionName); filterSet.add(functionName);
if (isHasSameValue) { if (isHasSameValue) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册