中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
如何在构建任务中执行shell脚本。
微信扫码分享
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. */ }