Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
nianba23 committed Sep 6, 2023
1 parent 725d004 commit 7d6b41c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
4 changes: 3 additions & 1 deletion packages/native-pack-tool/source/platforms/android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,15 @@ export class AndroidPackTool extends NativePackTool {
const originDir = process.cwd();
try {
process.chdir(projDir);
// TODO: cchelper 内还要添加 handleMessage 方法实例
// cchelper 需要先设置监听消息的方法,才能够在执行 runCmake 时传递消息
cchelper.handleMessage = this.handleMessage.bind(this);
await cchelper.runCmd(gradle, [buildMode], false, projDir);
} catch (e) {
throw e;
} finally {
// popd
process.chdir(originDir);
cchelper.handleMessage = null;
}


Expand Down
1 change: 1 addition & 0 deletions packages/native-pack-tool/source/platforms/windows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export class WindowsPackTool extends NativePackTool {
// toolHelper 需要先设置监听消息的方法,才能够在执行 runCmake 时传递消息
toolHelper.handleMessage = this.handleMessage.bind(this);
await toolHelper.runCmake(['--build', `"${cchelper.fixPath(nativePrjDir)}"`, '--config', this.params.debug ? 'Debug' : 'Release', '--', '-verbosity:quiet']);
toolHelper.handleMessage = null;
return true;
}

Expand Down
10 changes: 6 additions & 4 deletions packages/native-pack-tool/source/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ export const EXT_LIST = ['.js', '.ccc', '.ccd', '.jsg', '.jsc'];

export class cchelper {

static handleMessage: Function | null = null;

static replaceEnvVariables(str: string): string {
return str.replace(/\$\{([^}]*)\}/g, (_, n) => process.env[n] === undefined ? _ : process.env[n]!)
.replace(/(~)/g, (_, n) => process.env.HOME!);
}


static fixPath(p: string): string {
p = this.replaceEnvVariables(p);
if (os.platform() === 'win32') {
Expand Down Expand Up @@ -297,7 +298,6 @@ export class cchelper {
await fs.writeFile(filepath, newContent);
}


static exactValueFromFile(regexp: RegExp, filename: string, idx: number): string | undefined {
if (!(fs.existsSync(filename))) {
console.error(`file ${filename} not exist!`);
Expand Down Expand Up @@ -326,6 +326,8 @@ export class cchelper {
if (!slient) {
cp.stdout.on(`data`, (chunk) => {
console.log(`[runCmd ${cmd}] ${chunk}`);
// TODO: 此处是在 cchelper 里示例,需要自定义消息过滤
this.handleMessage && this.handleMessage(chunk);
});
cp.stderr.on(`data`, (chunk) => {
console.log(`[runCmd ${cmd} - error] ${chunk}`);
Expand Down Expand Up @@ -423,7 +425,7 @@ export class cchelper {
}

export const toolHelper = {
handleMessage(message: string) {},
handleMessage: null as ((msg: string) => void) | null,

getXcodeMajorVerion(): number {
try {
Expand Down Expand Up @@ -491,7 +493,7 @@ export const toolHelper = {
console.log(`[cmake] ${msg}`);
// TODO: 此处是在 toolHelper 里示例
// 自定义过滤日志信息, 但目前 cmake 并没有抛出什么信息
toolHelper.handleMessage(msg);
toolHelper.handleMessage && toolHelper.handleMessage(msg);
}
});
cp.stderr.on('data', (data: any) => {
Expand Down

0 comments on commit 7d6b41c

Please sign in to comment.