var fs = require('fs') // 引入fs模块
var join = require('path').join
const { configPodspec, updatePodfile, updateObjectCFile, updatePush } = require('../init/configPro.js')
var updatefile = require('../injection/updatefile.js')
const { config_git } = require('./git.js')
const { downloadGit } = require('./git.js')
const { applyProjectName } = require('../init/applyProjectName.js')
const os = require('os')
const path = require('path')

const index = () => {
    let rootPath = '/Users/ice/Desktop/work/微微科技/RNComponent/RNSample/Page103'
    let filePath = `${rootPath}/src/pages/product_1.0`
    let routerIndexPath = `${rootPath}/src/router/index.js`

    let appJsonPath = `${filePath}/app.json`
    if (fs.existsSync(filePath) && fs.existsSync(appJsonPath)) {
        let data = fs.readFileSync(appJsonPath)

        let appJson = JSON.parse(data)
        // 获取所有页面路径
        let pagesPath = appJson.pages
        // 获取根页面路径
        var entryPagePath = appJson.entryPagePath

        if (pagesPath != undefined) {
            // 注册页面路由
            updatefile.registerRouterConfig(filePath, pagesPath, routerIndexPath)

            // 如果有配置根页面则使用根页面（entryPagePath），如果没有配置根页面则默认取（pages）第一个配置页面为根页面，如果都没配置则默认 加载xupd默认页

            if (entryPagePath == undefined || entryPagePath.trim() == '') {
                if (pagesPath.length > 0) {
                    entryPagePath = pagesPath[0]
                } else {
                    entryPagePath = 'xupd'
                    console.log('app.json entryPagePath 未配置根视图路由')
                }
            }

            let routerName = entryPagePath.replace(/\//g, '_').replace(/\./g, '_')
            updatefile.changeXcodeAppDelegateLaunchRouterPage(routerName)
        } else {
            console.log(`请配置app.json pages 路由地址为空, 请参照如下配置 "pages": ["Pro/productList/pageA", "Pro/productList/pageB"]`)
        }
    }
}

const PLACEHOLDER_NPM = {
    "XcodeTemplateProject": RegExp("XcodeTemplateProject", 'ig'),
    "XcodeTemplateProject2": RegExp("XcodeTemplateProject2", 'ig'),
}

const test = () => {
    let a = 'XcodeTemplateProject'
    let sss = PLACEHOLDER_NPM[a]
    console.log(sss)
}

module.exports.test = test