在Continuos Integration Meteor应用程序上运行Facebook Flow

时间:2016-04-07 23:46:45

标签: meteor continuous-integration sh flowtype

我有一个带有Circle CI的Meteor应用程序作为持续集成服务。

Facebook Flow使用以下.flowconfig在本地运行:

[ignore]
.*/node_modules/.*

[options]
module.name_mapper='^\/\(.*\)$' -> '<PROJECT_ROOT>/\1'
module.name_mapper='^meteor\/\(.*\):\(.*\)$' -> '<PROJECT_ROOT>/.meteor/local/build/programs/server/packages/\1_\2'
module.name_mapper='^meteor\/\(.*\)$' -> '<PROJECT_ROOT>/.meteor/local/build/programs/server/packages/\1'

在CI中我遇到如下错误:

client/main.jsx:4
  4: import { Meteor } from 'meteor/meteor';
                            ^^^^^^^^^^^^^^^ meteor/meteor. Required module not found

Flow似乎找不到我的模块。重写规则不适用。通过SSH访问Circle CI,我发现<PROJECT_ROOT>/.meteor/local目录不存在。

在CI计算机上运行meteor后,将显示该目录。

问题:如果我运行meteor,Meteor服务器将启动,我的测试将超时。

据我所知,我需要

  1. 调整我的.flowconfig
  2. 找到一种让Meteor无需运行meteor
  3. 即可创建目录的方法
  4. 找到一种在服务器运行后终止meteor进程的方法。

2 个答案:

答案 0 :(得分:1)

我选择了第三个选项:

bbaja42共享script,保存程序的输出,并在达到关键字后终止程序。

根据我的情况,我有两个文件:

ci-tests.sh

#!/bin/sh

# Check if the output directory exits. Flow needs the modules there.
if [ ! -d ".meteor/local/build/programs/server/packages" ]; then
  echo "Meteor build directory does not exist. Starting Meteor."
  # Run Meteor so the output directory is built.
  ./build-and-kill-meteor.sh
else
  echo "Meteor build directory exists"
fi

./node_modules/.bin/flow --json
if [ $? -ne 0 ] ; then
   exit 1
fi

build-and-kill-meteor.sh

#!/bin/bash

OUTPUT=/tmp/meteor-launch.log
PROGRAM=meteor
$PROGRAM > $OUTPUT  &
PID=$!
echo Program is running under pid: $PID

#Every 10 seconds, check requirements
while true; do
   tail -1 $OUTPUT
   grep "App running at: http://localhost" $OUTPUT
   if [ $? -eq 0 ] ; then
      break
   fi
   sleep 10
done

kill $PID || echo "Killing process with pid $PID failed, try manual kill with -9 argument"

答案 1 :(得分:0)

我遇到了同样的问题,并根据OP的答案提出了自己的推导。我在每个 CI版本上运行此脚本,以确保Meteor始终安装我随附的任何新的氛围包。

#!/bin/bash

# Install meteor
if [ -d ~/.meteor ]; then sudo ln -s ~/.meteor/meteor /usr/local/bin/meteor; fi
if [ ! -e $HOME/.meteor/meteor ]; then curl https://install.meteor.com | sh; fi

OUTPUT=/tmp/meteor-launch.log
PROGRAM=meteor
$PROGRAM > $OUTPUT  &
PID=$!
echo Program is running under pid: $PID

# Start meteor to install atmosphere packages
while true; do
   tail -1 $OUTPUT
   grep "Your application is crashing." $OUTPUT
   # Cancel the program once meteor has started
   if [ $? -eq 0 ] ; then
      break
   fi
   sleep 10
done

kill $PID || echo "Killing process with pid $PID failed, try manual kill with -9 argument."