@@ -174,49 +174,64 @@ keytoolToAndroidConfig conf = runIdentity $ do
174174 , ("keyPassword", keypass)
175175 ]
176176
177−deployMobile :: MonadObelisk m => String -> [String] -> m ()
177+data PlatformDeployment = Android | IOS
178+ deriving (Show, Eq)
179+
180+renderPlatformDeployment :: PlatformDeployment -> String
181+renderPlatformDeployment = \case
182+ Android -> "android"
183+ IOS -> "ios"
184+
185+deployMobile :: MonadObelisk m => PlatformDeployment -> [String] -> m ()
178186deployMobile platform mobileArgs = withProjectRoot "." $ \root -> do
179187 let srcDir = root </> "src"
180188 exists <- liftIO $ doesDirectoryExist srcDir
181189 unless exists $ failWith "ob test should be run inside of a deploy directory"
182− when (platform == "android") $ do
183− let keystorePath = root </> "android_keystore.jks"
184− keytoolConfPath = root </> "android_keytool_config.json"
185− hasKeystore <- liftIO $ doesFileExist keystorePath
186− when (not hasKeystore) $ do
187− -- TODO log instructions for how to modify the keystore
188− putLog Notice $ "Creating keystore: " <> T.pack keystorePath
189− putLog Notice "Enter a keystore password: "
190− keyStorePassword <- liftIO $ withEcho False getLine
191− putLog Notice "Re-enter the keystore password: "
192− keyStorePassword' <- liftIO $ withEcho False getLine
193− unless (keyStorePassword' == keyStorePassword) $ failWith "passwords do not match"
194− let keyToolConf = KeytoolConfig
195− { _keytoolConfig_keystore = keystorePath
196− , _keytoolConfig_alias = "obelisk"
197− , _keytoolConfig_storepass = keyStorePassword
198− , _keytoolConfig_keypass = keyStorePassword
199− }
200− createKeystore root $ keyToolConf
201− liftIO $ BSL.writeFile keytoolConfPath $ encode keyToolConf
202− checkKeytoolConfExist <- liftIO $ doesFileExist keytoolConfPath
203− unless checkKeytoolConfExist $ failWith "Missing android KeytoolConfig"
204− keytoolConfContents <- liftIO $ BSL.readFile keytoolConfPath
205− liftIO $ putStrLn $ show keytoolConfContents
206− releaseKey <- case eitherDecode keytoolConfContents of
207− Left err -> failWith $ T.pack err
208− Right conf -> do
209− let nvset = toValue @(HM.HashMap Text (NValueNF Identity)) @Identity @(NValueNF Identity) $ keytoolToAndroidConfig conf
210− return $ printNix $ runIdentity nvset
211− result <- nixCmd $ NixCmd_Build $ def
212− & nixBuildConfig_outLink .~ OutLink_None
213− & nixCmdConfig_target .~ Target
190+ nixBuildTarget <- case platform of
191+ Android -> do
192+ let keystorePath = root </> "android_keystore.jks"
193+ keytoolConfPath = root </> "android_keytool_config.json"
194+ hasKeystore <- liftIO $ doesFileExist keystorePath
195+ when (not hasKeystore) $ do
196+ -- TODO log instructions for how to modify the keystore
197+ putLog Notice $ "Creating keystore: " <> T.pack keystorePath
198+ putLog Notice "Enter a keystore password: "
199+ keyStorePassword <- liftIO $ withEcho False getLine
200+ putLog Notice "Re-enter the keystore password: "
201+ keyStorePassword' <- liftIO $ withEcho False getLine
202+ unless (keyStorePassword' == keyStorePassword) $ failWith "passwords do not match"
203+ let keyToolConf = KeytoolConfig
204+ { _keytoolConfig_keystore = keystorePath
205+ , _keytoolConfig_alias = "obelisk"
206+ , _keytoolConfig_storepass = keyStorePassword
207+ , _keytoolConfig_keypass = keyStorePassword
208+ }
209+ createKeystore root $ keyToolConf
210+ liftIO $ BSL.writeFile keytoolConfPath $ encode keyToolConf
211+ checkKeytoolConfExist <- liftIO $ doesFileExist keytoolConfPath
212+ unless checkKeytoolConfExist $ failWith "Missing android KeytoolConfig"
213+ keytoolConfContents <- liftIO $ BSL.readFile keytoolConfPath
214+ liftIO $ putStrLn $ show keytoolConfContents
215+ releaseKey <- case eitherDecode keytoolConfContents of
216+ Left err -> failWith $ T.pack err
217+ Right conf -> do
218+ let nvset = toValue @(HM.HashMap Text (NValueNF Identity)) @Identity @(NValueNF Identity) $ keytoolToAndroidConfig conf
219+ return $ printNix $ runIdentity nvset
220+ return $ Target
214221 { _target_path = Nothing
215222 , _target_attr = Nothing
216− , _target_expr = Just $ "with (import " <> srcDir <> " {}); " <> platform <> ".frontend.override (drv: { releaseKey = (if builtins.isNull drv.releaseKey then {} else drv.releaseKey) // " <> releaseKey <> "; })"
223+ , _target_expr = Just $ "with (import " <> srcDir <> " {}); " <> renderPlatformDeployment platform <> ".frontend.override (drv: { releaseKey = (if builtins.isNull drv.releaseKey then {} else drv.releaseKey) // " <> releaseKey <> "; })"
217224 }
218− putLog Notice $ T.pack $ "Your recently built android apk can be found at the following path: " <> (show result)
219− callProcessAndLogOutput (Notice, Error) $ proc (result </> "bin" </> "deploy") mobileArgs
225+ IOS -> return $ Target
226+ { _target_path = Nothing
227+ , _target_attr = Just "ios.frontend"
228+ , _target_expr = Nothing
229+ }
230+ result <- nixCmd $ NixCmd_Build $ def
231+ & nixBuildConfig_outLink .~ OutLink_None
232+ & nixCmdConfig_target .~ nixBuildTarget
233+ putLog Notice $ T.pack $ "Your recently built android apk can be found at the following path: " <> (show result)
234+ callProcessAndLogOutput (Notice, Error) $ proc (result </> "bin" </> "deploy") mobileArgs
220235 where
221236 withEcho showEcho f = do
222237 prevEcho <- hGetEcho stdin