about summary refs log tree commit diff
path: root/plugins/starterPackAppClipExtension/withFiles.js
blob: ad99f5ae41a38a7a087bbe2ad46f240d7e543e3e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const {withXcodeProject} = require('@expo/config-plugins')
const path = require('path')
const fs = require('fs')

const FILES = ['AppDelegate.swift', 'ViewController.swift']

const withFiles = (config, {targetName}) => {
  // eslint-disable-next-line no-shadow
  return withXcodeProject(config, config => {
    const basePath = path.join(
      config.modRequest.projectRoot,
      'modules',
      targetName,
    )

    for (const file of FILES) {
      const sourcePath = path.join(basePath, file)
      const targetPath = path.join(
        config.modRequest.platformProjectRoot,
        targetName,
        file,
      )

      fs.mkdirSync(path.dirname(targetPath), {recursive: true})
      fs.copyFileSync(sourcePath, targetPath)
    }

    const imagesBasePath = path.join(basePath, 'Images.xcassets')
    const imagesTargetPath = path.join(
      config.modRequest.platformProjectRoot,
      targetName,
      'Images.xcassets',
    )
    fs.cpSync(imagesBasePath, imagesTargetPath, {recursive: true})

    return config
  })
}

module.exports = {withFiles}