UNPKG

bytefun

Version:

一个打通了原型设计、UI设计与代码转换、跨平台原生代码开发等的平台

85 lines (77 loc) 3.21 kB
import path from 'path'; import { WorkspaceUtils } from './workspaceUtils'; import * as fs from 'fs'; // 生成nonce用于CSP export function getNonce(): string { let text = ''; const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; for (let i = 0; i < 32; i++) { text += possible.charAt(Math.floor(Math.random() * possible.length)); } return text; } export function getMultiPlatformCodeData() { // 获取当前工作区根目录 const workspaceRoot = WorkspaceUtils.getProjectRootPath(); if (!workspaceRoot) { return; } // 获取根目录下的.bytefun/project.json文件,并读取里面的json数据 const projectJsonPath = path.join(workspaceRoot, '.bytefun', 'project.json'); const projectJsonContent = fs.readFileSync(projectJsonPath, 'utf8'); const projectConfig = JSON.parse(projectJsonContent); // 判断当前目录是否存在output/android/build.gradle文件,如果不存在,那就设置androidIsNull为true // 判断当前目录是否存在output/harmony/build-profile.json5文件,如果不存在,那就设置harmonyIsNull为true let androidIsNull = false let harmonyIsNull = false let backendIsNull = false let industryCode = 11 const androidBuildGradlePath = path.join(workspaceRoot, 'output', 'android', 'build.gradle'); const harmonyBuildProfilePath = path.join(workspaceRoot, 'output', 'harmony', 'build-profile.json5'); const backendPomXmlPath = path.join(workspaceRoot, 'backend', 'pom.xml'); if (!fs.existsSync(path.join(workspaceRoot, 'output'))) { fs.mkdirSync(path.join(workspaceRoot, 'output'), { recursive: true }); } if (!fs.existsSync(androidBuildGradlePath)) { androidIsNull = true; if (!fs.existsSync(path.join(workspaceRoot, 'output', 'android'))) { fs.mkdirSync(path.join(workspaceRoot, 'output', 'android'), { recursive: true }); } } if (!fs.existsSync(harmonyBuildProfilePath)) { harmonyIsNull = true; if (!fs.existsSync(path.join(workspaceRoot, 'output', 'harmony'))) { fs.mkdirSync(path.join(workspaceRoot, 'output', 'harmony'), { recursive: true }); } } if (!fs.existsSync(backendPomXmlPath)) { backendIsNull = true; if (!fs.existsSync(path.join(workspaceRoot, 'backend'))) { fs.mkdirSync(path.join(workspaceRoot, 'backend'), { recursive: true }); } } if (projectConfig.industryCode) { industryCode = projectConfig.industryCode; } const generateCodeVO = { packageName: projectConfig.packageName, versionName: projectConfig.versionName, versionCode: projectConfig.versionCode, projectId: projectConfig.projectID, platformList: [ { platform: 'android', pageList: [], }, { platform: 'harmony', pageList: [], } ], androidIsNull: androidIsNull, harmonyIsNull: harmonyIsNull, backendIsNull: backendIsNull, industryCode: industryCode, } return generateCodeVO; }