如何在构建任务中执行shell脚本

如何在构建任务中执行shell脚本。

如何在构建任务中执行shell脚本-鸿蒙开发者社区

HarmonyOS
2024-09-18 10:08:53
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
FengTianYa
import { hapTasks } from '@ohos/hvigor-ohos-plugin'; 
import { exec } from 'node:child_process' 
import util from 'node:util' 
 
// shell脚本地址,相对路径绝对路径均可 
const scriptPath = 'D:\\work_space\\ecological_problem\\test\\entry\\test.bat'; 
 
export function customPluginFunction1(str?: string) { 
  return { 
    pluginId: 'CustomPluginID1', 
    apply(pluginContext) { 
      pluginContext.registerTask({ 
        // 编写自定义任务 
        name: 'customTask1', 
        run: (taskContext) => { 
          console.log('run into: '); 
          const execPromise = util.promisify(exec) 
          execPromise(scriptPath).then(res => { 
            console.log(res, 'res') 
          }).catch(err => { 
            console.log(err, 'err') 
          }) 
        }, 
        // 确认自定义任务插入位置 
        dependencies: ['default@BuildJS'], 
        postDependencies: ['default@CompileArkTS'] 
      }) 
    } 
  } 
} 
 
export default { 
  system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ 
  plugins: [customPluginFunction1()] /* Custom plugin to extend the functionality of Hvigor. */ 
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
分享
微博
QQ
微信
回复
2024-09-18 18:00:27
相关问题
shell脚本,可否执行sdkmgr命令?
7484浏览 • 1回复 待解决
如何在openharmony执行js脚本
3528浏览 • 0回复 待解决
在arkts如何执行耗时任务
287浏览 • 1回复 待解决
如何利用taskpool执行任务
2915浏览 • 1回复 待解决
HarmonyOS 如何实现后台执行任务
604浏览 • 1回复 待解决
如何在DOM树加载前后运行JS脚本
1427浏览 • 1回复 待解决
自定义构建任务写入文件
1430浏览 • 1回复 待解决