From 0f6493e28d438b6b148209679c233b1b4f16d002 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Tue, 22 Mar 2022 18:30:40 +0000 Subject: [PATCH] chore: 1.0.3 ### [1.0.3](https://github.com/expo/config-plugins/compare/@config-plugins/ffmpeg-kit-react-native@1.0.2...@config-plugins/ffmpeg-kit-react-native@1.0.3) (2022-03-22) ### Other chores * git ignore build folders ([#59](https://github.com/expo/config-plugins/issues/59)) ([d6050be](https://github.com/expo/config-plugins/commit/d6050beb2a5c68dc59287c27ec388c2002ec7904)) --- packages/ffmpeg-kit-react-native/CHANGELOG.md | 7 +++ .../build/withAndroidFFMPEGPackage.d.ts | 3 + .../build/withAndroidFFMPEGPackage.js | 54 ++++++++++++++++ .../build/withCocoaPodsImport.d.ts | 5 ++ .../build/withCocoaPodsImport.js | 47 ++++++++++++++ .../build/withFFMPEG.d.ts | 11 ++++ .../build/withFFMPEG.js | 42 +++++++++++++ .../build/withIosDeploymentTarget.d.ts | 8 +++ .../build/withIosDeploymentTarget.js | 61 +++++++++++++++++++ packages/ffmpeg-kit-react-native/package.json | 2 +- 10 files changed, 239 insertions(+), 1 deletion(-) create mode 100644 packages/ffmpeg-kit-react-native/build/withAndroidFFMPEGPackage.d.ts create mode 100644 packages/ffmpeg-kit-react-native/build/withAndroidFFMPEGPackage.js create mode 100644 packages/ffmpeg-kit-react-native/build/withCocoaPodsImport.d.ts create mode 100644 packages/ffmpeg-kit-react-native/build/withCocoaPodsImport.js create mode 100644 packages/ffmpeg-kit-react-native/build/withFFMPEG.d.ts create mode 100644 packages/ffmpeg-kit-react-native/build/withFFMPEG.js create mode 100644 packages/ffmpeg-kit-react-native/build/withIosDeploymentTarget.d.ts create mode 100644 packages/ffmpeg-kit-react-native/build/withIosDeploymentTarget.js diff --git a/packages/ffmpeg-kit-react-native/CHANGELOG.md b/packages/ffmpeg-kit-react-native/CHANGELOG.md index 81dcd906..dc87a925 100644 --- a/packages/ffmpeg-kit-react-native/CHANGELOG.md +++ b/packages/ffmpeg-kit-react-native/CHANGELOG.md @@ -1,3 +1,10 @@ +### @config-plugins/ffmpeg-kit-react-native [1.0.3](https://github.com/expo/config-plugins/compare/@config-plugins/ffmpeg-kit-react-native@1.0.2...@config-plugins/ffmpeg-kit-react-native@1.0.3) (2022-03-22) + + +### Other chores + +* git ignore build folders ([#59](https://github.com/expo/config-plugins/issues/59)) ([d6050be](https://github.com/expo/config-plugins/commit/d6050beb2a5c68dc59287c27ec388c2002ec7904)) + ### @config-plugins/ffmpeg-kit-react-native [1.0.2](https://github.com/expo/config-plugins/compare/@config-plugins/ffmpeg-kit-react-native@1.0.1...@config-plugins/ffmpeg-kit-react-native@1.0.2) (2022-03-22) diff --git a/packages/ffmpeg-kit-react-native/build/withAndroidFFMPEGPackage.d.ts b/packages/ffmpeg-kit-react-native/build/withAndroidFFMPEGPackage.d.ts new file mode 100644 index 00000000..df108e47 --- /dev/null +++ b/packages/ffmpeg-kit-react-native/build/withAndroidFFMPEGPackage.d.ts @@ -0,0 +1,3 @@ +import { ConfigPlugin } from "@expo/config-plugins"; +export declare const withAndroidFFMPEGPackage: ConfigPlugin; +export declare function addPackageName(src: string, packageName?: string): string; diff --git a/packages/ffmpeg-kit-react-native/build/withAndroidFFMPEGPackage.js b/packages/ffmpeg-kit-react-native/build/withAndroidFFMPEGPackage.js new file mode 100644 index 00000000..700b1226 --- /dev/null +++ b/packages/ffmpeg-kit-react-native/build/withAndroidFFMPEGPackage.js @@ -0,0 +1,54 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.addPackageName = exports.withAndroidFFMPEGPackage = void 0; +const config_plugins_1 = require("@expo/config-plugins"); +const generateCode_1 = require("@expo/config-plugins/build/utils/generateCode"); +const withAndroidFFMPEGPackage = (config, packageName) => { + return config_plugins_1.withProjectBuildGradle(config, (config) => { + if (config.modResults.language === "groovy") { + config.modResults.contents = addPackageName(config.modResults.contents, packageName); + } + else { + throw new Error("Cannot add camera maven gradle because the build.gradle is not groovy"); + } + return config; + }); +}; +exports.withAndroidFFMPEGPackage = withAndroidFFMPEGPackage; +function addPackageName(src, packageName) { + const tag = "ffmpeg-kit-react-native-package"; + const gradleMaven = packageName + ? `ext { ffmpegKitPackage = "${packageName}" }` + : ""; + return appendContents({ + tag, + src, + newSrc: gradleMaven, + comment: "//", + }).contents; +} +exports.addPackageName = addPackageName; +// Fork of config-plugins mergeContents, but appends the contents to the end of the file. +function appendContents({ src, newSrc, tag, comment, }) { + const header = generateCode_1.createGeneratedHeaderComment(newSrc, tag, comment); + if (!src.includes(header)) { + // Ensure the old generated contents are removed. + let sanitizedTarget = generateCode_1.removeGeneratedContents(src, tag); + if (sanitizedTarget) + sanitizedTarget += "\n"; + const contentsToAdd = [ + // @something + header, + // contents + newSrc, + // @end + `${comment} @generated end ${tag}`, + ].join("\n"); + return { + contents: (sanitizedTarget !== null && sanitizedTarget !== void 0 ? sanitizedTarget : src) + contentsToAdd, + didMerge: true, + didClear: !!sanitizedTarget, + }; + } + return { contents: src, didClear: false, didMerge: false }; +} diff --git a/packages/ffmpeg-kit-react-native/build/withCocoaPodsImport.d.ts b/packages/ffmpeg-kit-react-native/build/withCocoaPodsImport.d.ts new file mode 100644 index 00000000..aa277b0d --- /dev/null +++ b/packages/ffmpeg-kit-react-native/build/withCocoaPodsImport.d.ts @@ -0,0 +1,5 @@ +import { ConfigPlugin } from "@expo/config-plugins"; +export declare const withPodfilePropertiesPackage: ConfigPlugin; +/** Dangerously adds the custom import to the CocoaPods. */ +export declare const withCocoaPodsImport: ConfigPlugin; +export declare function addCocoaPodsImport(src: string): string; diff --git a/packages/ffmpeg-kit-react-native/build/withCocoaPodsImport.js b/packages/ffmpeg-kit-react-native/build/withCocoaPodsImport.js new file mode 100644 index 00000000..26963a20 --- /dev/null +++ b/packages/ffmpeg-kit-react-native/build/withCocoaPodsImport.js @@ -0,0 +1,47 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.addCocoaPodsImport = exports.withCocoaPodsImport = exports.withPodfilePropertiesPackage = void 0; +const config_plugins_1 = require("@expo/config-plugins"); +const ios_plugins_1 = require("@expo/config-plugins/build/plugins/ios-plugins"); +const generateCode_1 = require("@expo/config-plugins/build/utils/generateCode"); +const fs_1 = require("fs"); +const path_1 = __importDefault(require("path")); +const withPodfilePropertiesPackage = (config, packageName) => { + return ios_plugins_1.withPodfileProperties(config, (config) => { + // @ts-ignore: wrong type + config.modResults["ffmpeg-kit-react-native.subspecs"] = [ + packageName, + ].filter(Boolean); + return config; + }); +}; +exports.withPodfilePropertiesPackage = withPodfilePropertiesPackage; +/** Dangerously adds the custom import to the CocoaPods. */ +const withCocoaPodsImport = (c) => { + return config_plugins_1.withDangerousMod(c, [ + "ios", + // eslint-disable-next-line @typescript-eslint/explicit-function-return-type + async (config) => { + const file = path_1.default.join(config.modRequest.platformProjectRoot, "Podfile"); + const contents = await fs_1.promises.readFile(file, "utf8"); + await fs_1.promises.writeFile(file, addCocoaPodsImport(contents), "utf-8"); + return config; + }, + ]); +}; +exports.withCocoaPodsImport = withCocoaPodsImport; +function addCocoaPodsImport(src) { + return generateCode_1.mergeContents({ + tag: `ffmpeg-kit-react-native-import`, + src, + newSrc: ` pod 'ffmpeg-kit-react-native', :subspecs => podfile_properties['ffmpeg-kit-react-native.subspecs'] || [], :podspec => File.join(File.dirname(\`node --print "require.resolve('ffmpeg-kit-react-native/package.json')"\`), "ffmpeg-kit-react-native.podspec")`, + anchor: /use_native_modules/, + // We can't go after the use_native_modules block because it might have parameters, causing it to be multi-line (see react-native template). + offset: 0, + comment: "#", + }).contents; +} +exports.addCocoaPodsImport = addCocoaPodsImport; diff --git a/packages/ffmpeg-kit-react-native/build/withFFMPEG.d.ts b/packages/ffmpeg-kit-react-native/build/withFFMPEG.d.ts new file mode 100644 index 00000000..eb939927 --- /dev/null +++ b/packages/ffmpeg-kit-react-native/build/withFFMPEG.d.ts @@ -0,0 +1,11 @@ +declare type Package = "min" | "min-gpl" | "https" | "https-gpl" | "audio" | "video" | "full" | "full-gpl"; +export declare type Props = { + package?: Package; + ios?: { + package?: Package; + }; + android?: { + package?: Package; + }; +}; +export {}; diff --git a/packages/ffmpeg-kit-react-native/build/withFFMPEG.js b/packages/ffmpeg-kit-react-native/build/withFFMPEG.js new file mode 100644 index 00000000..c8e6f3dc --- /dev/null +++ b/packages/ffmpeg-kit-react-native/build/withFFMPEG.js @@ -0,0 +1,42 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const config_plugins_1 = require("@expo/config-plugins"); +const withAndroidFFMPEGPackage_1 = require("./withAndroidFFMPEGPackage"); +const withCocoaPodsImport_1 = require("./withCocoaPodsImport"); +const withIosDeploymentTarget_1 = require("./withIosDeploymentTarget"); +let pkg = { + name: "ffmpeg-kit-react-native", +}; +try { + pkg = require("ffmpeg-kit-react-native/package.json"); +} +catch (_a) { + // empty catch block +} +const withFFMPEG = (config, _props) => { + var _a, _b; + const props = _props || {}; + const iosPackage = ((_a = props.ios) === null || _a === void 0 ? void 0 : _a.package) || props.package; + const androidPackage = ((_b = props.android) === null || _b === void 0 ? void 0 : _b.package) || props.package; + return config_plugins_1.withPlugins(config, [ + // iOS + [withCocoaPodsImport_1.withPodfilePropertiesPackage, iosPackage], + [ + withIosDeploymentTarget_1.withIosDeploymentTarget, + // https://github.com/tanersener/ffmpeg-kit/tree/main/react-native#211-package-names + { deploymentTarget: "12.1" }, + ], + withCocoaPodsImport_1.withCocoaPodsImport, + // Android + // Set min SDK Version to 24. + [ + config_plugins_1.AndroidConfig.Version.withBuildScriptExtMinimumVersion, + { + name: "minSdkVersion", + minVersion: 24, + }, + ], + [withAndroidFFMPEGPackage_1.withAndroidFFMPEGPackage, androidPackage], + ]); +}; +module.exports = config_plugins_1.createRunOncePlugin(withFFMPEG, pkg.name, pkg.version); diff --git a/packages/ffmpeg-kit-react-native/build/withIosDeploymentTarget.d.ts b/packages/ffmpeg-kit-react-native/build/withIosDeploymentTarget.d.ts new file mode 100644 index 00000000..372ee579 --- /dev/null +++ b/packages/ffmpeg-kit-react-native/build/withIosDeploymentTarget.d.ts @@ -0,0 +1,8 @@ +import { ConfigPlugin, XcodeProject } from "@expo/config-plugins"; +declare type IosDeploymentTargetConfigPlugin = ConfigPlugin<{ + deploymentTarget: string; +}>; +export declare const withIosDeploymentTarget: IosDeploymentTargetConfigPlugin; +export declare function updateDeploymentTargetPodfile(contents: string, deploymentTarget: string): string; +export declare function updateDeploymentTargetXcodeProject(project: XcodeProject, deploymentTarget: string): XcodeProject; +export {}; diff --git a/packages/ffmpeg-kit-react-native/build/withIosDeploymentTarget.js b/packages/ffmpeg-kit-react-native/build/withIosDeploymentTarget.js new file mode 100644 index 00000000..e79b3641 --- /dev/null +++ b/packages/ffmpeg-kit-react-native/build/withIosDeploymentTarget.js @@ -0,0 +1,61 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.updateDeploymentTargetXcodeProject = exports.updateDeploymentTargetPodfile = exports.withIosDeploymentTarget = void 0; +// Copied from https://github.com/expo/expo-cli/blob/main/packages/install-expo-modules/src/plugins/ios/withIosDeploymentTarget.ts +const config_plugins_1 = require("@expo/config-plugins"); +const fs_1 = __importDefault(require("fs")); +const path_1 = __importDefault(require("path")); +const semver_1 = __importDefault(require("semver")); +const withIosDeploymentTarget = (config, props) => { + config = withIosDeploymentTargetPodfile(config, props); + config = withIosDeploymentTargetXcodeProject(config, props); + return config; +}; +exports.withIosDeploymentTarget = withIosDeploymentTarget; +const withIosDeploymentTargetPodfile = (config, props) => { + return config_plugins_1.withDangerousMod(config, [ + "ios", + async (config) => { + const podfile = path_1.default.join(config.modRequest.platformProjectRoot, "Podfile"); + let contents = await fs_1.default.promises.readFile(podfile, "utf8"); + contents = updateDeploymentTargetPodfile(contents, props.deploymentTarget); + await fs_1.default.promises.writeFile(podfile, contents); + return config; + }, + ]); +}; +function updateDeploymentTargetPodfile(contents, deploymentTarget) { + return contents.replace(/^(\s*platform :ios, ['"])([\d.]+)(['"])/gm, (match, prefix, version, suffix) => { + if (semver_1.default.lt(toSemVer(version), toSemVer(deploymentTarget))) { + return `${prefix}${deploymentTarget}${suffix}`; + } + return match; + }); +} +exports.updateDeploymentTargetPodfile = updateDeploymentTargetPodfile; +const withIosDeploymentTargetXcodeProject = (config, props) => { + return config_plugins_1.withXcodeProject(config, (config) => { + config.modResults = updateDeploymentTargetXcodeProject(config.modResults, props.deploymentTarget); + return config; + }); +}; +function updateDeploymentTargetXcodeProject(project, deploymentTarget) { + const configurations = project.pbxXCBuildConfigurationSection(); + // @ts-ignore + for (const { buildSettings } of Object.values(configurations !== null && configurations !== void 0 ? configurations : {})) { + const currDeploymentTarget = buildSettings === null || buildSettings === void 0 ? void 0 : buildSettings.IPHONEOS_DEPLOYMENT_TARGET; + if (currDeploymentTarget && + semver_1.default.lt(toSemVer(currDeploymentTarget), toSemVer(deploymentTarget))) { + buildSettings.IPHONEOS_DEPLOYMENT_TARGET = deploymentTarget; + } + } + return project; +} +exports.updateDeploymentTargetXcodeProject = updateDeploymentTargetXcodeProject; +function toSemVer(version) { + var _a; + return (_a = semver_1.default.coerce(version)) !== null && _a !== void 0 ? _a : new semver_1.default.SemVer("0.0.0"); +} diff --git a/packages/ffmpeg-kit-react-native/package.json b/packages/ffmpeg-kit-react-native/package.json index c77c2763..85794017 100644 --- a/packages/ffmpeg-kit-react-native/package.json +++ b/packages/ffmpeg-kit-react-native/package.json @@ -1,6 +1,6 @@ { "name": "@config-plugins/ffmpeg-kit-react-native", - "version": "1.0.2", + "version": "1.0.3", "description": "Config plugin to auto configure FFMPEG on prebuild", "main": "build/withFFMPEG.js", "types": "build/withFFMPEG.d.ts",