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