繁体   English   中英

通过Shell脚本运行Gatsby Build

[英]Running Gatsby Build via a shell script

因此,在某些情况下,我使用gatsby创建了一个站点,该站点从Wordpress的API中提取数据。 我发现将帖子添加到我的functions.ph p文件中后,可以触发wordpress中的一个钩子触发。

add_action( 'save_post', 'fireFunctionOnSave' );
  function fireFunctionOnSave($post_id)
{
  if(wp_is_post_revision( $post_id) || wp_is_post_autosave( $post_id )) 
{
  return;
}
$old_path = getcwd();
chdir('/Applications/MAMP/htdocs/elliot-wp-gatsby/wp- 
content/themes/twentyseventeen/');
$output = shell_exec('./build.sh');
chdir($old_path);

$myfile = fopen("/Applications/MAMP/htdocs/elliot-wp-gatsby/wp- 
content/themes/twentyseventeen/output.txt", "w") or die("Unable to open 
file!");
fwrite($myfile, $output);
fclose($myfile);
}

到目前为止,它可以打开并运行我的shell脚本,但实际上不会运行gatsby来构建任何人有任何想法吗? 这是我的shell脚本。

#!/bin/bash
cd /Users/elliotm/Dev-local/Projects/gatsby-wp
npm run build
echo "site built/deployed"

谢谢

我不确定shell_exec是否适用于bash脚本和更改目录。 请尝试: exec('cd /Users/elliotm/Dev-local/Projects/gatsby-wp && npm run build')

&&将强制执行程序仅在第一部分成功的情况下执行第二部分。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM